From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Lorenzo Stoakes (ARM)" <ljs@kernel.org>
Cc: Hui Zhu <hui.zhu@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
"Liam R. Howlett" <liam@infradead.org>,
Vlastimil Babka <vbabka@kernel.org>,
Mike Rapoport <rppt@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
Hui Zhu <zhuhui@kylinos.cn>
Subject: Re: [PATCH v3] mm/memory: use pmdp_get_lockless() for the pmd read in do_fault_around()
Date: Wed, 4 Nov 2026 10:24:23 +0100 [thread overview]
Message-ID: <15b9dc96-d3eb-4ce7-8db0-589c2798ed41@kernel.org> (raw)
In-Reply-To: <aupAdlzeOtc0qSsQ@gremlin>
On 11/3/26 21:27, Lorenzo Stoakes (ARM) wrote:
> On Tue, Nov 03, 2026 at 08:51:38PM +0100, David Hildenbrand (Arm) wrote:
>> On 11/3/26 19:24, Lorenzo Stoakes (ARM) wrote:
>>> It turns out we're as wildly inconsistent on pmdp_get_lockless() as we are on
>>> pmdp_get(), so TL;DR my main concern is moot so:
>>
>> Yeah, I know that we use it in some core places already properly, like in
>> GUP-fast, __handle_mm_fault() or our complicated __pte_offset_map().
>
> Yup, but also inconsistently, basically mostly interchangeably with
> pmdp_get(). Rarely is this value actually used.
>
>>> * But it turns out it's all a giant mess (of course)... for
>>> CONFIG_GUP_GET_PXX_LOW_HIGH arches you really actually need to also do:
>>>
>>> pmdp_get_lockless_start();
>>> pmd = pmdp_get_lockless(...);
>>> pmdp_get_lockless_end();
>>>
>>> And that's because, as Hugh points out in commit 146b42e07494 ("mm/pgtable: add
>>> PAE safety to __pte_offset_map()")), you need IRQs disabled for these arches for
>>> it to be safe.
>>
>> Yes, there is this pmdp_get_lockless_start() magic ....
>
> One of those things that, the more you look into it, the more stuff you find...
>
>> It's really a mess. I wonder if we can remove that somehow completely ...
>>
>> arch/mips/Kconfig: select GUP_GET_PXX_LOW_HIGH if CPU_MIPS32 &&
>> PHYS_ADDR_T_64BIT
>> arch/sh/Kconfig: select GUP_GET_PXX_LOW_HIGH if X2TLB
>> arch/x86/Kconfig: select GUP_GET_PXX_LOW_HIGH if X86_PAE
>
> Yeah that'd be ideal.
>
> But actually could we not just simplify and allow these arches to be a little
> bit slower (who cares for museum pieces)?
>
> The only user of the start/end magic is __pte_offset_map(). And it does:
>
> irqflags = pmdp_get_lockless_start();
> pmdval = pmdp_get_lockless(pmd);
> pmdp_get_lockless_end(irqflags);
>
> So that could just get folded into pmdp_get_lockless() for these arches.
>
> That would mean the places that don't require IRQs to be disabled (optimstic
> checks) would now be needlessly enabling/disabling, but hey - use a system that
> doesn't live in a museum :)
It would be interesting to know the performance impact. IOW, whether this is
just a slight slowdown or whether it makes these installations unusable.
It looks like an interesting thing.
>
> That way we could safely convert every non-PMD lock holding caller to
> pmdp_get_lockless() without needing another pmdp_get*() variant + fix confusion
> about whether the start/end magic is required.
>
> And this would work even in places where the IRQs are already disabled as it's
> fine with nesting.
>
> So you'd just update thusly:
>
> static inline pmd_t pmdp_get_lockless(pmd_t *pmdp)
> {
> pmd_t pmd;
> + unsigned long flags;
>
> + local_irq_save(flags);
> do {
> pmd.pmd_low = pmdp->pmd_low;
> smp_rmb();
> pmd.pmd_high = pmdp->pmd_high;
> smp_rmb();
> } while (unlikely(pmd.pmd_low != pmdp->pmd_low));
> -
> + local_irq_restore(flags);
> return pmd;
> }
>
> ...
>
> pte_t *__pte_offset_map(pmd_t *pmd, unsigned long addr, pmd_t *pmdvalp)
> {
> - unsigned long irqflags;
> pmd_t pmdval;
>
> rcu_read_lock();
> - irqflags = pmdp_get_lockless_start();
> pmdval = pmdp_get_lockless(pmd);
> - pmdp_get_lockless_end(irqflags);
>
> ...
> }
>
> What do you think?
Sounds reasonable. I guess we should be able to disable IRQs on all callsites.
I am quite surprised that x86 shouldn't have an instruction to read/write PTEs
atomically.
I think if we require MMX we could just do atomic read+write, and let x86
implement pmdp_get_lockless() / pmdp_get() itself. But MMX seems to be a bit
younger than PAE. Apparently there is a hacky way to read through CMPXCHG8B.
Doesn't sound like a good use of our time ... but removing that handling
entirely would be very nice.
Simplifying is nice as well.
--
Cheers,
David
prev parent reply other threads:[~2026-11-04 9:24 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 1:47 Hui Zhu
2026-11-03 8:11 ` David Hildenbrand (Arm)
2026-11-03 9:50 ` Lorenzo Stoakes (ARM)
2026-11-03 16:15 ` David Hildenbrand (Arm)
2026-11-03 18:24 ` Lorenzo Stoakes (ARM)
2026-11-03 19:51 ` David Hildenbrand (Arm)
2026-11-03 20:27 ` Lorenzo Stoakes (ARM)
2026-11-04 9:24 ` David Hildenbrand (Arm) [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=15b9dc96-d3eb-4ce7-8db0-589c2798ed41@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=hui.zhu@linux.dev \
--cc=liam@infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=vbabka@kernel.org \
--cc=zhuhui@kylinos.cn \
/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®