All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/setup: call early_reserve_memory() earlier
@ 2021-09-14  9:41 Juergen Gross
  2021-09-14 10:03 ` Jan Beulich
                   ` (2 more replies)
  0 siblings, 3 replies; 27+ messages in thread
From: Juergen Gross @ 2021-09-14  9:41 UTC (permalink / raw)
  To: xen-devel, x86, linux-kernel
  Cc: Juergen Gross, Thomas Gleixner, Ingo Molnar, Borislav Petkov,
	H. Peter Anvin, stable, Marek Marczykowski-Górecki

Commit a799c2bd29d19c565 ("x86/setup: Consolidate early memory
reservations") introduced early_reserve_memory() to do all needed
initial memblock_reserve() calls in one function. Unfortunately the
call of early_reserve_memory() is done too late for Xen dom0, as in
some cases a Xen hook called by e820__memory_setup() will need those
memory reservations to have happened already.

Move the call of early_reserve_memory() to the beginning of
setup_arch() in order to avoid such problems.

Cc: stable@vger.kernel.org
Fixes: a799c2bd29d19c565 ("x86/setup: Consolidate early memory reservations")
Reported-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
---
 arch/x86/kernel/setup.c | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 79f164141116..f369c51ec580 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -757,6 +757,18 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
 
 void __init setup_arch(char **cmdline_p)
 {
+	/*
+	 * Do some memory reservations *before* memory is added to
+	 * memblock, so memblock allocations won't overwrite it.
+	 * Do it after early param, so we could get (unlikely) panic from
+	 * serial.
+	 *
+	 * After this point everything still needed from the boot loader or
+	 * firmware or kernel text should be early reserved or marked not
+	 * RAM in e820. All other memory is free game.
+	 */
+	early_reserve_memory();
+
 #ifdef CONFIG_X86_32
 	memcpy(&boot_cpu_data, &new_cpu_data, sizeof(new_cpu_data));
 
@@ -876,18 +888,6 @@ void __init setup_arch(char **cmdline_p)
 
 	parse_early_param();
 
-	/*
-	 * Do some memory reservations *before* memory is added to
-	 * memblock, so memblock allocations won't overwrite it.
-	 * Do it after early param, so we could get (unlikely) panic from
-	 * serial.
-	 *
-	 * After this point everything still needed from the boot loader or
-	 * firmware or kernel text should be early reserved or marked not
-	 * RAM in e820. All other memory is free game.
-	 */
-	early_reserve_memory();
-
 #ifdef CONFIG_MEMORY_HOTPLUG
 	/*
 	 * Memory used by the kernel cannot be hot-removed because Linux
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 27+ messages in thread
* [PATCH v2] x86/setup: call early_reserve_memory() earlier
@ 2021-09-20 12:04 Juergen Gross
  2021-09-22 17:18 ` [tip: x86/urgent] x86/setup: Call " tip-bot2 for Juergen Gross
  0 siblings, 1 reply; 27+ messages in thread
From: Juergen Gross @ 2021-09-20 12:04 UTC (permalink / raw)
  To: xen-devel, x86, linux-kernel
  Cc: efault, Juergen Gross, Thomas Gleixner, Ingo Molnar,
	Borislav Petkov, H. Peter Anvin, stable,
	Marek Marczykowski-Górecki

Commit a799c2bd29d19c565 ("x86/setup: Consolidate early memory
reservations") introduced early_reserve_memory() to do all needed
initial memblock_reserve() calls in one function. Unfortunately the
call of early_reserve_memory() is done too late for Xen dom0, as in
some cases a Xen hook called by e820__memory_setup() will need those
memory reservations to have happened already.

Move the call of early_reserve_memory() before the call of
e820__memory_setup() in order to avoid such problems.

Cc: stable@vger.kernel.org
Fixes: a799c2bd29d19c565 ("x86/setup: Consolidate early memory reservations")
Reported-by: Marek Marczykowski-Górecki <marmarek@invisiblethingslab.com>
Signed-off-by: Juergen Gross <jgross@suse.com>
---
V2:
- update comment (Jan Beulich, Boris Petkov)
- move call down in setup_arch() (Mike Galbraith)
---
 arch/x86/kernel/setup.c | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 79f164141116..40ed44ead063 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -830,6 +830,20 @@ void __init setup_arch(char **cmdline_p)
 
 	x86_init.oem.arch_setup();
 
+	/*
+	 * Do some memory reservations *before* memory is added to memblock, so
+	 * memblock allocations won't overwrite it.
+	 *
+	 * After this point, everything still needed from the boot loader or
+	 * firmware or kernel text should be early reserved or marked not RAM in
+	 * e820. All other memory is free game.
+	 *
+	 * This call needs to happen before e820__memory_setup() which calls the
+	 * xen_memory_setup() on Xen dom0 which relies on the fact that those
+	 * early reservations have happened already.
+	 */
+	early_reserve_memory();
+
 	iomem_resource.end = (1ULL << boot_cpu_data.x86_phys_bits) - 1;
 	e820__memory_setup();
 	parse_setup_data();
@@ -876,18 +890,6 @@ void __init setup_arch(char **cmdline_p)
 
 	parse_early_param();
 
-	/*
-	 * Do some memory reservations *before* memory is added to
-	 * memblock, so memblock allocations won't overwrite it.
-	 * Do it after early param, so we could get (unlikely) panic from
-	 * serial.
-	 *
-	 * After this point everything still needed from the boot loader or
-	 * firmware or kernel text should be early reserved or marked not
-	 * RAM in e820. All other memory is free game.
-	 */
-	early_reserve_memory();
-
 #ifdef CONFIG_MEMORY_HOTPLUG
 	/*
 	 * Memory used by the kernel cannot be hot-removed because Linux
-- 
2.26.2


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

end of thread, other threads:[~2021-11-04 17:36 UTC | newest]

Thread overview: 27+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-14  9:41 [PATCH] x86/setup: call early_reserve_memory() earlier Juergen Gross
2021-09-14 10:03 ` Jan Beulich
2021-09-14 11:06   ` Juergen Gross
2021-09-15 11:00     ` Borislav Petkov
2021-09-16  9:09       ` Mike Rapoport
2021-09-16 10:29         ` Borislav Petkov
2021-09-16 10:31           ` Juergen Gross
2021-09-14 10:49 ` Marek Marczykowski-Górecki
2021-09-16 10:50 ` [tip: x86/urgent] x86/setup: Call " tip-bot2 for Juergen Gross
2021-09-19 16:55   ` Mike Galbraith
2021-09-19 17:04     ` Mike Rapoport
2021-09-20  0:56       ` Mike Galbraith
2021-09-20  9:26         ` Mike Rapoport
2021-09-20  9:38           ` Borislav Petkov
2021-09-20 11:25           ` Mike Galbraith
2021-09-20 11:33             ` Juergen Gross
2021-09-19 17:15     ` Borislav Petkov
2021-09-20  6:00       ` Juergen Gross
2021-09-20  9:46         ` Mike Rapoport
2021-09-20 22:48       ` Nathan Chancellor
2021-09-21  3:38         ` Borislav Petkov
2021-09-21  3:59           ` Nathan Chancellor
2021-09-21  7:36             ` Borislav Petkov
2021-09-20 12:04 [PATCH v2] x86/setup: call " Juergen Gross
2021-09-22 17:18 ` [tip: x86/urgent] x86/setup: Call " tip-bot2 for Juergen Gross
2021-11-04  5:38   ` Williams, Dan J
2021-11-04 11:40     ` Borislav Petkov
2021-11-04 17:36       ` Dan Williams

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.