[kvm-unit-test PATCH v4 7/9] vmx: Allow vmx_tests to reset the test_guest_func

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

 



The guest state tests are to be grouped together under a single
vmx_test, vmx_guest_state_area_test(). However, each sub-test is an
independent test that sets up its guest. test_set_guest() only allows a
guest function to be set once in the lifetime of a vmx_test.

Add a new helper, vmx_reset_guest(), which the guest state tests may use
to set the guest function more than once. Also, this function will reset
the VMCS as if running another independent test.

Suggested-by: Krish Sadhukhan <krish.sadhukhan@xxxxxxxxxx>
Signed-off-by: Oliver Upton <oupton@xxxxxxxxxx>
---
 x86/vmx.c       | 13 +++++++++++++
 x86/vmx.h       |  1 +
 x86/vmx_tests.c |  2 +-
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/x86/vmx.c b/x86/vmx.c
index 6079420db33a..37e31c284399 100644
--- a/x86/vmx.c
+++ b/x86/vmx.c
@@ -1772,6 +1772,19 @@ void test_set_guest(test_guest_func func)
 	v2_guest_main = func;
 }
 
+/*
+ * Reset the target for the enter_guest call, re-initialize VMCS. For tests
+ * that wish to run multiple sub-tests under the same vmx_test parent function
+ */
+void test_reset_guest(test_guest_func func)
+{
+	assert(current->v2);
+	init_vmcs(&(current->vmcs));
+	v2_guest_main = func;
+	launched = 0;
+	guest_finished = 0;
+}
+
 static void check_for_guest_termination(void)
 {
 	if (is_hypercall()) {
diff --git a/x86/vmx.h b/x86/vmx.h
index 75abf9a489dd..217114c3bf3a 100644
--- a/x86/vmx.h
+++ b/x86/vmx.h
@@ -824,6 +824,7 @@ void enter_guest_with_invalid_guest_state(void);
 typedef void (*test_guest_func)(void);
 typedef void (*test_teardown_func)(void *data);
 void test_set_guest(test_guest_func func);
+void test_reset_guest(test_guest_func func);
 void test_add_teardown(test_teardown_func func, void *data);
 void test_skip(const char *msg);
 
diff --git a/x86/vmx_tests.c b/x86/vmx_tests.c
index f035f24a771a..6f46c7759c85 100644
--- a/x86/vmx_tests.c
+++ b/x86/vmx_tests.c
@@ -6858,7 +6858,7 @@ static void test_pat(u32 field, const char * field_name, u32 ctrl_field,
 	vmcs_clear_bits(ctrl_field, ctrl_bit);
 	if (field == GUEST_PAT) {
 		vmx_set_test_stage(1);
-		test_set_guest(guest_state_test_main);
+		test_reset_guest(guest_state_test_main);
 	}
 
 	for (i = 0; i < 256; i = (i < PAT_VAL_LIMIT) ? i + 1 : i * 2) {
-- 
2.23.0.187.g17f5b7556c-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