Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

x86/kexec: Add EFI config table identity mapping for kexec kernel

A kexec kernel boot failure is sometimes observed on AMD CPUs due to an
unmapped EFI config table array. This can be seen when "nogbpages" is on
the kernel command line, and has been observed as a full BIOS reboot rather
than a successful kexec.

This was also the cause of reported regressions attributed to Commit
7143c5f4cf20 ("x86/mm/ident_map: Use gbpages only where full GB page should
be mapped.") which was subsequently reverted.

To avoid this page fault, explicitly include the EFI config table array in
the kexec identity map.

Further explanation:

The following 2 commits caused the EFI config table array to be
accessed when enabling sev at kernel startup.

commit ec1c66af3a30 ("x86/compressed/64: Detect/setup SEV/SME features
earlier during boot")
commit c01fce9cef84 ("x86/compressed: Add SEV-SNP feature
detection/setup")

This is in the code that examines whether SEV should be enabled or not, so
it can even affect systems that are not SEV capable.

This may result in a page fault if the EFI config table array's address is
unmapped. Since the page fault occurs before the new kernel establishes its
own identity map and page fault routines, it is unrecoverable and kexec
fails.

Most often, this problem is not seen because the EFI config table array
gets included in the map by the luck of being placed at a memory address
close enough to other memory areas that *are* included in the map created
by kexec.

Both the "nogbpages" command line option and the "use gpbages only where
full GB page should be mapped" change greatly reduce the chance of being
included in the map by luck, which is why the problem appears.

Signed-off-by: Tao Liu <ltao@redhat.com>
Signed-off-by: Steve Wahl <steve.wahl@hpe.com>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Tested-by: Pavin Joseph <me@pavinjoseph.com>
Tested-by: Sarah Brofeldt <srhb@dbc.dk>
Tested-by: Eric Hagberg <ehagberg@gmail.com>
Reviewed-by: Ard Biesheuvel <ardb@kernel.org>
Link: https://lore.kernel.org/all/20240717213121.3064030-2-steve.wahl@hpe.com

authored by

Tao Liu and committed by
Thomas Gleixner
5760929f 6998a73e

+27
+27
arch/x86/kernel/machine_kexec_64.c
··· 28 28 #include <asm/setup.h> 29 29 #include <asm/set_memory.h> 30 30 #include <asm/cpu.h> 31 + #include <asm/efi.h> 31 32 32 33 #ifdef CONFIG_ACPI 33 34 /* ··· 88 87 { 89 88 #ifdef CONFIG_EFI 90 89 unsigned long mstart, mend; 90 + void *kaddr; 91 + int ret; 91 92 92 93 if (!efi_enabled(EFI_BOOT)) 93 94 return 0; ··· 104 101 105 102 if (!mstart) 106 103 return 0; 104 + 105 + ret = kernel_ident_mapping_init(info, level4p, mstart, mend); 106 + if (ret) 107 + return ret; 108 + 109 + kaddr = memremap(mstart, mend - mstart, MEMREMAP_WB); 110 + if (!kaddr) { 111 + pr_err("Could not map UEFI system table\n"); 112 + return -ENOMEM; 113 + } 114 + 115 + mstart = efi_config_table; 116 + 117 + if (efi_enabled(EFI_64BIT)) { 118 + efi_system_table_64_t *stbl = (efi_system_table_64_t *)kaddr; 119 + 120 + mend = mstart + sizeof(efi_config_table_64_t) * stbl->nr_tables; 121 + } else { 122 + efi_system_table_32_t *stbl = (efi_system_table_32_t *)kaddr; 123 + 124 + mend = mstart + sizeof(efi_config_table_32_t) * stbl->nr_tables; 125 + } 126 + 127 + memunmap(kaddr); 107 128 108 129 return kernel_ident_mapping_init(info, level4p, mstart, mend); 109 130 #endif