From nobody Thu Apr 2 14:10:31 2026 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 37F821FCF41 for ; Sat, 28 Mar 2026 08:16:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774685801; cv=none; b=DVKixy3guSFR1jR5jPSA8qFhh0HrSXSAukYERPgYy6zon1p6/BiUNeET9gs+PspUaJ8AwnxORYsh9fDueouZRCj5S8JjGRFf0wDENAx+4DK2K4MKMjZHfMMW8KrGvqCSq/56gutWqJiXGS9Uhh6ErrUC8PGOsywuQCZrx+06g/4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1774685801; c=relaxed/simple; bh=DANvmyDZd67uvTLqnzrjSAObicoJIl7E5lmM7R8T+P4=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=ejdCxJzajxjcNNQ253M4mfvJ0ARKh53Xyq4JreOAbZ3U6nGim5t7Ba2AGegGAM5EnDLB9IQU37QINjWz78b7hT+x1XnDD6KhFtTpSexIg+D8NRvRXf6847CvFGStvUzyhCcPjPau87Gyh4w6uIgnzjO69zOOsWh84Gc7rxYNQ8E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=pJ5Ts4w0; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="pJ5Ts4w0" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5BDF3C4CEF7; Sat, 28 Mar 2026 08:16:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1774685800; bh=DANvmyDZd67uvTLqnzrjSAObicoJIl7E5lmM7R8T+P4=; h=From:To:Cc:Subject:Date:From; b=pJ5Ts4w0Cz4GnpTxWjFSoHtH0wrJ2ibVF+IgIT1uKo+/9qzfjehjmEr00oLr0S1YD PaC2+gsQCCFpvMZ8Rcxlwll4n5BoAwQeT9orYJdImeNCYUEX2drl88txuvaTKqzXKt e46V9Sfc1jGiZ+GmMy9FDJWXCje5oSxV+B9AAupp7g/qH5w0MotXDeJLReCUxLvKqW RPQXARqLsW3i4SbEPD5/m1jaXhTVTbevWCcbhzlr/v+bmfkKTgElMtcbgdyHdKngV9 mMrnNN1SV9qF6ysQQgSEaZIhFYDLJelnfclHwCJYpwIYs9qdshX6aVJwQaSFovx4wQ Xq3ALw02cPGTA== From: Mike Rapoport To: x86@kernel.org Cc: Borislav Petkov , Bert Karwatzki , Dave Hansen , Ingo Molnar , Mike Rapoport , "H. Peter Anvin" , Peter Zijlstra , Thomas Gleixner , linux-kernel@vger.kernel.org Subject: [PATCH] x86/alternative: delay freeing of smp_locks section Date: Sat, 28 Mar 2026 11:16:34 +0300 Message-ID: <20260328081634.797552-1-rppt@kernel.org> X-Mailer: git-send-email 2.53.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: "Mike Rapoport (Microsoft)" 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) Tested-By: Bert Karwatzki Reported-by: Bert Karwatzki Tested-by: Bert Karwatzki --- 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 =20 + restart_nmi(); + alternatives_patched =3D 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() =3D=3D 1) { free_init_pages("SMP alternatives", (unsigned long)__smp_locks, (unsigned long)__smp_locks_end); } -#endif =20 - restart_nmi(); - alternatives_patched =3D 1; - - alt_reloc_selftest(); + return 0; } +arch_initcall(free_smp_locks); +#endif =20 /** * text_poke_early - Update instructions on a live kernel at boot time base-commit: e77a5a5cfe43b4c25bd44a3818e487033287517f --=20 2.53.0