public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/alternative: delay freeing of smp_locks section
@ 2026-03-28  8:16 Mike Rapoport
  2026-03-28 11:41 ` Borislav Petkov
  0 siblings, 1 reply; 9+ messages in thread
From: Mike Rapoport @ 2026-03-28  8:16 UTC (permalink / raw)
  To: x86
  Cc: Borislav Petkov, Bert Karwatzki, Dave Hansen, Ingo Molnar,
	Mike Rapoport, H. Peter Anvin, Peter Zijlstra, Thomas Gleixner,
	linux-kernel

From: "Mike Rapoport (Microsoft)" <rppt@kernel.org>

On UP systems alternative_instructions() frees memory occupied by smp_locks
section immediately after patching the lock instructions.

With CONFIG_DEFERRED_STRUCT_PAGE_INIT enabled this happens before the
memory map is fully initialized and the struct pages representing the freed
memory might get overwritten by deferred initialization of the memory map.

Move freeing of smp_locks section to an initcall to ensure it will happen
after the memory map is fully initialized.

Signed-off-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
Tested-By: Bert Karwatzki <spasswolf@web.de>
---
 arch/x86/kernel/alternative.c | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
index e87da25d1236..62936a3bde19 100644
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -2448,19 +2448,31 @@ void __init alternative_instructions(void)
 					    __smp_locks, __smp_locks_end,
 					    _text, _etext);
 	}
+#endif
 
+	restart_nmi();
+	alternatives_patched = 1;
+
+	alt_reloc_selftest();
+}
+
+#ifdef CONFIG_SMP
+/*
+ * With CONFIG_DEFERRED_STRUCT_PAGE_INIT enabled we can free_init_pages() only
+ * after the deferred initialization of the memory map is complete.
+ */
+static int __init free_smp_locks(void)
+{
 	if (!uniproc_patched || num_possible_cpus() == 1) {
 		free_init_pages("SMP alternatives",
 				(unsigned long)__smp_locks,
 				(unsigned long)__smp_locks_end);
 	}
-#endif
 
-	restart_nmi();
-	alternatives_patched = 1;
-
-	alt_reloc_selftest();
+	return 0;
 }
+arch_initcall(free_smp_locks);
+#endif
 
 /**
  * text_poke_early - Update instructions on a live kernel at boot time

base-commit: e77a5a5cfe43b4c25bd44a3818e487033287517f
-- 
2.53.0


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

end of thread, other threads:[~2026-03-30 20:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-28  8:16 [PATCH] x86/alternative: delay freeing of smp_locks section Mike Rapoport
2026-03-28 11:41 ` Borislav Petkov
2026-03-28 12:39   ` Mike Rapoport
2026-03-28 19:58     ` Borislav Petkov
2026-03-30 17:16       ` Mike Rapoport
2026-03-30 17:44         ` Borislav Petkov
2026-03-30 19:36           ` Peter Zijlstra
2026-03-30 19:43             ` H. Peter Anvin
2026-03-30 20:20               ` Borislav Petkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox