Re: [PATCH] powerpc/mm: Use pte_advance_pfn() in set_huge_pte_at()

Christophe Leroy (CS GROUP)
2025-12-18T18:30:17Z

Hi Andrew,

Le 18/12/2025 à 17:21, Andrew Donnellan a écrit :
> In set_huge_pte_at(), replace the existing open coded pte value
> calculation with the new helper pte_advance_pfn().
>
> Signed-off-by: Andrew Donnellan <ajd@linux.ibm.com>
> ---
> arch/powerpc/mm/pgtable.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/powerpc/mm/pgtable.c b/arch/powerpc/mm/pgtable.c
> index 56d7e8960e77d877390d6bcbf0d8a305cc222101..9073e373e1e8a88f904cae592e1e8c34707545e6 100644
> --- a/arch/powerpc/mm/pgtable.c
> +++ b/arch/powerpc/mm/pgtable.c
> @@ -365,7 +365,7 @@ void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, pte_t *ptep,
>
> for (i = 0; i < sz / pdsize; i++, ptep++, addr += pdsize) {
> __set_pte_at(mm, addr, ptep, pte, 0);
> - pte = __pte(pte_val(pte) + ((unsigned long long)pdsize / PAGE_SIZE << PFN_PTE_SHIFT));
> + pte = pte_advance_pfn(pte, pdsize / PAGE_SIZE);

How can this work ?

pdsize is 4M, PAGE_SIZE is 4k so pdsize/PAGE_SIZE is 0x400.

PFN_PTE_SHIFT is 24.

0x400 << 24 is more than what an unsigned long can contain in
pte_advance_pfn()

Christophe

> }
> }
> #endif
>
> ---
> base-commit: ea1013c1539270e372fc99854bc6e4d94eaeff66
> change-id: 20251219-set_huge_pte_at_pte_advance_pfn-0ae18078fcca
>
>
> --
> Andrew Donnellan OzLabs, ADL Canberra
> ajd@linux.ibm.com IBM Australia Limited
>