Re: [RFC PATCH 1/2] mm: make lazy MMU mode context-aware

From: Alexander Gordeev

Date: Mon Apr 13 2026 - 09:43:57 EST


On Tue, Mar 31, 2026 at 11:11:22PM +0200, David Hildenbrand (Arm) wrote:
> >>> + * lazy_mmu_mode_enable_pte() - Enable the lazy MMU mode with
> >>> parameters
> >>
> >> You have to be a lot clearer about implications. For example, what
> >> happens if we would bail out and not process all ptes? What are the
> >> exact semantics.
> >
> > The only implication is "only this address/PTE range could be updated
> > and that range may span one page table at most".
>
> Probably phrase it stronger. "No ptes outside of this range must be
> updated" etc.

That turns out to be bit more complicated. The below cases do not fit
such a strong requirement:

1. copy_pte_range() operates on two ranges: source and destination.
Though lazy_mmu_mode_enable_for_pte_range() applies to the source one,
updates to the destination are still happen while in tha lazy mode.
(Although the lazy mode is not actually needed for the destination
unattached MM).

2. move_ptes() also operates on a source and destination ranges, but
unlike copy_pte_range() the destination range is also attached to the
currently active task.

3. Though theoretical, nesting sections with interleaving calls to
lazy_mmu_mode_enable() and lazy_mmu_mode_enable_for_pte_range() make
it difficult to define (let alone to implement) which range is currently
active, if any.

All of these goes away if we switch from for_pte_range() to fast_pte_range()
semantics:

/**
* lazy_mmu_mode_enable_fast_pte_range() - Enable the lazy MMU mode with fast updates.
* @mm: Address space the ptes represent.
* @addr: Address of the first pte.
* @end: End address of the range.
* @ptep: Page table pointer for the first entry.
*
* Enters a new lazy MMU mode section and allows fast updates for PTEs
* within the specified range, while PTEs outside of the range are
* updated in the normal way - as if lazy_mmu_mode_enable() was called;
* if lazy MMU mode was not already enabled, enables it and calls
* arch_enter_lazy_mmu_mode_fast_pte_range(); if the mode was already
* enabled, the provided PTE range is ignored.
*
* The PTE range must belong to the provided memory space and must
* not cross a page table boundary.
*
* There are no requirements on the order or range completeness of PTE updates.
*
* 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
*/

Thoughts?

Thanks!