Re: [PATCH 1/6] arm64: use hw_pte_t for HW PTE pointers

From: Muhammad Usama Anjum

Date: Mon Sep 21 2026 - 04:25:29 EST


On 21/09/2026 8:59 am, Ryan Roberts wrote:
> On 14/09/2026 14:51, Muhammad Usama Anjum wrote:
>> With pte_t * used for HW PTE pointers, the compiler cannot distinguish
>> them from SW PTE value pointers. The generic HW PTE interfaces already
>> use hw_pte_t *, so arm64 HW PTE pointers must use that type before
>> ARCH_HAS_HW_PTE_T can make it distinct.
>>
>> Convert HW PTE pointers to hw_pte_t *, retaining pte_t for SW PTE
>> values. Helpers shared with PMD and PUD operations keep explicit casts
>> because this series does not introduce distinct entry types for those
>> levels.
>>
>> arm64 still uses the hw_pte_t alias in this patch. The new pointer
>> spelling therefore denotes the same type until the final opt-in.
>>
>> Include linux/pgtable_types.h in pi.h to make hw_pte_t visible.
>>
>> Signed-off-by: Muhammad Usama Anjum <usama.anjum@xxxxxxx>
>> ---
>> arch/arm64/include/asm/hugetlb.h | 19 ++---
>> arch/arm64/include/asm/pgalloc.h | 2 +-
>> arch/arm64/include/asm/pgtable.h | 143 ++++++++++++++++++++------------------
>> arch/arm64/include/asm/vmalloc.h | 2 +-
>> arch/arm64/kernel/efi.c | 3 +-
>> arch/arm64/kernel/pi/map_kernel.c | 4 +-
>> arch/arm64/kernel/pi/map_range.c | 9 +--
>> arch/arm64/kernel/pi/pi.h | 3 +-
>> arch/arm64/mm/contpte.c | 49 +++++++------
>> arch/arm64/mm/fault.c | 5 +-
>> arch/arm64/mm/fixmap.c | 6 +-
>> arch/arm64/mm/hugetlbpage.c | 48 +++++++------
>> arch/arm64/mm/kasan_init.c | 4 +-
>> arch/arm64/mm/mmu.c | 46 +++++++-----
>> arch/arm64/mm/pageattr.c | 4 +-
>> arch/arm64/mm/trans_pgd.c | 4 +-
>> 16 files changed, 190 insertions(+), 161 deletions(-)
>>
>
> [...]
>
>> diff --git a/arch/arm64/mm/fixmap.c b/arch/arm64/mm/fixmap.c
>> index f66a0016dd02d..237a9136bc73b 100644
>> --- a/arch/arm64/mm/fixmap.c
>> +++ b/arch/arm64/mm/fixmap.c
>> @@ -35,7 +35,7 @@ static pte_t bm_pte[NR_BM_PTE_TABLES][PTRS_PER_PTE] __bss_pgtbl;
>> static pmd_t bm_pmd[PTRS_PER_PMD] __bss_pgtbl __maybe_unused;
>> static pud_t bm_pud[PTRS_PER_PUD] __bss_pgtbl __maybe_unused;
>>
>> -static inline pte_t *fixmap_pte(unsigned long addr)
>> +static inline hw_pte_t *fixmap_pte(unsigned long addr)
>> {
>> return &bm_pte[BM_PTE_TABLE_IDX(addr)][pte_index(addr)];
>
> How does this work, given you haven't yet converted bm_pte? You're returning a
> pte_t* where you need a hw_pte_t*. Either the compiler is implicitly converting
> (which would defeat the whole purpose of this series) or this patch doesn't
> compile until you convert bm_pte later on (which I suspect is more likely).

At this point, hw_pte_t is still a preprocessor alias for pte_t:

#define hw_pte_t pte_t

After preprocessing, both expressions therefore have type pte_t *; no
implicit pointer conversion is involved.

Patch 6/6 then selects ARCH_HAS_HW_PTE_T, replacing the alias with the
distinct wrapper type. This ordering keeps every intermediate patch
type-correct and enables compiler enforcement only after the pointers and
storage have both been converted.

>
>> }
>> @@ -43,7 +43,7 @@ static inline pte_t *fixmap_pte(unsigned long addr)
>> static void __init early_fixmap_init_pte(pmd_t *pmdp, unsigned long addr)
>> {
>> pmd_t pmd = READ_ONCE(*pmdp);
>> - pte_t *ptep;
>> + hw_pte_t *ptep;
>>
>> if (pmd_none(pmd)) {
>> ptep = bm_pte[BM_PTE_TABLE_IDX(addr)];
>
> Same problem here?

The same applies here.

--
Thanks,
Usama