Message ID | ab93995d27055f055249e1e8770b22f89c980322.1715971869.git.christophe.leroy@csgroup.eu (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | Reimplement huge pages without hugepd on powerpc (8xx, e500, book3s/64) | expand |
On Fri, May 17, 2024 at 08:59:57PM +0200, Christophe Leroy wrote: > On powerpc 8xx, when a page is 8M size, the information is in the PMD > entry. So provide it to pte_leaf_size(). > > Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> Overall looks good to me. Would be nicer if we could left the arch code untouched. I wanted to see how this would be if we go down that road and focus only on 8xx at the risk of being more esoteric. pmd_pte_leaf_size() is a name of hell, but could be replaced with __pte_leaf_size for example. Worth it? Maybe not, anyway, just wanted to give it a go: diff --git a/arch/powerpc/include/asm/nohash/32/pte-8xx.h b/arch/powerpc/include/asm/nohash/32/pte-8xx.h index 137dc3c84e45..9e3fe6e1083f 100644 --- a/arch/powerpc/include/asm/nohash/32/pte-8xx.h +++ b/arch/powerpc/include/asm/nohash/32/pte-8xx.h @@ -151,7 +151,7 @@ static inline unsigned long pgd_leaf_size(pgd_t pgd) #define pgd_leaf_size pgd_leaf_size -static inline unsigned long pte_leaf_size(pte_t pte) +static inline unsigned long pmd_pte_leaf_size(pte_t pte) { pte_basic_t val = pte_val(pte); @@ -162,7 +162,7 @@ static inline unsigned long pte_leaf_size(pte_t pte) return SZ_4K; } -#define pte_leaf_size pte_leaf_size +#define pmd_pte_leaf_size pmd_pte_leaf_size /* * On the 8xx, the page tables are a bit special. For 16k pages, we have diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 18019f037bae..2bc2fe3b2b53 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1891,6 +1891,9 @@ typedef unsigned int pgtbl_mod_mask; #ifndef pte_leaf_size #define pte_leaf_size(x) PAGE_SIZE #endif +#ifndef pmd_pte_leaf_size +#define pmd_pte_leaf_size(x, y) pte_leaf_size(y) +#endif /* * We always define pmd_pfn for all archs as it's used in lots of generic diff --git a/kernel/events/core.c b/kernel/events/core.c index f0128c5ff278..e90a547d2fb2 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7596,7 +7596,7 @@ static u64 perf_get_pgtable_size(struct mm_struct *mm, unsigned long addr) pte = ptep_get_lockless(ptep); if (pte_present(pte)) - size = pte_leaf_size(pte); + size = pmd_pte_leaf_size(pmd, pte); pte_unmap(ptep); #endif /* CONFIG_HAVE_GUP_FAST */
Le 21/05/2024 à 11:39, Oscar Salvador a écrit : > On Fri, May 17, 2024 at 08:59:57PM +0200, Christophe Leroy wrote: >> On powerpc 8xx, when a page is 8M size, the information is in the PMD >> entry. So provide it to pte_leaf_size(). >> >> Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> > > Overall looks good to me. > > Would be nicer if we could left the arch code untouched. > I wanted to see how this would be if we go down that road and focus only > on 8xx at the risk of being more esoteric. > pmd_pte_leaf_size() is a name of hell, but could be replaced > with __pte_leaf_size for example. > > Worth it? Maybe not, anyway, just wanted to give it a go: I like the idea, it doesn't look that bad after all, it avoids changes to other arches. > > > diff --git a/arch/powerpc/include/asm/nohash/32/pte-8xx.h b/arch/powerpc/include/asm/nohash/32/pte-8xx.h > index 137dc3c84e45..9e3fe6e1083f 100644 > --- a/arch/powerpc/include/asm/nohash/32/pte-8xx.h > +++ b/arch/powerpc/include/asm/nohash/32/pte-8xx.h > @@ -151,7 +151,7 @@ static inline unsigned long pgd_leaf_size(pgd_t pgd) > > #define pgd_leaf_size pgd_leaf_size > > -static inline unsigned long pte_leaf_size(pte_t pte) > +static inline unsigned long pmd_pte_leaf_size(pte_t pte) > { > pte_basic_t val = pte_val(pte); > > @@ -162,7 +162,7 @@ static inline unsigned long pte_leaf_size(pte_t pte) > return SZ_4K; > } > > -#define pte_leaf_size pte_leaf_size > +#define pmd_pte_leaf_size pmd_pte_leaf_size > > /* > * On the 8xx, the page tables are a bit special. For 16k pages, we have > diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h > index 18019f037bae..2bc2fe3b2b53 100644 > --- a/include/linux/pgtable.h > +++ b/include/linux/pgtable.h > @@ -1891,6 +1891,9 @@ typedef unsigned int pgtbl_mod_mask; > #ifndef pte_leaf_size > #define pte_leaf_size(x) PAGE_SIZE > #endif > +#ifndef pmd_pte_leaf_size > +#define pmd_pte_leaf_size(x, y) pte_leaf_size(y) > +#endif > > /* > * We always define pmd_pfn for all archs as it's used in lots of generic > diff --git a/kernel/events/core.c b/kernel/events/core.c > index f0128c5ff278..e90a547d2fb2 100644 > --- a/kernel/events/core.c > +++ b/kernel/events/core.c > @@ -7596,7 +7596,7 @@ static u64 perf_get_pgtable_size(struct mm_struct *mm, unsigned long addr) > > pte = ptep_get_lockless(ptep); > if (pte_present(pte)) > - size = pte_leaf_size(pte); > + size = pmd_pte_leaf_size(pmd, pte); > pte_unmap(ptep); > #endif /* CONFIG_HAVE_GUP_FAST */ > > >
diff --git a/arch/arm64/include/asm/pgtable.h b/arch/arm64/include/asm/pgtable.h index afdd56d26ad7..57c40f2498ab 100644 --- a/arch/arm64/include/asm/pgtable.h +++ b/arch/arm64/include/asm/pgtable.h @@ -624,7 +624,7 @@ extern pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn, #define pmd_bad(pmd) (!pmd_table(pmd)) #define pmd_leaf_size(pmd) (pmd_cont(pmd) ? CONT_PMD_SIZE : PMD_SIZE) -#define pte_leaf_size(pte) (pte_cont(pte) ? CONT_PTE_SIZE : PAGE_SIZE) +#define pte_leaf_size(pmd, pte) (pte_cont(pte) ? CONT_PTE_SIZE : PAGE_SIZE) #if defined(CONFIG_ARM64_64K_PAGES) || CONFIG_PGTABLE_LEVELS < 3 static inline bool pud_sect(pud_t pud) { return false; } diff --git a/arch/powerpc/include/asm/nohash/32/pte-8xx.h b/arch/powerpc/include/asm/nohash/32/pte-8xx.h index 137dc3c84e45..07df6b664861 100644 --- a/arch/powerpc/include/asm/nohash/32/pte-8xx.h +++ b/arch/powerpc/include/asm/nohash/32/pte-8xx.h @@ -151,7 +151,7 @@ static inline unsigned long pgd_leaf_size(pgd_t pgd) #define pgd_leaf_size pgd_leaf_size -static inline unsigned long pte_leaf_size(pte_t pte) +static inline unsigned long pte_leaf_size(pmd_t pmd, pte_t pte) { pte_basic_t val = pte_val(pte); diff --git a/arch/riscv/include/asm/pgtable.h b/arch/riscv/include/asm/pgtable.h index 6afd6bb4882e..9d9abe161a89 100644 --- a/arch/riscv/include/asm/pgtable.h +++ b/arch/riscv/include/asm/pgtable.h @@ -434,7 +434,7 @@ static inline pte_t pte_mkhuge(pte_t pte) } #ifdef CONFIG_RISCV_ISA_SVNAPOT -#define pte_leaf_size(pte) (pte_napot(pte) ? \ +#define pte_leaf_size(pmd, pte) (pte_napot(pte) ? \ napot_cont_size(napot_cont_order(pte)) :\ PAGE_SIZE) #endif diff --git a/arch/sparc/include/asm/pgtable_64.h b/arch/sparc/include/asm/pgtable_64.h index 4d1bafaba942..67063af2ff8f 100644 --- a/arch/sparc/include/asm/pgtable_64.h +++ b/arch/sparc/include/asm/pgtable_64.h @@ -1175,7 +1175,7 @@ extern unsigned long pud_leaf_size(pud_t pud); extern unsigned long pmd_leaf_size(pmd_t pmd); #define pte_leaf_size pte_leaf_size -extern unsigned long pte_leaf_size(pte_t pte); +extern unsigned long pte_leaf_size(pmd_t pmd, pte_t pte); #endif /* CONFIG_HUGETLB_PAGE */ diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c index 5a342199e837..60c845a15bee 100644 --- a/arch/sparc/mm/hugetlbpage.c +++ b/arch/sparc/mm/hugetlbpage.c @@ -276,7 +276,7 @@ static unsigned long huge_tte_to_size(pte_t pte) unsigned long pud_leaf_size(pud_t pud) { return 1UL << tte_to_shift(*(pte_t *)&pud); } unsigned long pmd_leaf_size(pmd_t pmd) { return 1UL << tte_to_shift(*(pte_t *)&pmd); } -unsigned long pte_leaf_size(pte_t pte) { return 1UL << tte_to_shift(pte); } +unsigned long pte_leaf_size(pmd_t pmd, pte_t pte) { return 1UL << tte_to_shift(pte); } pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma, unsigned long addr, unsigned long sz) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 85fc7554cd52..e605a4149fc7 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -1802,7 +1802,7 @@ typedef unsigned int pgtbl_mod_mask; #define pmd_leaf_size(x) PMD_SIZE #endif #ifndef pte_leaf_size -#define pte_leaf_size(x) PAGE_SIZE +#define pte_leaf_size(x, y) PAGE_SIZE #endif /* diff --git a/kernel/events/core.c b/kernel/events/core.c index 724e6d7e128f..5c1c083222b2 100644 --- a/kernel/events/core.c +++ b/kernel/events/core.c @@ -7585,7 +7585,7 @@ static u64 perf_get_pgtable_size(struct mm_struct *mm, unsigned long addr) pte = ptep_get_lockless(ptep); if (pte_present(pte)) - size = pte_leaf_size(pte); + size = pte_leaf_size(pmd, pte); pte_unmap(ptep); #endif /* CONFIG_HAVE_FAST_GUP */
On powerpc 8xx, when a page is 8M size, the information is in the PMD entry. So provide it to pte_leaf_size(). Signed-off-by: Christophe Leroy <christophe.leroy@csgroup.eu> --- arch/arm64/include/asm/pgtable.h | 2 +- arch/powerpc/include/asm/nohash/32/pte-8xx.h | 2 +- arch/riscv/include/asm/pgtable.h | 2 +- arch/sparc/include/asm/pgtable_64.h | 2 +- arch/sparc/mm/hugetlbpage.c | 2 +- include/linux/pgtable.h | 2 +- kernel/events/core.c | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-)