kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements
@ 2021-06-09 18:29 Nadav Amit
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 1/8] lib/x86: report result through serial console when no test device Nadav Amit
                   ` (8 more replies)
  0 siblings, 9 replies; 15+ messages in thread
From: Nadav Amit @ 2021-06-09 18:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Nadav Amit

From: Nadav Amit <nadav.amit@gmail.com>

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(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH 1/8] lib/x86: report result through serial console when no test device
  2021-06-09 18:29 [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Nadav Amit
@ 2021-06-09 18:29 ` Nadav Amit
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 2/8] x86/tsx-ctrl: report skipping tests correctly Nadav Amit
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Nadav Amit @ 2021-06-09 18:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Nadav Amit

From: Nadav Amit <nadav.amit@gmail.com>

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.

Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
---
 lib/x86/io.c   | 3 +++
 x86/realmode.c | 5 +++++
 2 files changed, 8 insertions(+)

diff --git a/lib/x86/io.c b/lib/x86/io.c
index f4ffb44..c21dfb8 100644
--- a/lib/x86/io.c
+++ b/lib/x86/io.c
@@ -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
         asm volatile("out %0, %1" : : "a"(code), "d"((short)0xf4));
 #endif
+	if (no_test_device)
+		printf("--- DONE: %d ---\n", code);
 
 	/* Fallback */
 	while (1) {
diff --git a/x86/realmode.c b/x86/realmode.c
index c8a6ae0..b4fa603 100644
--- a/x86/realmode.c
+++ b/x86/realmode.c
@@ -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) {
 		asm volatile("hlt" ::: "memory");
 	}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH 2/8] x86/tsx-ctrl: report skipping tests correctly
  2021-06-09 18:29 [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Nadav Amit
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 1/8] lib/x86: report result through serial console when no test device Nadav Amit
@ 2021-06-09 18:29 ` Nadav Amit
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 3/8] x86/smptest: handle non-consecutive APIC IDs Nadav Amit
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Nadav Amit @ 2021-06-09 18:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Nadav Amit

From: Nadav Amit <nadav.amit@gmail.com>

When tsx-ctrl tests are skipped due to lack of hardware support, they
are not reported as skipped. Fix it.

Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
---
 x86/tsx-ctrl.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/x86/tsx-ctrl.c b/x86/tsx-ctrl.c
index 079ad59..3b197ca 100644
--- a/x86/tsx-ctrl.c
+++ b/x86/tsx-ctrl.c
@@ -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");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH 3/8] x86/smptest: handle non-consecutive APIC IDs
  2021-06-09 18:29 [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Nadav Amit
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 1/8] lib/x86: report result through serial console when no test device Nadav Amit
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 2/8] x86/tsx-ctrl: report skipping tests correctly Nadav Amit
@ 2021-06-09 18:29 ` Nadav Amit
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 4/8] x86/hypercall: enable the test on non-KVM environment Nadav Amit
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Nadav Amit @ 2021-06-09 18:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Nadav Amit

From: Nadav Amit <nadav.amit@gmail.com>

When APIC IDs are not allocated consecutively, smptest fails. Fix it by
using id_map, which maps CPU numbers to their apic-IDs.

Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
---
 x86/smptest.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/x86/smptest.c b/x86/smptest.c
index 2989aa0..cbb4e60 100644
--- a/x86/smptest.c
+++ b/x86/smptest.c
@@ -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++;
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH 4/8] x86/hypercall: enable the test on non-KVM environment
  2021-06-09 18:29 [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Nadav Amit
                   ` (2 preceding siblings ...)
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 3/8] x86/smptest: handle non-consecutive APIC IDs Nadav Amit
@ 2021-06-09 18:29 ` Nadav Amit
  2021-06-09 18:37   ` Jim Mattson
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 5/8] x86/hyperv: skip hyperv-clock test if unsupported by host Nadav Amit
                   ` (4 subsequent siblings)
  8 siblings, 1 reply; 15+ messages in thread
From: Nadav Amit @ 2021-06-09 18:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Nadav Amit

From: Nadav Amit <nadav.amit@gmail.com>

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 <nadav.amit@gmail.com>
---
 lib/x86/processor.h |  8 ++++++++
 x86/hypercall.c     | 31 +++++++++++++++++++++++--------
 2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index abc04b0..517ee70 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -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)
 
