From nobody Fri Oct 31 17:53:14 2025 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 106F222CBF4; Fri, 30 May 2025 14:05:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.140.110.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748613912; cv=none; b=Ssb0FgrK05F10MV5Hi73oRhyV3qrsjamdGrTH4I6mkHm06xYdswcp2qYXr3G7V8cWeNc/TLER7qJUU5RIlu2t5x9gxmV1xJu7481xKbhrSCWfxC1FGyfXGsfBeFACwQtbCTPVke1SQ4PSAXwGOCA6Paw1nmabfS1H4hEfNsRzSU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748613912; c=relaxed/simple; bh=ZBQiaYaMbLwJcZqn/mkzd8jTs4bL3ZRi0KrTn2K5OF8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WivFanahqfZnGMllS18Smfz5hp4NSAnFBMKud4dbbL6v9xXDKKt/eZMlpRkyhVkEB7USfruPIJKaH3oXbC90UvrHrcXCXOJq3f8UK+vBrklOuLfeud2lj99Me4oVvn46QSbmCisOXR4uvuisRtURXVEG/z7jvaTycev5MJAaIIc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com; spf=pass smtp.mailfrom=arm.com; arc=none smtp.client-ip=217.140.110.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id C1E0E16F8; Fri, 30 May 2025 07:04:53 -0700 (PDT) Received: from e125769.cambridge.arm.com (e125769.cambridge.arm.com [10.1.196.27]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 3973B3F673; Fri, 30 May 2025 07:05:05 -0700 (PDT) From: Ryan Roberts To: Catalin Marinas , Will Deacon , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , "David S. Miller" , Andreas Larsson , Juergen Gross , Ajay Kaher , Alexey Makhalov , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Boris Ostrovsky , "Aneesh Kumar K.V" , Andrew Morton , Peter Zijlstra , Arnd Bergmann , David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Alexei Starovoitov , Andrey Ryabinin Cc: Ryan Roberts , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org, virtualization@lists.linux.dev, xen-devel@lists.xenproject.org, linux-mm@kvack.org Subject: [RFC PATCH v1 1/6] fs/proc/task_mmu: Fix pte update and tlb maintenance ordering in pagemap_scan_pmd_entry() Date: Fri, 30 May 2025 15:04:39 +0100 Message-ID: <20250530140446.2387131-2-ryan.roberts@arm.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250530140446.2387131-1-ryan.roberts@arm.com> References: <20250530140446.2387131-1-ryan.roberts@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" pagemap_scan_pmd_entry() was previously modifying ptes while in lazy mmu mode, then performing tlb maintenance for the modified ptes, then leaving lazy mmu mode. But any pte modifications during lazy mmu mode may be deferred until arch_leave_lazy_mmu_mode(), inverting the required ordering between pte modificaiton and tlb maintenance. Let's fix that by leaving mmu mode, forcing all the pte updates to be actioned, before doing the tlb maintenance. This is a theorectical bug discovered during code review. Fixes: 52526ca7fdb9 ("fs/proc/task_mmu: implement IOCTL to get and optional= ly clear info about PTEs") Signed-off-by: Ryan Roberts --- fs/proc/task_mmu.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 994cde10e3f4..361f3ffd9a0c 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -2557,10 +2557,9 @@ static int pagemap_scan_pmd_entry(pmd_t *pmd, unsign= ed long start, } =20 flush_and_return: + arch_leave_lazy_mmu_mode(); if (flush_end) flush_tlb_range(vma, start, addr); - - arch_leave_lazy_mmu_mode(); pte_unmap_unlock(start_pte, ptl); =20 cond_resched(); --=20 2.43.0