Skip to contentSkip to conversation

KVM: SVM: Fix nested VM-Exit on #GP interception handling

PATCH Applied Sean Christopherson 2 participants 2 messages Feb 24, 2021 – Feb 25, 2021

Subsystems (3)
lore
Share & tools
lore

Sean Christopherson

author maintainer
#0 lore raw

PATCH 1/1 KVM: SVM: Fix nested VM-Exit on #GP interception handling

Fix the interpreation of nested_svm_vmexit()'s return value when synthesizing a nested VM-Exit after intercepting an SVM instruction while L2 was running. The helper returns '0' on success, whereas a return value of '0' in the exit handler path means "exit to userspace". The incorrect return value causes KVM to exit to userspace without filling the run state, e.g. QEMU logs "KVM: unknown exit, hardware reason 0".

Fixes 14c2bf81fcd2 ("KVM: SVM: Fix #GP handling for doubly-nested virtualization")
---
 arch/x86/kvm/svm/svm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/svm.c +6 -1
index 14e41dddc7eb..c4f2f2f6b945 100644
@@ -2200,13 +2200,18 @@ static int emulate_svm_instr(struct kvm_vcpu *vcpu, int opcode)
 		[SVM_INSTR_VMSAVE] = vmsave_interception,
 	};
 	struct vcpu_svm *svm = to_svm(vcpu);
+	int ret;
 
 	if (is_guest_mode(vcpu)) {
 		svm->vmcb->control.exit_code = guest_mode_exit_codes[opcode];
 		svm->vmcb->control.exit_info_1 = 0;
 		svm->vmcb->control.exit_info_2 = 0;
 
-		return nested_svm_vmexit(svm);
+		/* Returns '1' or -errno on failure, '0' on success. */
+		ret = nested_svm_vmexit(svm);
+		if (ret)
+			return ret;
+		return 1;
 	}
 	return svm_instr_handlers[opcode](vcpu);
 }
Signature · 1 line
2.30.0.617.g56c4b15f3c-goog
maintainer Applied
#1 lore raw
Quoted 28 lines · Sean Christopherson

Fix the interpreation of nested_svm_vmexit()'s return value when synthesizing a nested VM-Exit after intercepting an SVM instruction while L2 was running. The helper returns '0' on success, whereas a return value of '0' in the exit handler path means "exit to userspace". The incorrect return value causes KVM to exit to userspace without filling the run state, e.g. QEMU logs "KVM: unknown exit, hardware reason 0".

Fixes 14c2bf81fcd2 ("KVM: SVM: Fix #GP handling for doubly-nested virtualization")
---
  arch/x86/kvm/svm/svm.c | 7 ++++++-
  1 file changed, 6 insertions(+), 1 deletion(-)
arch/x86/kvm/svm/svm.c +1 -0
index 14e41dddc7eb..c4f2f2f6b945 100644
@@ -2200,13 +2200,18 @@ static int emulate_svm_instr(struct kvm_vcpu *vcpu, int opcode)
  		[SVM_INSTR_VMSAVE] = vmsave_interception,
  	};
  	struct vcpu_svm *svm = to_svm(vcpu);
+	int ret;
 
  	if (is_guest_mode(vcpu)) {
  		svm->vmcb->control.exit_code = guest_mode_exit_codes[opcode];
  		svm->vmcb->control.exit_info_1 = 0;
  		svm->vmcb->control.exit_info_2 = 0;

arch/x86/kvm/svm/svm.c static int emulate_svm_instr(struct kvm_vcpu *vcpu, int opcode) · line 2217

Quoted 10 lines
arch/x86/kvm/svm/svm.c +5 -1
 
-		return nested_svm_vmexit(svm);
+		/* Returns '1' or -errno on failure, '0' on success. */
+		ret = nested_svm_vmexit(svm);
+		if (ret)
+			return ret;
+		return 1;
  	}
  	return svm_instr_handlers[opcode](vcpu);
  }

Queued, thanks.

Paolo