x86: Remove Xen as a hard requirement to run XTF.
PATCH 1/1 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.
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.
---
I tested PV and HVM still run fine under Xen, and I did account for viridian-enlightened guests, though I didn't test them.
--- arch/x86/setup.c | 68 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 13 deletions(-)
arch/x86/setup.c +55 -13
@@ -31,6 +31,8 @@ const char environment_description[] = ENVIRONMENT_DESCRIPTION; shared_info_t shared_info __page_aligned_bss; +static bool has_xen_hypervisor; +static void collect_cpuid (cpuid_count_fn_t cpuid_fn) {unsigned int tmp, eax, ebx, ecx, edx, addr =0 ;
@@ -243,11 +245,19 @@ static void map_shared_info(void)panic ("Failed to map shared_info: %d\n" , rc); } +static void pio_write (uint16_t port,const char *buf,size_t len) +{ + asmvolatile ("rep; outsb" :"+S" (buf),"+c" (len) :"d" (port)); +} +static void qemu_console_write (const char *buf,size_t len) { - asmvolatile ("rep outsb" - :"+S" (buf),"+c" (len) - :"d" (0x12 )); +pio_write (0x12 , buf, len); +} + +static void com1_console_write (const char *buf,size_t len) +{ +pio_write (0x3f8 , buf, len); }static void xen_console_write (const char *buf,size_t len)
@@ -255,12 +265,41 @@ static void xen_console_write(const char *buf, size_t len)hypercall_console_write (buf, len); } +static bool detect_xen_runtime (void ) +{ +uint32_t eax, ebx, ecx, edx; + +/* PV tests always run under Xen */ +if (IS_DEFINED (CONFIG_PV ) ) +return true; + +/* HVM tests may additionally run on non-Xen hypervisors or baremetal */ +cpuid_count (0x40000000 ,0 , &eax, &ebx, &ecx, &edx); +if ( ebx ==XEN_CPUID_SIGNATURE_EBX && + ecx ==XEN_CPUID_SIGNATURE_ECX && + edx ==XEN_CPUID_SIGNATURE_EDX ) +return true; + +/* Viridian guests have the Xen leaves higher up, so check there too */ +cpuid_count (0x40000100 ,0 , &eax, &ebx, &ecx, &edx); +return ebx ==XEN_CPUID_SIGNATURE_EBX && + ecx ==XEN_CPUID_SIGNATURE_ECX && + edx ==XEN_CPUID_SIGNATURE_EDX ; +} +void arch_setup (void ) { -if (IS_DEFINED (CONFIG_HVM ) && !pvh_start_info ) -register_console_callback (qemu_console_write); + has_xen_hypervisor =detect_xen_runtime (); + +if ( has_xen_hypervisor ) + { +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);
@@ -268,15 +307,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 )
base-commit: 0cbf4c35b06b2b285fc325b8458132e844c5cf0e
Signature · 1 line
2.43.0
Quoted 6 lines · Alejandro Vallejo
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.This patch enables running XTF on QEMU-TCG/KVM out of the box.
When I did a KVM branch for amluto,
https://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen-test-framework.git;a=shortlog;h=refs/heads/kvm
was what was necessary to get tests to pass.
I can see the need for MB1 going away now that KVM uses the PVH entrypoint, but is the rest really unnecessary?
arch/x86/setup.c static void map_shared_info(void) · line 251
Quoted 12 lines
arch/x86/setup.c +4
-0@@ -243,11 +245,19 @@ static void map_shared_info(void)panic ("Failed to map shared_info: %d\n" , rc); } +static void pio_write (uint16_t port,const char *buf,size_t len) +{ + asmvolatile ("rep; outsb" :"+S" (buf),"+c" (len) :"d" (port)); +}
I've factored out rep_movsb() in the proper place for library functions, and without the rebasing issue reinserting the erroneous ;.
Quoted 15 lines
arch/x86/setup.c +11
-0@@ -255,12 +265,41 @@ static void xen_console_write(const char *buf, size_t len)hypercall_console_write (buf, len); } +static bool detect_xen_runtime (void ) +{ +uint32_t eax, ebx, ecx, edx; + +/* PV tests always run under Xen */ +if (IS_DEFINED (CONFIG_PV ) ) +return true; + +/* HVM tests may additionally run on non-Xen hypervisors or baremetal */ +cpuid_count (0x40000000 ,0 , &eax, &ebx, &ecx, &edx); + if ( ebx == XEN_CPUID_SIGNATURE_EBX &&
arch/x86/setup.c static void xen_console_write(const char *buf, size_t len) · line 288
Quoted 10 lines
arch/x86/setup.c +10
-0+ ecx == XEN_CPUID_SIGNATURE_ECX && + edx == XEN_CPUID_SIGNATURE_EDX ) +return true; + +/* Viridian guests have the Xen leaves higher up, so check there too */ +cpuid_count (0x40000100 ,0 , &eax, &ebx, &ecx, &edx); +return ebx ==XEN_CPUID_SIGNATURE_EBX && + ecx ==XEN_CPUID_SIGNATURE_ECX && + edx ==XEN_CPUID_SIGNATURE_EDX ; +}
This isn't quite correct. There's a find_xen_leaves() helper which should do what you want.
~Andrew
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · Alejandro Vallejo
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.
Quoted 8 lines
Quoted 1 line
This patch enables running XTF on QEMU-TCG/KVM out of the box.
When I did a KVM branch for amluto,
https://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen-test-framework.git;a=shortlog;h=refs/heads/kvm
was what was necessary to get tests to pass.I can see the need for MB1 going away now that KVM uses the PVH entrypoint, but is the rest really unnecessary?
I do run it, as-is and it works.
Depends what you're after. As-is the commit spins at the end for a lack of the code knowing how to turn off QEMU. 0xF4 isn't the default qemu-debug-exit PIO, (that'd be 0x501), but I assume that was the intent and you (or someone else) got it from the TCG unit tests, that have a non-default PIO.
I didn't include something like that because it relies on the user having set up " -device isa-debug-exit" in their QEMU cmdline. Thinking about it, the worst case scenario is that the PIO write is ignored, so I'll just go with that.
Also, I'm not sure QEMU implements PIO 0xE9? I've only seen it in Xen. This patch writes directly to COM1, and that seems like the better option.
Quoted 9 lines
Quoted 9 lines
arch/x86/setup.c +0
-0@@ -243,11 +245,19 @@ static void map_shared_info(void)panic ("Failed to map shared_info: %d\n" , rc); }
Quoted 7 lines
arch/x86/setup.c static void map_shared_info(void) · line 251
Quoted 4 lines
arch/x86/setup.c +4
-0+static void pio_write (uint16_t port,const char *buf,size_t len) +{ + asmvolatile ("rep; outsb" :"+S" (buf),"+c" (len) :"d" (port)); +}I've factored out
rep_movsb()in the proper place for library functions, and without the rebasing issue reinserting the erroneous ;.
You meant rep_outsb(). Too much ERMS is bad for you ;). It's just the commit title that's wrong, the patch is still good. So I'll resend with using that helper.
I'm a bit triggered by the port being the last argument rather than the first, but I'll get over it.
Quoted 21 lines
Quoted 21 lines
arch/x86/setup.c +16
-0@@ -255,12 +265,41 @@ static void xen_console_write(const char *buf, size_t len)hypercall_console_write (buf, len); } +static bool detect_xen_runtime (void ) +{ +uint32_t eax, ebx, ecx, edx; + +/* PV tests always run under Xen */ +if (IS_DEFINED (CONFIG_PV ) ) +return true; + +/* HVM tests may additionally run on non-Xen hypervisors or baremetal */ +cpuid_count (0x40000000 ,0 , &eax, &ebx, &ecx, &edx); +if ( ebx ==XEN_CPUID_SIGNATURE_EBX && + ecx ==XEN_CPUID_SIGNATURE_ECX && + edx ==XEN_CPUID_SIGNATURE_EDX ) +return true; + +/* Viridian guests have the Xen leaves higher up, so check there too */
Quoted 8 lines
arch/x86/setup.c static void xen_console_write(const char *buf, size_t len) · line 288
Quoted 5 lines
arch/x86/setup.c +5
-0+cpuid_count (0x40000100 ,0 , &eax, &ebx, &ecx, &edx); +return ebx ==XEN_CPUID_SIGNATURE_EBX && + ecx ==XEN_CPUID_SIGNATURE_ECX && + edx ==XEN_CPUID_SIGNATURE_EDX ; +}This isn't quite correct. There's a
find_xen_leaves()helper which should do what you want.
Right. find_xen_leaves() wants adjusting so it returns a sentinel leaf when no such leaf exists, like -1ULL, or 0. I'll go with the former tentatively.
Now that I've noticed the existing detection function I might be able to just do early returns where it's invoked rather than avoiding calling them altogether.
I'll send a v2 shortly.
Cheers,
Alejandro
Quoted 21 lines · Alejandro Vallejo
Quoted 6 lines · Andrew Cooper
Quoted 5 lines · Alejandro Vallejo
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.Quoted 7 lines
Quoted 1 line
This patch enables running XTF on QEMU-TCG/KVM out of the box.
When I did a KVM branch for amluto,
https://xenbits.xen.org/gitweb/?p=people/andrewcoop/xen-test-framework.git;a=shortlog;h=refs/heads/kvm
was what was necessary to get tests to pass.I can see the need for MB1 going away now that KVM uses the PVH entrypoint, but is the rest really unnecessary?
I do run it, as-is and it works.
Depends what you're after. As-is the commit spins at the end for a lack of the code knowing how to turn off QEMU.
0xF4isn't the default qemu-debug-exit PIO, (that'd be0x501), but I assume that was the intent and you (or someone else) got it from the TCG unit tests, that have a non-default PIO.
Quoted 6 lines
I didn't include something like that because it relies on the user having set up " -device isa-debug-exit" in their QEMU cmdline. Thinking about it, the worst case scenario is that the PIO write is ignored, so I'll just go with that.
Also, I'm not sure QEMU implements PIO
0xE9? I've only seen it in Xen. This patch writes directly to COM1, and that seems like the better option.
I can't remember exactly where I got that -device isa-debug-exit invocation from, but it was some example documentation from QEMU itself.
If there's a better way then I'm all ears, but spinning is no use for non-interactive tasks such as using ./xtf-runner for all tests.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
arch/x86/setup.c +0
-0@@ -243,11 +245,19 @@ static void map_shared_info(void)panic ("Failed to map shared_info: %d\n" , rc); }
Quoted 7 lines
Quoted 6 lines
arch/x86/setup.c static void map_shared_info(void) · line 251
Quoted 4 lines
arch/x86/setup.c +4
-0+static void pio_write (uint16_t port,const char *buf,size_t len) +{ + asmvolatile ("rep; outsb" :"+S" (buf),"+c" (len) :"d" (port)); +}I've factored out
rep_movsb()in the proper place for library functions, and without the rebasing issue reinserting the erroneous ;.You meant
rep_outsb(). Too much ERMS is bad for you ;).
Urgh I thought I fixed all of those typos. Oh well.
Quoted 6 lines
It's just the commit
title that's wrong, the patch is still good. So I'll resend with using that helper.I'm a bit triggered by the port being the last argument rather than the first, but I'll get over it.
For better or worse, that's how outb() and friends are defined (which itself is a side effect of AT&T syntax).
~Andrew