public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] x86/reboot: Don't corrupt memory on non-BIOS systems
@ 2025-01-09 20:43 Roman Kisel
  2025-01-10  3:23 ` H. Peter Anvin
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Roman Kisel @ 2025-01-09 20:43 UTC (permalink / raw)
  To: akpm, bhe, bp, dave.hansen, hpa, kai.huang, kirill.shutemov,
	mingo, pbonzini, tglx, x86, linux-kernel
  Cc: apais, benhill, ssengar, sunilmut, vdso

native_machine_emergency_restart() writes unconditionally
to the physical address of 0x472 to pass the warm reboot
flags to BIOS. The BIOS reads this on booting to bypass memory
test and do the warm boot. On the non-BIOS systems, other
means have to be employed, and this write is a memory corruption.

Fix that by moving the offending write into the case where
the machine is rebooted via BIOS.

Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
---
 arch/x86/kernel/reboot.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
index 615922838c51..6eec8653493f 100644
--- a/arch/x86/kernel/reboot.c
+++ b/arch/x86/kernel/reboot.c
@@ -637,9 +637,8 @@ static void native_machine_emergency_restart(void)
 
 	tboot_shutdown(TB_SHUTDOWN_REBOOT);
 
-	/* Tell the BIOS if we want cold or warm reboot */
+	/* Tell the firmware if we want cold or warm reboot */
 	mode = reboot_mode == REBOOT_WARM ? 0x1234 : 0;
-	*((unsigned short *)__va(0x472)) = mode;
 
 	/*
 	 * If an EFI capsule has been registered with the firmware then
@@ -681,6 +680,7 @@ static void native_machine_emergency_restart(void)
 			break;
 
 		case BOOT_BIOS:
+			*((unsigned short *)__va(0x472)) = mode;
 			machine_real_restart(MRR_BIOS);
 
 			/* We're probably dead after this, but... */

base-commit: eea6e4b4dfb8859446177c32961c96726d0117be
-- 
2.34.1


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

end of thread, other threads:[~2025-02-25 20:47 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-09 20:43 [PATCH] x86/reboot: Don't corrupt memory on non-BIOS systems Roman Kisel
2025-01-10  3:23 ` H. Peter Anvin
2025-01-10 20:51   ` Roman Kisel
2025-01-10  3:25 ` H. Peter Anvin
2025-01-10 21:05   ` Roman Kisel
2025-02-25 20:25 ` Ingo Molnar
2025-02-25 20:28   ` H. Peter Anvin
2025-02-25 20:39     ` Ingo Molnar
2025-02-25 20:46       ` H. Peter Anvin

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