linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: selftests: restore special vmmcall code layout needed by the harness
@ 2022-11-30 18:11 Paolo Bonzini
  2022-11-30 22:56 ` Sean Christopherson
  0 siblings, 1 reply; 5+ messages in thread
From: Paolo Bonzini @ 2022-11-30 18:11 UTC (permalink / raw)
  To: linux-kernel, kvm; +Cc: Vitaly Kuznetsov

Commit 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values
in vmmcall()/vmcall()", 2022-11-21) broke the svm_nested_soft_inject_test
because it placed a "pop rbp" instruction after vmmcall.  While this is
correct and mimics what is done in the VMX case, this particular test
expects a ud2 instruction right after the vmmcall, so that it can skip
over it in the L1 part of the test.

Inline a suitably-modified version of vmmcall() to restore the
functionality of the test.

Fixes: 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values in vmmcall()/vmcall()"
Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 .../kvm/x86_64/svm_nested_soft_inject_test.c        | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c
index e497ace629c1..b34980d45648 100644
--- a/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c
+++ b/tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c
@@ -41,8 +41,17 @@ static void guest_int_handler(struct ex_regs *regs)
 static void l2_guest_code_int(void)
 {
 	GUEST_ASSERT_1(int_fired == 1, int_fired);
-	vmmcall();
-	ud2();
+
+	/*
+         * Same as the vmmcall() function, but with a ud2 sneaked after the
+         * vmmcall.  The caller injects an exception with the return address
+         * increased by 2, so the "pop rbp" must be after the ud2 and we cannot
+	 * use vmmcall() directly.
+         */
+	__asm__ __volatile__("push %%rbp; vmmcall; ud2; pop %%rbp"
+                             : : "a"(0xdeadbeef), "c"(0xbeefdead)
+                             : "rbx", "rdx", "rsi", "rdi", "r8", "r9",
+                               "r10", "r11", "r12", "r13", "r14", "r15");
 
 	GUEST_ASSERT_1(bp_fired == 1, bp_fired);
 	hlt();
-- 
2.31.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: selftests: restore special vmmcall code layout needed by the harness
  2022-11-30 18:11 [PATCH] KVM: selftests: restore special vmmcall code layout needed by the harness Paolo Bonzini
@ 2022-11-30 22:56 ` Sean Christopherson
  2022-12-01  9:28   ` Vitaly Kuznetsov
  0 siblings, 1 reply; 5+ messages in thread
From: Sean Christopherson @ 2022-11-30 22:56 UTC (permalink / raw)
  To: Paolo Bonzini; +Cc: linux-kernel, kvm, Vitaly Kuznetsov

On Wed, Nov 30, 2022, Paolo Bonzini wrote:
> Commit 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values
> in vmmcall()/vmcall()", 2022-11-21) broke the svm_nested_soft_inject_test
> because it placed a "pop rbp" instruction after vmmcall.  While this is
> correct and mimics what is done in the VMX case, this particular test
> expects a ud2 instruction right after the vmmcall, so that it can skip
> over it in the L1 part of the test.
> 
> Inline a suitably-modified version of vmmcall() to restore the
> functionality of the test.
>
> Fixes: 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values in vmmcall()/vmcall()"
> Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---

We really, really need to save/restore guest GPRs in L1 when handling exits from L2.

For now,

Reviewed-by: Sean Christopherson <seanjc@google.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: selftests: restore special vmmcall code layout needed by the harness
  2022-11-30 22:56 ` Sean Christopherson
@ 2022-12-01  9:28   ` Vitaly Kuznetsov
  2022-12-01 13:48     ` Maxim Levitsky
  0 siblings, 1 reply; 5+ messages in thread
From: Vitaly Kuznetsov @ 2022-12-01  9:28 UTC (permalink / raw)
  To: Sean Christopherson, Paolo Bonzini; +Cc: linux-kernel, kvm

Sean Christopherson <seanjc@google.com> writes:

> On Wed, Nov 30, 2022, Paolo Bonzini wrote:
>> Commit 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values
>> in vmmcall()/vmcall()", 2022-11-21) broke the svm_nested_soft_inject_test
>> because it placed a "pop rbp" instruction after vmmcall.  While this is
>> correct and mimics what is done in the VMX case, this particular test
>> expects a ud2 instruction right after the vmmcall, so that it can skip
>> over it in the L1 part of the test.
>> 
>> Inline a suitably-modified version of vmmcall() to restore the
>> functionality of the test.
>>
>> Fixes: 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values in vmmcall()/vmcall()"
>> Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
>> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>> ---
>
> We really, really need to save/restore guest GPRs in L1 when handling exits from L2.

