[kvm-unit-tests PATCH 3/7] nVMX: Assert that the test is configured for 64-bit mode

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

 



The nVMX tests are 64-bit only, assert as much to reduce the probability
of the tests not actually running due to some funky bug.  It's easy to
re-add an if-statement if the nVMX tests ever gain 32-bit support, whereas
most developers lack the psychic powers necessary to detect that a test
isn't doing anything useful.

Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
---
 x86/vmx_tests.c | 69 ++++++++++++++++++++++++-------------------------
 1 file changed, 34 insertions(+), 35 deletions(-)

diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index 9ec0f512..03da5307 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -7619,49 +7619,48 @@ static void test_host_addr_size(void)
 	int i;
 	u64 tmp;
 
-	if (vmcs_read(EXI_CONTROLS) & EXI_HOST_64) {
-		assert(cr4_saved & X86_CR4_PAE);
+	assert(vmcs_read(EXI_CONTROLS) & EXI_HOST_64);
+	assert(cr4_saved & X86_CR4_PAE);
 
-		vmcs_write(ENT_CONTROLS, entry_ctrl_saved | ENT_GUEST_64);
-		report_prefix_pushf("\"IA-32e mode guest\" enabled");
+	vmcs_write(ENT_CONTROLS, entry_ctrl_saved | ENT_GUEST_64);
+	report_prefix_pushf("\"IA-32e mode guest\" enabled");
+	test_vmx_vmlaunch(0);
+	report_prefix_pop();
+
+	if (this_cpu_has(X86_FEATURE_PCID)) {
+		vmcs_write(HOST_CR4, cr4_saved | X86_CR4_PCIDE);
+		report_prefix_pushf("\"CR4.PCIDE\" set");
 		test_vmx_vmlaunch(0);
 		report_prefix_pop();
+	}
 
-		if (this_cpu_has(X86_FEATURE_PCID)) {
-			vmcs_write(HOST_CR4, cr4_saved | X86_CR4_PCIDE);
-			report_prefix_pushf("\"CR4.PCIDE\" set");
-			test_vmx_vmlaunch(0);
-			report_prefix_pop();
-		}
-
-		for (i = 32; i <= 63; i = i + 4) {
-			tmp = rip_saved | 1ull << i;
-			vmcs_write(HOST_RIP, tmp);
-			report_prefix_pushf("HOST_RIP %lx", tmp);
-			test_vmx_vmlaunch(0);
-			report_prefix_pop();
-		}
-
-		vmcs_write(HOST_CR4, cr4_saved  & ~X86_CR4_PAE);
-		report_prefix_pushf("\"CR4.PAE\" unset");
-		test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD);
-		vmcs_write(HOST_CR4, cr4_saved);
+	for (i = 32; i <= 63; i = i + 4) {
+		tmp = rip_saved | 1ull << i;
+		vmcs_write(HOST_RIP, tmp);
+		report_prefix_pushf("HOST_RIP %lx", tmp);
+		test_vmx_vmlaunch(0);
 		report_prefix_pop();
+	}
 
-		vmcs_write(HOST_RIP, NONCANONICAL);
-		report_prefix_pushf("HOST_RIP %llx", NONCANONICAL);
-		test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD);
-		report_prefix_pop();
+	vmcs_write(HOST_CR4, cr4_saved  & ~X86_CR4_PAE);
+	report_prefix_pushf("\"CR4.PAE\" unset");
+	test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD);
+	vmcs_write(HOST_CR4, cr4_saved);
+	report_prefix_pop();
 
-		vmcs_write(ENT_CONTROLS, entry_ctrl_saved | ENT_GUEST_64);
-		vmcs_write(HOST_RIP, rip_saved);
-		vmcs_write(HOST_CR4, cr4_saved);
+	vmcs_write(HOST_RIP, NONCANONICAL);
+	report_prefix_pushf("HOST_RIP %llx", NONCANONICAL);
+	test_vmx_vmlaunch(VMXERR_ENTRY_INVALID_HOST_STATE_FIELD);
+	report_prefix_pop();
 
-		/* Restore host's active RIP and CR4 values. */
-		report_prefix_pushf("restore host state");
-		test_vmx_vmlaunch(0);
-		report_prefix_pop();
-	}
+	vmcs_write(ENT_CONTROLS, entry_ctrl_saved | ENT_GUEST_64);
+	vmcs_write(HOST_RIP, rip_saved);
+	vmcs_write(HOST_CR4, cr4_saved);
+
+	/* Restore host's active RIP and CR4 values. */
+	report_prefix_pushf("restore host state");
+	test_vmx_vmlaunch(0);
+	report_prefix_pop();
 }
 
 /*
-- 
2.42.0.283.g2d96d420d3-goog




[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux