[PATCH v2 6/7] x86/mm: remove p4d_leaf definition

Baoquan He posted 7 patches 8 months, 3 weeks ago
There is a newer version of this series
[PATCH v2 6/7] x86/mm: remove p4d_leaf definition
Posted by Baoquan He 8 months, 3 weeks ago
There's no p4d huge page support yet, let's use the generic definition.

And also update the BUILD_BUG_ON() in pti_user_pagetable_walk_pmd()
because p4d_leaf() returns boolean value.

Signed-off-by: Baoquan He <bhe@redhat.com>
Cc: x86@kernel.org
---
 arch/x86/include/asm/pgtable.h | 7 -------
 arch/x86/mm/pti.c              | 2 +-
 2 files changed, 1 insertion(+), 8 deletions(-)

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 5f4fcc0eea17..5ddba366d3b4 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -292,13 +292,6 @@ static inline unsigned long pgd_pfn(pgd_t pgd)
 	return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
 }
 
-#define p4d_leaf p4d_leaf
-static inline bool p4d_leaf(p4d_t p4d)
-{
-	/* No 512 GiB pages yet */
-	return 0;
-}
-
 #define pte_page(pte)	pfn_to_page(pte_pfn(pte))
 
 #define pmd_leaf pmd_leaf
diff --git a/arch/x86/mm/pti.c b/arch/x86/mm/pti.c
index c2e1de40136f..190299834011 100644
--- a/arch/x86/mm/pti.c
+++ b/arch/x86/mm/pti.c
@@ -206,7 +206,7 @@ static pmd_t *pti_user_pagetable_walk_pmd(unsigned long address)
 	if (!p4d)
 		return NULL;
 
