Skip to contentSkip to conversation

KVM: selftests: Don't skip L2's VMCALL in SMM test for SVM guest

PATCH Applied Sean Christopherson 3 participants 3 messages Jan 25, 2022 – Jan 26, 2022

Subsystems (2)
lore
Share & tools
lore

Sean Christopherson

author reviewer
#0 lore raw

PATCH 1/1 KVM: selftests: Don't skip L2's VMCALL in SMM test for SVM guest

Don't skip the vmcall() in l2_guest_code() prior to re-entering L2, doing so will result in L2 running to completion, popping '0' off the stack for RET, jumping to address '0', and ultimately dying with a triple fault shutdown.

It's not at all obvious why the test re-enters L2 and re-executes VMCALL, but presumably it serves a purpose. The VMX path doesn't skip vmcall(), and the test can't possibly have passed on SVM, so just do what VMX does.

Fixes d951b2210c1a ("KVM: selftests: smm_test: Test SMM enter from L2")
Cc Maxim Levitsky <[email protected]>
---
 tools/testing/selftests/kvm/x86_64/smm_test.c | 1 -
 1 file changed, 1 deletion(-)
tools/testing/selftests/kvm/x86_64/smm_test.c +0 -1
index 2da8eb8e2d96..a626d40fdb48 100644
@@ -105,7 +105,6 @@ static void guest_code(void *arg)
 
 		if (cpu_has_svm()) {
 			run_guest(svm->vmcb, svm->vmcb_gpa);
-			svm->vmcb->save.rip += 3;
 			run_guest(svm->vmcb, svm->vmcb_gpa);
 		} else {
 			vmlaunch();

base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4

Signature · 1 line
2.35.0.rc0.227.g00780c9af4-goog
#1 lore raw
Quoted 7 lines · Sean Christopherson

Don't skip the vmcall() in l2_guest_code() prior to re-entering L2, doing so will result in L2 running to completion, popping '0' off the stack for RET, jumping to address '0', and ultimately dying with a triple fault shutdown.

It's not at all obvious why the test re-enters L2 and re-executes VMCALL, but presumably it serves a purpose.

I managed to forget everything but it seems my intentions were to test two things:

- "Enter SMM during L2 execution and check that we correctly return from it."
- "Perform save/restore while the guest is in SMM triggered during L2 execution"

the later could've been complemented with "and try running L2 after".

Quoted 2 lines

The VMX path doesn't skip vmcall(), and the test can't possibly have passed on SVM

Well, it kind of works for me (pre-patch) :-) I do see #DF in the trace but not #TF.

Quoted 2 lines

, so just do what VMX does.

Makes sense. I can't recall how "+= 3" appeared.

Quoted 20 lines
Fixes d951b2210c1a ("KVM: selftests: smm_test: Test SMM enter from L2")
Cc Maxim Levitsky <[email protected]>
---
 tools/testing/selftests/kvm/x86_64/smm_test.c | 1 -
 1 file changed, 1 deletion(-)
tools/testing/selftests/kvm/x86_64/smm_test.c +0 -1
index 2da8eb8e2d96..a626d40fdb48 100644
@@ -105,7 +105,6 @@ static void guest_code(void *arg)
 
 		if (cpu_has_svm()) {
 			run_guest(svm->vmcb, svm->vmcb_gpa);
-			svm->vmcb->save.rip += 3;
 			run_guest(svm->vmcb, svm->vmcb_gpa);
 		} else {
 			vmlaunch();
Quoted 1 line

base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4

Signature · 1 line
Vitaly
maintainer Applied
#2 lore raw
In reply to Sean Christopherson
Quoted 29 lines · Sean Christopherson

Don't skip the vmcall() in l2_guest_code() prior to re-entering L2, doing so will result in L2 running to completion, popping '0' off the stack for RET, jumping to address '0', and ultimately dying with a triple fault shutdown.

It's not at all obvious why the test re-enters L2 and re-executes VMCALL, but presumably it serves a purpose. The VMX path doesn't skip vmcall(), and the test can't possibly have passed on SVM, so just do what VMX does.

Fixes d951b2210c1a ("KVM: selftests: smm_test: Test SMM enter from L2")
Cc Maxim Levitsky <[email protected]>
---
  tools/testing/selftests/kvm/x86_64/smm_test.c | 1 -
  1 file changed, 1 deletion(-)
tools/testing/selftests/kvm/x86_64/smm_test.c +0 -1
index 2da8eb8e2d96..a626d40fdb48 100644
@@ -105,7 +105,6 @@ static void guest_code(void *arg)
 
  		if (cpu_has_svm()) {
  			run_guest(svm->vmcb, svm->vmcb_gpa);
-			svm->vmcb->save.rip += 3;
  			run_guest(svm->vmcb, svm->vmcb_gpa);
  		} else {
  			vmlaunch();
Quoted 1 line

base-commit: e2e83a73d7ce66f62c7830a85619542ef59c90e4

Queued, thanks.

Paolo