Subject: [PATCH 2/2] arm64: kaslr: take free space at start of DRAM into account

From: Ard Biesheuvel <[email-masked]>
Date: Wed, 15 Dec 2021 15:52:28 +0100

Commit 97d6786e0669 ("arm64: mm: account for hotplug memory when
randomizing the linear region") limited the randomization range of the
linear region substantially, or even eliminated it entirely for
configurations where the VA range equals or exceeds the maximum PA
range, even in cases where most of the PA range is not occupied to begin
with.

In such cases, we can recover this ability to some extent by taking
advantage of the reduced value of ARM64_MEMSTART_ALIGN, and disregarding
the physical region below the first memblock, allowing us to randomize
the placement of physical DRAM within the linear region even in cases
where the PArange equals the virtual range.

NOTE: this relies on the assumption that hotpluggable memory will never
appear below the lowest boot-time memblock memory region, but only
above.

Signed-off-by: Ard Biesheuvel <[email-masked]>
---
 arch/arm64/mm/init.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm64/mm/init.c b/arch/arm64/mm/init.c
index a8834434af99..b3ffb356bc8b 100644
--- a/arch/arm64/mm/init.c
+++ b/arch/arm64/mm/init.c
@@ -288,7 +288,8 @@ void __init arm64_memblock_init(void)
 		int parange = cpuid_feature_extract_unsigned_field(
 					mmfr0, ID_AA64MMFR0_PARANGE_SHIFT);
 		s64 range = linear_region_size -
-			    BIT(id_aa64mmfr0_parange_to_phys_shift(parange));
+			    BIT(id_aa64mmfr0_parange_to_phys_shift(parange)) +
+			    memblock_start_of_DRAM();
 
 		/*
 		 * If the size of the linear region exceeds, by a sufficient
-- 
2.30.2

_______________________________________________
linux-arm-kernel mailing list
[email-masked]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel