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

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


  • To: <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>
  • Date: Mon, 6 Oct 2025 12:25:56 +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=fLCpUEK0V9qedPMxM85zA4whQVIbTmvcxPg6YTqoMRQ=; b=JrJuTxFdsV8AnoiGk1EmD+fCsJW3NhHYxfne2c6kjRsA6NR8ZNWRKa4fEMzf6lOIEw4jgadn9wTrP6sfCjPyEMb3fAWIotpGz+SBTkXE+/gTi+JdCoFTDnn+rfDDubb+PBTH/dKfSbJrp1694MjGSjfGiYka/KTilZRCVB6LBT9eD7+2pRmhRKocve+pvrqiLpeZsr2EoPbRfh28LQgtKGDvkA5NSiXeOjZS7hgoZS/n+zMqk9OZpxUDBiNORgm25Xb84JSY15Clofu3pKSbgOMxzQN4CKQcAf6yZyJThI3PyrmuwCVmhLlVb2kag2p89dT02PpsL8CucgxXCKKyag==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=l7RU2Xez19v92gri4TwOsOVgGOwThejfxJzqT+cDi7zsowC4/ITSLWXDN1+uKQ7m2LJF+mrWsKdi/ZigxVoppSvJ3kQ1ywMvBfZ1rwJNSOBKw8hZM0smvJAEQaAmxRnwA1vKnpntJp6PHeCT1EUHq+nQEAmmhHnthbWuN5v+WF9y+M8m8umCm80hN3jroijg+PkVMltcHotPf9B9YKmXLZSlalJVR31ALOPY/92Ae4HbrYtRwoeeCf41mPt9k1lx/y4iaJKZIFTd4a11vzTx6NxeAeaDz300ijaxH34XCnrQWiJsn3VQ4b0M81KB5Sjh7C+fZFqvAVgSAXUUcD107Q==
  • Cc: Alejandro Vallejo <alejandro.garciavallejo@xxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>, Roger Pau Monne <roger.pau@xxxxxxxxxx>
  • Delivery-date: Mon, 06 Oct 2025 10:28:34 +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>
---
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(-)

diff --git a/arch/x86/include/arch/cpuid.h b/arch/x86/include/arch/cpuid.h
index 364b0b4..518aaf2 100644
--- a/arch/x86/include/arch/cpuid.h
+++ b/arch/x86/include/arch/cpuid.h
@@ -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 */
 
 /*
diff --git a/arch/x86/setup.c b/arch/x86/setup.c
index ba6f9c3..929d8aa 100644
--- a/arch/x86/setup.c
+++ b/arch/x86/setup.c
@@ -26,6 +26,7 @@ enum x86_vendor x86_vendor;
 unsigned int max_leaf, max_extd_leaf;
 unsigned int x86_family, x86_model, x86_stepping;
 unsigned int maxphysaddr, maxvirtaddr;
+bool cpu_has_xen = IS_DEFINED(CONFIG_PV);
 
 const char environment_description[] = ENVIRONMENT_DESCRIPTION;
 
@@ -102,12 +103,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 )
@@ -122,11 +124,19 @@ static unsigned int find_xen_leaves(void)
              ((eax - l) >= 2) )
         {
             leaves = l;
+            cpu_has_xen = true;
+
             return l;
         }
     }
 
-    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 +150,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 +258,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 +270,17 @@ 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);
+    find_xen_leaves(IS_DEFINED(CONFIG_PV));
+
+    if ( cpu_has_xen )
+    {
+        if ( IS_DEFINED(CONFIG_HVM) && !pvh_start_info )
+            register_console_callback(qemu_console_write);
 
-    register_console_callback(xen_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 +288,18 @@ void arch_setup(void)
 
     arch_init_traps();
 
-    init_hypercalls();
-
-    if ( !is_initdomain() )
+    if ( cpu_has_xen )
     {
-        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 +307,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®.