diff mbox series

[PATCHv2,2/2] x86/boot/KASLR: Fix boot with some memory above MAXMEM

Message ID 20200608125424.70198-3-kirill.shutemov@linux.intel.com
State New
Headers show
Series None | expand

Commit Message

Kirill A. Shutemov June 8, 2020, 12:54 p.m. UTC
A 5-level paging capable machine can have memory above 46-bit in the
physical address space. This memory is only addressable in the 5-level
paging mode: we don't have enough virtual address space to create direct
mapping for such memory in the 4-level paging mode

Teach KASLR to avoid memory regions above MAXMEM or truncate the region
if the end is above MAXMEM.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Reviewed-by: Dave Hansen <dave.hansen@intel.com>
Cc: stable@vger.kernel.org # v4.14
---
 arch/x86/boot/compressed/kaslr.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/arch/x86/boot/compressed/kaslr.c b/arch/x86/boot/compressed/kaslr.c
index d7408af55738..99db18eeb40e 100644
--- a/arch/x86/boot/compressed/kaslr.c
+++ b/arch/x86/boot/compressed/kaslr.c
@@ -695,7 +695,18 @@  static bool process_mem_region(struct mem_vector *region,
 			       unsigned long long minimum,
 			       unsigned long long image_size)
 {
+	unsigned long long end;
 	int i;
+
+	/* Cannot access memory region above MAXMEM: skip it. */
+	if (region->start >= MAXMEM)
+		return 0;
+
+	/* Truncate the region if the end is above MAXMEM */
+	end = region->start + region->size;
+	end = min_t(unsigned long long, end, MAXMEM - 1);
+	region->size = end - region->start;
+
 	/*
 	 * If no immovable memory found, or MEMORY_HOTREMOVE disabled,
 	 * use @region directly.