Skip to content

Commit a4ee286

Browse files
Anshuman Khandualwilldeacon
authored andcommitted
arm64/mm: Simplify and document pte_to_phys() for 52 bit addresses
pte_to_phys() assembly definition does multiple bits field transformations to derive physical address, embedded inside a page table entry. Unlike its C counter part i.e __pte_to_phys(), pte_to_phys() is not very apparent. It simplifies these operations via a new macro PTE_ADDR_HIGH_SHIFT indicating how far the pte encoded higher address bits need to be left shifted. While here, this also updates __pte_to_phys() and __phys_to_pte_val(). Cc: Catalin Marinas <[email protected]> Cc: Will Deacon <[email protected]> Cc: Mark Brown <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Ard Biesheuvel <[email protected]> Cc: [email protected] Cc: [email protected] Reviewed-by: Ard Biesheuvel <[email protected]> Suggested-by: Ard Biesheuvel <[email protected]> Signed-off-by: Anshuman Khandual <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent f0c4d9f commit a4ee286

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

arch/arm64/include/asm/assembler.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -660,12 +660,10 @@ alternative_endif
660660
.endm
661661

662662
.macro pte_to_phys, phys, pte
663-
#ifdef CONFIG_ARM64_PA_BITS_52
664-
ubfiz \phys, \pte, #(48 - 16 - 12), #16
665-
bfxil \phys, \pte, #16, #32
666-
lsl \phys, \phys, #16
667-
#else
668663
and \phys, \pte, #PTE_ADDR_MASK
664+
#ifdef CONFIG_ARM64_PA_BITS_52
665+
orr \phys, \phys, \phys, lsl #PTE_ADDR_HIGH_SHIFT
666+
and \phys, \phys, GENMASK_ULL(PHYS_MASK_SHIFT - 1, PAGE_SHIFT)
669667
#endif
670668
.endm
671669

arch/arm64/include/asm/pgtable-hwdef.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@
159159
#ifdef CONFIG_ARM64_PA_BITS_52
160160
#define PTE_ADDR_HIGH (_AT(pteval_t, 0xf) << 12)
161161
#define PTE_ADDR_MASK (PTE_ADDR_LOW | PTE_ADDR_HIGH)
162+
#define PTE_ADDR_HIGH_SHIFT 36
162163
#else
163164
#define PTE_ADDR_MASK PTE_ADDR_LOW
164165
#endif

arch/arm64/include/asm/pgtable.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,11 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
7777
static inline phys_addr_t __pte_to_phys(pte_t pte)
7878
{
7979
return (pte_val(pte) & PTE_ADDR_LOW) |
80-
((pte_val(pte) & PTE_ADDR_HIGH) << 36);
80+
((pte_val(pte) & PTE_ADDR_HIGH) << PTE_ADDR_HIGH_SHIFT);
8181
}
8282
static inline pteval_t __phys_to_pte_val(phys_addr_t phys)
8383
{
84-
return (phys | (phys >> 36)) & PTE_ADDR_MASK;
84+
return (phys | (phys >> PTE_ADDR_HIGH_SHIFT)) & PTE_ADDR_MASK;
8585
}
8686
#else
8787
#define __pte_to_phys(pte) (pte_val(pte) & PTE_ADDR_MASK)

0 commit comments

Comments
 (0)