-	BUILD_BUG_ON(p4d_leaf(*p4d) != 0);
+	BUILD_BUG_ON(p4d_leaf(*p4d));
 	if (p4d_none(*p4d)) {
 		unsigned long new_pud_page = __get_free_page(gfp);
 		if (WARN_ON_ONCE(!new_pud_page))
-- 
2.41.0
Re: [PATCH v2 6/7] x86/mm: remove p4d_leaf definition
Posted by Oscar Salvador 8 months, 3 weeks ago
On Mon, Mar 31, 2025 at 04:13:26PM +0800, Baoquan He wrote:
> There's no p4d huge page support yet, let's use the generic definition.
> 
> And also update the BUILD_BUG_ON() in pti_user_pagetable_walk_pmd()
> because p4d_leaf() returns boolean value.
> 
> Signed-off-by: Baoquan He <bhe@redhat.com>
> Cc: x86@kernel.org

Reviewed-by: Oscar Salvador <osalvador@suse.de>


-- 
Oscar Salvador
SUSE Labs
Re: [PATCH v2 6/7] x86/mm: remove p4d_leaf definition
Posted by Ingo Molnar 8 months, 3 weeks ago
* Baoquan He <bhe@redhat.com> wrote:

> There's no p4d huge page support yet, let's use the generic definition.
> 
> And also update the BUILD_BUG_ON() in pti_user_pagetable_walk_pmd()
> because p4d_leaf() returns boolean value.


> -#define p4d_leaf p4d_leaf
> -static inline bool p4d_leaf(p4d_t p4d)
> -{
> -	/* No 512 GiB pages yet */
> -	return 0;
> -}

This comment was also incorrect I believe:

1 PTE entry on x86-64 covers 4K virtual memory, 512 PTE entries make up 
a 4K pagetable page, and each level of paging adds another level of 512 
pagetable entries:

 - level 0:                 4K pages
 - level 1: 512x    4K =   2MB 'large' pages
 - level 2: 512x   2MB =   1GB 'huge' pages
 - level 3: 512x   1GB = 512GB 'PGD' pages
 - level 4: 512x 512GB = 256TB 'P4D' pages

So the above comment should have said '256 TB' pages, unless there's 
some naming weirdness I missed.

Thanks,

	Ingo
Re: [PATCH v2 6/7] x86/mm: remove p4d_leaf definition
Posted by Baoquan He 8 months, 3 weeks ago
On 03/31/25 at 11:57am, Ingo Molnar wrote:
> 
> * Baoquan He <bhe@redhat.com> wrote:
> 
> > There's no p4d huge page support yet, let's use the generic definition.
> > 
> > And also update the BUILD_BUG_ON() in pti_user_pagetable_walk_pmd()
> > because p4d_leaf() returns boolean value.

Thanks a lot for cleaning up the patch logs and rearranging x86 patches
into tip tree.

> 
> 
> > -#define p4d_leaf p4d_leaf
> > -static inline bool p4d_leaf(p4d_t p4d)
> > -{
> > -	/* No 512 GiB pages yet */
> > -	return 0;
> > -}
> 
> This comment was also incorrect I believe:
> 
> 1 PTE entry on x86-64 covers 4K virtual memory, 512 PTE entries make up 
> a 4K pagetable page, and each level of paging adds another level of 512 
> pagetable entries:
> 
>  - level 0:                 4K pages
>  - level 1: 512x    4K =   2MB 'large' pages
>  - level 2: 512x   2MB =   1GB 'huge' pages
>  - level 3: 512x   1GB = 512GB 'PGD' pages
>  - level 4: 512x 512GB = 256TB 'P4D' pages
> 
> So the above comment should have said '256 TB' pages, unless there's 
> some naming weirdness I missed.

Hmm, there could be misunderstanding here. In 5-level paging, PGD is the
highest level, P4D is the next level of PGD. You may have reversed their
order. So one P4D entry maps one PUD table which is 512 x 1GB. Then the
mentioned comment seems correct to me.
Re: [PATCH v2 6/7] x86/mm: remove p4d_leaf definition
Posted by Ingo Molnar 8 months, 3 weeks ago
* Baoquan He <bhe@redhat.com> wrote:

> > So the above comment should have said '256 TB' pages, unless 
> > there's some naming weirdness I missed.
> 
> Hmm, there could be misunderstanding here. In 5-level paging, PGD is 
> the highest level, P4D is the next level of PGD. You may have 
> reversed their order.

Erm, yes indeed I flipped those two, so the correct table should be:

  - level 0:                 4K pages
  - level 1: 512x    4K =   2MB 'large' pages
  - level 2: 512x   2MB =   1GB 'huge' pages
  - level 3: 512x   1GB = 512GB 'P4D' pages
  - level 4: 512x 512GB = 256TB 'PGD' pages

I'm wondering whether 512GB pages will be called 'terapages'. ;-)

Thanks,

	Ingo
Re: [PATCH v2 6/7] x86/mm: remove p4d_leaf definition
Posted by Baoquan He 8 months, 2 weeks ago
On 04/01/25 at 09:20am, Ingo Molnar wrote:
> 
> * Baoquan He <bhe@redhat.com> wrote:
> 
> > > So the above comment should have said '256 TB' pages, unless 
> > > there's some naming weirdness I missed.
> > 
> > Hmm, there could be misunderstanding here. In 5-level paging, PGD is 
> > the highest level, P4D is the next level of PGD. You may have 
> > reversed their order.
> 
> Erm, yes indeed I flipped those two, so the correct table should be:
> 
>   - level 0:                 4K pages
>   - level 1: 512x    4K =   2MB 'large' pages
>   - level 2: 512x   2MB =   1GB 'huge' pages
>   - level 3: 512x   1GB = 512GB 'P4D' pages
>   - level 4: 512x 512GB = 256TB 'PGD' pages
> 
> I'm wondering whether 512GB pages will be called 'terapages'. ;-)

Forgot replying to this one.

With my understanding, MM usually don't name large page of different
size a specific name, just call them hugepage + size, e.g 2M huge page,
or 1G huge page. Sometime when we build mapping for them, we will call
them PMD hugepage or PUD hugepage.

I remember in x86 ARCH direct mapping is built with invocation of
init_mem_mapping(), and the mapping to 2M or 1G directly is called
large page mapping or PMD/PUD huge page mapping. They are similar.

Hope other MM people can correct me if I am wrong.
[tip: x86/mm] x86/mm: Remove the arch-specific p4d_leaf() definition
Posted by tip-bot2 for Baoquan He 8 months, 3 weeks ago
The following commit has been merged into the x86/mm branch of tip:

Commit-ID:     c083eff324edd73eb23f4bd3f40f388a3e7c2cd2
Gitweb:        https://git.kernel.org/tip/c083eff324edd73eb23f4bd3f40f388a3e7c2cd2
Author:        Baoquan He <bhe@redhat.com>
AuthorDate:    Mon, 31 Mar 2025 16:13:26 +08:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 01 Apr 2025 22:48:51 +02:00

x86/mm: Remove the arch-specific p4d_leaf() definition

P4D huge pages are not supported yet, let's use the generic definition
in <linux/pgtable.h>.

[ mingo: Cleaned up the changelog. ]

Signed-off-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Oscar Salvador <osalvador@suse.de>
Link: https://lore.kernel.org/r/20250331081327.256412-7-bhe@redhat.com
---
 arch/x86/include/asm/pgtable.h | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 5f4fcc0..5ddba36 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -292,13 +292,6 @@ static inline unsigned long pgd_pfn(pgd_t pgd)
 	return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
 }
 
