diff mbox series

[1/2] nSVM: Add a variant of svm_vmrun() for executing custom guest code

Message ID 20210715180824.234781-2-krish.sadhukhan@oracle.com (mailing list archive)
State New, archived
Headers show
Series Test: nSVM: Test the effect of guest EFLAGS.TF on VMRUN | expand

Commit Message

Krish Sadhukhan July 15, 2021, 6:08 p.m. UTC
Current implementation of svm_vmrun() and test_run() sets the guest RIP to a
wrapper function which executes the guest code being used by tests. This is
not suitable for tests like testing the effect of guest EFLAGS.TF on VMRUN
because the trap handler will point to the second guest instruction to which
the test code does not have access.

Therefore, add a variant of svm_vmrun() that will set the guest RIP to the
actual guest code that tests want to test. This will be used by the next
patch in this series.

Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
---
 x86/svm.c | 14 ++++++++++++--
 x86/svm.h |  1 +
 2 files changed, 13 insertions(+), 2 deletions(-)

Comments

Sean Christopherson July 15, 2021, 7:05 p.m. UTC | #1
On Thu, Jul 15, 2021, Krish Sadhukhan wrote:
> Current implementation of svm_vmrun() and test_run() sets the guest RIP to a
> wrapper function which executes the guest code being used by tests. This is
> not suitable for tests like testing the effect of guest EFLAGS.TF on VMRUN
> because the trap handler will point to the second guest instruction to which
> the test code does not have access.
> 
> Therefore, add a variant of svm_vmrun() that will set the guest RIP to the
> actual guest code that tests want to test. This will be used by the next
> patch in this series.
> 
> Signed-off-by: Krish Sadhukhan <krish.sadhukhan@oracle.com>
> ---
>  x86/svm.c | 14 ++++++++++++--
>  x86/svm.h |  1 +
>  2 files changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/x86/svm.c b/x86/svm.c
> index f185ca0..50b6a15 100644
> --- a/x86/svm.c
> +++ b/x86/svm.c
> @@ -227,9 +227,9 @@ struct svm_test *v2_test;
>  
>  u64 guest_stack[10000];
>  
> -int svm_vmrun(void)
> +static int _svm_vmrun(u64 rip)

I'd prefer to stay with the kernel style of two underscores for inner helpers.

>  {
> -	vmcb->save.rip = (ulong)test_thunk;
> +	vmcb->save.rip = (ulong)rip;
>  	vmcb->save.rsp = (ulong)(guest_stack + ARRAY_SIZE(guest_stack));
>  	regs.rdi = (ulong)v2_test;
>  
> @@ -244,6 +244,16 @@ int svm_vmrun(void)
>  	return (vmcb->control.exit_code);
>  }
>  
> +int svm_vmrun(void)
> +{
> +	return _svm_vmrun((u64)test_thunk);
> +}
> +
> +int svm_vmrun_custom(u64 rip)
> +{
> +	return _svm_vmrun(rip);
> +}

Why bother with the "custom" wrapper?  Just expose the inner helper.
diff mbox series

Patch

diff --git a/x86/svm.c b/x86/svm.c
index f185ca0..50b6a15 100644
--- a/x86/svm.c
+++ b/x86/svm.c
@@ -227,9 +227,9 @@  struct svm_test *v2_test;
 
 u64 guest_stack[10000];
 
-int svm_vmrun(void)
+static int _svm_vmrun(u64 rip)
 {
-	vmcb->save.rip = (ulong)test_thunk;
+	vmcb->save.rip = (ulong)rip;
 	vmcb->save.rsp = (ulong)(guest_stack + ARRAY_SIZE(guest_stack));
 	regs.rdi = (ulong)v2_test;
 
@@ -244,6 +244,16 @@  int svm_vmrun(void)
 	return (vmcb->control.exit_code);
 }
 
+int svm_vmrun(void)
+{
+	return _svm_vmrun((u64)test_thunk);
+}
+
+int svm_vmrun_custom(u64 rip)
+{
+	return _svm_vmrun(rip);
+}
+
 extern u64 *vmrun_rip;
 
 static void test_run(struct svm_test *test)
diff --git a/x86/svm.h b/x86/svm.h
index 995b0f8..3753e2e 100644
--- a/x86/svm.h
+++ b/x86/svm.h
@@ -409,6 +409,7 @@  void vmcb_ident(struct vmcb *vmcb);
 struct regs get_regs(void);
 void vmmcall(void);
 int svm_vmrun(void);
+int svm_vmrun_custom(u64 rip);
 void test_set_guest(test_guest_func func);
 
 extern struct vmcb *vmcb;