kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] KVM: SVM: Fix nested VM-Exit on #GP interception handling
@ 2021-02-24  0:56 Sean Christopherson
  2021-02-25 10:15 ` Paolo Bonzini
  0 siblings, 1 reply; 2+ messages in thread
From: Sean Christopherson @ 2021-02-24  0:56 UTC (permalink / raw)
  To: Paolo Bonzini
  Cc: Sean Christopherson, Vitaly Kuznetsov, Wanpeng Li, Jim Mattson,
	Joerg Roedel, kvm, linux-kernel

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);
 }
-- 
2.30.0.617.g56c4b15f3c-goog


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

* Re: [PATCH] KVM: SVM: Fix nested VM-Exit on #GP interception handling
  2021-02-24  0:56 [PATCH] KVM: SVM: Fix nested VM-Exit on #GP interception handling Sean Christopherson
@ 2021-02-25 10:15 ` Paolo Bonzini
  0 siblings, 0 replies; 2+ messages in thread
From: Paolo Bonzini @ 2021-02-25 10:15 UTC (permalink / raw)
  To: Sean Christopherson
  Cc: Vitaly Kuznetsov, Wanpeng Li, Jim Mattson, Joerg Roedel, kvm,
	linux-kernel

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


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

end of thread, other threads:[~2021-02-25 10:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-24  0:56 [PATCH] KVM: SVM: Fix nested VM-Exit on #GP interception handling Sean Christopherson
2021-02-25 10:15 ` Paolo Bonzini

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).