Skip to content

Commit 0cf6361

Browse files
committed
x86/hyperv: Add VTL mode emergency restart callback
By default, X86(-64) systems use the emergecy restart routine in the course of which the code unconditionally writes to the physical address of 0x472 to indicate the boot mode to the firmware (BIOS or UEFI). When the kernel itself runs as a firmware in the VTL mode, that write corrupts the memory of the guest upon emergency restarting. Preserving the state intact in that situation is important for debugging, at least. Define the specialized machine callback to avoid that write and use the triple fault to perform emergency restart. Signed-off-by: Roman Kisel <[email protected]>
1 parent b63e906 commit 0cf6361

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

arch/x86/hyperv/hv_vtl.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <asm/fpu/xcr.h>
1818
#include <asm/realmode.h>
1919
#include <asm/tdx.h>
20+
#include <asm/reboot.h>
2021
#include <asm/sev.h>
2122
#include <uapi/asm/mtrr.h>
2223

@@ -47,6 +48,27 @@ static bool hv_vtl_is_private_mmio_tdx(u64 addr)
4748
return mb_addr && within_page(addr, mb_addr);
4849
}
4950

51+
/*
52+
* The `native_machine_emergency_restart` function from `reboot.c` writes
53+
* to the physical address 0x472 to indicate the type of reboot for the
54+
* firmware. We cannot have that in VSM as the memory composition might
55+
* be more generic, and such write effectively corrupts the memory thus
56+
* making diagnostics harder at the very least.
57+
*/
58+
static void __noreturn hv_vtl_emergency_restart(void)
59+
{
60+
/*
61+
* Cause a triple fault and the immediate reset. Here the code does not run
62+
* on the top of any firmware, whereby cannot reach out to its services.
63+
* The inifinite loop is for the improbable case that the triple fault does
64+
* not work and have to preserve the state intact for debugging.
65+
*/
66+
for (;;) {
67+
idt_invalidate();
68+
__asm__ __volatile__("int3");
69+
}
70+
}
71+
5072
void __init hv_vtl_init_platform(void)
5173
{
5274
pr_info("Linux runs in Hyper-V Virtual Trust Level\n");
@@ -231,6 +253,7 @@ static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip, unsi
231253

232254
int __init hv_vtl_early_init(void)
233255
{
256+
machine_ops.emergency_restart = hv_vtl_emergency_restart;
234257
/*
235258
* `boot_cpu_has` returns the runtime feature support,
236259
* and here is the earliest it can be used.

0 commit comments

Comments
 (0)