[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <93d04ef8-0364-4013-8839-ba599d930cb2@kernel.org>
Date: Thu, 4 Dec 2025 12:52:32 +0100
From: "David Hildenbrand (Red Hat)" <david@...nel.org>
To: Anshuman Khandual <anshuman.khandual@....com>,
Kevin Brodsky <kevin.brodsky@....com>, linux-mm@...ck.org
Cc: linux-kernel@...r.kernel.org, Alexander Gordeev <agordeev@...ux.ibm.com>,
Andreas Larsson <andreas@...sler.com>,
Andrew Morton <akpm@...ux-foundation.org>,
Boris Ostrovsky <boris.ostrovsky@...cle.com>, Borislav Petkov
<bp@...en8.de>, Catalin Marinas <catalin.marinas@....com>,
Christophe Leroy <christophe.leroy@...roup.eu>,
Dave Hansen <dave.hansen@...ux.intel.com>,
"David S. Miller" <davem@...emloft.net>,
David Woodhouse <dwmw2@...radead.org>, "H. Peter Anvin" <hpa@...or.com>,
Ingo Molnar <mingo@...hat.com>, Jann Horn <jannh@...gle.com>,
Juergen Gross <jgross@...e.com>, "Liam R. Howlett"
<Liam.Howlett@...cle.com>, Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
Madhavan Srinivasan <maddy@...ux.ibm.com>,
Michael Ellerman <mpe@...erman.id.au>, Michal Hocko <mhocko@...e.com>,
Mike Rapoport <rppt@...nel.org>, Nicholas Piggin <npiggin@...il.com>,
Peter Zijlstra <peterz@...radead.org>,
"Ritesh Harjani (IBM)" <ritesh.list@...il.com>,
Ryan Roberts <ryan.roberts@....com>, Suren Baghdasaryan <surenb@...gle.com>,
Thomas Gleixner <tglx@...utronix.de>,
Venkat Rao Bagalkote <venkat88@...ux.ibm.com>,
Vlastimil Babka <vbabka@...e.cz>, Will Deacon <will@...nel.org>,
Yeoreum Yun <yeoreum.yun@....com>, linux-arm-kernel@...ts.infradead.org,
linuxppc-dev@...ts.ozlabs.org, sparclinux@...r.kernel.org,
xen-devel@...ts.xenproject.org, x86@...nel.org
Subject: Re: [PATCH v5 08/12] mm: enable lazy_mmu sections to nest
Some comments from my side:
>> static inline void arch_enter_lazy_mmu_mode(void)
>> {
>> - /*
>> - * lazy_mmu_mode is not supposed to permit nesting. But in practice this
>> - * does happen with CONFIG_DEBUG_PAGEALLOC, where a page allocation
>> - * inside a lazy_mmu_mode section (such as zap_pte_range()) will change
>> - * permissions on the linear map with apply_to_page_range(), which
>> - * re-enters lazy_mmu_mode. So we tolerate nesting in our
>> - * implementation. The first call to arch_leave_lazy_mmu_mode() will
>> - * flush and clear the flag such that the remainder of the work in the
>> - * outer nest behaves as if outside of lazy mmu mode. This is safe and
>> - * keeps tracking simple.
>> - */
>> -
>> set_thread_flag(TIF_LAZY_MMU);> }
>
> Should not platform specific changes be deferred to subsequent patches until
> nesting is completely enabled in generic first ? Although no problem as such
> but would be bit cleaner.
This could indeed be done in a separate patch. But I also don't see a
problem with updating the doc in this patch.
>
>>
>> diff --git a/include/linux/mm_types_task.h b/include/linux/mm_types_task.h
>> index a82aa80c0ba4..11bf319d78ec 100644
>> --- a/include/linux/mm_types_task.h
>> +++ b/include/linux/mm_types_task.h
>> @@ -88,4 +88,9 @@ struct tlbflush_unmap_batch {
>> #endif
>> };
>>
>> +struct lazy_mmu_state {
>> + u8 enable_count;
>> + u8 pause_count;
>> +};
>> +
>
> Should not this be wrapped with CONFIG_ARCH_HAS_LAZY_MMU_MODE as the task_struct
> element 'lazy_mmu_state' is only available with the feature.
No strong opinion; the compiler will ignore it either way. And less
ifdef is good, right? :)
... and there is nothing magical in there that would result in other
dependencies.
> Besides, is a depth
> of 256 really expected here ? 4 bits for each element would not be sufficient for
> a depth of 16 ?
We could indeed use something like
struct lazy_mmu_state {
u8 enable_count : 4;
u8 pause_count : 4;
};
but then, the individual operations on enable_count/pause_count need
more instructions.
Further, as discussed, this 1 additional byte barely matters given the
existing size of the task struct.
No strong opinion.
>
>> */
>> #ifdef CONFIG_ARCH_HAS_LAZY_MMU_MODE
>> +/**
>> + * lazy_mmu_mode_enable() - Enable the lazy MMU mode.
>> + *
>> + * Enters a new lazy MMU mode section; if the mode was not already enabled,
>> + * enables it and calls arch_enter_lazy_mmu_mode().
>> + *
>> + * Must be paired with a call to lazy_mmu_mode_disable().
>> + *
>> + * Has no effect if called:
>> + * - While paused - see lazy_mmu_mode_pause()
>> + * - In interrupt context
>> + */
>> static inline void lazy_mmu_mode_enable(void)
>> {
>> - if (in_interrupt())
>> + struct lazy_mmu_state *state = ¤t->lazy_mmu_state;
>> +
>> + if (in_interrupt() || state->pause_count > 0)
>> return;
>>
>> - arch_enter_lazy_mmu_mode();
>> + VM_WARN_ON_ONCE(state->enable_count == U8_MAX);
>> +
>> + if (state->enable_count++ == 0)
>> + arch_enter_lazy_mmu_mode();
>
> When lazy_mmu_mode_enable() gets called for the first time with state->enable_count as 0,
> then arch_enter_lazy_mmu_mode() will not get called ? Bit confused.
state->enable_count++ returns the old value (0). Are you thinking of
++state->enable_count?
But maybe I misudnerstood your concern.
[...]
>> +/**
>> + * lazy_mmu_mode_pause() - Resume the lazy MMU mode.
>> + *
>> + * Resumes the lazy MMU mode; if it was active at the point where the matching
>> + * call to lazy_mmu_mode_pause() was made, re-enables it and calls
>> + * arch_enter_lazy_mmu_mode().
>> + *
>> + * Must match a call to lazy_mmu_mode_pause().
>> + *
>> + * Has no effect if called:
>> + * - While paused (inside another pause()/resume() pair)
>> + * - In interrupt context
>> + */
>> static inline void lazy_mmu_mode_resume(void)
>> {
>> + struct lazy_mmu_state *state = ¤t->lazy_mmu_state;
>> +
>> if (in_interrupt())
>> return;
>>
>> - arch_enter_lazy_mmu_mode();
>> + VM_WARN_ON_ONCE(state->pause_count == 0);
>> +
>> + if (--state->pause_count == 0 && state->enable_count > 0)
>> + arch_enter_lazy_mmu_mode();
>> }
>
> Should not state->pause/enable_count tests and increment/decrement be handled
> inside include/linux/sched via helpers like in_lazy_mmu_mode() ? This is will
> ensure cleaner abstraction with respect to task_struct.
I don't think this is required given that this code here implements
CONFIG_ARCH_HAS_LAZY_MMU_MODE support.
--
Cheers
David
Powered by blists - more mailing lists