-#define p4d_leaf p4d_leaf
-static inline bool p4d_leaf(p4d_t p4d)
-{
-	/* No 512 GiB pages yet */
-	return 0;
-}
-
 #define pte_page(pte)	pfn_to_page(pte_pfn(pte))
 
 #define pmd_leaf pmd_leaf
[tip: x86/mm] x86/mm: Remove the arch-specific p4d_leaf() definition
Posted by tip-bot2 for Baoquan He 8 months, 3 weeks ago
The following commit has been merged into the x86/mm branch of tip:

Commit-ID:     06e6e99da66cfca1ebac52c09c3a025ef5ccf959
Gitweb:        https://git.kernel.org/tip/06e6e99da66cfca1ebac52c09c3a025ef5ccf959
Author:        Baoquan He <bhe@redhat.com>
AuthorDate:    Mon, 31 Mar 2025 16:13:26 +08:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Tue, 01 Apr 2025 22:47:02 +02:00

x86/mm: Remove the arch-specific p4d_leaf() definition

P4D huge pages are not supported yet, let's use the generic definition
in <linux/pgtable.h>.

[ mingo: Cleaned up the changelog. ]

Signed-off-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20250331081327.256412-7-bhe@redhat.com
---
 arch/x86/include/asm/pgtable.h | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 5f4fcc0..5ddba36 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -292,13 +292,6 @@ static inline unsigned long pgd_pfn(pgd_t pgd)
 	return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
 }
 
-#define p4d_leaf p4d_leaf
-static inline bool p4d_leaf(p4d_t p4d)
-{
-	/* No 512 GiB pages yet */
-	return 0;
-}
-
 #define pte_page(pte)	pfn_to_page(pte_pfn(pte))
 
 #define pmd_leaf pmd_leaf
[tip: x86/mm] x86/mm: Remove the arch-specific p4d_leaf() definition
Posted by tip-bot2 for Baoquan He 8 months, 3 weeks ago
The following commit has been merged into the x86/mm branch of tip:

Commit-ID:     3532c1f79ffcc57d14b8387a67b01797cc0e8be0
Gitweb:        https://git.kernel.org/tip/3532c1f79ffcc57d14b8387a67b01797cc0e8be0
Author:        Baoquan He <bhe@redhat.com>
AuthorDate:    Mon, 31 Mar 2025 16:13:26 +08:00
Committer:     Ingo Molnar <mingo@kernel.org>
CommitterDate: Mon, 31 Mar 2025 12:08:17 +02:00

x86/mm: Remove the arch-specific p4d_leaf() definition

P4D huge pages are not supported yet, let's use the generic definition
in <linux/pgtable.h>.

[ mingo: Cleaned up the changelog. ]

Signed-off-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20250331081327.256412-7-bhe@redhat.com
---
 arch/x86/include/asm/pgtable.h | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
index 5f4fcc0..5ddba36 100644
--- a/arch/x86/include/asm/pgtable.h
+++ b/arch/x86/include/asm/pgtable.h
@@ -292,13 +292,6 @@ static inline unsigned long pgd_pfn(pgd_t pgd)
 	return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
 }
 
-#define p4d_leaf p4d_leaf
-static inline bool p4d_leaf(p4d_t p4d)
-{
-	/* No 512 GiB pages yet */
-	return 0;
-}
-
 #define pte_page(pte)	pfn_to_page(pte_pfn(pte))
 
 #define pmd_leaf pmd_leaf