Skip to contentSkip to conversation

make kexec work with efi=noruntime or efi=old_map

PATCH In review Kairui Song 4 participants 8 messages Jan 18, 2019 – Feb 1, 2019

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v3 cover make kexec work with efi=noruntime or efi=old_map

This patch series fix the kexec panic on efi=noruntime or efi=old_map pass acpi_rsdp_addr to the second kernel and make it boot up properly.

Update from V2:
- Store acpi rsdp value, and add an acpi_os_get_root_pointer_late as a helper, leveraging existing codes so we don't need to reparse RSDP.

Update from V1:
- Add a cover letter and fix some type in commit message
- Previous patches are not sent in a single thread

Kairui Song (3):
x86, kexec_file_load: Don't setup EFI info if EFI runtime is not
enabled
acpi: store acpi_rsdp address for later kexec usage
x86, kexec_file_load: make it work with efi=noruntime or efi=old_map

 arch/x86/kernel/kexec-bzimage64.c | 13 +++++++++++++
 drivers/acpi/osl.c                | 10 ++++++++++
 include/linux/acpi.h              |  3 +++
 3 files changed, 26 insertions(+)
Signature · 1 line
2.20.1
#1 lore raw

PATCH v3 1/3 x86, kexec_file_load: Don't setup EFI info if EFI runtime is not enabled

Currently with "efi=noruntime" in kernel command line, calling kexec_file_load will raise below problem:

[   97.967067] BUG: unable to handle kernel NULL pointer dereference at 0000000000000000
[   97.967894] #PF error: [normal kernel read fault]
...
[   97.980456] Call Trace:
[   97.980724]  efi_runtime_map_copy+0x28/0x30
[   97.981267]  bzImage64_load+0x688/0x872
[   97.981794]  arch_kexec_kernel_image_load+0x6d/0x70
[   97.982441]  kimage_file_alloc_init+0x13e/0x220
[   97.983035]  __x64_sys_kexec_file_load+0x144/0x290
[   97.983586]  do_syscall_64+0x55/0x1a0
[   97.983962]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

When efi runtime is not enabled, efi memmap is not mapped, so just skip EFI info setup.

---
 arch/x86/kernel/kexec-bzimage64.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/kexec-bzimage64.c +3 -0
