Skip to contentSkip to conversation

Remove Xen as a hard requirement to run XTF

PATCH In review Alejandro Vallejo 1 participant 5 messages Oct 6, 2025 x86

lore
Share & tools
lore
#0 lore raw

v3 cover Remove Xen as a hard requirement to run XTF

Hi,

This version includes gating access to the hypercall page on shutdown through a new cpu_has_xen global boolean. I also implemented Rogers' suggestion to poison the hypercall page with int3 (opcode 0xcc).

Cheers,
Alejandro

Alejandro Vallejo (3):
x86: Remove Xen as a hard requirement to run XTF.
x86: Allow exiting QEMU in TCG/QEMU
x86: Poison hypercall page with int3 rather than ret

 arch/x86/hypercall_page.S     |  4 +--
 arch/x86/include/arch/cpuid.h |  2 ++
 arch/x86/setup.c              | 55 +++++++++++++++++++++++++----------
 arch/x86/traps.c              | 15 ++++++++++
 common/lib.c                  |  2 +-
 common/report.c               |  8 +++--
 include/xtf/framework.h       |  3 ++
 7 files changed, 68 insertions(+), 21 deletions(-)

base-commit: 453490df6f65fb503a39b1bddf0093441eece9ae

Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/3 x86: Remove Xen as a hard requirement to run XTF.

If Xen isn't detected on CPUID, then:

* Skip setting up Xenbus/PV-console/shared_info/hypercalls/qemu-debug.
* Register COM1 as an output callback.
* Attempt a QEMU exit via the ISA debug exit device

This patch enables running XTF on QEMU-TCG/KVM out of the box. And a minor tweaks to set up baud rate make it work on real hardware too.

---
v3:
* Introduce cpu_has_xen. To be used in next patch to skip issuing a hypercall when Xen ain't there.

---
 arch/x86/include/arch/cpuid.h |  2 ++
 arch/x86/setup.c              | 55 +++++++++++++++++++++++++----------
 2 files changed, 42 insertions(+), 15 deletions(-)
arch/x86/include/arch/cpuid.h +2 -0
index 364b0b4..518aaf2 100644
@@ -101,6 +101,8 @@ static inline bool cpu_has(unsigned int feature)
 
 #define cpu_has_rtm_always_abort cpu_has(X86_FEATURE_RTM_ALWAYS_ABORT)
 
+extern bool cpu_has_xen;
+
 #endif /* XTF_X86_CPUID_H */
 
 /*
arch/x86/setup.c +40 -15

114 lines not on this page · raw message

Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/3 x86: Allow exiting QEMU in TCG/QEMU

In reply to Alejandro Vallejo

If QEMU has a debug isa-debug-exit device, we can simply write to it to exit rather than spinning after a failed hypercall.

There's nothing to signal its existence, so it's a best-effort write after a shutdown attempt via hypercall.

---
v3:
* Moved arch_shutdown() from HVM/PV folders to arch/x86/traps.c There's nothing terribly specific about it.
* Gated calling hypercall_shutdown() on cpu_has_xen being set

---
 arch/x86/traps.c        | 15 +++++++++++++++
 common/lib.c            |  2 +-
 common/report.c         |  8 +++++---
 include/xtf/framework.h |  3 +++
 4 files changed, 24 insertions(+), 4 deletions(-)
arch/x86/traps.c +15 -0
index 1f82752..b530719 100644
@@ -80,6 +80,21 @@ void __weak do_evtchn(struct cpu_regs *regs)
     panic("Unhandled evtchn upcall\n");
 }
 
+void arch_shutdown(unsigned int reason)
+{
+    if ( cpu_has_xen )
+        hypercall_shutdown(reason);
+
+    /*
+     * Not running under Xen. Attempt exit via the QEMU ISA debug exit device on
+     * its default port.
+     *
+     * QEMU's rc is (reason << 1) | 1, if "-device isa-debug-exit" is set.
+     */
+    if ( IS_DEFINED(CONFIG_HVM) )
+        outb(reason, 0x501);
+}
+
 /*
  * Local variables:
  * mode: C
common/lib.c +1 -1
index 7f1813f..f4de22e 100644
@@ -25,7 +25,7 @@ void __noreturn panic(const char *fmt, ...)
 
     printk("******************************\n");
 
-    hypercall_shutdown(SHUTDOWN_crash);
+    arch_shutdown(SHUTDOWN_crash);
     arch_crash_hard();
 }
 
common/report.c +5 -3
index ffdf098..158876e 100644
@@ -1,6 +1,8 @@
+#include <xtf/framework.h>
 #include <xtf/lib.h>
 #include <xtf/report.h>
-#include <xtf/hypercall.h>
+
+#include <xen/sched.h>
 
 enum test_status {
     STATUS_RUNNING, /**< Test not yet completed.       */
