* [PATCH hyperv-next v2 0/2] x86/hyperv: VTL mode reboot fixes
@ 2025-02-20 20:23 Roman Kisel
2025-02-20 20:23 ` [PATCH hyperv-next v2 1/2] x86/hyperv: VTL mode emergency restart callback Roman Kisel
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Roman Kisel @ 2025-02-20 20:23 UTC (permalink / raw)
To: bp, dave.hansen, decui, haiyangz, hpa, kys, mingo, tglx, wei.liu,
ssengar, linux-hyperv, linux-kernel, x86
Cc: apais, benhill, sunilmut
The first patch defines a specialized machine emergency restart
callback not to write to the physical address of 0x472 which is
what the native_machine_emergency_restart() does unconditionally.
I first wanted to tweak that function[1], and in the course of
the discussion it looked as the risks of doing that would
outweigh the benefit: the bare-metal systems have likely adopted
that behavior as a standard although I could not find any mentions
of that magic address in the UEFI+ACPI specification.
The second patch removes the need to always supply "reboot=t"
to the kernel command line in the OpenHCL bootloader[2]. There is
no other option at the moment; when/if it appears the newly added
callback's code can be adjusted as required.
Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
[1] https://lore.kernel.org/all/20250109204352.1720337-1-romank@linux.microsoft.com/
[2] https://github.com/microsoft/openvmm/blob/7a9d0e0a00461be6e5f3267af9ea54cc7157c900/openhcl/openhcl_boot/src/main.rs#L139
[V2]:
- Fixed the warning from the kernel robot about using C23.
** Thank you, kernel robot!**
- Tightened up wording in the comments and the commit
descriptions.
** Thank you, Saurabh!**
- Dropped the CC: stable tag as there is no specific commit
this patch series fixes.
** Thank you, Saurabh!**
[V1]: https://lore.kernel.org/linux-hyperv/20250117210702.1529580-1-romank@linux.microsoft.com/
Roman Kisel (2):
x86/hyperv: VTL mode emergency restart callback
x86/hyperv: VTL mode callback for restarting the system
arch/x86/hyperv/hv_vtl.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
base-commit: 3a7f7785eae7cf012af128ca9e383c91e4955354
--
2.43.0
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH hyperv-next v2 1/2] x86/hyperv: VTL mode emergency restart callback
2025-02-20 20:23 [PATCH hyperv-next v2 0/2] x86/hyperv: VTL mode reboot fixes Roman Kisel
@ 2025-02-20 20:23 ` Roman Kisel
2025-02-20 20:23 ` [PATCH hyperv-next v2 2/2] x86/hyperv: VTL mode callback for restarting the system Roman Kisel
2025-02-21 13:04 ` [PATCH hyperv-next v2 0/2] x86/hyperv: VTL mode reboot fixes Ingo Molnar
2 siblings, 0 replies; 5+ messages in thread
From: Roman Kisel @ 2025-02-20 20:23 UTC (permalink / raw)
To: bp, dave.hansen, decui, haiyangz, hpa, kys, mingo, tglx, wei.liu,
ssengar, linux-hyperv, linux-kernel, x86
Cc: apais, benhill, sunilmut
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 <romank@linux.microsoft.com>
---
arch/x86/hyperv/hv_vtl.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c
index 4e1b1e3b5658..4421b75ad9a9 100644
--- a/arch/x86/hyperv/hv_vtl.c
+++ b/arch/x86/hyperv/hv_vtl.c
@@ -12,6 +12,7 @@
#include <asm/i8259.h>
#include <asm/mshyperv.h>
#include <asm/realmode.h>
+#include <asm/reboot.h>
#include <../kernel/smpboot.h>
extern struct boot_params boot_params;
@@ -22,6 +23,27 @@ static bool __init hv_vtl_msi_ext_dest_id(void)
return true;
}
+/*
+ * The `native_machine_emergency_restart` function from `reboot.c` writes
+ * to the physical address 0x472 to indicate the type of reboot for the
+ * firmware. We cannot have that in VSM as the memory composition might
+ * be more generic, and such write effectively corrupts the memory thus
+ * making diagnostics harder at the very least.
+ */
+static void __noreturn hv_vtl_emergency_restart(void)
+{
+ /*
+ * Cause a triple fault and the immediate reset. Here the code does not run
+ * on the top of any firmware, whereby cannot reach out to its services.
+ * The inifinite loop is for the improbable case that the triple fault does
+ * not work and have to preserve the state intact for debugging.
+ */
+ for (;;) {
+ idt_invalidate();
+ __asm__ __volatile__("int3");
+ }
+}
+
void __init hv_vtl_init_platform(void)
{
pr_info("Linux runs in Hyper-V Virtual Trust Level\n");
@@ -235,6 +257,7 @@ static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip)
int __init hv_vtl_early_init(void)
{
+ machine_ops.emergency_restart = hv_vtl_emergency_restart;
/*
* `boot_cpu_has` returns the runtime feature support,
* and here is the earliest it can be used.
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH hyperv-next v2 2/2] x86/hyperv: VTL mode callback for restarting the system
2025-02-20 20:23 [PATCH hyperv-next v2 0/2] x86/hyperv: VTL mode reboot fixes Roman Kisel
2025-02-20 20:23 ` [PATCH hyperv-next v2 1/2] x86/hyperv: VTL mode emergency restart callback Roman Kisel
@ 2025-02-20 20:23 ` Roman Kisel
2025-02-21 13:04 ` [PATCH hyperv-next v2 0/2] x86/hyperv: VTL mode reboot fixes Ingo Molnar
2 siblings, 0 replies; 5+ messages in thread
From: Roman Kisel @ 2025-02-20 20:23 UTC (permalink / raw)
To: bp, dave.hansen, decui, haiyangz, hpa, kys, mingo, tglx, wei.liu,
ssengar, linux-hyperv, linux-kernel, x86
Cc: apais, benhill, sunilmut
The kernel runs as a firmware in the VTL mode, and the only way
to restart in the VTL mode on x86 is to triple fault. Thus, one
has to always supply "reboot=t" on the kernel command line in the
VTL mode, and missing that renders rebooting not working.
Define the machine restart callback to always use the triple
fault to provide the robust configuration by default.
Signed-off-by: Roman Kisel <romank@linux.microsoft.com>
---
arch/x86/hyperv/hv_vtl.c | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/arch/x86/hyperv/hv_vtl.c b/arch/x86/hyperv/hv_vtl.c
index 4421b75ad9a9..582fe820e29c 100644
--- a/arch/x86/hyperv/hv_vtl.c
+++ b/arch/x86/hyperv/hv_vtl.c
@@ -44,6 +44,15 @@ static void __noreturn hv_vtl_emergency_restart(void)
}
}
+/*
+ * The only way to restart in the VTL mode is to triple fault as the kernel runs
+ * as firmware.
+ */
+static void __noreturn hv_vtl_restart(char __maybe_unused *cmd)
+{
+ hv_vtl_emergency_restart();
+}
+
void __init hv_vtl_init_platform(void)
{
pr_info("Linux runs in Hyper-V Virtual Trust Level\n");
@@ -258,6 +267,8 @@ static int hv_vtl_wakeup_secondary_cpu(u32 apicid, unsigned long start_eip)
int __init hv_vtl_early_init(void)
{
machine_ops.emergency_restart = hv_vtl_emergency_restart;
+ machine_ops.restart = hv_vtl_restart;
+
/*
* `boot_cpu_has` returns the runtime feature support,
* and here is the earliest it can be used.
--
2.43.0
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH hyperv-next v2 0/2] x86/hyperv: VTL mode reboot fixes
2025-02-20 20:23 [PATCH hyperv-next v2 0/2] x86/hyperv: VTL mode reboot fixes Roman Kisel
2025-02-20 20:23 ` [PATCH hyperv-next v2 1/2] x86/hyperv: VTL mode emergency restart callback Roman Kisel
2025-02-20 20:23 ` [PATCH hyperv-next v2 2/2] x86/hyperv: VTL mode callback for restarting the system Roman Kisel
@ 2025-02-21 13:04 ` Ingo Molnar
2025-02-24 16:57 ` Roman Kisel
2 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2025-02-21 13:04 UTC (permalink / raw)
To: Roman Kisel
Cc: bp, dave.hansen, decui, haiyangz, hpa, kys, mingo, tglx, wei.liu,
ssengar, linux-hyperv, linux-kernel, x86, apais, benhill,
sunilmut
* Roman Kisel <romank@linux.microsoft.com> wrote:
> Roman Kisel (2):
> x86/hyperv: VTL mode emergency restart callback
> x86/hyperv: VTL mode callback for restarting the system
A: These two patch titles verbs.
...
...
B: These two patch titles are missing verbs.
Like me you prefer B too, right? If so, please add back the missing
verbs to the titles. I suggest "Add"/"Introduce", and "Call". Thank you!
Ingo
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH hyperv-next v2 0/2] x86/hyperv: VTL mode reboot fixes
2025-02-21 13:04 ` [PATCH hyperv-next v2 0/2] x86/hyperv: VTL mode reboot fixes Ingo Molnar
@ 2025-02-24 16:57 ` Roman Kisel
0 siblings, 0 replies; 5+ messages in thread
From: Roman Kisel @ 2025-02-24 16:57 UTC (permalink / raw)
To: Ingo Molnar
Cc: bp, dave.hansen, decui, haiyangz, hpa, kys, mingo, tglx, wei.liu,
ssengar, linux-hyperv, linux-kernel, x86, apais, benhill,
sunilmut
On 2/21/2025 5:04 AM, Ingo Molnar wrote:
>
> * Roman Kisel <romank@linux.microsoft.com> wrote:
>
>> Roman Kisel (2):
>> x86/hyperv: VTL mode emergency restart callback
>> x86/hyperv: VTL mode callback for restarting the system
>
> A: These two patch titles verbs.
> ...
> ...
> B: These two patch titles are missing verbs.
>
> Like me you prefer B too, right? If so, please add back the missing
> verbs to the titles. I suggest "Add"/"Introduce", and "Call". Thank you!
Right :) Thank you for taking the time to help me, much appreciated!
>
> Ingo
--
Thank you,
Roman
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-02-24 16:57 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-20 20:23 [PATCH hyperv-next v2 0/2] x86/hyperv: VTL mode reboot fixes Roman Kisel
2025-02-20 20:23 ` [PATCH hyperv-next v2 1/2] x86/hyperv: VTL mode emergency restart callback Roman Kisel
2025-02-20 20:23 ` [PATCH hyperv-next v2 2/2] x86/hyperv: VTL mode callback for restarting the system Roman Kisel
2025-02-21 13:04 ` [PATCH hyperv-next v2 0/2] x86/hyperv: VTL mode reboot fixes Ingo Molnar
2025-02-24 16:57 ` Roman Kisel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).