diff mbox series

[kvm-unit-tests,4/6] fix vmx_apic_reg_virt for older platforms

Message ID 1554504223-7919-5-git-send-email-pbonzini@redhat.com (mailing list archive)
State New, archived
Headers show
Series x86: nVMX: test APIC reg features | expand

Commit Message

Paolo Bonzini April 5, 2019, 10:43 p.m. UTC
From: Marc Orr <marcorr@google.com>

This test was failing because "Use TPR shadow" virtualization behaves
differently across platforms. For example, on Sandy Bridge the upper
three bytes of the VTPR are cleared upon VM entry, whereas they
are left as is on Skylake.

This difference in behavior is consistent with the SDM, which according
to Volume 3, Section 26.2.1.1 VM-Execution Control Fields, says:
... bytes 3:1 of VTPR may be cleared (behavior may be
implementation-specific). ...

Signed-off-by: Marc Orr <marcorr@google.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 x86/vmx_tests.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 092e70e..41c763d 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -5405,6 +5405,7 @@  struct apic_reg_virt_guest_args {
 	u32 reg;
 	u32 val;
 	bool check_rd;
+	u32 (*virt_fn)(u32);
 } apic_reg_virt_guest_args;
 
 static void apic_reg_virt_guest(void)
@@ -5418,6 +5419,7 @@  static void apic_reg_virt_guest(void)
 		u32 reg = args->reg;
 		u32 val = args->val;
 		bool check_rd = args->check_rd;
+		u32 (*virt_fn)(u32) = args->virt_fn;
 
 		if (op == TERMINATE)
 			break;
@@ -5425,9 +5427,13 @@  static void apic_reg_virt_guest(void)
 		if (op == APIC_OP_XAPIC_RD) {
 			u32 ret = vmx_xapic_read(apic_access_address, reg);
 
-			if (check_rd)
+			if (check_rd) {
+				u32 want = virt_fn(val);
+				u32 got = virt_fn(ret);
+
 				report("read 0x%x, expected 0x%x.",
-				       ret == val, ret, val);
+				       got == want, got, want);
+			}
 		} else if (op == APIC_OP_XAPIC_WR) {
 			vmx_xapic_write(apic_access_address, reg, val);
 		}
@@ -5457,6 +5463,7 @@  static void test_xapic_rd(
 	args->reg = reg;
 	args->val = val;
 	args->check_rd = exit_reason_want == VMX_VMCALL;
+	args->virt_fn = expectation->virt_fn;
 
 	/* Setup virtual APIC page */
 	if (!expectation->virtualize_apic_accesses) {