Re: [PATCH v9 01/10] arm64/mm: add pte_set_huge() and pte_clear_huge()

From: Barry Song

Date: Wed Sep 23 2026 - 17:30:19 EST


On Wed, Sep 23, 2026 at 2:28 PM Wen Jiang <jiangwenxiaomi@xxxxxxxxx> wrote:
>
> vmap installs PTE-level block mappings (PTE_CONT on arm64) by reusing
> set_huge_pte_at() and huge_ptep_get_and_clear(), which are HugeTLB
> helpers gated by CONFIG_HUGETLB_PAGE. This makes the feature silently
> unavailable on CONFIG_HUGETLB_PAGE=n kernels and couples mm/vmalloc.c to
> HugeTLB internals it does not otherwise need.
>
> Add pte_set_huge()/pte_clear_huge() to arm64, joining the existing
> pmd_set_huge()/pud_set_huge() family in mm/mmu.c. They build on
> __set_ptes() and __get_and_clear_full_ptes() directly, so they do not
> depend on CONFIG_HUGETLB_PAGE.
>
> There is no caller yet: mm/vmalloc.c is converted later in this series,
> once the generic fallbacks are in place.
>
> Signed-off-by: Wen Jiang <jiangwen6@xxxxxxxxxx>

LGTM. Please see the comment below.

Reviewed-by: Barry Song <baohua@xxxxxxxxxx>

[...]

> +void pte_set_huge(pte_t *ptep, unsigned long addr, phys_addr_t phys,
> + pgprot_t prot, unsigned long size)
> +{
> + unsigned long pfn = __phys_to_pfn(phys);
> + pte_t pte = pte_mkcont(pfn_pte(pfn, prot));
> + unsigned int nr = size >> PAGE_SHIFT;
> +
> + VM_WARN_ON(!IS_ALIGNED(size, CONT_PTE_SIZE));
> + VM_WARN_ON(!IS_ALIGNED(addr, CONT_PTE_SIZE));
> + VM_WARN_ON(!IS_ALIGNED(pfn, CONT_PTES));
> +
> + __set_ptes(&init_mm, addr, ptep, pte, nr);

You have patch 4 to revert the `clear_flush()` modification from
06fc959fcff ("arm64/mm: Support huge pte-mapped pages in vmap").

I guess you may still need to guard against the case I mentioned in my
reply to patch 4:
https://lore.kernel.org/linux-mm/CAGsJ_4xiLScr2PrPu7Eem73GvPCtsuYd3J05kW3SC4QSs5Q4aQ@xxxxxxxxxxxxxx/

Something like this:
VM_WARN_ON (pte_valid(__ptep_get(ptep)));

Best Regards
Barry