mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ryan Roberts <ryan.roberts@arm.com>
To: Kevin Brodsky <kevin.brodsky@arm.com>, Fuad Tabba <fuad.tabba@linux.dev>
Cc: Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Ard Biesheuvel <ardb@kernel.org>,
	Yang Shi <yang@os.amperecomputing.com>,
	Anshuman Khandual <anshuman.khandual@arm.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, stable@vger.kernel.org
Subject: Re: [PATCH 3/3] arm64: mm: Don't defer the barriers when installing a fixmap entry
Date: Tue, 24 Nov 2026 11:45:27 +0000	[thread overview]
Message-ID: <3d88c31d-04cc-49e4-b30a-3ece06908da6@arm.com> (raw)
In-Reply-To: <f9a42849-fe8f-4a96-81a1-ab58193b222d@arm.com>

On 24/11/2026 08:22, Kevin Brodsky wrote:
> On 23/11/2026 19:54, Ryan Roberts wrote:
>> 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...
> 
> Yes that's essentially the same as the explicit call to
> arch_flush_lazy_mmu_mode() I mentioned below. IMHO that looks pretty
> obfuscated though - the casual reader will wonder why we're creating a
> lazy MMU section for setting just one PTE. If we go down this route, I'd
> argue the explicit call to arch_flush_lazy_mmu_mode() is clearer (and
> our implementation is safe to call even outside of a lazy MMU section).

OK let's just leave it as Faud has done it then. I don't have a strong opinion.

> 
> - Kevin
> 
>>> 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@arm.com>
>>>
>>> - Kevin
>>>
>>> [1] https://lore.kernel.org/r/20261109-kpkeys-v10-0-aa6c4d9603bc@arm.com


      reply	other threads:[~2026-11-24 11:45 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 12:16 [PATCH 0/3] arm64: Missing barriers in kernel page-table updates Fuad Tabba
2026-11-20 12:16 ` [PATCH 1/3] arm64: pi: Add an ISB after mapping the FDT in the initial ID map Fuad Tabba
2026-11-21 10:42   ` Ryan Roberts
2026-11-20 12:16 ` [PATCH 2/3] arm64: mm: Add an ISB after remapping the KPTI page-table slot Fuad Tabba
2026-11-21 10:48   ` Ryan Roberts
2026-11-20 12:16 ` [PATCH 3/3] arm64: mm: Don't defer the barriers when installing a fixmap entry Fuad Tabba
2026-11-21 11:01   ` Ryan Roberts
2026-11-23  7:35     ` Fuad Tabba
2026-11-23 10:36       ` Ryan Roberts
2026-11-23 13:08         ` Kevin Brodsky
2026-11-23 18:54           ` Ryan Roberts
2026-11-24  8:22             ` Kevin Brodsky
2026-11-24 11:45               ` Ryan Roberts [this message]

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=3d88c31d-04cc-49e4-b30a-3ece06908da6@arm.com \
    --to=ryan.roberts@arm.com \
    --cc=anshuman.khandual@arm.com \
    --cc=ardb@kernel.org \
    --cc=catalin.marinas@arm.com \
    --cc=fuad.tabba@linux.dev \
    --cc=kevin.brodsky@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=stable@vger.kernel.org \
    --cc=will@kernel.org \
    --cc=yang@os.amperecomputing.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

all inboxes | Powered by JetHome®