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:24:02 EST
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?