Skip to content

Commit 925a0eb

Browse files
ardbiesheuvelctmarinas
authored andcommitted
arm64: mm: Add LPA2 support to phys<->pte conversion routines
In preparation for enabling LPA2 support, introduce the mask values for converting between physical addresses and their representations in a page table descriptor. While at it, move the pte_to_phys asm macro into its only user, so that we can freely modify it to use its input value register as a temp register. For LPA2, the PTE_ADDR_MASK contains two non-adjacent sequences of zero bits, which means it no longer fits into the immediate field of an ordinary ALU instruction. So let's redefine it to include the bits in between as well, and only use it when converting from physical address to PTE representation, where the distinction does not matter. Also update the name accordingly to emphasize this. Signed-off-by: Ard Biesheuvel <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent db95ea7 commit 925a0eb

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

arch/arm64/include/asm/assembler.h

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -612,25 +612,13 @@ alternative_endif
612612

613613
.macro phys_to_pte, pte, phys
614614
#ifdef CONFIG_ARM64_PA_BITS_52
615-
/*
616-
* We assume \phys is 64K aligned and this is guaranteed by only
617-
* supporting this configuration with 64K pages.
618-
*/
619-
orr \pte, \phys, \phys, lsr #36
620-
and \pte, \pte, #PTE_ADDR_MASK
615+
orr \pte, \phys, \phys, lsr #PTE_ADDR_HIGH_SHIFT
616+
and \pte, \pte, #PHYS_TO_PTE_ADDR_MASK
621617
#else
622618
mov \pte, \phys
623619
#endif
624620
.endm
625621

626-
.macro pte_to_phys, phys, pte
627-
and \phys, \pte, #PTE_ADDR_MASK
628-
#ifdef CONFIG_ARM64_PA_BITS_52
629-
orr \phys, \phys, \phys, lsl #PTE_ADDR_HIGH_SHIFT
630-
and \phys, \phys, GENMASK_ULL(PHYS_MASK_SHIFT - 1, PAGE_SHIFT)
631-
#endif
632-
.endm
633-
634622
/*
635623
* tcr_clear_errata_bits - Clear TCR bits that trigger an errata on this CPU.
636624
*/

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,17 @@
155155
#define PTE_PXN (_AT(pteval_t, 1) << 53) /* Privileged XN */
156156
#define PTE_UXN (_AT(pteval_t, 1) << 54) /* User XN */
157157

158-
#define PTE_ADDR_LOW (((_AT(pteval_t, 1) << (48 - PAGE_SHIFT)) - 1) << PAGE_SHIFT)
158+
#define PTE_ADDR_LOW (((_AT(pteval_t, 1) << (50 - PAGE_SHIFT)) - 1) << PAGE_SHIFT)
159159
#ifdef CONFIG_ARM64_PA_BITS_52
160+
#ifdef CONFIG_ARM64_64K_PAGES
160161
#define PTE_ADDR_HIGH (_AT(pteval_t, 0xf) << 12)
161-
#define PTE_ADDR_MASK (PTE_ADDR_LOW | PTE_ADDR_HIGH)
162162
#define PTE_ADDR_HIGH_SHIFT 36
163+
#define PHYS_TO_PTE_ADDR_MASK (PTE_ADDR_LOW | PTE_ADDR_HIGH)
163164
#else
164-
#define PTE_ADDR_MASK PTE_ADDR_LOW
165+
#define PTE_ADDR_HIGH (_AT(pteval_t, 0x3) << 8)
166+
#define PTE_ADDR_HIGH_SHIFT 42
167+
#define PHYS_TO_PTE_ADDR_MASK GENMASK_ULL(49, 8)
168+
#endif
165169
#endif
166170

167171
/*

arch/arm64/include/asm/pgtable.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,16 @@ extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
8080
#ifdef CONFIG_ARM64_PA_BITS_52
8181
static inline phys_addr_t __pte_to_phys(pte_t pte)
8282
{
83+
pte_val(pte) &= ~PTE_MAYBE_SHARED;
8384
return (pte_val(pte) & PTE_ADDR_LOW) |
8485
((pte_val(pte) & PTE_ADDR_HIGH) << PTE_ADDR_HIGH_SHIFT);
8586
}
8687
static inline pteval_t __phys_to_pte_val(phys_addr_t phys)
8788
{
88-
return (phys | (phys >> PTE_ADDR_HIGH_SHIFT)) & PTE_ADDR_MASK;
89+
return (phys | (phys >> PTE_ADDR_HIGH_SHIFT)) & PHYS_TO_PTE_ADDR_MASK;
8990
}
9091
#else
91-
#define __pte_to_phys(pte) (pte_val(pte) & PTE_ADDR_MASK)
92+
#define __pte_to_phys(pte) (pte_val(pte) & PTE_ADDR_LOW)
9293
#define __phys_to_pte_val(phys) (phys)
9394
#endif
9495

arch/arm64/mm/proc.S

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ SYM_FUNC_ALIAS(__pi_idmap_cpu_replace_ttbr1, idmap_cpu_replace_ttbr1)
205205

206206
.pushsection ".idmap.text", "a"
207207

208+
.macro pte_to_phys, phys, pte
209+
and \phys, \pte, #PTE_ADDR_LOW
210+
#ifdef CONFIG_ARM64_PA_BITS_52
211+
and \pte, \pte, #PTE_ADDR_HIGH
212+
orr \phys, \phys, \pte, lsl #PTE_ADDR_HIGH_SHIFT
213+
#endif
214+
.endm
215+
208216
.macro kpti_mk_tbl_ng, type, num_entries
209217
add end_\type\()p, cur_\type\()p, #\num_entries * 8
210218
.Ldo_\type:

0 commit comments

Comments
 (0)