From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E21EEC433DB for ; Wed, 27 Jan 2021 23:54:10 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 85E5C64DD6 for ; Wed, 27 Jan 2021 23:54:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 85E5C64DD6 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0E6986B006C; Wed, 27 Jan 2021 18:54:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 070FC6B006E; Wed, 27 Jan 2021 18:54:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E54376B0070; Wed, 27 Jan 2021 18:54:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0093.hostedemail.com [216.40.44.93]) by kanga.kvack.org (Postfix) with ESMTP id C54656B006C for ; Wed, 27 Jan 2021 18:54:09 -0500 (EST) Received: from smtpin02.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 93858180AD807 for ; Wed, 27 Jan 2021 23:54:09 +0000 (UTC) X-FDA: 77753211018.02.fog07_3b05dad2759b Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin02.hostedemail.com (Postfix) with ESMTP id 7009B10097AA1 for ; Wed, 27 Jan 2021 23:54:09 +0000 (UTC) X-HE-Tag: fog07_3b05dad2759b X-Filterd-Recvd-Size: 4296 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by imf11.hostedemail.com (Postfix) with ESMTP for ; Wed, 27 Jan 2021 23:54:08 +0000 (UTC) Received: by mail.kernel.org (Postfix) with ESMTPSA id 7A0B364DD4; Wed, 27 Jan 2021 23:54:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1611791648; bh=jmM4gVRGgilnA81ZMlj6tXbIsH9e4Kl+pn5Cw5j3RJk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uaRQ4V3KQ4lw1arqtiyzsTsE0CP5+RywkTTNZe0WPosVGZfZ0/cEkeBgtr1UpK29v qg0jydqu3jnaKy5PgKPgvhgUfncloK74x1uQ/o11xaRUqNqH5ITw15vlbKvx7qbGxs aAx43nvq6S8M/BMNsdZa8asIm8l2U0RkV6WriyiymeZ4IiYsIiNVK02CFksG8U25Bp TFao6SLyDNw2xyg6xbdA8GQVRbuYLtetkGI08lDQwM9zFsfb3ixnjPnI13SoLb67NN 4FhlrVv87lvhJs/hsZX6kEtvarip626Mkn1ue2N1y9XKpiggZDueUNiRVkbh1MEbYH YiNExzz+oKxoQ== From: Will Deacon To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, linux-mm@kvack.org, Will Deacon , Yu Zhao , Minchan Kim , Peter Zijlstra , Thomas Gleixner , Linus Torvalds , Vlastimil Babka , Mohamed Alzayat , "Aneesh Kumar K.V" , Nadav Amit , Andrea Arcangeli Subject: [PATCH v3 1/6] mm: proc: Invalidate TLB after clearing soft-dirty page state Date: Wed, 27 Jan 2021 23:53:42 +0000 Message-Id: <20210127235347.1402-2-will@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20210127235347.1402-1-will@kernel.org> References: <20210127235347.1402-1-will@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: Since commit 0758cd830494 ("asm-generic/tlb: avoid potential double flush"), TLB invalidation is elided in tlb_finish_mmu() if no entries were batched via the tlb_remove_*() functions. Consequently, the page-table modifications performed by clear_refs_write() in response to a write to /proc//clear_refs do not perform TLB invalidation. Although this is fine when simply aging the ptes, in the case of clearing the "soft-dirty" state we can end up with entries where pte_write() is false, yet a writable mapping remains in the TLB. Fix this by avoiding the mmu_gather API altogether: managing both the 'tlb_flush_pending' flag on the 'mm_struct' and explicit TLB invalidation for the sort-dirty path, much like mprotect() does already. Fixes: 0758cd830494 ("asm-generic/tlb: avoid potential double flush=E2=80= =9D) Acked-by: Peter Zijlstra (Intel) Reviewed-by: Yu Zhao Signed-off-by: Will Deacon --- fs/proc/task_mmu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 602e3a52884d..3cec6fbef725 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -1210,7 +1210,6 @@ static ssize_t clear_refs_write(struct file *file, = const char __user *buf, struct mm_struct *mm; struct vm_area_struct *vma; enum clear_refs_types type; - struct mmu_gather tlb; int itype; int rv; =20 @@ -1249,7 +1248,6 @@ static ssize_t clear_refs_write(struct file *file, = const char __user *buf, goto out_unlock; } =20 - tlb_gather_mmu(&tlb, mm, 0, -1); if (type =3D=3D CLEAR_REFS_SOFT_DIRTY) { for (vma =3D mm->mmap; vma; vma =3D vma->vm_next) { if (!(vma->vm_flags & VM_SOFTDIRTY)) @@ -1258,15 +1256,18 @@ static ssize_t clear_refs_write(struct file *file= , const char __user *buf, vma_set_page_prot(vma); } =20 + inc_tlb_flush_pending(mm); mmu_notifier_range_init(&range, MMU_NOTIFY_SOFT_DIRTY, 0, NULL, mm, 0, -1UL); mmu_notifier_invalidate_range_start(&range); } walk_page_range(mm, 0, mm->highest_vm_end, &clear_refs_walk_ops, &cp); - if (type =3D=3D CLEAR_REFS_SOFT_DIRTY) + if (type =3D=3D CLEAR_REFS_SOFT_DIRTY) { mmu_notifier_invalidate_range_end(&range); - tlb_finish_mmu(&tlb, 0, -1); + flush_tlb_mm(mm); + dec_tlb_flush_pending(mm); + } out_unlock: mmap_write_unlock(mm); out_mm: --=20 2.30.0.365.g02bc693789-goog