From: Kevin Brodsky <kevin.brodsky@arm.com>
To: linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org,
Kevin Brodsky <kevin.brodsky@arm.com>,
Alexander Gordeev <agordeev@linux.ibm.com>,
Andreas Larsson <andreas@gaisler.com>,
Andrew Morton <akpm@linux-foundation.org>,
Boris Ostrovsky <boris.ostrovsky@oracle.com>,
Borislav Petkov <bp@alien8.de>,
Catalin Marinas <catalin.marinas@arm.com>,
Christophe Leroy <christophe.leroy@csgroup.eu>,
Dave Hansen <dave.hansen@linux.intel.com>,
David Hildenbrand <david@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
"H. Peter Anvin" <hpa@zytor.com>, Ingo Molnar <mingo@redhat.com>,
Jann Horn <jannh@google.com>, Juergen Gross <jgross@suse.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
Lorenzo Stoakes <lorenzo.stoakes@oracle.com>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Michal Hocko <mhocko@suse.com>, Mike Rapoport <rppt@kernel.org>,
Nicholas Piggin <npiggin@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Ryan Roberts <ryan.roberts@arm.com>,
Suren Baghdasaryan <surenb@google.com>,
Thomas Gleixner <tglx@linutronix.de>,
Vlastimil Babka <vbabka@suse.cz>, Will Deacon <will@kernel.org>,
Yeoreum Yun <yeoreum.yun@arm.com>,
linux-arm-kernel@lists.infradead.org,
linuxppc-dev@lists.ozlabs.org, sparclinux@vger.kernel.org,
xen-devel@lists.xenproject.org
Subject: [PATCH v2 0/7] Nesting support for lazy MMU mode
Date: Mon, 8 Sep 2025 08:39:24 +0100 [thread overview]
Message-ID: <20250908073931.4159362-1-kevin.brodsky@arm.com> (raw)
When the lazy MMU mode was introduced eons ago, it wasn't made clear
whether such a sequence was legal:
arch_enter_lazy_mmu_mode()
...
arch_enter_lazy_mmu_mode()
...
arch_leave_lazy_mmu_mode()
...
arch_leave_lazy_mmu_mode()
It seems fair to say that nested calls to
arch_{enter,leave}_lazy_mmu_mode() were not expected, and most
architectures never explicitly supported it.
Ryan Roberts' series from March [1] attempted to prevent nesting from
ever occurring, and mostly succeeded. Unfortunately, a corner case
(DEBUG_PAGEALLOC) may still cause nesting to occur on arm64. Ryan
proposed [2] to address that corner case at the generic level but this
approach received pushback; [3] then attempted to solve the issue on
arm64 only, but it was deemed too fragile.
It feels generally fragile to rely on lazy_mmu sections not to nest,
because callers of various standard mm functions do not know if the
function uses lazy_mmu itself. This series therefore performs a U-turn
and adds support for nested lazy_mmu sections, on all architectures.
The main change enabling nesting is patch 2, following the approach
suggested by Catalin Marinas [4]: have enter() return some state and
the matching leave() take that state. In this series, the state is only
used to handle nesting, but it could be used for other purposes such as
restoring context modified by enter(); the proposed kpkeys framework
would be an immediate user [5].
Patch overview:
* Patch 1: general cleanup - not directly related, but avoids any doubt
regarding the expected behaviour of arch_flush_lazy_mmu_mode() outside
x86
* Patch 2: main API change, no functional change
* Patch 3-6: nesting support for all architectures that support lazy_mmu
* Patch 7: clarification that nesting is supported in the documentation
Patch 4-6 are technically not required at this stage since nesting is
only observed on arm64, but they ensure future correctness in case
nesting is (re)introduced in generic paths. For instance, it could be
beneficial in some configurations to enter lazy_mmu set_ptes() once
again.
This series has been tested by running the mm kselfetsts on arm64 with
DEBUG_PAGEALLOC and KFENCE. It was also build-tested on other
architectures (with and without XEN_PV on x86).
- Kevin
[1] https://lore.kernel.org/all/20250303141542.3371656-1-ryan.roberts@arm.com/
[2] https://lore.kernel.org/all/20250530140446.2387131-1-ryan.roberts@arm.com/
[3] https://lore.kernel.org/all/20250606135654.178300-1-ryan.roberts@arm.com/
[4] https://lore.kernel.org/all/aEhKSq0zVaUJkomX@arm.com/
[5] https://lore.kernel.org/linux-hardening/20250815085512.2182322-19-kevin.brodsky@arm.com/
---
Changelog
v1..v2:
- Rebased on mm-unstable.
- Patch 2: handled new calls to enter()/leave(), clarified how the "flush"
pattern (leave() followed by enter()) is handled.
- Patch 5,6: removed unnecessary local variable [Alexander Gordeev's
suggestion].
- Added Mike Rapoport's Acked-by.
v1: https://lore.kernel.org/all/20250904125736.3918646-1-kevin.brodsky@arm.com/
---
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Andreas Larsson <andreas@gaisler.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Boris Ostrovsky <boris.ostrovsky@oracle.com>
Cc: Borislav Petkov <bp@alien8.de>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Dave Hansen <dave.hansen@linux.intel.com>
Cc: David Hildenbrand <david@redhat.com>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jann Horn <jannh@google.com>
Cc: Juergen Gross <jgross@suse.com>
Cc: "Liam R. Howlett" <Liam.Howlett@oracle.com>
Cc: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Will Deacon <will@kernel.org>
Cc: Yeoreum Yun <yeoreum.yun@arm.com>
Cc: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org
Cc: linuxppc-dev@lists.ozlabs.org
Cc: sparclinux@vger.kernel.org
Cc: xen-devel@lists.xenproject.org
---
Kevin Brodsky (7):
mm: remove arch_flush_lazy_mmu_mode()
mm: introduce local state for lazy_mmu sections
arm64: mm: fully support nested lazy_mmu sections
x86/xen: support nested lazy_mmu sections (again)
powerpc/mm: support nested lazy_mmu sections
sparc/mm: support nested lazy_mmu sections
mm: update lazy_mmu documentation
arch/arm64/include/asm/pgtable.h | 34 ++++++-------------
.../include/asm/book3s/64/tlbflush-hash.h | 22 ++++++++----
arch/powerpc/mm/book3s64/hash_tlb.c | 10 +++---
arch/powerpc/mm/book3s64/subpage_prot.c | 5 +--
arch/sparc/include/asm/tlbflush_64.h | 6 ++--
arch/sparc/mm/tlb.c | 17 +++++++---
arch/x86/include/asm/paravirt.h | 8 ++---
arch/x86/include/asm/paravirt_types.h | 6 ++--
arch/x86/include/asm/pgtable.h | 3 +-
arch/x86/xen/enlighten_pv.c | 2 +-
arch/x86/xen/mmu_pv.c | 13 ++++---
fs/proc/task_mmu.c | 5 +--
include/linux/mm_types.h | 3 ++
include/linux/pgtable.h | 21 +++++++++---
mm/kasan/shadow.c | 4 +--
mm/madvise.c | 20 ++++++-----
mm/memory.c | 20 ++++++-----
mm/migrate_device.c | 5 +--
mm/mprotect.c | 5 +--
mm/mremap.c | 5 +--
mm/userfaultfd.c | 5 +--
mm/vmalloc.c | 15 ++++----
mm/vmscan.c | 15 ++++----
23 files changed, 148 insertions(+), 101 deletions(-)
base-commit: b024763926d2726978dff6588b81877d000159c1
--
2.47.0
next reply other threads:[~2025-09-08 7:40 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-08 7:39 Kevin Brodsky [this message]
2025-09-08 7:39 ` [PATCH v2 1/7] mm: remove arch_flush_lazy_mmu_mode() Kevin Brodsky
2025-09-08 9:29 ` Yeoreum Yun
2025-09-09 9:00 ` David Hildenbrand
2025-09-08 7:39 ` [PATCH v2 2/7] mm: introduce local state for lazy_mmu sections Kevin Brodsky
2025-09-08 9:30 ` Yeoreum Yun
2025-09-09 5:40 ` Andrew Morton
2025-09-09 9:05 ` Kevin Brodsky
2025-09-09 9:07 ` David Hildenbrand
2025-09-09 9:40 ` Alexander Gordeev
2025-09-09 10:09 ` David Hildenbrand
2025-09-09 11:45 ` Alexander Gordeev
2025-09-09 11:54 ` David Hildenbrand
2025-09-09 13:49 ` Kevin Brodsky
2025-09-09 14:02 ` Kevin Brodsky
2025-09-09 14:28 ` David Hildenbrand
2025-09-10 15:16 ` Kevin Brodsky
2025-09-10 15:37 ` David Hildenbrand
2025-09-11 16:19 ` Kevin Brodsky
2025-09-11 18:14 ` David Hildenbrand
2025-09-12 7:26 ` Kevin Brodsky
2025-09-12 8:04 ` David Hildenbrand
2025-09-12 8:48 ` Kevin Brodsky
2025-09-12 8:55 ` David Hildenbrand
2025-09-12 12:37 ` Alexander Gordeev
2025-09-12 12:40 ` David Hildenbrand
2025-09-12 12:56 ` Alexander Gordeev
2025-09-12 13:02 ` David Hildenbrand
2025-09-12 14:05 ` Alexander Gordeev
2025-09-12 14:25 ` David Hildenbrand
2025-09-12 15:02 ` Kevin Brodsky
2025-09-09 14:38 ` Alexander Gordeev
2025-09-10 16:11 ` Kevin Brodsky
2025-09-11 12:06 ` Alexander Gordeev
2025-09-11 16:20 ` Kevin Brodsky
2025-09-09 10:57 ` Juergen Gross
2025-09-09 14:15 ` Kevin Brodsky
2025-09-09 10:08 ` Jürgen Groß
2025-09-08 7:39 ` [PATCH v2 3/7] arm64: mm: fully support nested " Kevin Brodsky
2025-09-08 9:30 ` Yeoreum Yun
2025-09-08 7:39 ` [PATCH v2 4/7] x86/xen: support nested lazy_mmu sections (again) Kevin Brodsky
2025-09-09 9:13 ` David Hildenbrand
2025-09-09 9:37 ` Jürgen Groß
2025-09-09 9:56 ` David Hildenbrand
2025-09-09 11:28 ` Kevin Brodsky
2025-09-09 9:42 ` Jürgen Groß
2025-09-08 7:39 ` [PATCH v2 5/7] powerpc/mm: support nested lazy_mmu sections Kevin Brodsky
2025-09-08 7:39 ` [PATCH v2 6/7] sparc/mm: " Kevin Brodsky
2025-09-08 7:39 ` [PATCH v2 7/7] mm: update lazy_mmu documentation Kevin Brodsky
2025-09-08 9:30 ` Yeoreum Yun
2025-09-08 16:56 ` [PATCH v2 0/7] Nesting support for lazy MMU mode Lorenzo Stoakes
2025-09-09 9:10 ` Kevin Brodsky
2025-09-09 2:16 ` Andrew Morton
2025-09-09 9:21 ` David Hildenbrand
2025-09-09 13:59 ` Kevin Brodsky
2025-09-12 15:25 ` Kevin Brodsky
2025-09-15 6:28 ` Alexander Gordeev
2025-09-15 11:19 ` Kevin Brodsky
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250908073931.4159362-1-kevin.brodsky@arm.com \
--to=kevin.brodsky@arm.com \
--cc=Liam.Howlett@oracle.com \
--cc=agordeev@linux.ibm.com \
--cc=akpm@linux-foundation.org \
--cc=andreas@gaisler.com \
--cc=boris.ostrovsky@oracle.com \
--cc=bp@alien8.de \
--cc=catalin.marinas@arm.com \
--cc=christophe.leroy@csgroup.eu \
--cc=dave.hansen@linux.intel.com \
--cc=davem@davemloft.net \
--cc=david@redhat.com \
--cc=hpa@zytor.com \
--cc=jannh@google.com \
--cc=jgross@suse.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=maddy@linux.ibm.com \
--cc=mhocko@suse.com \
--cc=mingo@redhat.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=peterz@infradead.org \
--cc=rppt@kernel.org \
--cc=ryan.roberts@arm.com \
--cc=sparclinux@vger.kernel.org \
--cc=surenb@google.com \
--cc=tglx@linutronix.de \
--cc=vbabka@suse.cz \
--cc=will@kernel.org \
--cc=xen-devel@lists.xenproject.org \
--cc=yeoreum.yun@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox