Re: [PATCH 3/3] arm64: mm: Don't defer the barriers when installing a fixmap entry

From: Ryan Roberts

Date: Mon Nov 23 2026 - 13:55:06 EST


On 23/11/2026 13:08, Kevin Brodsky wrote:
> On 23/11/2026 11:36, Ryan Roberts wrote:
>>>
>>>>> @@ -127,7 +127,9 @@ void __set_fixmap(enum fixed_addresses idx,
>>>>> ptep = fixmap_pte(addr);
>>>>>
>>>>> if (pgprot_val(flags)) {
>>>>> - __set_pte(ptep, pfn_pte(phys >> PAGE_SHIFT, flags));
>>>>> + /* The slot must be usable on return, even in lazy MMU mode. */
>>>>> + __set_pte_nosync(ptep, pfn_pte(phys >> PAGE_SHIFT, flags));
>>>>> + emit_pte_barriers();
>>>> I wonder if it would be clearer to wrap __set_ptes():
>>>>
>>>> lazy_mmu_mode_pause()
>>>> __set_ptes()
>>>> lazy_mmu_mode_resume()
>>> That would work. However, there's the stable backport. 6.18 has the
>>> bug, but lazy_mmu_mode_pause() was added in 7.0, so 6.18.y would need
>>> its own patch. This patch applies to 6.18 unchanged.
>>>
>>> I'm happy with either, or with a followup patch in the same series.
>> I'd personally prefer to use pause/resume since it's makes it very clear what's
>> going on and avoids the layer violation. Perhaps your approach as the back
>> portable one, then pause/resume as follow up (along with ptep_try_set() tidy
>> up)? Others might think differently though...
>
> Using pause/resume does work, but it is a bigger hammer than necessary.
> If other features make use of lazy MMU mode, then we may end up paying
> extra cost by leaving/re-entering the mode.
>
> For instance, with page table hardening [1], using the pause/resume
> approach means 4 extra ISBs:
> - 1 when pause() leaves lazy MMU mode: restoring default kpkeys context
> - 2 in __set_pte(): switching to page table update kpkeys context, and
> then back to default
> - 1 when resume() enters lazy MMU mode: entering page table update
> kpkeys context
>
> An explicit __set_pte_nosync() + emit_pte_barriers() achieves exactly
> what we're after (immediately visible PTE update) and doesn't disrupt
> lazy MMU mode - we don't unnecessarily set TIF_LAZY_MMU_PENDING. 

It's so ugly to spill this stuff everywhere though.

How about a nested lazy mmu section?

lazy_mmu_mode_enable()
__set_ptes()
lazy_mmu_mode_disable()

If it's nested the enable() is essentially nop, and the disable is a flush,
which emits the barriers. If it's the first enable, we still set
TIF_LAZY_MMU_PENDING though...

>
> An alternative approach that addresses your point about layer violation
> is to call arch_flush_lazy_mmu_mode() and leave the __set_pte() call
> unchanged. This is slightly slower as we still end up setting/clearing
> the TIF flag in that case. Not sure this is worth it - ultimately we
> have to be mindful of what lazy MMU mode is doing to ensure this code is
> correct. I'm happy with the current approach.
>
> Reviewed-by: Kevin Brodsky <kevin.brodsky@xxxxxxx>
>
> - Kevin
>
> [1] https://lore.kernel.org/r/20261109-kpkeys-v10-0-aa6c4d9603bc@xxxxxxx