Skip to contentSkip to conversation

mm: use standard page table accessors

PATCH In review Wei Yang 4 participants 9 messages Nov 26, 2025

Subsystems (3)
lore
Share & tools
lore

Wei Yang

author
#0 lore raw

PATCH 1/1 mm: use standard page table accessors

Use standard page table accessors i.e pxdp_get() to get the value of pxdp.

---
 include/linux/pgtable.h | 2 +-
 mm/huge_memory.c        | 2 +-
 mm/memory.c             | 8 ++++----
 3 files changed, 6 insertions(+), 6 deletions(-)
include/linux/pgtable.h +1 -1
index b13b6f42be3c..a9efd58658bc 100644
@@ -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;
mm/huge_memory.c +1 -1
index 0d2ac331ccad..dd3577e40d16 100644
@@ -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);
mm/memory.c +4 -4
index 8933069948e5..39839bf0c3f5 100644
@@ -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)
Signature · 1 line
2.34.1
#1 lore raw

Le 26/11/2025 à 07:47, Wei Yang a écrit :

Quoted 2 lines

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/[email protected]/

Christophe

Quoted 72 lines
---
  include/linux/pgtable.h | 2 +-
  mm/huge_memory.c        | 2 +-
  mm/memory.c             | 8 ++++----
  3 files changed, 6 insertions(+), 6 deletions(-)
include/linux/pgtable.h +1 -1
index b13b6f42be3c..a9efd58658bc 100644
@@ -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;
mm/huge_memory.c +1 -1
index 0d2ac331ccad..dd3577e40d16 100644
@@ -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);
mm/memory.c +4 -4
index 8933069948e5..39839bf0c3f5 100644
@@ -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)
author
#2 lore raw
Quoted 6 lines · Christophe Leroy (CS GROUP)

Le 26/11/2025 à 07:47, Wei Yang a écrit :

Quoted 2 lines

Use standard page table accessors i.e pxdp_get() to get the value of pxdp.

Quoted 7 lines

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/[email protected]/

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?

Quoted 2 lines

Christophe

Signature · 2 lines
Wei Yang
Help you, Help me
#3 lore raw

Le 26/11/2025 à 11:03, Wei Yang a écrit :

Quoted 13 lines · Christophe Leroy (CS GROUP)
Quoted 12 lines

Le 26/11/2025 à 07:47, Wei Yang a écrit :

Quoted 2 lines

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:

Quoted 6 lines
Quoted 1 line

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>

Quoted 3 lines

If this is the case, sounds other platform with less pagetable level would be affected too.

Indeed.

Quoted 3 lines

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

author
#4 lore raw
Quoted 35 lines · Christophe Leroy (CS GROUP)

Le 26/11/2025 à 11:03, Wei Yang a écrit :

Quoted 13 lines · Christophe Leroy (CS GROUP)
Quoted 12 lines

Le 26/11/2025 à 07:47, Wei Yang a écrit :

Quoted 2 lines

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:

Quoted 6 lines
Quoted 1 line

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>

Quoted 3 lines

If this is the case, sounds other platform with less pagetable level would be affected too.

Quoted 9 lines

Indeed.

Quoted 3 lines

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 :-)

Quoted 1 line

Christophe

Signature · 2 lines
Wei Yang
Help you, Help me
reviewer
#7 lore raw
In reply to David Hildenbrand (Red Hat)

+ Anshuman

Quoted 7 lines · David Hildenbrand (Red Hat)
Quoted 3 lines · Wei Yang

Use standard page table accessors i.e pxdp_get() to get the value of pxdp.

Isn't this covered by

Quoted 7 lines

https://lkml.kernel.org/r/[email protected]

In particular

https://lkml.kernel.org/r/[email protected]

?

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

reviewer
#8 lore raw
Quoted 16 lines · Ryan Roberts

+ Anshuman

Quoted 13 lines · David Hildenbrand (Red Hat)
Quoted 3 lines · Wei Yang

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/[email protected]

In particular

https://lkml.kernel.org/r/[email protected]

Quoted 7 lines
Quoted 1 line

?

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/[email protected]/

Quoted 8 lines

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