Re: [PATCH v4 2/5] KVM: x86: Tell ->inject_page_fault() whether or a fault came from hardware
From: Yosry Ahmed
Date: Tue May 26 2026 - 14:53:20 EST
On Tue, May 26, 2026 at 11:48 AM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
>
> On Tue, May 26, 2026, Yosry Ahmed wrote:
> > On Fri, May 22, 2026 at 4:27 PM Sean Christopherson <seanjc@xxxxxxxxxx> wrote:
> > >
> > > When injecting a page fault (including nested TDP faults into L1), tell the
> > > injection routine whether or not the fault originated in hardware, i.e. if
> > > KVM is effectively forwarding a fault it intercept. For nested TDP fault
> > > injection, KVM needs to grab PAGE_WALK vs. GUEST_FINAL information from the
> > > VMCB/VMCS, _if_ the fault originated in hardware.
> > >
> > > No functional change intended (nothing uses the new param, yet...).
> > >
> > > Signed-off-by: Sean Christopherson <seanjc@xxxxxxxxxx>
> > > ---
> > > arch/x86/include/asm/kvm_host.h | 18 ++++++++++++++----
> > > arch/x86/kvm/mmu/paging_tmpl.h | 2 +-
> > > arch/x86/kvm/svm/nested.c | 3 ++-
> > > arch/x86/kvm/vmx/nested.c | 3 ++-
> > > arch/x86/kvm/x86.c | 16 +++++++++-------
> > > 5 files changed, 28 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
> > > index 271bdd109a98..d11063c36f03 100644
> > > --- a/arch/x86/include/asm/kvm_host.h
> > > +++ b/arch/x86/include/asm/kvm_host.h
> > > @@ -484,7 +484,8 @@ struct kvm_mmu {
> > > u64 (*get_pdptr)(struct kvm_vcpu *vcpu, int index);
> > > int (*page_fault)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault);
> > > void (*inject_page_fault)(struct kvm_vcpu *vcpu,
> > > - struct x86_exception *fault);
> > > + struct x86_exception *fault,
> > > + bool from_hardware);
> >
> > Probably a bit late to ask this question, but why do we need
> > from_hardware (or the previous hardware_nested_page_fault) as opposed
> > to just checking exit_code / exit_reason? Is it possible to get an
> > NPF/EPT violation but then synthesize a different one into L1 rather
> > than forwarding the one we got from HW?
>
> Yes. E.g. if access to emulated MMIO from L2 hit a !PRESENT fault (EPT Violation
> or #NPF), e.g. because MMIO caching is disabled or it's the first time the GPA has
> been accessed by L2, then KVM will enter the emulator. If emulating the MMIO
> access then hits a TDP fault, e.g. because L2 was accessing MMIO with a MOVQ
> (memory-to-memory move), or because L1 has since unmapped the code stream, then
> the TDP fault synthesized to L1 will not be the "same" fault the triggered the
> VM-Exit.
Interesting, thanks for the example. Probably worth documenting this
somewhere (changelog? comment?).