Skip to contentSkip to conversation

KVM: selftests: restore special vmmcall code layout needed by the harness

PATCH In review Paolo Bonzini 4 participants 5 messages Nov 30, 2022 – Dec 28, 2022

Subsystems (2)
lore
Share & tools
lore

Paolo Bonzini

author maintainer
#0 lore raw

PATCH 1/1 KVM: selftests: restore special vmmcall code layout needed by the harness

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 <[email protected]>
---
 .../kvm/x86_64/svm_nested_soft_inject_test.c        | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)
tools/testing/selftests/kvm/x86_64/svm_nested_soft_inject_test.c +11 -2
index e497ace629c1..b34980d45648 100644
@@ -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();
Signature · 1 line
2.31.1
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 7 lines · Paolo Bonzini

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.

Quoted 7 lines

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 <[email protected]>

---

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

For now,

Reviewed-by
#2 lore raw
Quoted 11 lines · Sean Christopherson
Quoted 10 lines · Paolo Bonzini

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.

Quoted 6 lines
Quoted 4 lines
Fixes 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values in vmmcall()/vmcall()"
Cc Vitaly Kuznetsov <[email protected]>

---

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.

Quoted 5 lines

For now,

Signature · 1 line
Vitaly
Reviewed-by
#3 lore raw
Quoted 23 lines · Vitaly Kuznetsov
Quoted 11 lines · Sean Christopherson
Quoted 10 lines · Paolo Bonzini

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.

Quoted 6 lines
Quoted 4 lines
Fixes 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values in vmmcall()/vmcall()"
Cc Vitaly Kuznetsov <[email protected]>

---

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.

Quoted 7 lines
Quoted 4 lines

For now,

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

Best regards,
Maxim Levitsky

#4 lore raw
Quoted 32 lines · Maxim Levitsky
Quoted 23 lines · Vitaly Kuznetsov
Quoted 11 lines · Sean Christopherson
Quoted 10 lines · Paolo Bonzini

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.

Quoted 6 lines
Quoted 4 lines
Fixes 8fda37cf3d41 ("KVM: selftests: Stuff RAX/RCX with 'safe' values in vmmcall()/vmcall()"
Cc Vitaly Kuznetsov <[email protected]>

---

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.

Quoted 7 lines
Quoted 4 lines

For now,

Quoted 6 lines

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

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