diff mbox series

[5/5] KVM: nSVM: set a dummy exit reason in L1 vmcb when loading the nested state

Message ID 20210503125446.1353307-6-mlevitsk@redhat.com (mailing list archive)
State New, archived
Headers show
Series KVM: nSVM: few fixes for the nested migration | expand

Commit Message

Maxim Levitsky May 3, 2021, 12:54 p.m. UTC
Since the nested migration is a result of a VMRUN, this makes it
possible to keep a warning that L1 vmcb should always have
VMRUN exit reason when switching back to it, which
otherwise triggers incorrectly.

Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
---
 arch/x86/kvm/svm/nested.c | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Paolo Bonzini May 3, 2021, 2:02 p.m. UTC | #1
On 03/05/21 14:54, Maxim Levitsky wrote:
> Since the nested migration is a result of a VMRUN, this makes it
> possible to keep a warning that L1 vmcb should always have
> VMRUN exit reason when switching back to it, which
> otherwise triggers incorrectly.
> 
> Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>

Does this fix "KVM: nSVM: If VMRUN is single-stepped, queue the #DB 
intercept in nested_svm_vmexit()"?  I don't like this, and also vmcb12 
is not initialized here (nested_load_control_from_vmcb12 is using the 
state passed in from userspace instead).

I think you should just remove the WARN instead.

Paolo

> ---
>   arch/x86/kvm/svm/nested.c | 6 ++++++
>   1 file changed, 6 insertions(+)
> 
> diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> index 12a12ae940fa..146be4b5084b 100644
> --- a/arch/x86/kvm/svm/nested.c
> +++ b/arch/x86/kvm/svm/nested.c
> @@ -1338,6 +1338,12 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
>   	svm->vmcb01.ptr->save.rip = save->rip;
>   	svm->vmcb01.ptr->save.cpl = 0;
>   
> +	/*
> +	 * For consistency sake, restore the L1 exit reason
> +	 * (that happened prior to the migration) to SVM_EXIT_VMRUN.
> +	 */
> +	svm->vmcb->control.exit_code = SVM_EXIT_VMRUN;
> +
>   	nested_load_control_from_vmcb12(svm, ctl);
>   
>   	svm_switch_vmcb(svm, &svm->nested.vmcb02);
>
Maxim Levitsky May 3, 2021, 2:26 p.m. UTC | #2
On Mon, 2021-05-03 at 16:02 +0200, Paolo Bonzini wrote:
> On 03/05/21 14:54, Maxim Levitsky wrote:
> > Since the nested migration is a result of a VMRUN, this makes it
> > possible to keep a warning that L1 vmcb should always have
> > VMRUN exit reason when switching back to it, which
> > otherwise triggers incorrectly.
> > 
> > Signed-off-by: Maxim Levitsky <mlevitsk@redhat.com>
> 
> Does this fix "KVM: nSVM: If VMRUN is single-stepped, queue the #DB 
> intercept in nested_svm_vmexit()"?  I don't like this, and also vmcb12 
> is not initialized here (nested_load_control_from_vmcb12 is using the 
> state passed in from userspace instead).

> 
> I think you should just remove the WARN instead.
All right, I'll do this!

Best regards,
	Maxim Levitsky


> 
> Paolo
> 
> > ---
> >   arch/x86/kvm/svm/nested.c | 6 ++++++
> >   1 file changed, 6 insertions(+)
> > 
> > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> > index 12a12ae940fa..146be4b5084b 100644
> > --- a/arch/x86/kvm/svm/nested.c
> > +++ b/arch/x86/kvm/svm/nested.c
> > @@ -1338,6 +1338,12 @@ static int svm_set_nested_state(struct kvm_vcpu *vcpu,
> >   	svm->vmcb01.ptr->save.rip = save->rip;
> >   	svm->vmcb01.ptr->save.cpl = 0;
> >   
> > +	/*
> > +	 * For consistency sake, restore the L1 exit reason
> > +	 * (that happened prior to the migration) to SVM_EXIT_VMRUN.
> > +	 */
> > +	svm->vmcb->control.exit_code = SVM_EXIT_VMRUN;
> > +
> >   	nested_load_control_from_vmcb12(svm, ctl);
> >   
> >   	svm_switch_vmcb(svm, &svm->nested.vmcb02);
> >
diff mbox series

Patch

diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
index 12a12ae940fa..146be4b5084b 100644
--- a/arch/x86/kvm/svm/nested.c
+++ b/arch/x86/kvm/svm/nested.c
@@ -1338,6 +1338,12 @@  static int svm_set_nested_state(struct kvm_vcpu *vcpu,
 	svm->vmcb01.ptr->save.rip = save->rip;
 	svm->vmcb01.ptr->save.cpl = 0;
 
+	/*
+	 * For consistency sake, restore the L1 exit reason
+	 * (that happened prior to the migration) to SVM_EXIT_VMRUN.
+	 */
+	svm->vmcb->control.exit_code = SVM_EXIT_VMRUN;
+
 	nested_load_control_from_vmcb12(svm, ctl);
 
 	svm_switch_vmcb(svm, &svm->nested.vmcb02);