From patchwork Thu Oct 21 12:23:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nadav Amit X-Patchwork-Id: 12576371 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E240EC433F5 for ; Thu, 21 Oct 2021 19:54:40 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 93DEC611C7 for ; Thu, 21 Oct 2021 19:54:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 93DEC611C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 2BFB06B006C; Thu, 21 Oct 2021 15:54:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 249176B0071; Thu, 21 Oct 2021 15:54:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C07B900002; Thu, 21 Oct 2021 15:54:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id EA6266B006C for ; Thu, 21 Oct 2021 15:54:39 -0400 (EDT) Received: from smtpin32.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A3CFC30165 for ; Thu, 21 Oct 2021 19:54:39 +0000 (UTC) X-FDA: 78721497078.32.520648B Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) by imf18.hostedemail.com (Postfix) with ESMTP id 1CC644002096 for ; Thu, 21 Oct 2021 19:54:34 +0000 (UTC) Received: by mail-pf1-f177.google.com with SMTP id t184so1648749pfd.0 for ; Thu, 21 Oct 2021 12:54:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PcS8bbhskcuqX8GVfAbpnHbwNDrvmLq+rqAWrOVM9lI=; b=L+FcixtzsXJDLtnIg36G3Irwlyfvc8bA787ySj/Q05tZq3xT8aUK5zeUAtvD7MtTg9 jsl1++y+VopTt4nSQhEah8GfiD2O8vubjlWK+L4xpIL7Vb1lxXYSsL21m3Ieg6Jz15HP NvFRmwltvdZZUc/JD1iyRbUeIK2BYXQAmHB9fOuQXw5tSDCKNEuOx2UUcmLRkn5QoAck TYW5zrHi/uC+lkKxTpA4phtuGp+9tqkkMMADgc+VHkwJyrYxHSGoLbBjR4Q2OgjJsmOA 73mcv78pVzn8R7CrkOXIsSug6zNj8YBwPLFxqumdEzkbWTwNnL0Z9yP0K4KAdtU13cGA 2Nlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=PcS8bbhskcuqX8GVfAbpnHbwNDrvmLq+rqAWrOVM9lI=; b=l8Rc7Y+i4rouzYVddlesvWrmn6A/tMxSEbBIj0UUHfdYxMJgsw9odB53f1uo7MMD5c 8cdVsrkzaJQCKpE5dfpbF6Gkq9GXAqT+67hNJMT++X4QXsIuKHzVCUotJ8kbtfzZT+EX XPAbnG28wqsgsNgJpyJo1CDfoRbgcz2aujj4M0gfkZCXuVoRk7Za6jn7JrB/Qzi0sgKh OyXJH4RGb4Vm7Y/CCPEtQRXiWB61E726dWlU/4q1mIJf5GsMvHx1a323y9z8iqBuFWQ1 7fnFTFDB4c/ntKOufFAGIht+rOc6MANtRM233w4dP/2sSLsh+hxNTkf+Z2N48UMCbWE2 5yCg== X-Gm-Message-State: AOAM533OAtwJMxZJQzCWcQBAKVd5vo87vAfMgFn0G7v+YKfWzdxBXSJh WRIj+zaGuBtztmYwj8tdHFioIEg/6lw= X-Google-Smtp-Source: ABdhPJz3bY2ItMBqVLKJfjL1FqVvimBucwFEt+xIpcw3N5x3a824VsfnVBK60Y/ZSrYY//In0exxOQ== X-Received: by 2002:a63:2484:: with SMTP id k126mr5905030pgk.297.1634846077549; Thu, 21 Oct 2021 12:54:37 -0700 (PDT) Received: from sc2-haas01-esx0118.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id v8sm6883407pjd.7.2021.10.21.12.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Oct 2021 12:54:37 -0700 (PDT) From: Nadav Amit X-Google-Original-From: Nadav Amit To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Nadav Amit , Andrea Arcangeli , Andrew Cooper , Andrew Morton , Andy Lutomirski , Dave Hansen , Peter Zijlstra , Thomas Gleixner , Will Deacon , Yu Zhao , Nick Piggin , x86@kernel.org Subject: [PATCH] mm: use correct VMA flags when freeing page-tables Date: Thu, 21 Oct 2021 05:23:22 -0700 Message-Id: <20211021122322.592822-1-namit@vmware.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-Stat-Signature: ipqtr5wmfx4i7pi9j8t56zu3pz9y1jtu X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 1CC644002096 Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=L+Fcixtz; dmarc=pass (policy=none) header.from=gmail.com; spf=none (imf18.hostedemail.com: domain of mail-pf1-f177.google.com has no SPF policy when checking 209.85.210.177) smtp.helo=mail-pf1-f177.google.com X-HE-Tag: 1634846074-323609 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Nadav Amit Consistent use of the mmu_gather interface requires a call to tlb_start_vma() and tlb_end_vma() for each VMA. free_pgtables() does not follow this pattern. Certain architectures need tlb_start_vma() to be called in order for tlb_update_vma_flags() to update the VMA flags (tlb->vma_exec and tlb->vma_huge), which are later used for the proper TLB flush to be issued. Since tlb_start_vma() is not called, this can lead to the wrong VMA flags being used when the flush is performed. Specifically, the munmap syscall would call unmap_region(), which unmaps the VMAs and then frees the page-tables. A flush is needed after the page-tables are removed to prevent page-walk caches from holding stale entries, but this flush would use the flags of the VMA flags of the last VMA that was flushed. This does not appear to be right. Use tlb_start_vma() and tlb_end_vma() to prevent this from happening. This might lead to unnecessary calls to flush_cache_range() on certain arch's. If needed, a new flag can be added to mmu_gather to indicate that the flush is not needed. Cc: Andrea Arcangeli Cc: Andrew Cooper Cc: Andrew Morton Cc: Andy Lutomirski Cc: Dave Hansen Cc: Peter Zijlstra Cc: Thomas Gleixner Cc: Will Deacon Cc: Yu Zhao Cc: Nick Piggin Cc: x86@kernel.org Signed-off-by: Nadav Amit --- mm/memory.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index 12a7b2094434..056fbfdd3c1f 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -412,6 +412,8 @@ void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *vma, unlink_anon_vmas(vma); unlink_file_vma(vma); + tlb_start_vma(tlb, vma); + if (is_vm_hugetlb_page(vma)) { hugetlb_free_pgd_range(tlb, addr, vma->vm_end, floor, next ? next->vm_start : ceiling); @@ -429,6 +431,8 @@ void free_pgtables(struct mmu_gather *tlb, struct vm_area_struct *vma, free_pgd_range(tlb, addr, vma->vm_end, floor, next ? next->vm_start : ceiling); } + + tlb_end_vma(tlb, vma); vma = next; } }