diff mbox series

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

Message ID 20210224005627.657028-1-seanjc@google.com (mailing list archive)
State New, archived
Headers show
Series KVM: SVM: Fix nested VM-Exit on #GP interception handling | expand

Commit Message

Sean Christopherson Feb. 24, 2021, 12:56 a.m. UTC
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")
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
 arch/x86/kvm/svm/svm.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

Comments

Paolo Bonzini Feb. 25, 2021, 10:15 a.m. UTC | #1
On 24/02/21 01:56, Sean Christopherson wrote:
> 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")
> Signed-off-by: Sean Christopherson <seanjc@google.com>
> ---
>   arch/x86/kvm/svm/svm.c | 7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
> index 14e41dddc7eb..c4f2f2f6b945 100644
> --- a/arch/x86/kvm/svm/svm.c
> +++ b/arch/x86/kvm/svm/svm.c
> @@ -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);
>   }
> 

Queued, thanks.

Paolo
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c
index 14e41dddc7eb..c4f2f2f6b945 100644
--- a/arch/x86/kvm/svm/svm.c
+++ b/arch/x86/kvm/svm/svm.c
@@ -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);
 }