Re: [PATCH v7 26/26] KVM: selftest: Add a selftest for VMRUN/#VMEXIT with unmappable vmcb12
From: Sean Christopherson
Date: Fri Mar 06 2026 - 11:41:12 EST
On Fri, Mar 06, 2026, Yosry Ahmed wrote:
> > diff --git a/arch/x86/kvm/svm/nested.c b/arch/x86/kvm/svm/nested.c
> > index b191c6cab57d..78a542c6ddf1 100644
> > --- a/arch/x86/kvm/svm/nested.c
> > +++ b/arch/x86/kvm/svm/nested.c
> > @@ -1105,10 +1105,8 @@ int nested_svm_vmrun(struct kvm_vcpu *vcpu)
> >
> > vmcb12_gpa = svm->vmcb->save.rax;
> > err = nested_svm_copy_vmcb12_to_cache(vcpu, vmcb12_gpa);
> > - if (err == -EFAULT) {
> > - kvm_inject_gp(vcpu, 0);
> > - return 1;
> > - }
> > + if (err == -EFAULT)
> > + return kvm_handle_memory_failure(vcpu, X86EMUL_UNHANDLEABLE, NULL);
>
> Why not call kvm_prepare_emulation_failure_exit() directly?
Mostly because my mental coin-flip came up heads. But it's also one less line
of code, woot woot!
> Is the premise that kvm_handle_memory_failure() might evolve to do more
> things for emulation failures that are specifically caused by memory
> failures, other than potentially injecting an exception?
Yeah, more or less. I doubt kvm_handle_memory_failure() will ever actually evolve
into anything more sophisticated, but at the very least, using
kvm_handle_memory_failure() documents _why_ KVM can't handle emulation.
On second thought, I think using X86EMUL_IO_NEEDED would be more appropriate.
The memremap() is only reachable if allow_unsafe_mappings is enabled, and so for
a "default" configuration, failure can only occur on:
if (is_error_noslot_pfn(map->pfn))
return -EINVAL;
Which doesn't _guarantee_ that emulated I/O is required, but we're definitely
beyond splitting hairs at that point.