linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/3] make kexec work with efi=noruntime or efi=old_map
@ 2019-01-18 11:13 Kairui Song
  2019-01-18 11:13 ` [PATCH v3 1/3] x86, kexec_file_load: Don't setup EFI info if EFI runtime is not enabled Kairui Song
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Kairui Song @ 2019-01-18 11:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, bp, hpa, x86, dyoung, bhe, kexec, akpm,
	robert.moore, erik.schmauss, rafael.j.wysocki, lenb, fanc.fnst,
	linux-acpi, Kairui Song

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH v3 1/3] x86, kexec_file_load: Don't setup EFI info if EFI runtime is not enabled
  2019-01-18 11:13 [PATCH v3 0/3] make kexec work with efi=noruntime or efi=old_map Kairui Song
@ 2019-01-18 11:13 ` Kairui Song
  2019-01-25  2:53   ` Dave Young
  2019-02-01 17:36   ` [tip:x86/urgent] x86/kexec: " tip-bot for Kairui Song
  2019-01-18 11:13 ` [PATCH v3 2/3] acpi: store acpi_rsdp address for later kexec usage Kairui Song
  2019-01-18 11:13 ` [PATCH v3 3/3] x86, kexec_file_load: make it work with efi=noruntime or efi=old_map Kairui Song
  2 siblings, 2 replies; 8+ messages in thread
From: Kairui Song @ 2019-01-18 11:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, bp, hpa, x86, dyoung, bhe, kexec, akpm,
	robert.moore, erik.schmauss, rafael.j.wysocki, lenb, fanc.fnst,
	linux-acpi, 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.

Suggested-by: Dave Young <dyoung@redhat.com>
Signed-off-by: Kairui Song <kasong@redhat.com>
---
 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 2/3] acpi: store acpi_rsdp address for later kexec usage
  2019-01-18 11:13 [PATCH v3 0/3] make kexec work with efi=noruntime or efi=old_map Kairui Song
  2019-01-18 11:13 ` [PATCH v3 1/3] x86, kexec_file_load: Don't setup EFI info if EFI runtime is not enabled Kairui Song
@ 2019-01-18 11:13 ` Kairui Song
  2019-01-18 11:26   ` Borislav Petkov
  2019-01-18 11:13 ` [PATCH v3 3/3] x86, kexec_file_load: make it work with efi=noruntime or efi=old_map Kairui Song
  2 siblings, 1 reply; 8+ messages in thread
From: Kairui Song @ 2019-01-18 11:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, bp, hpa, x86, dyoung, bhe, kexec, akpm,
	robert.moore, erik.schmauss, rafael.j.wysocki, lenb, fanc.fnst,
	linux-acpi, 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.

Signed-off-by: Kairui Song <kasong@redhat.com>
---
 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH v3 3/3] x86, kexec_file_load: make it work with efi=noruntime or efi=old_map
  2019-01-18 11:13 [PATCH v3 0/3] make kexec work with efi=noruntime or efi=old_map Kairui Song
  2019-01-18 11:13 ` [PATCH v3 1/3] x86, kexec_file_load: Don't setup EFI info if EFI runtime is not enabled Kairui Song
  2019-01-18 11:13 ` [PATCH v3 2/3] acpi: store acpi_rsdp address for later kexec usage Kairui Song
@ 2019-01-18 11:13 ` Kairui Song
  2 siblings, 0 replies; 8+ messages in thread
From: Kairui Song @ 2019-01-18 11:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: tglx, mingo, bp, hpa, x86, dyoung, bhe, kexec, akpm,
	robert.moore, erik.schmauss, rafael.j.wysocki, lenb, fanc.fnst,
	linux-acpi, 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.

Suggested-by: Dave Young <dyoung@redhat.com>
Signed-off-by: Kairui Song <kasong@redhat.com>
---
 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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 2/3] acpi: store acpi_rsdp address for later kexec usage
  2019-01-18 11:13 ` [PATCH v3 2/3] acpi: store acpi_rsdp address for later kexec usage Kairui Song
@ 2019-01-18 11:26   ` Borislav Petkov
  2019-01-18 11:43     ` Kairui Song
  0 siblings, 1 reply; 8+ messages in thread
From: Borislav Petkov @ 2019-01-18 11:26 UTC (permalink / raw)
  To: Kairui Song
  Cc: linux-kernel, tglx, mingo, hpa, x86, dyoung, bhe, kexec, akpm,
	robert.moore, erik.schmauss, rafael.j.wysocki, lenb, fanc.fnst,
	linux-acpi

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 <kasong@redhat.com>
> ---
>  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.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 2/3] acpi: store acpi_rsdp address for later kexec usage
  2019-01-18 11:26   ` Borislav Petkov
@ 2019-01-18 11:43     ` Kairui Song
  0 siblings, 0 replies; 8+ messages in thread
