* [PATCH] mm: use standard page table accessors
@ 2025-11-26 6:47 Wei Yang
2025-11-26 8:15 ` Christophe Leroy (CS GROUP)
2025-11-26 9:09 ` David Hildenbrand (Red Hat)
0 siblings, 2 replies; 9+ messages in thread
From: Wei Yang @ 2025-11-26 6:47 UTC (permalink / raw)
To: akpm, david, lorenzo.stoakes, Liam.Howlett, vbabka, rppt, surenb,
mhocko, ziy, baolin.wang, npache, ryan.roberts, dev.jain, baohua,
lance.yang
Cc: linux-mm, Wei Yang
Use standard page table accessors i.e pxdp_get() to get the value of
pxdp.
Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
---
include/linux/pgtable.h | 2 +-
mm/huge_memory.c | 2 +-
mm/memory.c | 8 ++++----
3 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
index b13b6f42be3c..a9efd58658bc 100644
--- a/include/linux/pgtable.h
+++ b/include/linux/pgtable.h
@@ -1810,7 +1810,7 @@ static inline int pud_trans_unstable(pud_t *pud)
{
#if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \
defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)
- pud_t pudval = READ_ONCE(*pud);
+ pud_t pudval = pudp_get(pud);
if (pud_none(pudval) || pud_trans_huge(pudval))
return 1;
diff --git a/mm/huge_memory.c b/mm/huge_memory.c
index 0d2ac331ccad..dd3577e40d16 100644
--- a/mm/huge_memory.c
+++ b/mm/huge_memory.c
@@ -1486,7 +1486,7 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf)
}
vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd);
ret = 0;
- if (pmd_none(*vmf->pmd)) {
+ if (pmd_none(pmdp_get(vmf->pmd))) {
ret = check_stable_address_space(vma->vm_mm);
if (ret) {
spin_unlock(vmf->ptl);
diff --git a/mm/memory.c b/mm/memory.c
index 8933069948e5..39839bf0c3f5 100644
--- a/mm/memory.c
+++ b/mm/memory.c
@@ -6193,7 +6193,7 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf)
{
pte_t entry;
- if (unlikely(pmd_none(*vmf->pmd))) {
+ if (unlikely(pmd_none(pmdp_get(vmf->pmd)))) {
/*
* Leave __pte_alloc() until later: because vm_ops->fault may
* want to allocate huge page, and if we expose page table
@@ -6309,13 +6309,13 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma,
if (!vmf.pud)
return VM_FAULT_OOM;
retry_pud:
- if (pud_none(*vmf.pud) &&
+ if (pud_none(pudp_get(vmf.pud)) &&
thp_vma_allowable_order(vma, vm_flags, TVA_PAGEFAULT, PUD_ORDER)) {
ret = create_huge_pud(&vmf);
if (!(ret & VM_FAULT_FALLBACK))
return ret;
} else {
- pud_t orig_pud = *vmf.pud;
+ pud_t orig_pud = pudp_get(vmf.pud);
barrier();
if (pud_trans_huge(orig_pud)) {
@@ -6343,7 +6343,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma,
if (pud_trans_unstable(vmf.pud))
goto retry_pud;
- if (pmd_none(*vmf.pmd) &&
+ if (pmd_none(pmdp_get(vmf.pmd)) &&
thp_vma_allowable_order(vma, vm_flags, TVA_PAGEFAULT, PMD_ORDER)) {
ret = create_huge_pmd(&vmf);
if (ret & VM_FAULT_FALLBACK)
--
2.34.1
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] mm: use standard page table accessors
2025-11-26 6:47 [PATCH] mm: use standard page table accessors Wei Yang
@ 2025-11-26 8:15 ` Christophe Leroy (CS GROUP)
2025-11-26 10:03 ` Wei Yang
2025-11-26 9:09 ` David Hildenbrand (Red Hat)
1 sibling, 1 reply; 9+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2025-11-26 8:15 UTC (permalink / raw)
To: Wei Yang, akpm, david, lorenzo.stoakes, Liam.Howlett, vbabka,
rppt, surenb, mhocko, ziy, baolin.wang, npache, ryan.roberts,
dev.jain, baohua, lance.yang
Cc: linux-mm
Le 26/11/2025 à 07:47, Wei Yang a écrit :
> Use standard page table accessors i.e pxdp_get() to get the value of
> pxdp.
Please provide more detail of why you want to do that and how you are
sure it doesn't break existing implementation.
There was similar tentative in the past already which proved to give
suboptimal results, see discussion here:
https://lore.kernel.org/all/f40ea8bf-0862-41a7-af19-70bfbd838568@csgroup.eu/
Christophe
>
> Signed-off-by: Wei Yang <richard.weiyang@gmail.com>
> ---
> include/linux/pgtable.h | 2 +-
> mm/huge_memory.c | 2 +-
> mm/memory.c | 8 ++++----
> 3 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h
> index b13b6f42be3c..a9efd58658bc 100644
> --- a/include/linux/pgtable.h
> +++ b/include/linux/pgtable.h
> @@ -1810,7 +1810,7 @@ static inline int pud_trans_unstable(pud_t *pud)
> {
> #if defined(CONFIG_TRANSPARENT_HUGEPAGE) && \
> defined(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD)
> - pud_t pudval = READ_ONCE(*pud);
> + pud_t pudval = pudp_get(pud);
>
> if (pud_none(pudval) || pud_trans_huge(pudval))
> return 1;
> diff --git a/mm/huge_memory.c b/mm/huge_memory.c
> index 0d2ac331ccad..dd3577e40d16 100644
> --- a/mm/huge_memory.c
> +++ b/mm/huge_memory.c
> @@ -1486,7 +1486,7 @@ vm_fault_t do_huge_pmd_anonymous_page(struct vm_fault *vmf)
> }
> vmf->ptl = pmd_lock(vma->vm_mm, vmf->pmd);
> ret = 0;
> - if (pmd_none(*vmf->pmd)) {
> + if (pmd_none(pmdp_get(vmf->pmd))) {
> ret = check_stable_address_space(vma->vm_mm);
> if (ret) {
> spin_unlock(vmf->ptl);
> diff --git a/mm/memory.c b/mm/memory.c
> index 8933069948e5..39839bf0c3f5 100644
> --- a/mm/memory.c
> +++ b/mm/memory.c
> @@ -6193,7 +6193,7 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf)
> {
> pte_t entry;
>
> - if (unlikely(pmd_none(*vmf->pmd))) {
> + if (unlikely(pmd_none(pmdp_get(vmf->pmd)))) {
> /*
> * Leave __pte_alloc() until later: because vm_ops->fault may
> * want to allocate huge page, and if we expose page table
> @@ -6309,13 +6309,13 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma,
> if (!vmf.pud)
> return VM_FAULT_OOM;
> retry_pud:
> - if (pud_none(*vmf.pud) &&
> + if (pud_none(pudp_get(vmf.pud)) &&
> thp_vma_allowable_order(vma, vm_flags, TVA_PAGEFAULT, PUD_ORDER)) {
> ret = create_huge_pud(&vmf);
> if (!(ret & VM_FAULT_FALLBACK))
> return ret;
> } else {
> - pud_t orig_pud = *vmf.pud;
> + pud_t orig_pud = pudp_get(vmf.pud);
>
> barrier();
> if (pud_trans_huge(orig_pud)) {
> @@ -6343,7 +6343,7 @@ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma,
> if (pud_trans_unstable(vmf.pud))
> goto retry_pud;
>
> - if (pmd_none(*vmf.pmd) &&
> + if (pmd_none(pmdp_get(vmf.pmd)) &&
> thp_vma_allowable_order(vma, vm_flags, TVA_PAGEFAULT, PMD_ORDER)) {
> ret = create_huge_pmd(&vmf);
> if (ret & VM_FAULT_FALLBACK)
^ permalink raw reply [flat|nested] 9+ messages in thread* Re: [PATCH] mm: use standard page table accessors
2025-11-26 8:15 ` Christophe Leroy (CS GROUP)
@ 2025-11-26 10:03 ` Wei Yang
2025-11-26 10:28 ` Christophe Leroy (CS GROUP)
0 siblings, 1 reply; 9+ messages in thread
From: Wei Yang @ 2025-11-26 10:03 UTC (permalink / raw)
To: Christophe Leroy (CS GROUP)
Cc: Wei Yang, akpm, david, lorenzo.stoakes, Liam.Howlett, vbabka,
rppt, surenb, mhocko, ziy, baolin.wang, npache, ryan.roberts,
dev.jain, baohua, lance.yang, linux-mm
On Wed, Nov 26, 2025 at 09:15:24AM +0100, Christophe Leroy (CS GROUP) wrote:
>
>
>Le 26/11/2025 à 07:47, Wei Yang a écrit :
>> Use standard page table accessors i.e pxdp_get() to get the value of
>> pxdp.
>
>Please provide more detail of why you want to do that and how you are sure it
>doesn't break existing implementation.
>
>There was similar tentative in the past already which proved to give
>suboptimal results, see discussion here:
>
>https://lore.kernel.org/all/f40ea8bf-0862-41a7-af19-70bfbd838568@csgroup.eu/
Interesting.
The reason is P4D/PUD/PMD on PPC32 actually just has PGD/PMD. So it is not
necessary to retrieve P4D and PUD.
If this is the case, sounds other platform with less pagetable level would be
affected too.
And this looks only affect when we walk the pagetable from pgd. If we just
iterating pmd/pte, we won't have this issue, right?
>
>Christophe
--
Wei Yang
Help you, Help me
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mm: use standard page table accessors
2025-11-26 10:03 ` Wei Yang
@ 2025-11-26 10:28 ` Christophe Leroy (CS GROUP)
2025-11-26 12:15 ` Wei Yang
0 siblings, 1 reply; 9+ messages in thread
From: Christophe Leroy (CS GROUP) @ 2025-11-26 10:28 UTC (permalink / raw)
To: Wei Yang
Cc: akpm, david, lorenzo.stoakes, Liam.Howlett, vbabka, rppt, surenb,
mhocko, ziy, baolin.wang, npache, ryan.roberts, dev.jain, baohua,
lance.yang, linux-mm
Le 26/11/2025 à 11:03, Wei Yang a écrit :
> On Wed, Nov 26, 2025 at 09:15:24AM +0100, Christophe Leroy (CS GROUP) wrote:
>>
>>
>> Le 26/11/2025 à 07:47, Wei Yang a écrit :
>>> Use standard page table accessors i.e pxdp_get() to get the value of
>>> pxdp.
>>
>> Please provide more detail of why you want to do that and how you are sure it
>> doesn't break existing implementation.
>>
>> There was similar tentative in the past already which proved to give
>> suboptimal results, see discussion here:
>>
>> https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2Ff40ea8bf-0862-41a7-af19-70bfbd838568%40csgroup.eu%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C63a7608567de4df0a16308de2cd31076%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638997482180349327%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=ly4LRRjkKqQNBY6ZpkbHS7%2B0xuu2c1r0op1eysPtbSQ%3D&reserved=0
>
> Interesting.
>
> The reason is P4D/PUD/PMD on PPC32 actually just has PGD/PMD. So it is not
> necessary to retrieve P4D and PUD.
More exactly, PPC32 just has PGD and PTE, no PMD either:
arch/powerpc/include/asm/book3s/32/pgtable.h:#include
<asm-generic/pgtable-nopmd.h>
arch/powerpc/include/asm/nohash/32/pgtable.h:#include
<asm-generic/pgtable-nopmd.h>
>
> If this is the case, sounds other platform with less pagetable level would be
> affected too.
Indeed.
>
> And this looks only affect when we walk the pagetable from pgd. If we just
> iterating pmd/pte, we won't have this issue, right?
Maybe. I have not looked at your changes in details, it just lit up a
memory in my mind.
Christophe
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mm: use standard page table accessors
2025-11-26 10:28 ` Christophe Leroy (CS GROUP)
@ 2025-11-26 12:15 ` Wei Yang
0 siblings, 0 replies; 9+ messages in thread
From: Wei Yang @ 2025-11-26 12:15 UTC (permalink / raw)
To: Christophe Leroy (CS GROUP)
Cc: Wei Yang, akpm, david, lorenzo.stoakes, Liam.Howlett, vbabka,
rppt, surenb, mhocko, ziy, baolin.wang, npache, ryan.roberts,
dev.jain, baohua, lance.yang, linux-mm
On Wed, Nov 26, 2025 at 11:28:37AM +0100, Christophe Leroy (CS GROUP) wrote:
>
>
>Le 26/11/2025 à 11:03, Wei Yang a écrit :
>> On Wed, Nov 26, 2025 at 09:15:24AM +0100, Christophe Leroy (CS GROUP) wrote:
>> >
>> >
>> > Le 26/11/2025 à 07:47, Wei Yang a écrit :
>> > > Use standard page table accessors i.e pxdp_get() to get the value of
>> > > pxdp.
>> >
>> > Please provide more detail of why you want to do that and how you are sure it
>> > doesn't break existing implementation.
>> >
>> > There was similar tentative in the past already which proved to give
>> > suboptimal results, see discussion here:
>> >
>> > https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2Ff40ea8bf-0862-41a7-af19-70bfbd838568%40csgroup.eu%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C63a7608567de4df0a16308de2cd31076%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638997482180349327%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=ly4LRRjkKqQNBY6ZpkbHS7%2B0xuu2c1r0op1eysPtbSQ%3D&reserved=0
>>
>> Interesting.
>>
>> The reason is P4D/PUD/PMD on PPC32 actually just has PGD/PMD. So it is not
>> necessary to retrieve P4D and PUD.
>
>More exactly, PPC32 just has PGD and PTE, no PMD either:
>
>arch/powerpc/include/asm/book3s/32/pgtable.h:#include
><asm-generic/pgtable-nopmd.h>
>arch/powerpc/include/asm/nohash/32/pgtable.h:#include
><asm-generic/pgtable-nopmd.h>
>
>
>>
>> If this is the case, sounds other platform with less pagetable level would be
>> affected too.
>
>Indeed.
>
>>
>> And this looks only affect when we walk the pagetable from pgd. If we just
>> iterating pmd/pte, we won't have this issue, right?
>
>Maybe. I have not looked at your changes in details, it just lit up a memory
>in my mind.
>
Thanks for noticing me this, I learned a lesson from you :-)
>Christophe
--
Wei Yang
Help you, Help me
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mm: use standard page table accessors
2025-11-26 6:47 [PATCH] mm: use standard page table accessors Wei Yang
2025-11-26 8:15 ` Christophe Leroy (CS GROUP)
@ 2025-11-26 9:09 ` David Hildenbrand (Red Hat)
2025-11-26 9:42 ` Wei Yang
2025-11-26 10:19 ` Ryan Roberts
1 sibling, 2 replies; 9+ messages in thread
From: David Hildenbrand (Red Hat) @ 2025-11-26 9:09 UTC (permalink / raw)
To: Wei Yang, akpm, lorenzo.stoakes, Liam.Howlett, vbabka, rppt,
surenb, mhocko, ziy, baolin.wang, npache, ryan.roberts, dev.jain,
baohua, lance.yang
Cc: linux-mm
On 11/26/25 07:47, Wei Yang wrote:
> Use standard page table accessors i.e pxdp_get() to get the value of
> pxdp.
>
Isn't this covered by
https://lkml.kernel.org/r/20251113014656.2605447-1-samuel.holland@sifive.com
In particular
https://lkml.kernel.org/r/20251113014656.2605447-7-samuel.holland@sifive.com
?
--
Cheers
David
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mm: use standard page table accessors
2025-11-26 9:09 ` David Hildenbrand (Red Hat)
@ 2025-11-26 9:42 ` Wei Yang
2025-11-26 10:19 ` Ryan Roberts
1 sibling, 0 replies; 9+ messages in thread
From: Wei Yang @ 2025-11-26 9:42 UTC (permalink / raw)
To: David Hildenbrand (Red Hat)
Cc: Wei Yang, akpm, lorenzo.stoakes, Liam.Howlett, vbabka, rppt,
surenb, mhocko, ziy, baolin.wang, npache, ryan.roberts, dev.jain,
baohua, lance.yang, linux-mm
On Wed, Nov 26, 2025 at 10:09:20AM +0100, David Hildenbrand (Red Hat) wrote:
>On 11/26/25 07:47, Wei Yang wrote:
>> Use standard page table accessors i.e pxdp_get() to get the value of
>> pxdp.
>>
>
>Isn't this covered by
>
>https://lkml.kernel.org/r/20251113014656.2605447-1-samuel.holland@sifive.com
>
>In particular
>
>https://lkml.kernel.org/r/20251113014656.2605447-7-samuel.holland@sifive.com
>
>?
>
You are right, just see it.
--
Wei Yang
Help you, Help me
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mm: use standard page table accessors
2025-11-26 9:09 ` David Hildenbrand (Red Hat)
2025-11-26 9:42 ` Wei Yang
@ 2025-11-26 10:19 ` Ryan Roberts
2025-11-26 11:32 ` Ryan Roberts
1 sibling, 1 reply; 9+ messages in thread
From: Ryan Roberts @ 2025-11-26 10:19 UTC (permalink / raw)
To: David Hildenbrand (Red Hat),
Wei Yang, akpm, lorenzo.stoakes, Liam.Howlett, vbabka, rppt,
surenb, mhocko, ziy, baolin.wang, npache, dev.jain, baohua,
lance.yang, Anshuman Khandual
Cc: linux-mm
+ Anshuman
On 26/11/2025 09:09, David Hildenbrand (Red Hat) wrote:
> On 11/26/25 07:47, Wei Yang wrote:
>> Use standard page table accessors i.e pxdp_get() to get the value of
>> pxdp.
>>
>
> Isn't this covered by
>
> https://lkml.kernel.org/r/20251113014656.2605447-1-samuel.holland@sifive.com
>
> In particular
>
> https://lkml.kernel.org/r/20251113014656.2605447-7-samuel.holland@sifive.com
>
> ?
Ahh this is very interesting - I wasn't aware of this new attempt! We could
benefit from this on arm64 too.
We have some experience and opinions about this; I'll reply to the patch with
some details...
But as for this patch, I don't see the value in changing just a few instances.
I'd prefer to see it converted systematically, taking into consideration all the
complexities.
Thanks,
Ryan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] mm: use standard page table accessors
2025-11-26 10:19 ` Ryan Roberts
@ 2025-11-26 11:32 ` Ryan Roberts
0 siblings, 0 replies; 9+ messages in thread
From: Ryan Roberts @ 2025-11-26 11:32 UTC (permalink / raw)
To: David Hildenbrand (Red Hat),
Wei Yang, akpm, lorenzo.stoakes, Liam.Howlett, vbabka, rppt,
surenb, mhocko, ziy, baolin.wang, npache, dev.jain, baohua,
lance.yang, Anshuman Khandual
Cc: linux-mm
On 26/11/2025 10:19, Ryan Roberts wrote:
> + Anshuman
>
> On 26/11/2025 09:09, David Hildenbrand (Red Hat) wrote:
>> On 11/26/25 07:47, Wei Yang wrote:
>>> Use standard page table accessors i.e pxdp_get() to get the value of
>>> pxdp.
>>>
>>
>> Isn't this covered by
>>
>> https://lkml.kernel.org/r/20251113014656.2605447-1-samuel.holland@sifive.com
>>
>> In particular
>>
>> https://lkml.kernel.org/r/20251113014656.2605447-7-samuel.holland@sifive.com
>>
>> ?
>
> Ahh this is very interesting - I wasn't aware of this new attempt! We could
> benefit from this on arm64 too.
>
> We have some experience and opinions about this; I'll reply to the patch with
> some details...
https://lore.kernel.org/all/02e3b3bd-ae6a-4db4-b4a1-8cbc1bc0a1c8@arm.com/
>
> But as for this patch, I don't see the value in changing just a few instances.
> I'd prefer to see it converted systematically, taking into consideration all the
> complexities.
>
> Thanks,
> Ryan
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2025-11-26 12:15 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-11-26 6:47 [PATCH] mm: use standard page table accessors Wei Yang
2025-11-26 8:15 ` Christophe Leroy (CS GROUP)
2025-11-26 10:03 ` Wei Yang
2025-11-26 10:28 ` Christophe Leroy (CS GROUP)
2025-11-26 12:15 ` Wei Yang
2025-11-26 9:09 ` David Hildenbrand (Red Hat)
2025-11-26 9:42 ` Wei Yang
2025-11-26 10:19 ` Ryan Roberts
2025-11-26 11:32 ` Ryan Roberts
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox