diff mbox series

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

Message ID 20190906210313.128316-8-oupton@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: VMX: Add full nested support for IA32_PERF_GLOBAL_CTRL | expand

Commit Message

Oliver Upton Sept. 6, 2019, 9:03 p.m. UTC
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@oracle.com>
Signed-off-by: Oliver Upton <oupton@google.com>
---
 x86/vmx.c       | 13 +++++++++++++
 x86/vmx.h       |  1 +
 x86/vmx_tests.c |  2 +-
 3 files changed, 15 insertions(+), 1 deletion(-)

Comments

Krish Sadhukhan Sept. 10, 2019, 8:49 p.m. UTC | #1
On 09/06/2019 02:03 PM, Oliver Upton wrote:
> 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.

The commit header should have "nVMX" instead of "vmx".

>
> Suggested-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> Signed-off-by: Oliver Upton <oupton@google.com>
> ---
>   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) {

Except the commit header issue,

   Reviewed-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
diff mbox series

Patch

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