Re: [PATCH 3/9] KVM: SVM: Add a helper to detect VMRUN failures
From: Sean Christopherson
Date: Thu Nov 13 2025 - 18:35:43 EST
On Thu, Nov 13, 2025, Yosry Ahmed wrote:
> On Thu, Nov 13, 2025 at 02:56:15PM -0800, Sean Christopherson wrote:
> > Add a helper to detect VMRUN failures so that KVM can guard against its
> > own long-standing bug, where KVM neglects to set exitcode[63:32] when
> > synthesizing a nested VMFAIL_INVALID VM-Exit. This will allow fixing
> > KVM's mess of treating exitcode as two separate 32-bit values without
> > breaking KVM-on-KVM when running on an older, unfixed KVM.
> >
> > Cc: Jim Mattson <jmattson@xxxxxxxxxx>
> > Cc: Yosry Ahmed <yosry.ahmed@xxxxxxxxx>
> > Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> > ---
> > arch/x86/kvm/svm/nested.c | 16 +++++++---------
> > arch/x86/kvm/svm/svm.c | 4 ++--
> > arch/x86/kvm/svm/svm.h | 5 +++++
> > 3 files changed, 14 insertions(+), 11 deletions(-)
> >
> > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> > index ba0f11c68372..8070e20ed5a7 100644
> > --- a/arch/x86/kvm/svm/nested.c
> > +++ b/arch/x86/kvm/svm/nested.c
> > @@ -1134,7 +1134,7 @@ int nested_svm_vmexit(struct vcpu_svm *svm)
> > vmcb12->control.exit_info_1 = vmcb02->control.exit_info_1;
> > vmcb12->control.exit_info_2 = vmcb02->control.exit_info_2;
> >
> > - if (vmcb12->control.exit_code != SVM_EXIT_ERR)
> > + if (svm_is_vmrun_failure(vmcb12->control.exit_code))
>
> This was flipped, wasn't it?
Ugh, yes. Hrm, I'm surprised this wasn't caught by svm_nested_soft_inject_test.c.
Oof. We should probably also extend svm_is_vmrun_failure() (in the future) to
detect any failure, e.g. VMEXIT_INVALID_PMC might be relevant soon?
> > nested_save_pending_event_to_vmcb12(svm, vmcb12);