diff --git a/x86/hypercall.c b/x86/hypercall.c
index 28760e3..a02ee33 100644
--- a/x86/hypercall.c
+++ b/x86/hypercall.c
@@ -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();
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH 5/8] x86/hyperv: skip hyperv-clock test if unsupported by host
  2021-06-09 18:29 [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Nadav Amit
                   ` (3 preceding siblings ...)
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 4/8] x86/hypercall: enable the test on non-KVM environment Nadav Amit
@ 2021-06-09 18:29 ` Nadav Amit
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 6/8] x86/syscall: skip TF-test if running neither on KVM nor AMD Nadav Amit
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Nadav Amit @ 2021-06-09 18:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Nadav Amit

From: Nadav Amit <nadav.amit@gmail.com>

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.

Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
---
 x86/hyperv_clock.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/x86/hyperv_clock.c b/x86/hyperv_clock.c
index b4cfc9f..f1e7204 100644
--- a/x86/hyperv_clock.c
+++ b/x86/hyperv_clock.c
@@ -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();
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH 6/8] x86/syscall: skip TF-test if running neither on KVM nor AMD
  2021-06-09 18:29 [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Nadav Amit
                   ` (4 preceding siblings ...)
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 5/8] x86/hyperv: skip hyperv-clock test if unsupported by host Nadav Amit
@ 2021-06-09 18:29 ` Nadav Amit
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 7/8] x86/pmu: Skip the tests on PMU version 1 Nadav Amit
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 15+ messages in thread
From: Nadav Amit @ 2021-06-09 18:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Nadav Amit

From: Nadav Amit <nadav.amit@gmail.com>

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.

Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
---
 x86/syscall.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/x86/syscall.c b/x86/syscall.c
