x86: non-KVM improvements
cover x86: non-KVM improvements
From: Nadav Amit <[email protected]>
This set includes various fixes and improvements, mostly for non-KVM environments.
The purpose of the patches are: easier to parse test results, skipping tests that are unsupported and few fixes to tests.
Nadav Amit (8):
lib/x86: report result through serial console when no test device x86/tsx-ctrl: report skipping tests correctly x86/smptest: handle non-consecutive APIC IDs x86/hypercall: enable the test on non-KVM environment x86/hyperv: skip hyperv-clock test if unsupported by host x86/syscall: skip TF-test if running neither on KVM nor AMD x86/pmu: Skip the tests on PMU version 1
x86/vmx: skip error-code delivery tests for #CP
lib/x86/io.c | 3 +++ lib/x86/processor.h | 9 +++++++++ x86/hypercall.c | 31 +++++++++++++++++++++++-------- x86/hyperv_clock.c | 5 +++++ x86/pmu.c | 6 ++++++ x86/realmode.c | 5 +++++ x86/smptest.c | 3 ++- x86/syscall.c | 7 ++++++- x86/tsx-ctrl.c | 6 +++--- x86/vmx_tests.c | 3 +++ 10 files changed, 65 insertions(+), 13 deletions(-)
Signature · 1 line
2.25.1
PATCH 1/8 lib/x86: report result through serial console when no test device
From: Nadav Amit <[email protected]>
If there are no test devices, we might be running on bare-metal or other environment, in which port 0xF4, which reports the test result, is not monitored. In such environments, print also the result of the test to the serial console.
For realmode: just give a simple indication whether the test passed or failed in a similar fashion.
This can allow automation tools to figure out the test is done and its result.
--- lib/x86/io.c | 3 +++ x86/realmode.c | 5 +++++ 2 files changed, 8 insertions(+)
lib/x86/io.c +3 -0
@@ -1,5 +1,6 @@#include "libcflat.h" #include "smp.h" +#include "fwcfg.h" #include "asm/io.h" #include "asm/page.h" #include "vmalloc.h"
@@ -99,6 +100,8 @@ void exit(int code)#else asmvolatile ("out %0, %1" : :"a" (code),"d" ((short )0xf4 ));#endif +if (no_test_device) +printf ("--- DONE: %d ---\n" , code);/* Fallback */ while (1 ) {
x86/realmode.c +5 -0
@@ -125,6 +125,11 @@ static void exit(int code) {outb (code,0xf4 ); +if (code ==0 ) +print_serial ("--- DONE: 0 ---\n" ); +else +print_serial ("--- DONE: 1 ---\n" ); +while (1 ) { asmvolatile ("hlt" :::"memory" ); }
Signature · 1 line
2.25.1
PATCH 2/8 x86/tsx-ctrl: report skipping tests correctly
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
When tsx-ctrl tests are skipped due to lack of hardware support, they are not reported as skipped. Fix it.
--- x86/tsx-ctrl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
x86/tsx-ctrl.c +3 -3
@@ -27,15 +27,15 @@ int main(int ac, char **av) {if (!this_cpu_has (X86_FEATURE_RTM )) {report_skip ("TSX not available" ); -return 0 ; +return report_summary (); }if (!this_cpu_has (X86_FEATURE_ARCH_CAPABILITIES )) {report_skip ("ARCH_CAPABILITIES not available" ); -return 0 ; +return report_summary (); }if (!(rdmsr (MSR_IA32_ARCH_CAPABILITIES ) &ARCH_CAP_TSX_CTRL_MSR )) {report_skip ("TSX_CTRL not available" ); -return 0 ; +return report_summary (); }report (rdmsr (MSR_IA32_TSX_CTRL ) ==0 ,"TSX_CTRL should be 0" );
Signature · 1 line
2.25.1
PATCH 3/8 x86/smptest: handle non-consecutive APIC IDs
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
When APIC IDs are not allocated consecutively, smptest fails. Fix it by using id_map, which maps CPU numbers to their apic-IDs.
--- x86/smptest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
x86/smptest.c +2 -1
@@ -1,4 +1,5 @@#include "libcflat.h" +#include "apic.h" #include "smp.h" unsigned nipis;
@@ -8,7 +9,7 @@ static void ipi_test(void *data)int n = (long )data;printf ("ipi called, cpu %d\n" , n); -if (n !=smp_id ()) +if (id_map[n] !=smp_id ())printf ("but wrong cpu %d\n" ,smp_id ());else nipis++;
Signature · 1 line
2.25.1
PATCH 4/8 x86/hypercall: enable the test on non-KVM environment
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
KVM knows to emulate both vmcall and vmmcall regardless of the actual architecture. Native hardware does not behave this way. Based on the availability of test-device, figure out that the test is run on non-KVM environment, and if so, run vmcall/vmmcall based on the actual architecture.
--- lib/x86/processor.h | 8 ++++++++ x86/hypercall.c | 31 +++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-)
lib/x86/processor.h +8 -0
@@ -118,6 +118,14 @@ static inline u8 cpuid_maxphyaddr(void)return raw_cpuid (0x80000008 ,0 ).a &0xff ; } +static inline bool is_intel (void ) +{ +struct cpuid c =cpuid (0 ); +u32 name[4 ] = {c.b, c.d, c.c }; + +return strcmp ((char *)name,"GenuineIntel" ) ==0 ; +} +#define CPUID (a, b, c, d) ((((unsigned long long) a) << 32) | (b << 16) | \ (c << 8) | d)
x86/hypercall.c +23 -8
@@ -2,6 +2,7 @@#include "vm.h" #include "desc.h" #include "alloc_page.h" +#include "fwcfg.h" #define KVM_HYPERCALL_INTEL ".byte 0x0f,0x01,0xc1"#define KVM_HYPERCALL_AMD ".byte 0x0f,0x01,0xd9"
@@ -51,10 +52,18 @@ test_edge(void)int main (int ac,char **av) { -kvm_hypercall0_intel (-1u ); -printf ("Hypercall via VMCALL: OK\n" ); -kvm_hypercall0_amd (-1u ); -printf ("Hypercall via VMMCALL: OK\n" ); +bool test_vmcall = !no_test_device ||is_intel (); +bool test_vmmcall = !no_test_device || !is_intel (); + +if (test_vmcall) { +kvm_hypercall0_intel (-1u ); +printf ("Hypercall via VMCALL: OK\n" ); + } + +if (test_vmmcall) { +kvm_hypercall0_amd (-1u ); +printf ("Hypercall via VMMCALL: OK\n" ); + }#ifdef __x86_64__setup_vm ();
@@ -70,12 +79,18 @@ int main(int ac, char **av) topmost[4093 ] =0x0f ; topmost[4094 ] =0x01 ; topmost[4095 ] =0xc1 ; -report (test_edge (), -"VMCALL on edge of canonical address space (intel)" ); + +if (test_vmcall) { +report (test_edge (), +"VMCALL on edge of canonical address space (intel)" ); + } topmost[4095 ] =0xd9 ; -report (test_edge (), -"VMMCALL on edge of canonical address space (AMD)" ); + +if (test_vmmcall) { +report (test_edge (), +"VMMCALL on edge of canonical address space (AMD)" ); + }#endif return report_summary ();
Signature · 1 line
2.25.1
Re: [kvm-unit-tests PATCH 4/8] x86/hypercall: enable the test on non-KVM environment
Quoted 21 lines · Nadav Amit
From: Nadav Amit <[email protected]>
KVM knows to emulate both vmcall and vmmcall regardless of the actual architecture. Native hardware does not behave this way. Based on the availability of test-device, figure out that the test is run on non-KVM environment, and if so, run vmcall/vmmcall based on the actual architecture.
Signed-off-by Nadav Amit <[email protected]>--- lib/x86/processor.h | 8 ++++++++ x86/hypercall.c | 31 +++++++++++++++++++++++-------- 2 files changed, 31 insertions(+), 8 deletions(-)lib/x86/processor.h +0
-0@@ -118,6 +118,14 @@ static inline u8 cpuid_maxphyaddr(void)return raw_cpuid (0x80000008 ,0 ).a &0xff ;
lib/x86/processor.h static inline u8 cpuid_maxphyaddr(void) · line 128
Quoted 10 lines
lib/x86/processor.h +8
-0} +static inline bool is_intel (void ) +{ +struct cpuid c =cpuid (0 ); +u32 name[4 ] = {c.b, c.d, c.c }; + +return strcmp ((char *)name,"GenuineIntel" ) ==0 ; +} +
Don't VIA CPUs also require vmcall, since they implement VMX rather than SVM?
Re: [kvm-unit-tests PATCH 4/8] x86/hypercall: enable the test on non-KVM environment
Quoted 28 lines · Jim Mattson
Quoted 23 lines · Nadav Amit
From: Nadav Amit <[email protected]>
KVM knows to emulate both vmcall and vmmcall regardless of the actual architecture. Native hardware does not behave this way. Based on the availability of test-device, figure out that the test is run on non-KVM environment, and if so, run vmcall/vmmcall based on the actual architecture.
Signed-off-by Nadav Amit <[email protected]>---
lib/x86/processor.h| 8 ++++++++x86/hypercall.c| 31 +++++++++++++++++++++++--------2 files changed, 31 insertions(+), 8 deletions(-)lib/x86/processor.h +0
-0@@ -118,6 +118,14 @@ static inline u8 cpuid_maxphyaddr(void)return raw_cpuid (0x80000008 ,0 ).a &0xff ; }
Quoted 9 lines
lib/x86/processor.h static inline u8 cpuid_maxphyaddr(void) · line 128
Quoted 8 lines
lib/x86/processor.h +8
-0+static inline bool is_intel (void ) +{ +struct cpuid c =cpuid (0 ); +u32 name[4 ] = {c.b, c.d, c.c }; + +return strcmp ((char *)name,"GenuineIntel" ) ==0 ; +} +Don't VIA CPUs also require vmcall, since they implement VMX rather than SVM?
I would add VIA for the sake of correctness, although I presume it does not really matter in real-life.
PATCH 5/8 x86/hyperv: skip hyperv-clock test if unsupported by host
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
Skip the hyperv-clock tests if time reference counter is unsupported by the host, similarly to the way other hyperv tests first check support of the host.
--- x86/hyperv_clock.c | 5 +++++ 1 file changed, 5 insertions(+)
x86/hyperv_clock.c +5 -0
@@ -150,6 +150,11 @@ int main(int ac, char **av)uint64_t tsc1, t1, tsc2, t2;uint64_t ref1, ref2; +if (!hv_time_ref_counter_supported ()) { +report_skip ("time reference counter is unsupported" ); +return report_summary (); + } +setup_vm (); ncpus =cpu_count ();
Signature · 1 line
2.25.1
PATCH 6/8 x86/syscall: skip TF-test if running neither on KVM nor AMD
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
The syscall TF-test runs syscall on 32-bit mode, which is unsupported by Intel. As a result, if the test is executed on non-KVM environment and the system does not have AMD CPU, the test crashes. Skip the test in such case.
--- x86/syscall.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
x86/syscall.c +6 -1
@@ -4,6 +4,7 @@#include "processor.h" #include "msr.h" #include "desc.h" +#include "fwcfg.h" static void test_syscall_lazy_load (void ) {
@@ -101,7 +102,11 @@ static void test_syscall_tf(void)int main (int ac,char **av) {test_syscall_lazy_load (); -test_syscall_tf (); + +if (!no_test_device || !is_intel ()) +test_syscall_tf (); +else +report_skip ("syscall TF handling" );return report_summary (); }
Signature · 1 line
2.25.1
PATCH 7/8 x86/pmu: Skip the tests on PMU version 1
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
x86's PMU tests are not compatible with version 1. Instead of finding how to adapt them, just skip them if the PMU version is too old.
--- x86/pmu.c | 6 ++++++ 1 file changed, 6 insertions(+)
x86/pmu.c +6 -0
@@ -544,6 +544,12 @@ int main(int ac, char **av)printf ("No pmu is detected!\n" );return report_summary (); } + +if (eax.split.version_id ==1 ) { +printf ("PMU version 1 is not supported\n" ); +return report_summary (); + } +printf ("PMU version: %d\n" , eax.split.version_id);printf ("GP counters: %d\n" , eax.split.num_counters);printf ("GP counter width: %d\n" , eax.split.bit_width);
Signature · 1 line
2.25.1
Re: [kvm-unit-tests PATCH 7/8] x86/pmu: Skip the tests on PMU version 1
Hi Nadav,
Quoted 5 lines · Nadav Amit <[email protected]> 于2021年6月10日周四 上午2:33写道:
From: Nadav Amit <[email protected]>
x86's PMU tests are not compatible with version 1. Instead of finding how to adapt them, just skip them if the PMU version is too old.
Instead of skipping pmu.v1, it would be better to just skip the tests of fixed counters.
But considering this version is really too old, this change looks fine to me.
Quoted 26 lines
Signed-off-by Nadav Amit <[email protected]>--- x86/pmu.c | 6 ++++++ 1 file changed, 6 insertions(+)x86/pmu.c +6
-1@@ -544,6 +544,12 @@ int main(int ac, char **av)printf ("No pmu is detected!\n" );return report_summary (); } + +if (eax.split.version_id ==1 ) { +printf ("PMU version 1 is not supported\n" ); +return report_summary (); + } +printf ("PMU version: %d\n" , eax.split.version_id);printf ("GP counters: %d\n" , eax.split.num_counters);printf ("GP counter width: %d\n" , eax.split.bit_width); --2.25.1
Re: [kvm-unit-tests PATCH 7/8] x86/pmu: Skip the tests on PMU version 1
Quoted 8 lines · Like Xu
Hi Nadav,
Quoted 1 line · Nadav Amit <[email protected]> 于2021年6月10日周四 上午2:33写道:
Quoted 8 lines
Quoted 4 lines
From: Nadav Amit <[email protected]>
x86's PMU tests are not compatible with version 1. Instead of finding how to adapt them, just skip them if the PMU version is too old.
Instead of skipping pmu.v1, it would be better to just skip the tests of fixed counters.
But considering this version is really too old, this change looks fine to me.
If it were that simple, I would have done it.
v1 does not support MSR_CORE_PERF_GLOBAL_OVF_CTRL, MSR_CORE_PERF_GLOBAL_STATUS and MSR_CORE_PERF_GLOBAL_CTRL, which are being used all over the code. These MSRs were only introduced on version 2 (Intel SDM, section 18.2.2 "Architectural Performance Monitoring Version 2”).
Re: [kvm-unit-tests PATCH 7/8] x86/pmu: Skip the tests on PMU version 1
Quoted 18 lines · Nadav Amit
Quoted 9 lines · Like Xu
Hi Nadav,
Quoted 1 line · Nadav Amit <[email protected]> 于2021年6月10日周四 上午2:33写道:
Quoted 8 lines
Quoted 4 lines
From: Nadav Amit <[email protected]>
x86's PMU tests are not compatible with version 1. Instead of finding how to adapt them, just skip them if the PMU version is too old.
Instead of skipping pmu.v1, it would be better to just skip the tests of fixed counters.
But considering this version is really too old, this change looks fine to me.
Quoted 8 lines
If it were that simple, I would have done it.
v1 does not support
MSR_CORE_PERF_GLOBAL_OVF_CTRL,MSR_CORE_PERF_GLOBAL_STATUSandMSR_CORE_PERF_GLOBAL_CTRL, which are being used all over the code. These MSRs were only introduced on version 2 (Intel SDM, section 18.2.2 "Architectural Performance Monitoring Version 2”).
From the log of feature enbling code, this is true.
But accroding to Table 2-2. IA-32 Architectural MSRs,
- IA32_PERF_GLOBAL_OVF_CTRL, if CPUID.0AH: EAX[7:0] > 0 && CPUID.0AH:
EAX[7:0] <= 3
- IA32_PERF_GLOBAL_STATUS, if CPUID.0AH: EAX[7:0] > 0
- IA32_PERF_GLOBAL_CTRL, if CPUID.0AH: EAX[7:0] > 0
PATCH 8/8 x86/vmx: skip error-code delivery tests for #CP
In reply to Nadav AmitFrom: Nadav Amit <[email protected]>
Old Intel CPUs, which do not support control protection exception, do not expect an error code for #CP, while new ones expect an error-code.
Intel SDM does not say that the delivery of an error-code for #CP is conditional on anything, not even CPU support of CET. So it appears that the correct testing is just to skip the error-code delivery test for the #CP exception.
--- lib/x86/processor.h | 1 + x86/vmx_tests.c | 3 +++ 2 files changed, 4 insertions(+)
lib/x86/processor.h +1 -0
@@ -28,6 +28,7 @@#define GP_VECTOR 13#define PF_VECTOR 14#define AC_VECTOR 17 +#define CP_VECTOR 21#define X86_CR0_PE 0x00000001#define X86_CR0_MP 0x00000002
x86/vmx_tests.c +3 -0
@@ -4413,6 +4413,9 @@ skip_unrestricted_guest:case PF_VECTOR :case AC_VECTOR : has_error_code = true; +case CP_VECTOR : +/* Some CPUs have error code and some do not, skip */ +continue ; }/* Negative case */
Signature · 1 line
2.25.1
Quoted 16 lines · Nadav Amit
This set includes various fixes and improvements, mostly for non-KVM environments.
The purpose of the patches are: easier to parse test results, skipping tests that are unsupported and few fixes to tests.
Nadav Amit (8):
lib/x86: report result through serial console when no test device x86/tsx-ctrl: report skipping tests correctly x86/smptest: handle non-consecutive APIC IDs x86/hypercall: enable the test on non-KVM environment x86/hyperv: skip hyperv-clock test if unsupported by host x86/syscall: skip TF-test if running neither on KVM nor AMD x86/pmu: Skip the tests on PMU version 1
x86/vmx: skip error-code delivery tests for #CP
Quoted 1 line
[...]
Applied, thanks!
[1/8] lib/x86: report result through serial console when no test device
commit: 5747945371b47c51cb16187a26111d06f58f06b2
[2/8] x86/tsx-ctrl: report skipping tests correctly
commit: c8312cbd25df6bf350a9654b6c0364b213ba406c
[3/8] x86/smptest: handle non-consecutive APIC IDs
commit: 90ab30c22dbb18b6d9804421ef3f160cfef031b8
[4/8] x86/hypercall: enable the test on non-KVM environment
commit: 22abdd3999b7c17ba976d31706852b92fb45cd5a
[5/8] x86/hyperv: skip hyperv-clock test if unsupported by host
commit: 5067df40755d6f3a3363c99a1054b6de21a556e1
[6/8] x86/syscall: skip TF-test if running neither on KVM nor AMD
commit: c1e64e2fe08cecc9dcac5b2f72488c74c5134d34
[7/8] x86/pmu: Skip the tests on PMU version 1
commit: 70972e212ee4af14b603131fc27c67a0cf29d458
[8/8] x86/vmx: skip error-code delivery tests for #CP
commit: c986dbe8670535e4f88871b1e8b8480bdc256dedBest regards,
Signature · 1 line
Paolo Bonzini <[email protected]>