Skip to content

Commit bf74bb7

Browse files
ardbiesheuvelwilldeacon
authored andcommitted
arm64/mm: Reduce PA space to 48 bits when LPA2 is not enabled
Currently, LPA2 kernel support implies support for up to 52 bits of physical addressing, and this is reflected in global definitions such as PHYS_MASK_SHIFT and MAX_PHYSMEM_BITS. This is potentially problematic, given that LPA2 hardware support is modeled as a CPU feature which can be overridden, and with LPA2 hardware support turned off, attempting to map physical regions with address bits [51:48] set (which may exist on LPA2 capable systems booting with arm64.nolva) will result in corrupted mappings with a truncated output address and bogus shareability attributes. This means that the accepted physical address range in the mapping routines should be at most 48 bits wide when LPA2 support is configured but not enabled at runtime. Fixes: 352b039 ("arm64: Enable 52-bit virtual addressing for 4k and 16k granule configs") Cc: stable@vger.kernel.org Reviewed-by: Anshuman Khandual <anshuman.khandual@arm.com> Signed-off-by: Ard Biesheuvel <ardb@kernel.org> Acked-by: Marc Zyngier <maz@kernel.org> Link: https://lore.kernel.org/r/20241212081841.2168124-9-ardb+git@google.com Signed-off-by: Will Deacon <will@kernel.org>
1 parent fac04ef commit bf74bb7

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,6 @@
222222
*/
223223
#define S1_TABLE_AP (_AT(pmdval_t, 3) << 61)
224224

225-
/*
226-
* Highest possible physical address supported.
227-
*/
228-
#define PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS)
229-
#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1)
230-
231225
#define TTBR_CNP_BIT (UL(1) << 0)
232226

233227
/*

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ extern unsigned long prot_ns_shared;
8181
#define lpa2_is_enabled() false
8282
#define PTE_MAYBE_SHARED PTE_SHARED
8383
#define PMD_MAYBE_SHARED PMD_SECT_S
84+
#define PHYS_MASK_SHIFT (CONFIG_ARM64_PA_BITS)
8485
#else
8586
static inline bool __pure lpa2_is_enabled(void)
8687
{
@@ -89,8 +90,14 @@ static inline bool __pure lpa2_is_enabled(void)
8990

9091
#define PTE_MAYBE_SHARED (lpa2_is_enabled() ? 0 : PTE_SHARED)
9192
#define PMD_MAYBE_SHARED (lpa2_is_enabled() ? 0 : PMD_SECT_S)
93+
#define PHYS_MASK_SHIFT (lpa2_is_enabled() ? CONFIG_ARM64_PA_BITS : 48)
9294
#endif
9395

96+
/*
97+
* Highest possible physical address supported.
98+
*/
99+
#define PHYS_MASK ((UL(1) << PHYS_MASK_SHIFT) - 1)
100+
94101
/*
95102
* If we have userspace only BTI we don't want to mark kernel pages
96103
* guarded even if the system does support BTI.

arch/arm64/include/asm/sparsemem.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55
#ifndef __ASM_SPARSEMEM_H
66
#define __ASM_SPARSEMEM_H
77

8-
#define MAX_PHYSMEM_BITS CONFIG_ARM64_PA_BITS
8+
#include <asm/pgtable-prot.h>
9+
10+
#define MAX_PHYSMEM_BITS PHYS_MASK_SHIFT
11+
#define MAX_POSSIBLE_PHYSMEM_BITS (52)
912

1013
/*
1114
* Section size must be at least 512MB for 64K base

0 commit comments

Comments
 (0)