index 8cef860..a8045cb 100644
--- a/x86/syscall.c
+++ b/x86/syscall.c
@@ -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();
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH 7/8] x86/pmu: Skip the tests on PMU version 1
  2021-06-09 18:29 [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Nadav Amit
                   ` (5 preceding siblings ...)
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 6/8] x86/syscall: skip TF-test if running neither on KVM nor AMD Nadav Amit
@ 2021-06-09 18:29 ` Nadav Amit
  2021-06-10  1:22   ` Like Xu
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 8/8] x86/vmx: skip error-code delivery tests for #CP Nadav Amit
  2021-06-10 12:30 ` [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Paolo Bonzini
  8 siblings, 1 reply; 15+ messages in thread
From: Nadav Amit @ 2021-06-09 18:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Nadav Amit

From: Nadav Amit <nadav.amit@gmail.com>

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.

Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
---
 x86/pmu.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/x86/pmu.c b/x86/pmu.c
index 5a3d55b..ec61ac9 100644
--- a/x86/pmu.c
+++ b/x86/pmu.c
@@ -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


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* [kvm-unit-tests PATCH 8/8] x86/vmx: skip error-code delivery tests for #CP
  2021-06-09 18:29 [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Nadav Amit
                   ` (6 preceding siblings ...)
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 7/8] x86/pmu: Skip the tests on PMU version 1 Nadav Amit
@ 2021-06-09 18:29 ` Nadav Amit
  2021-06-10 12:30 ` [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Paolo Bonzini
  8 siblings, 0 replies; 15+ messages in thread
From: Nadav Amit @ 2021-06-09 18:29 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: kvm, Nadav Amit

From: Nadav Amit <nadav.amit@gmail.com>

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.

Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
---
 lib/x86/processor.h | 1 +
 x86/vmx_tests.c     | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/lib/x86/processor.h b/lib/x86/processor.h
index 517ee70..53e71fc 100644
--- a/lib/x86/processor.h
+++ b/lib/x86/processor.h
@@ -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
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 179a55b..5b9faa2 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -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 */
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH 4/8] x86/hypercall: enable the test on non-KVM environment
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 4/8] x86/hypercall: enable the test on non-KVM environment Nadav Amit
@ 2021-06-09 18:37   ` Jim Mattson
  2021-06-09 18:39     ` Nadav Amit
  0 siblings, 1 reply; 15+ messages in thread
From: Jim Mattson @ 2021-06-09 18:37 UTC (permalink / raw)
  To: Nadav Amit; +Cc: Paolo Bonzini, kvm list

On Wed, Jun 9, 2021 at 11:32 AM Nadav Amit <nadav.amit@gmail.com> wrote:
>
> From: Nadav Amit <nadav.amit@gmail.com>
>
> 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 <nadav.amit@gmail.com>
> ---
>  lib/x86/processor.h |  8 ++++++++
>  x86/hypercall.c     | 31 +++++++++++++++++++++++--------
>  2 files changed, 31 insertions(+), 8 deletions(-)
>
> diff --git a/lib/x86/processor.h b/lib/x86/processor.h
> index abc04b0..517ee70 100644
> --- a/lib/x86/processor.h
> +++ b/lib/x86/processor.h
> @@ -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;
> +}
> +
Don't VIA CPUs also require vmcall, since they implement VMX rather than SVM?

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH 4/8] x86/hypercall: enable the test on non-KVM environment
  2021-06-09 18:37   ` Jim Mattson
@ 2021-06-09 18:39     ` Nadav Amit
  0 siblings, 0 replies; 15+ messages in thread
From: Nadav Amit @ 2021-06-09 18:39 UTC (permalink / raw)
  To: Jim Mattson; +Cc: Paolo Bonzini, kvm list



> On Jun 9, 2021, at 11:37 AM, Jim Mattson <jmattson@google.com> wrote:
> 
> On Wed, Jun 9, 2021 at 11:32 AM Nadav Amit <nadav.amit@gmail.com> wrote:
>> 
>> From: Nadav Amit <nadav.amit@gmail.com>
>> 
>> 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 <nadav.amit@gmail.com>
>> ---
>> lib/x86/processor.h |  8 ++++++++
>> x86/hypercall.c     | 31 +++++++++++++++++++++++--------
>> 2 files changed, 31 insertions(+), 8 deletions(-)
>> 
>> diff --git a/lib/x86/processor.h b/lib/x86/processor.h
>> index abc04b0..517ee70 100644
>> --- a/lib/x86/processor.h
>> +++ b/lib/x86/processor.h
>> @@ -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;
>> +}
>> +
> 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.


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH 7/8] x86/pmu: Skip the tests on PMU version 1
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 7/8] x86/pmu: Skip the tests on PMU version 1 Nadav Amit
@ 2021-06-10  1:22   ` Like Xu
  2021-06-10  7:44     ` Nadav Amit
  0 siblings, 1 reply; 15+ messages in thread
From: Like Xu @ 2021-06-10  1:22 UTC (permalink / raw)
  To: Nadav Amit; +Cc: Paolo Bonzini, kvm

Hi Nadav,

Nadav Amit <nadav.amit@gmail.com> 于2021年6月10日周四 上午2:33写道:
>
> From: Nadav Amit <nadav.amit@gmail.com>
>
> 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.

>
> Signed-off-by: Nadav Amit <nadav.amit@gmail.com>
> ---
>  x86/pmu.c | 6 ++++++
>  1 file changed, 6 insertions(+)
>
> diff --git a/x86/pmu.c b/x86/pmu.c
> index 5a3d55b..ec61ac9 100644
> --- a/x86/pmu.c
> +++ b/x86/pmu.c
> @@ -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
>

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH 7/8] x86/pmu: Skip the tests on PMU version 1
  2021-06-10  1:22   ` Like Xu
@ 2021-06-10  7:44     ` Nadav Amit
  2021-06-10  8:30       ` Like Xu
  0 siblings, 1 reply; 15+ messages in thread
From: Nadav Amit @ 2021-06-10  7:44 UTC (permalink / raw)
  To: Like Xu; +Cc: Paolo Bonzini, kvm



> On Jun 9, 2021, at 6:22 PM, Like Xu <like.xu.linux@gmail.com> wrote:
> 
> Hi Nadav,
> 
> Nadav Amit <nadav.amit@gmail.com> 于2021年6月10日周四 上午2:33写道:
>> 
>> From: Nadav Amit <nadav.amit@gmail.com>
>> 
>> 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”).


^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH 7/8] x86/pmu: Skip the tests on PMU version 1
  2021-06-10  7:44     ` Nadav Amit
@ 2021-06-10  8:30       ` Like Xu
  0 siblings, 0 replies; 15+ messages in thread
From: Like Xu @ 2021-06-10  8:30 UTC (permalink / raw)
  To: Nadav Amit; +Cc: Paolo Bonzini, kvm

On Thu, Jun 10, 2021 at 3:44 PM Nadav Amit <nadav.amit@gmail.com> wrote:
>
>
>
> > On Jun 9, 2021, at 6:22 PM, Like Xu <like.xu.linux@gmail.com> wrote:
> >
> > Hi Nadav,
> >
> > Nadav Amit <nadav.amit@gmail.com> 于2021年6月10日周四 上午2:33写道:
> >>
> >> From: Nadav Amit <nadav.amit@gmail.com>
> >>
> >> 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”).
>

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

