From: Kevin Brodsky <kevin.brodsky@arm.com>
To: David Hildenbrand <david@redhat.com>,
Andrew Morton <akpm@linux-foundation.org>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Alexander Gordeev <agordeev@linux.ibm.com>,
Andreas Larsson <andreas@gaisler.com>,
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 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,
Mark Rutland <Mark.Rutland@arm.com>
Subject: Re: [PATCH v2 0/7] Nesting support for lazy MMU mode
Date: Fri, 12 Sep 2025 17:25:27 +0200 [thread overview]
Message-ID: <338ef811-1dab-4c4e-bc5f-8ebd8cb68435@arm.com> (raw)
In-Reply-To: <d1b4ff2a-052f-4556-91ae-273962edbed0@redhat.com>
On 09/09/2025 11:21, David Hildenbrand wrote:
> On 09.09.25 04:16, Andrew Morton wrote:
>> On Mon, 8 Sep 2025 08:39:24 +0100 Kevin Brodsky
>> <kevin.brodsky@arm.com> wrote:
>>
>>> 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.
>>
>> This is so totally the correct way. Thanks.
>
> Staring at this, I wonder if we could alternatively handle it like
> pagefault_disable()/pagefault_enable(), having something like
> current->lazy_mmu_enabled.
>
> We wouldn't have to worry about preemption in that case I guess
> (unless the arch has special requirements).
>
> Not sure if that was already discussed, just a thought.
Based on the outcome of the discussion with David on patch 2 [1p], there
is indeed an alternative approach that we should seriously consider. In
summary:
* Keep the API stateless, handle nesting with a counter in task_struct
* Introduce new functions to temporarily disable lazy_mmu without
impacting nesting, track that with a bool in task_struct (addresses the
situation in mm/kasan/shadow.c and possibly some x86 cases too)
* Move as much handling from arch_* to generic functions
What the new generic infrastructure would look like:
struct task_struct {
...
#ifdef CONFIG_ARCH_LAZY_MMU
struct {
uint8_t count;
bool enabled; /* or paused, see below */
} lazy_mmu_state;
#endif
}
* lazy_mmu_mode_enable():
if (!lazy_mmu_state.count) {
arch_enter_lazy_mmu_mode();
lazy_mmu_state.enabled = true;
}
lazy_mmu_state.count++;
* lazy_mmu_mode_disable():
lazy_mmu_count--;
if (!lazy_mmu_state.count) {
lazy_mmu_state.enabled = false;
arch_leave_lazy_mmu_mode();
} else {
arch_flush_lazy_mmu_mode();
}
* lazy_mmu_mode_pause():
lazy_mmu_state.enabled = false;
arch_leave_lazy_mmu_mode();
* lazy_mmu_mode_resume();
arch_enter_lazy_mmu_mode();
lazy_mmu_state.enabled = true;
The generic enable()/disable() helpers are able to handle most of the
logic, leaving only truly arch-specific code to the arch callbacks:
* Updating lazy_mmu_state
* Sanity checks on lazy_mmu_state (e.g. count underflow/overflow,
pause()/resume() only called when count > 0, etc.)
* Bailing out if in_interrupt() (not done consistently across arch's at
the moment)
A further improvement is to make arch code check lazy_mmu_state.enabled
to determine whether lazy_mmu is enabled at any given point. At the
moment every arch uses a different mechanism, and this is an occasion to
make them converge.
The arch callback interface remains unchanged, and we are resurrecting
arch_flush_lazy_mmu_mode() to handle the nested disable() case (flushing
must happen when exiting a section regardless of nesting):
enable() -> arch_enter()
enable() -> [nothing]
disable() -> arch_flush()
disable() -> arch_leave()
Note: lazy_mmu_state.enabled (set whenever lazy_mmu is actually enabled)
could be replaced with lazy_mmu_state.paused (set inside a
pause()/resume() section). I believe this is equivalent but the former
is slightly more convenient for arch code - to be confirmed in practice.
Any thoughts on this? Unless there are concerns, I will move towards
that approach in v3.
- Kevin
[1p]
https://lore.kernel.org/all/4aa28016-5678-4c66-8104-8dcc3fa2f5ce@redhat.com/t/#u
next prev parent reply other threads:[~2025-09-12 15:25 UTC|newest]
Thread overview: 58+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-08 7:39 Kevin Brodsky
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 [this message]
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=338ef811-1dab-4c4e-bc5f-8ebd8cb68435@arm.com \
--to=kevin.brodsky@arm.com \
--cc=Liam.Howlett@oracle.com \
--cc=Mark.Rutland@arm.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