[PATCH] x86/boot/compressed/64: Print error if 5-level paging is not supported

From: Kirill A. Shutemov
Date: Thu Nov 30 2017 - 02:23:53 EST


We cannot proceed booting if the machine doesn't support the paging mode
kernel was compiled for.

Getting error the usual way -- via validate_cpu() -- is not going to
work. We need to enable appropriate paging mode before that, otherwise
kernel would triple-fault during KASLR setup.

This code will go away once we get support for boot-time switching
between paging modes.

Signed-off-by: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
---
arch/x86/boot/compressed/misc.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
index b50c42455e25..5205e848dc33 100644
--- a/arch/x86/boot/compressed/misc.c
+++ b/arch/x86/boot/compressed/misc.c
@@ -40,6 +40,8 @@
/* Functions used by the included decompressor code below. */
void *memmove(void *dest, const void *src, size_t n);

+int l5_paging_required(void);
+
/*
* This is set up by the setup-routine at boot-time
*/
@@ -362,6 +364,13 @@ asmlinkage __visible void *extract_kernel(void *rmode, memptr heap,
console_init();
debug_putstr("early console in extract_kernel\n");

+ if (IS_ENABLED(CONFIG_X86_5LEVEL) && !l5_paging_required()) {
+ error("The kernel is compiled with 5-level paging enabled, "
+ "but the CPU doesn't support la57\n"
+ "Unable to boot - please use "
+ "a kernel appropriate for your CPU.\n");
+ }
+
free_mem_ptr = heap; /* Heap */
free_mem_end_ptr = heap + BOOT_HEAP_SIZE;

--
Kirill A. Shutemov