+1, the amount of stuff we do to workaround the shortcoming (and time
we waste debugging) is getting ridiculously high. 

>
> For now,
>
> Reviewed-by: Sean Christopherson <seanjc@google.com>
>

Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>

-- 
Vitaly


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: selftests: restore special vmmcall code layout needed by the harness
  2022-12-01  9:28   ` Vitaly Kuznetsov
@ 2022-12-01 13:48     ` Maxim Levitsky
  2022-12-28  9:53       ` mlevitsk
  0 siblings, 1 reply; 5+ messages in thread
From: Maxim Levitsky @ 2022-12-01 13:48 UTC (permalink / raw)
  To: Vitaly Kuznetsov, Sean Christopherson, Paolo Bonzini; +Cc: linux-kernel, kvm

On Thu, 2022-12-01 at 10:28 +0100, Vitaly Kuznetsov wrote:
> Sean Christopherson <seanjc@google.com> writes:
> 
> > On Wed, Nov 30, 2022, Paolo Bonzini wrote:
> > > Commit 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values
> > > in vmmcall()/vmcall()", 2022-11-21) broke the svm_nested_soft_inject_test
> > > because it placed a "pop rbp" instruction after vmmcall.  While this is
> > > correct and mimics what is done in the VMX case, this particular test
> > > expects a ud2 instruction right after the vmmcall, so that it can skip
> > > over it in the L1 part of the test.
> > > 
> > > Inline a suitably-modified version of vmmcall() to restore the
> > > functionality of the test.
> > > 
> > > Fixes: 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values in vmmcall()/vmcall()"
> > > Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
> > > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > > ---
> > 
> > We really, really need to save/restore guest GPRs in L1 when handling exits from L2.
> 
> +1, the amount of stuff we do to workaround the shortcoming (and time
> we waste debugging) is getting ridiculously high. 
> 
> > For now,
> > 
> > Reviewed-by: Sean Christopherson <seanjc@google.com>
> > 
> 
> Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> 

I didn't notice this fix and also found this issue.

Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>

Best regards,
	Maxim Levitsky


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] KVM: selftests: restore special vmmcall code layout needed by the harness
  2022-12-01 13:48     ` Maxim Levitsky
@ 2022-12-28  9:53       ` mlevitsk
  0 siblings, 0 replies; 5+ messages in thread
From: mlevitsk @ 2022-12-28  9:53 UTC (permalink / raw)
  To: Vitaly Kuznetsov, Sean Christopherson, Paolo Bonzini; +Cc: linux-kernel, kvm

On Thu, 2022-12-01 at 15:48 +0200, Maxim Levitsky wrote:
> On Thu, 2022-12-01 at 10:28 +0100, Vitaly Kuznetsov wrote:
> > Sean Christopherson <seanjc@google.com> writes:
> > 
> > > On Wed, Nov 30, 2022, Paolo Bonzini wrote:
> > > > Commit 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values
> > > > in vmmcall()/vmcall()", 2022-11-21) broke the svm_nested_soft_inject_test
> > > > because it placed a "pop rbp" instruction after vmmcall.  While this is
> > > > correct and mimics what is done in the VMX case, this particular test
> > > > expects a ud2 instruction right after the vmmcall, so that it can skip
> > > > over it in the L1 part of the test.
> > > > 
> > > > Inline a suitably-modified version of vmmcall() to restore the
> > > > functionality of the test.
> > > > 
> > > > Fixes: 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values in vmmcall()/vmcall()"
> > > > Cc: Vitaly Kuznetsov <vkuznets@redhat.com>
> > > > Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> > > > ---
> > > 
> > > We really, really need to save/restore guest GPRs in L1 when handling exits from L2.
> > 
> > +1, the amount of stuff we do to workaround the shortcoming (and time
> > we waste debugging) is getting ridiculously high. 
> > 
> > > For now,
> > > 
> > > Reviewed-by: Sean Christopherson <seanjc@google.com>
> > > 
> > 
> > Reviewed-by: Vitaly Kuznetsov <vkuznets@redhat.com>
> > 
> 
> I didn't notice this fix and also found this issue.
> 
> Reviewed-by: Maxim Levitsky <mlevitsk@redhat.com>
> 
> Best regards,
> 	Maxim Levitsky

Seems that this patch got through the cracks,
pinging so someone else won't need to debug this
test too.

Best regards,
	Maxim Levitsky


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-12-28  9:55 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-30 18:11 [PATCH] KVM: selftests: restore special vmmcall code layout needed by the harness Paolo Bonzini
2022-11-30 22:56 ` Sean Christopherson
2022-12-01  9:28   ` Vitaly Kuznetsov
2022-12-01 13:48     ` Maxim Levitsky
2022-12-28  9:53       ` mlevitsk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).