2019-01-18 11:15:38

by Kairui Song

[permalink] [raw]
Subject: [PATCH v3 0/3] 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(+)

--
2.20.1



2019-01-18 11:15:41

by Kairui Song

[permalink] [raw]
Subject: [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.

Suggested-by: Dave Young <[email protected]>
Signed-off-by: Kairui Song <[email protected]>
---
arch/x86/kernel/kexec-bzimage64.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 2c007abd3d40..097f52fb02e3 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -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;

--
2.20.1


2019-01-18 11:16:00

by Kairui Song

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

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.

Signed-off-by: Kairui Song <[email protected]>
---
drivers/acpi/osl.c | 10 ++++++++++
include/linux/acpi.h | 3 +++
2 files changed, 13 insertions(+)

diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
index f29e427d0d1d..6340d34d0df1 100644
--- a/drivers/acpi/osl.c
+++ b/drivers/acpi/osl.c
@@ -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)
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 87715f20b69a..226f2572eb8e 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -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
--
2.20.1


2019-01-18 11:16:31

by Kairui Song

[permalink] [raw]
Subject: [PATCH v3 3/3] x86, kexec_file_load: make it work with efi=noruntime or efi=old_map

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.

Suggested-by: Dave Young <[email protected]>
Signed-off-by: Kairui Song <[email protected]>
---
arch/x86/kernel/kexec-bzimage64.c | 10 ++++++++++
1 file changed, 10 insertions(+)

diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 097f52fb02e3..63101b2194fb 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -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));
--
2.20.1


2019-01-18 11:28:12

by Borislav Petkov

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

On Fri, Jan 18, 2019 at 07:13:09PM +0800, Kairui Song wrote:
> 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.
>
> Signed-off-by: Kairui Song <[email protected]>
> ---
> drivers/acpi/osl.c | 10 ++++++++++
> include/linux/acpi.h | 3 +++
> 2 files changed, 13 insertions(+)
>
> diff --git a/drivers/acpi/osl.c b/drivers/acpi/osl.c
> index f29e427d0d1d..6340d34d0df1 100644
> --- a/drivers/acpi/osl.c
> +++ b/drivers/acpi/osl.c
> @@ -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;
> +}

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.

--
Regards/Gruss,
Boris.

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

2019-01-18 11:46:08

by Kairui Song

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

On Fri, Jan 18, 2019 at 7:26 PM Borislav Petkov <[email protected]> wrote:

> 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.
>
> --
> 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

2019-01-25 02:54:36

by Dave Young

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

On 01/18/19 at 07:13pm, Kairui Song wrote:
> 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.
>
> Suggested-by: Dave Young <[email protected]>
> Signed-off-by: Kairui Song <[email protected]>
> ---
> arch/x86/kernel/kexec-bzimage64.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
> index 2c007abd3d40..097f52fb02e3 100644
> --- a/arch/x86/kernel/kexec-bzimage64.c
> +++ b/arch/x86/kernel/kexec-bzimage64.c
> @@ -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;
>
> --
> 2.20.1
>

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

Acked-by: Dave Young <[email protected]>

Thanks
Dave

Subject: [tip:x86/urgent] 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. ]

Suggested-by: Dave Young <[email protected]>
Signed-off-by: Kairui Song <[email protected]>
Signed-off-by: Borislav Petkov <[email protected]>
Acked-by: Dave Young <[email protected]>
Cc: AKASHI Takahiro <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Ard Biesheuvel <[email protected]>
Cc: [email protected]
Cc: David Howells <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: "H. Peter Anvin" <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: Philipp Rudo <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Thomas Gleixner <[email protected]>
Cc: x86-ml <[email protected]>
Cc: Yannik Sembritzki <[email protected]>
Link: https://lkml.kernel.org/r/[email protected]
---
arch/x86/kernel/kexec-bzimage64.c | 3 +++
1 file changed, 3 insertions(+)

diff --git a/arch/x86/kernel/kexec-bzimage64.c b/arch/x86/kernel/kexec-bzimage64.c
index 0d5efa34f359..53917a3ebf94 100644
--- a/arch/x86/kernel/kexec-bzimage64.c
+++ b/arch/x86/kernel/kexec-bzimage64.c
@@ -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;