[PATCH 5/6] arm64: use HW PTE accessors in early map_range()

Ryan Roberts ryan.roberts at arm.com
Mon Sep 21 02:44:15 PDT 2026


On 14/09/2026 14:51, Muhammad Usama Anjum wrote:
> map_range() uses HW PTE pointers to build early translation tables at
> each level. Directly testing, decoding, or assigning *tbl treats an
> HW PTE as a SW PTE value, which requires explicit conversion once
> hw_pte_t becomes distinct.
> 
> Use __ptep_get() to load a SW PTE value for the empty-entry check and
> child-table address, and __set_pte_nosync() to convert SW PTE values to
> HW PTEs on stores. The no-sync helper performs WRITE_ONCE() without
> adding the completion barriers used by __set_pte().
> 
> Signed-off-by: Muhammad Usama Anjum <usama.anjum at arm.com>

Reviewed-by: Ryan Roberts <ryan.roberts at arm.com>

> ---
>  arch/arm64/kernel/pi/map_range.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
> 
> diff --git a/arch/arm64/kernel/pi/map_range.c b/arch/arm64/kernel/pi/map_range.c
> index 94f06da76e333..9c4c8060c5df4 100644
> --- a/arch/arm64/kernel/pi/map_range.c
> +++ b/arch/arm64/kernel/pi/map_range.c
> @@ -51,19 +51,21 @@ void __init map_range(phys_addr_t *pte, u64 start, u64 end, phys_addr_t pa,
>  
>  	while (start < end) {
>  		u64 next = min((start | lmask) + 1, PAGE_ALIGN(end));
> +		pte_t entry = __ptep_get(tbl);
>  
>  		if (level < 2 || (level == 2 && (start | next | pa) & lmask)) {
>  			/*
>  			 * This chunk needs a finer grained mapping. Create a
>  			 * table mapping if necessary and recurse.
>  			 */
> -			if (pte_none(*tbl)) {
> -				*tbl = __pte(__phys_to_pte_val(*pte) |
> +			if (pte_none(entry)) {
> +				entry = __pte(__phys_to_pte_val(*pte) |
>  					     PMD_TYPE_TABLE | PMD_TABLE_UXN);
> -				*pte += PTRS_PER_PTE * sizeof(pte_t);
> +				__set_pte_nosync(tbl, entry);
> +				*pte += PTRS_PER_PTE * sizeof(hw_pte_t);
>  			}
>  			map_range(pte, start, next, pa, prot, level + 1,
> -				  (hw_pte_t *)(__pte_to_phys(*tbl) + va_offset),
> +				  (hw_pte_t *)(__pte_to_phys(entry) + va_offset),
>  				  may_use_cont, va_offset);
>  		} else {
>  			/*
> @@ -81,7 +83,8 @@ void __init map_range(phys_addr_t *pte, u64 start, u64 end, phys_addr_t pa,
>  				protval &= ~PTE_CONT;
>  
>  			/* Put down a block or page mapping */
> -			*tbl = __pte(__phys_to_pte_val(pa) | protval);
> +			entry = __pte(__phys_to_pte_val(pa) | protval);
> +			__set_pte_nosync(tbl, entry);
>  		}
>  		pa += next - start;
>  		start = next;
> 




More information about the linux-arm-kernel mailing list