@@ -124,8 +126,8 @@ bool xtf_status_reported(void)
 void xtf_exit(void)
 {
     xtf_report_status();
-    hypercall_shutdown(SHUTDOWN_poweroff);
-    panic("xtf_exit(): hypercall_shutdown(SHUTDOWN_poweroff) returned\n");
+    arch_shutdown(SHUTDOWN_poweroff);
+    panic("xtf_exit(): arch_shutdown(SHUTDOWN_poweroff) returned\n");
 }
 
 /*
include/xtf/framework.h +3 -0
index 95de195..e852882 100644
@@ -16,6 +16,9 @@ void arch_setup(void);
 /* Set up test-specific configuration. */
 void test_setup(void);
 
+/* Stop the machine. See SHUTDOWN_poweroff et al for reasons */
+void arch_shutdown(unsigned int reason);
+
 /*
  * In the case that normal shutdown actions have failed, contain execution as
  * best as possible.
Signature · 1 line
2.43.0
#3 lore raw

Re: [XTF PATCH v3 2/3] x86: Allow exiting QEMU in TCG/QEMU

Quoted 24 lines · Alejandro Vallejo

If QEMU has a debug isa-debug-exit device, we can simply write to it to exit rather than spinning after a failed hypercall.

There's nothing to signal its existence, so it's a best-effort write after a shutdown attempt via hypercall.

---
v3:
* Moved arch_shutdown() from HVM/PV folders to arch/x86/traps.c There's nothing terribly specific about it.
* Gated calling hypercall_shutdown() on cpu_has_xen being set

---
 arch/x86/traps.c        | 15 +++++++++++++++
 common/lib.c            |  2 +-
 common/report.c         |  8 +++++---
 include/xtf/framework.h |  3 +++
 4 files changed, 24 insertions(+), 4 deletions(-)
arch/x86/traps.c +0 -0
index 1f82752..b530719 100644

arch/x86/traps.c void __weak do_evtchn(struct cpu_regs *regs) · line 81

Quoted 2 lines
arch/x86/traps.c +0 -0
@@ -80,6 +80,21 @@ void __weak do_evtchn(struct cpu_regs *regs)
     panic("Unhandled evtchn upcall\n");
 }

Bah. Missing "#include <xtf/hypercall.h>"

Otherwise works as intended.

Cheers,
Alejandro

#4 lore raw

PATCH v3 3/3 x86: Poison hypercall page with `int3` rather than `ret`

In reply to Alejandro Vallejo

Making a hypercall with the hypercall page absent should not have a happy ending. At best it's just weird, but at worst it might allow an otherwise failing test to pass.

---
./xtf-runner -a passes

v3:
* New patch based on Roger's suggestion

---
 arch/x86/hypercall_page.S | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/x86/hypercall_page.S +2 -2
index cc6ddc2..de0a991 100644
@@ -6,8 +6,8 @@
         .p2align PAGE_SHIFT
 
 GLOBAL(hypercall_page)
-         /* Poisoned with `ret` for safety before hypercalls are set up. */
-        .fill PAGE_SIZE, 1, 0xc3
+         /* Poisoned with `int3` so a stray hypercall is patently clear */
+        .fill PAGE_SIZE, 1, 0xcc
         .type hypercall_page, STT_OBJECT
         .size hypercall_page, PAGE_SIZE
 
Signature · 1 line
2.43.0