From: Kairui Song @ 2019-01-18 11:43 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Linux Kernel Mailing List, Thomas Gleixner, Ingo Molnar,
	H. Peter Anvin, the arch/x86 maintainers, Dave Young, Baoquan He,
	kexec, Andrew Morton, Robert Moore, Schmauss, Erik,
	Rafael Wysocki, Len Brown, Chao Fan, ACPI Devel Maling List

On Fri, Jan 18, 2019 at 7:26 PM Borislav Petkov <bp@alien8.de> 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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH v3 1/3] x86, kexec_file_load: Don't setup EFI info if EFI runtime is not enabled
  2019-01-18 11:13 ` [PATCH v3 1/3] x86, kexec_file_load: Don't setup EFI info if EFI runtime is not enabled Kairui Song
@ 2019-01-25  2:53   ` Dave Young
  2019-02-01 17:36   ` [tip:x86/urgent] x86/kexec: " tip-bot for Kairui Song
  1 sibling, 0 replies; 8+ messages in thread
From: Dave Young @ 2019-01-25  2:53 UTC (permalink / raw)
  To: Kairui Song
  Cc: linux-kernel, tglx, mingo, bp, hpa, x86, bhe, kexec, akpm,
	robert.moore, erik.schmauss, rafael.j.wysocki, lenb, fanc.fnst,
	linux-acpi

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 <dyoung@redhat.com>
> Signed-off-by: Kairui Song <kasong@redhat.com>
> ---
>  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 <dyoung@redhat.com>

Thanks
Dave

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tip:x86/urgent] x86/kexec: Don't setup EFI info if EFI runtime is not enabled
  2019-01-18 11:13 ` [PATCH v3 1/3] x86, kexec_file_load: Don't setup EFI info if EFI runtime is not enabled Kairui Song
  2019-01-25  2:53   ` Dave Young
@ 2019-02-01 17:36   ` tip-bot for Kairui Song
  1 sibling, 0 replies; 8+ messages in thread
From: tip-bot for Kairui Song @ 2019-02-01 17:36 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: x86, hpa, takahiro.akashi, linux-kernel, bp, dyoung, akpm, tglx,
	dhowells, yannik, kasong, mingo, prudo, ard.biesheuvel, mingo

Commit-ID:  2aa958c99c7fd3162b089a1a56a34a0cdb778de1
Gitweb:     https://git.kernel.org/tip/2aa958c99c7fd3162b089a1a56a34a0cdb778de1
Author:     Kairui Song <kasong@redhat.com>
AuthorDate: Fri, 18 Jan 2019 19:13:08 +0800
Committer:  Borislav Petkov <bp@suse.de>
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 <dyoung@redhat.com>
Signed-off-by: Kairui Song <kasong@redhat.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Acked-by: Dave Young <dyoung@redhat.com>
Cc: AKASHI Takahiro <takahiro.akashi@linaro.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Cc: bhe@redhat.com
Cc: David Howells <dhowells@redhat.com>
Cc: erik.schmauss@intel.com
Cc: fanc.fnst@cn.fujitsu.com
Cc: "H. Peter Anvin" <hpa@zytor.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: kexec@lists.infradead.org
Cc: lenb@kernel.org
Cc: linux-acpi@vger.kernel.org
Cc: Philipp Rudo <prudo@linux.vnet.ibm.com>
Cc: rafael.j.wysocki@intel.com
Cc: robert.moore@intel.com
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: x86-ml <x86@kernel.org>
Cc: Yannik Sembritzki <yannik@sembritzki.me>
Link: https://lkml.kernel.org/r/20190118111310.29589-2-kasong@redhat.com
---
 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;
 

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-02-01 17:37 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-01-18 11:13 [PATCH v3 0/3] make kexec work with efi=noruntime or efi=old_map Kairui Song
2019-01-18 11:13 ` [PATCH v3 1/3] x86, kexec_file_load: Don't setup EFI info if EFI runtime is not enabled Kairui Song
2019-01-25  2:53   ` Dave Young
2019-02-01 17:36   ` [tip:x86/urgent] x86/kexec: " tip-bot for Kairui Song
2019-01-18 11:13 ` [PATCH v3 2/3] acpi: store acpi_rsdp address for later kexec usage Kairui Song
2019-01-18 11:26   ` Borislav Petkov
2019-01-18 11:43     ` Kairui Song
2019-01-18 11:13 ` [PATCH v3 3/3] x86, kexec_file_load: make it work with efi=noruntime or efi=old_map Kairui Song

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).