index 2c007abd3d40..097f52fb02e3 100644
@@ -167,6 +167,9 @@ setup_efi_state(struct boot_params *params, unsigned long params_load_addr,
 	struct efi_info *current_ei = &boot_params.efi_info;
 	struct efi_info *ei = &params->efi_info;
 
+	if (!efi_enabled(EFI_RUNTIME_SERVICES))
+		return 0;
+
 	if (!current_ei->efi_memmap_size)
 		return 0;
 
Signature · 1 line
2.20.1
Acked-by on v3 1/3
#2 lore raw

Re: [PATCH v3 1/3] x86, kexec_file_load: Don't setup EFI info if EFI runtime is not enabled

Quoted 41 lines · Kairui Song

Currently with "efi=noruntime" in kernel command line, calling kexec_file_load will raise below problem:

[   97.967067] BUG: unable to handle kernel NULL pointer dereference at 0000000000000000
[   97.967894] #PF error: [normal kernel read fault]
...
[   97.980456] Call Trace:
[   97.980724]  efi_runtime_map_copy+0x28/0x30
[   97.981267]  bzImage64_load+0x688/0x872
[   97.981794]  arch_kexec_kernel_image_load+0x6d/0x70
[   97.982441]  kimage_file_alloc_init+0x13e/0x220
[   97.983035]  __x64_sys_kexec_file_load+0x144/0x290
[   97.983586]  do_syscall_64+0x55/0x1a0
[   97.983962]  entry_SYSCALL_64_after_hwframe+0x44/0xa9

When efi runtime is not enabled, efi memmap is not mapped, so just skip EFI info setup.

---
 arch/x86/kernel/kexec-bzimage64.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/kexec-bzimage64.c +3 -0
index 2c007abd3d40..097f52fb02e3 100644
@@ -167,6 +167,9 @@ setup_efi_state(struct boot_params *params, unsigned long params_load_addr,
 	struct efi_info *current_ei = &boot_params.efi_info;
 	struct efi_info *ei = &params->efi_info;
 
+	if (!efi_enabled(EFI_RUNTIME_SERVICES))
+		return 0;
+
 	if (!current_ei->efi_memmap_size)
 		return 0;
 
Signature · 1 line
2.20.1

Patch 1/3 looks good to me, 2-3 should depend on Chao's early rsdp parsing according to Boris.

Thanks
Dave

#3 lore raw

[tip:x86/urgent] x86/kexec: Don't setup EFI info if EFI runtime is not enabled

In reply to Kairui Song
x86/kexec: Don't setup EFI info if EFI runtime is not enabled
Commit-ID:  2aa958c99c7fd3162b089a1a56a34a0cdb778de1
Gitweb:     https://git.kernel.org/tip/2aa958c99c7fd3162b089a1a56a34a0cdb778de1
Author:     Kairui Song <[email protected]>
AuthorDate: Fri, 18 Jan 2019 19:13:08 +0800
Committer:  Borislav Petkov <[email protected]>
CommitDate: Fri, 1 Feb 2019 18:18:54 +0100

x86/kexec: Don't setup EFI info if EFI runtime is not enabled

Kexec-ing a kernel with "efi=noruntime" on the first kernel's command line causes the following null pointer dereference:

  BUG: unable to handle kernel NULL pointer dereference at 0000000000000000
  #PF error: [normal kernel read fault]
  Call Trace:
   efi_runtime_map_copy+0x28/0x30
   bzImage64_load+0x688/0x872
   arch_kexec_kernel_image_load+0x6d/0x70
   kimage_file_alloc_init+0x13e/0x220
   __x64_sys_kexec_file_load+0x144/0x290
   do_syscall_64+0x55/0x1a0
   entry_SYSCALL_64_after_hwframe+0x44/0xa9

Just skip the EFI info setup if EFI runtime services are not enabled.

[ bp: Massage commit message. ]

---
 arch/x86/kernel/kexec-bzimage64.c | 3 +++
 1 file changed, 3 insertions(+)
arch/x86/kernel/kexec-bzimage64.c +3 -0
index 0d5efa34f359..53917a3ebf94 100644
@@ -167,6 +167,9 @@ setup_efi_state(struct boot_params *params, unsigned long params_load_addr,
 	struct efi_info *current_ei = &boot_params.efi_info;
 	struct efi_info *ei = &params->efi_info;
 
+	if (!efi_enabled(EFI_RUNTIME_SERVICES))
+		return 0;
+
 	if (!current_ei->efi_memmap_size)
 		return 0;
 
#4 lore raw

PATCH v3 2/3 acpi: store acpi_rsdp address for later kexec usage

In reply to Kairui Song

Currently we have acpi_os_get_root_pointer as the universal function to get RSDP address. But the function itself and some functions it depends on are in .init section and make it not easy to retrieve the RSDP value once kernel is initialized.

And for kexec, it need to retrive RSDP again if EFI is disabled, because the second kernel will not be able get the RSDP value in such case, so it expects either the user specify the RSDP value using kernel cmdline, or kexec could retrive and pass the RSDP value using boot_params.

This patch stores the RSDP address when initialized is done, and introduce an acpi_os_get_root_pointer_late for later kexec usage.

---
 drivers/acpi/osl.c   | 10 ++++++++++
 include/linux/acpi.h |  3 +++
 2 files changed, 13 insertions(+)
drivers/acpi/osl.c +10 -0
index f29e427d0d1d..6340d34d0df1 100644
@@ -187,6 +187,16 @@ static int __init setup_acpi_rsdp(char *arg)
 	return kstrtoul(arg, 16, &acpi_rsdp);
 }
 early_param("acpi_rsdp", setup_acpi_rsdp);
+
+acpi_physical_address acpi_os_get_root_pointer_late(void) {
+	return acpi_rsdp;
+}
+
+static int __init acpi_store_root_pointer(void) {
+	acpi_rsdp = acpi_os_get_root_pointer();
+	return 0;
+}
+late_initcall(acpi_store_root_pointer);
 #endif
 
 acpi_physical_address __init acpi_os_get_root_pointer(void)
include/linux/acpi.h +3 -0
index 87715f20b69a..226f2572eb8e 100644
@@ -892,6 +892,9 @@ static inline void arch_reserve_mem_area(acpi_physical_address addr,
 {
 }
 #endif /* CONFIG_X86 */
+#ifdef CONFIG_KEXEC
+acpi_physical_address acpi_os_get_root_pointer_late(void);
+#endif
 #else
 #define acpi_os_set_prepare_sleep(func, pm1a_ctrl, pm1b_ctrl) do { } while (0)
 #endif
Signature · 1 line
2.20.1
maintainer
#5 lore raw

Re: [PATCH v3 2/3] acpi: store acpi_rsdp address for later kexec usage

Quoted 26 lines · Kairui Song

Currently we have acpi_os_get_root_pointer as the universal function to get RSDP address. But the function itself and some functions it depends on are in .init section and make it not easy to retrieve the RSDP value once kernel is initialized.

And for kexec, it need to retrive RSDP again if EFI is disabled, because the second kernel will not be able get the RSDP value in such case, so it expects either the user specify the RSDP value using kernel cmdline, or kexec could retrive and pass the RSDP value using boot_params.

This patch stores the RSDP address when initialized is done, and introduce an acpi_os_get_root_pointer_late for later kexec usage.

---
 drivers/acpi/osl.c   | 10 ++++++++++
 include/linux/acpi.h |  3 +++
 2 files changed, 13 insertions(+)
drivers/acpi/osl.c +0 -0
index f29e427d0d1d..6340d34d0df1 100644
@@ -187,6 +187,16 @@ static int __init setup_acpi_rsdp(char *arg)
 	return kstrtoul(arg, 16, &acpi_rsdp);
 }

drivers/acpi/osl.c static int __init setup_acpi_rsdp(char *arg) · line 198

Quoted 10 lines
drivers/acpi/osl.c +9 -0
 early_param("acpi_rsdp", setup_acpi_rsdp);
+
+acpi_physical_address acpi_os_get_root_pointer_late(void) {
+	return acpi_rsdp;
+}
+
+static int __init acpi_store_root_pointer(void) {
+	acpi_rsdp = acpi_os_get_root_pointer();
+	return 0;
+}

No, this is getting completely nuts: there's a bunch of functions which all end up returning boot_params's field except pvh_get_root_pointer().

And now you're adding a late variant. And the cmdline paramater acpi_rsdp is in a CONFIG_KEXEC wrapper, and and...

Wait until Chao Fan's stuff is applied, then do your changes ontop an drop all that ifdeffery. We will make this RDSP thing enabled unconditionally so that there's no need for ifdeffery and function wrappers.

Also, after Chao's stuff, you won't need to call acpi_os_get_root_pointer() because the early code would've done that.

Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
#6 lore raw

Re: [PATCH v3 2/3] acpi: store acpi_rsdp address for later kexec usage

Quoted 11 lines · Borislav Petkov

No, this is getting completely nuts: there's a bunch of functions which all end up returning boot_params's field except pvh_get_root_pointer().

And now you're adding a late variant. And the cmdline paramater acpi_rsdp is in a CONFIG_KEXEC wrapper, and and...

Wait until Chao Fan's stuff is applied, then do your changes ontop an drop all that ifdeffery. We will make this RDSP thing enabled unconditionally so that there's no need for ifdeffery and function wrappers.

Quoted 8 lines

Also, after Chao's stuff, you won't need to call acpi_os_get_root_pointer() because the early code would've done that.

--
Regards/Gruss,
Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.

Good suggestion, will wait for Chao's update then.

--
Best Regards,
Kairui Song

#7 lore raw

PATCH v3 3/3 x86, kexec_file_load: make it work with efi=noruntime or efi=old_map

In reply to Kairui Song

When efi=noruntime or efi=oldmap is used, EFI services won't be available in the second kernel, therefore the second kernel will not be able to get the ACPI RSDP address from firmware by calling EFI services and won't boot. Previously we are expecting the user to set the acpi_rsdp=<addr> on kernel command line for second kernel as there was no way to pass RSDP address to second kernel.

After commit e6e094e053af ('x86/acpi, x86/boot: Take RSDP address from boot params if available'), now it's possible to set an acpi_rsdp_addr parameter in the boot_params passed to second kernel, this commit makes use of it, detect and set the RSDP address when it's required for second kernel to boot.

Tested with an EFI enabled KVM VM with efi=noruntime.

---
 arch/x86/kernel/kexec-bzimage64.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
arch/x86/kernel/kexec-bzimage64.c +10 -0
index 097f52fb02e3..63101b2194fb 100644
@@ -20,6 +20,7 @@
 #include <linux/mm.h>
 #include <linux/efi.h>
 #include <linux/verification.h>
+#include <linux/acpi.h>
 
 #include <asm/bootparam.h>
 #include <asm/setup.h>
@@ -255,8 +256,17 @@ setup_boot_parameters(struct kimage *image, struct boot_params *params,
 	/* Setup EFI state */
 	setup_efi_state(params, params_load_addr, efi_map_offset, efi_map_sz,
 			efi_setup_data_offset);
+
+#ifdef CONFIG_ACPI
+	/* Setup ACPI RSDP pointer in case EFI is not available in second kernel */
+	if (!acpi_disabled && (!efi_enabled(EFI_RUNTIME_SERVICES) || efi_enabled(EFI_OLD_MEMMAP))) {
+		params->acpi_rsdp_addr = acpi_os_get_root_pointer_late();
+		if (!params->acpi_rsdp_addr)
+			pr_warn("RSDP is not available for second kernel\n");
+	}
 #endif
 
+#endif
 	/* Setup EDD info */
 	memcpy(params->eddbuf, boot_params.eddbuf,
 				EDDMAXNR * sizeof(struct edd_info));
Signature · 1 line
2.20.1