linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Brodsky <kevin.brodsky@arm.com>
To: David Hildenbrand <david@redhat.com>,
	Alexander Gordeev <agordeev@linux.ibm.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
	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 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 2/7] mm: introduce local state for lazy_mmu sections
Date: Fri, 12 Sep 2025 09:26:18 +0200	[thread overview]
Message-ID: <15d01c8b-5475-442e-9df5-ca37b0d5dc04@arm.com> (raw)
In-Reply-To: <4aa28016-5678-4c66-8104-8dcc3fa2f5ce@redhat.com>

On 11/09/2025 20:14, David Hildenbrand wrote:
>>>> On the other hand, with a pagefault_disabled-like approach, there
>>>> is no
>>>> way to instruct call {3} to fully exit lazy_mmu regardless of the
>>>> nesting level.
>>>
>>> Sure there is, with a better API. See below. :)
>>
>> I meant while keeping the existing shape of the API but yes fair enough!
>
> Time to do it properly I guess :)

Yes, I think the discussions on that series have shown that we might as
well refactor it completely. Once and for all™!

>
> [...]
>
>>> Assume we store in the task_struct
>>>
>>> uint8_t lazy_mmu_enabled_count;
>>> bool lazy_mmu_paused;
>>
>> I didn't think of that approach! I can't immediately see any problem
>> with it, assuming we're fine with storing arch-specific context in
>> thread_struct (which seems to be the case as things stand).
>
> Right, just to complete the picture:
>
> a) We will have some CONFIG_ARCH_LAZY_MMU
>
> b) Without that config, all lazy_mmu_*() functions are a nop and no
> lazy_mmu_state is stored in task_struct 

Agreed on both counts (replacing __HAVE_ARCH_ENTER_LAZY_MMU_MODE).

>
> struct lazy_mmu_state {
>     uint8_t enabled_count;
>     bool paused;

Looking at the arm64 implementation, I'm thinking: instead of the paused
member, how about a PF_LAZY_MMU task flag? It would be set when lazy_mmu
is actually enabled (i.e. inside an enter()/leave() section, and not
inside a pause()/resume() section). This way, architectures could use
that flag directly to tell if lazy_mmu is enabled instead of reinventing
the wheel, all in slightly different ways. Namely:

* arm64 uses a thread flag (TIF_LAZY_MMU) - this is trivially replaced
with PF_LAZY_MMU
* powerpc and sparc use batch->active where batch is a per-CPU variable;
I expect this can also be replaced with PF_LAZY_MMU
* x86/xen is more complex as it has xen_lazy_mode which tracks both
LAZY_MMU and LAZY_CPU modes. I'd probably leave that one alone, unless a
Xen expert is motivated to refactor it.

With that approach, the implementation of arch_enter() and arch_leave()
becomes very simple (no tracking of lazy_mmu status) on arm64, powerpc
and sparc.

(Of course we could also have an "enabled" member in lazy_mmu_state
instead of PF_LAZY_MMU, there is no functional difference.)

> }
>
> c) With that config, common-code lazy_mmu_*() functions implement the
> updating of the lazy_mmu_state in task_struct and call into arch code
> on the transition from 0->1, 1->0 etc.

Indeed, this is how I thought about it. There is actually quite a lot
that can be moved to the generic functions:
* Updating lazy_mmu_state
* Sanity checks on lazy_mmu_state (e.g. underflow/overflow)
* Bailing out if in_interrupt() (not done consistently across arch's at
the moment)

>
> Maybe that can be done through exiting
> arch_enter_lazy_mmu_mode()/arch_leave_lazy_mmu_mode() callbacks, maybe
> we need more. I feel like
> we might be able to implement that through the existing helpers.

We might want to rename them to align with the new generic helpers, but
yes otherwise the principle should remain unchanged.

In fact, we will also need to revive arch_flush_lazy_mmu_mode(). Indeed,
in the nested situation, we need the following arch calls:

enter() -> arch_enter()
    enter() -> [nothing]
    leave() -> arch_flush()
leave() -> arch_leave()

leave() must always flush whatever arch state was batched, as may be
expected by the caller.

How does all that sound?

>
> [...]
>
>>
>> Overall what you're proposing seems sensible to me, the additional
>> fields in task_struct don't take much space and we can keep the API
>> unchanged in most cases. It is also good to have the option to check
>> that the API is used correctly. I'll reply to the cover letter to let
>> anyone who didn't follow this thread chip in, before I go ahead and try
>> out that new approach.
>
> And on top of the proposal above we will have some
>
> struct arch_lazy_mmu_state;
>
> define by the architecture (could be an empty struct on most).
>
> We can store that inside "struct lazy_mmu_state;" or if we ever have
> to, start returning only that from the enable/disable etc. functions.

I'm not sure we'd want to mix those styles (task_struct member + local
variable), that's adding complexity without much upside... Also having a
local variable at every nesting level only makes sense if we have an
arch callback regardless of nesting level, which is unnecessary in this
proposed API.

>
> For now, I'd say just store it in the task struct in the
> lazy_mmu_state. But we can always adjust later if required.
>
> In the first (this) series we probably don't even have to introduce
> arch_lazy_mmu_state. 

I suppose this could improve the overall struct layout - but otherwise I
don't really see the need compared to adding members to thread_struct
(which is fully arch-specific).

- Kevin


  reply	other threads:[~2025-09-12  7:26 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-08  7:39 [PATCH v2 0/7] Nesting support for lazy MMU mode 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 [this message]
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=15d01c8b-5475-442e-9df5-ca37b0d5dc04@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