^ permalink raw reply	[flat|nested] 15+ messages in thread

* Re: [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements
  2021-06-09 18:29 [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Nadav Amit
                   ` (7 preceding siblings ...)
  2021-06-09 18:29 ` [kvm-unit-tests PATCH 8/8] x86/vmx: skip error-code delivery tests for #CP Nadav Amit
@ 2021-06-10 12:30 ` Paolo Bonzini
  8 siblings, 0 replies; 15+ messages in thread
From: Paolo Bonzini @ 2021-06-10 12:30 UTC (permalink / raw)
  To: kvm, Nadav Amit

On Wed, 9 Jun 2021 18:29:37 +0000, Nadav Amit wrote:
> 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
> 
> [...]

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: c986dbe8670535e4f88871b1e8b8480bdc256ded

Best regards,
-- 
Paolo Bonzini <pbonzini@redhat.com>


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-06-10 12:30 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-09 18:29 [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Nadav Amit
2021-06-09 18:29 ` [kvm-unit-tests PATCH 1/8] lib/x86: report result through serial console when no test device Nadav Amit
2021-06-09 18:29 ` [kvm-unit-tests PATCH 2/8] x86/tsx-ctrl: report skipping tests correctly Nadav Amit
2021-06-09 18:29 ` [kvm-unit-tests PATCH 3/8] x86/smptest: handle non-consecutive APIC IDs Nadav Amit
2021-06-09 18:29 ` [kvm-unit-tests PATCH 4/8] x86/hypercall: enable the test on non-KVM environment Nadav Amit
2021-06-09 18:37   ` Jim Mattson
2021-06-09 18:39     ` Nadav Amit
2021-06-09 18:29 ` [kvm-unit-tests PATCH 5/8] x86/hyperv: skip hyperv-clock test if unsupported by host Nadav Amit
2021-06-09 18:29 ` [kvm-unit-tests PATCH 6/8] x86/syscall: skip TF-test if running neither on KVM nor AMD Nadav Amit
2021-06-09 18:29 ` [kvm-unit-tests PATCH 7/8] x86/pmu: Skip the tests on PMU version 1 Nadav Amit
2021-06-10  1:22   ` Like Xu
2021-06-10  7:44     ` Nadav Amit
2021-06-10  8:30       ` Like Xu
2021-06-09 18:29 ` [kvm-unit-tests PATCH 8/8] x86/vmx: skip error-code delivery tests for #CP Nadav Amit
2021-06-10 12:30 ` [kvm-unit-tests PATCH 0/8] x86: non-KVM improvements Paolo Bonzini

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).