[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[XTF PATCH v2 1/2] x86: Remove Xen as a hard requirement to run XTF.


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
  • Date: Thu, 2 Oct 2025 15:55:33 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0)
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=1F0c76oApIucIy9Rt+2Zft8XHzgKLKIorNjQ2faBZ/Y=; b=vZQhe06Bvx6iYa+LGyRArT7a3hF7qVQ4A2hALc8QojlGKWTMu74cNSbUKy8geIHYsC40Z5a2Ptue5WO4gxcYSTBRZzzocLHXByZq2IFSyuHTerWZE2tR5Di0IGd4Lu9k9GyU4NuJj/ZzEj68b3wNk4PLNJ0ma8G6ONnIazS5soRoQvMrCfAWRLZSxoNS+ny0gVxdSgLtbp0bHTRJRkvTJ+uwS8RQ0SJc1s8sbcqhJPX8XkvWxrwTE+kHIBohnf1ft10Sdol7CPzzcNCdo9i0JqgyTY1EhAUtp7wHC8o2C4T1TGy/e3soyOZxAjr5nPQrLtBqACDyvJqaLu0Ps11/Qw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=cZLtZfWDRKa8v9HpEldTju8eCwK4exQsf3AfskLna6HD68ovCnV7HAkGOHGeh0yeHtdQod465NDFK6FkYpFKltOkgtk9Qvaa/JyLqxaWaX8JgPzcKRGzjEUJF3sJAfxRDGEjFdYrwi7fstLqtAf0k00k2hvwEABQbH41mSd4+wvKmUy5BrLuFJTw7/wIA73HmNsRsYVmn405YAg44B42cqJZh+qeC3wNzUr9VoNfZbbz0ivGOfHUOA5xVYiOkfeQN0hwyC44HHcoQQqzabeSI6YtG8qPhN9Zw+G7USHbT5euvCgrkEcEJq7p8XstUIJqoOBpLhUKyRrVWkXW+sM/ow==
  • Cc: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Thu, 02 Oct 2025 13:56:16 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

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.

Signed-off-by: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
---
I can't really integrate the checks on find_xen_leaves() as I intended because
many functions just don't need it (prepping xenbus, for instance), so I've left
things as they were in v1. It does work this way.

v2:
  * Use new now available rep_outsb() helper for the com1 writer
  * Make find_xen_leaves() fallible, and add an extra boolean to preserve
    the panic behaviour where it still matters.
---
 arch/x86/setup.c | 53 ++++++++++++++++++++++++++++++++++--------------
 1 file changed, 38 insertions(+), 15 deletions(-)

diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index ba6f9c3..be42c84 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -102,12 +102,13 @@ static void collect_cpuid(cpuid_count_fn_t cpuid_fn)
  * Find the Xen CPUID leaves.  They may be at 0x4000_0000, or at 0x4000_0100
  * if Xen is e.g. providing a viridian interface to the guest too.
  */
-static unsigned int find_xen_leaves(void)
+static unsigned int find_xen_leaves(bool assert_found)
 {
+#define XEN_LEAVES_NOT_FOUND (-1U)
     static unsigned int leaves;
 
     if ( leaves )
-        return leaves;
+        goto out;
 
     for ( unsigned int l = XEN_CPUID_FIRST_LEAF;
           l < XEN_CPUID_FIRST_LEAF + 0x10000; l += 0x100 )
@@ -126,7 +127,13 @@ static unsigned int find_xen_leaves(void)
         }
     }
 
-    panic("Unable to locate Xen CPUID leaves\n");
+    leaves = XEN_LEAVES_NOT_FOUND;
+
+out:
+    if ( assert_found && (leaves == XEN_LEAVES_NOT_FOUND) )
+        panic("Unable to locate Xen CPUID leaves\n");
+
+    return leaves;
 }
 
 /*
@@ -140,7 +147,7 @@ static void init_hypercalls(void)
     if ( IS_DEFINED(CONFIG_HVM) )
     {
         uint32_t eax, ebx, ecx, edx;
-        unsigned int base = find_xen_leaves();
+        unsigned int base = find_xen_leaves(true);
 
         cpuid(base + 2, &eax, &ebx, &ecx, &edx);
         wrmsr(ebx, _u(hypercall_page));
@@ -248,6 +255,11 @@ static void qemu_console_write(const char *buf, size_t len)
     rep_outsb(buf, len, 0x12);
 }
 
+static void com1_console_write(const char *buf, size_t len)
+{
+    rep_outsb(buf, len, 0x3f8);
+}
+
 static void xen_console_write(const char *buf, size_t len)
 {
     hypercall_console_write(buf, len);
@@ -255,10 +267,18 @@ static void xen_console_write(const char *buf, size_t len)
 
 void arch_setup(void)
 {
-    if ( IS_DEFINED(CONFIG_HVM) && !pvh_start_info )
-        register_console_callback(qemu_console_write);
+    bool has_xen_hypervisor =
+        find_xen_leaves(IS_DEFINED(CONFIG_PV)) != XEN_LEAVES_NOT_FOUND;
 
-    register_console_callback(xen_console_write);
+    if ( has_xen_hypervisor )
+    {
+        if ( IS_DEFINED(CONFIG_HVM) && !pvh_start_info )
+            register_console_callback(qemu_console_write);
+
+        register_console_callback(xen_console_write);
+    }
+    else
+        register_console_callback(com1_console_write);
 
     collect_cpuid(IS_DEFINED(CONFIG_PV) ? pv_cpuid_count : cpuid_count);
 
@@ -266,15 +286,18 @@ void arch_setup(void)
 
     arch_init_traps();
 
-    init_hypercalls();
-
-    if ( !is_initdomain() )
+    if ( has_xen_hypervisor )
     {
-        setup_pv_console();
-        setup_xenbus();
-    }
+        init_hypercalls();
 
-    map_shared_info();
+        if ( !is_initdomain() )
+        {
+            setup_pv_console();
+            setup_xenbus();
+        }
+
+        map_shared_info();
+    }
 }
 
 int arch_get_domid(void)
@@ -282,7 +305,7 @@ int arch_get_domid(void)
     if ( IS_DEFINED(CONFIG_HVM) )
     {
         uint32_t eax, ebx, ecx, edx;
-        unsigned int base = find_xen_leaves();
+        unsigned int base = find_xen_leaves(true);
 
         cpuid_count(base + 4, 0, &eax, &ebx, &ecx, &edx);
 
-- 
2.43.0




 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.