KVM: X86: Fix nested TDP error code info
Sean Christopherson
maintainerv4 cover KVM: X86: Fix nested TDP error code info
Kevin's series to fix how KVM populates error information when injecting nested page faults (NPF on SVM, EPT violations on VMX) to L1 during instruction emulation.
See v3 for the full cover letter.
v4:
- Pass @from_hardware directly instead of stuff a flag in x86_exception.
- Use the bits in @access (thanks to MBEC+GMET) to get the fault stage.
- Check the entire PFEC/EXIT_QUAL in the selftest.
- Use hardware _or_ KVM information, never merge the two.
- Name the selftest nested_tdp_fault_test.
v3:
- https://lore.kernel.org/all/[email protected]
- Introduce hardware_nested_page_fault in struct x86_exception to distinguish hardware NPF/EPT exits from emulation-triggered faults as per Sean
- For SVM, take PFERR_GUEST_FAULT_STAGE bits from hardware exit_info_1 on hardware NPF exits, and from fault->error_code on emulation faults
- For VMX, conditionally OR hardware exit qualification GVA_IS_VALID/ GVA_TRANSLATED bits only for hardware EPT violation exits as per Sean
- Replace #if PTTYPE != PTTYPE_EPT preprocessor guards in paging_tmpl.h with runtime kvm_nested_fault_is_ept() helper that checks guest_mmu as per Sean
v2:
- https://lore.kernel.org/all/[email protected]
- Split out the widening of the x86_exception error code into a separate patch as per Sean.
- Added a WARN if both PFERR_GUEST_* bits are set and force the exit_info_1 to PFERR_GUEST_FINAL_MASK if this occurs.
- Removed the selftest TDP helpers as per Sean
- Added a patch to populate the EPT violation bits for VMX nested page faults as per Sean.
- Expanded the added selftest to support VMX and also added a test case for write protected pages using the INS instruction.
v1: https://lore.kernel.org/all/[email protected]
Kevin Cheng (4):
KVM: x86: Widen x86_exception's error_code to 64 bits
KVM: SVM: Fix nested NPF injection of PFERR_GUEST_{PAGE,FINAL}_MASK
bits
KVM: VMX: Synthesize nested EPT violation GVA_IS_VALID/GVA_TRANSLATED
bits
KVM: selftests: Add nested page fault injection test
Sean Christopherson (1):
KVM: x86: Tell ->inject_page_fault() whether or a fault came from
hardware
arch/x86/include/asm/kvm_host.h | 20 +- arch/x86/kvm/kvm_emulate.h | 2 +- arch/x86/kvm/mmu/paging_tmpl.h | 36 +- arch/x86/kvm/svm/nested.c | 38 ++- arch/x86/kvm/vmx/nested.c | 29 +- arch/x86/kvm/x86.c | 16 +- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/include/x86/processor.h | 9 + .../selftests/kvm/x86/nested_tdp_fault_test.c | 313 ++++++++++++++++++ 9 files changed, 422 insertions(+), 42 deletions(-) create mode 100644 tools/testing/selftests/kvm/x86/nested_tdp_fault_test.c
base-commit: 66939c1603bd5579e63278f9dc72cba5b79da9b5
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
Sean Christopherson
maintainerPATCH v4 1/5 KVM: x86: Widen x86_exception's error_code to 64 bits
From: Kevin Cheng <[email protected]>
Widen the error_code field in struct x86_exception from u16 to u64 to accommodate AMD's NPF error code, which defines information bits above bit 31, e.g. PFERR_GUEST_FINAL_MASK (bit 32), and PFERR_GUEST_PAGE_MASK (bit 33).
Retain the u16 type for the local errcode variable in walk_addr_generic as the walker synthesizes conventional #PF error codes that are architecturally limited to bits 15:0.
--- arch/x86/kvm/kvm_emulate.h | 2 +- arch/x86/kvm/mmu/paging_tmpl.h | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-)
arch/x86/kvm/kvm_emulate.h +1 -1
@@ -22,7 +22,7 @@ enum x86_intercept_stage;struct x86_exception {u8 vector;bool error_code_valid; -u16 error_code; +u64 error_code;bool nested_page_fault;union {u64 address;/* cr2 or nested page fault gpa */
arch/x86/kvm/mmu/paging_tmpl.h +6 -0
@@ -328,6 +328,12 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,const int write_fault = access &PFERR_WRITE_MASK ;const int user_fault = access &PFERR_USER_MASK ;const int fetch_fault = access &PFERR_FETCH_MASK ; +/* +* Note! Track the error_code that's common to legacy shadow paging +* and NPT shadow paging as a u16 to guard against unintentionally +* setting any of bits 63:16. Architecturally, the #PF error code is +* 32 bits, and Intel CPUs don't support settings bits 31:16. +*/ u16 errcode =0 ;gpa_t real_gpa;gfn_t gfn;
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
Sean Christopherson
maintainerPATCH v4 2/5 KVM: x86: Tell ->inject_page_fault() whether or a fault came from hardware
In reply to Sean ChristophersonWhen 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...).
--- 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(-)
arch/x86/include/asm/kvm_host.h +14 -4
@@ -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);gpa_t (*gva_to_gpa)(struct kvm_vcpu *vcpu,struct kvm_mmu *mmu,gpa_t gva_or_gpa,u64 access,struct x86_exception *exception);
@@ -2305,9 +2306,18 @@ void kvm_queue_exception_e(struct kvm_vcpu *vcpu, unsigned nr, u32 error_code);void kvm_queue_exception_p (struct kvm_vcpu *vcpu,unsigned nr,unsigned long payload);void kvm_requeue_exception (struct kvm_vcpu *vcpu,unsigned int nr,bool has_error_code,u32 error_code); -void kvm_inject_page_fault (struct kvm_vcpu *vcpu,struct x86_exception *fault); -void kvm_inject_emulated_page_fault (struct kvm_vcpu *vcpu, -struct x86_exception *fault); +void kvm_inject_page_fault (struct kvm_vcpu *vcpu,struct x86_exception *fault, +bool from_hardware); +void __kvm_inject_emulated_page_fault (struct kvm_vcpu *vcpu, +struct x86_exception *fault, +bool from_hardware); + +static inline void kvm_inject_emulated_page_fault (struct kvm_vcpu *vcpu, +struct x86_exception *fault) +{ +__kvm_inject_emulated_page_fault (vcpu, fault, false); +} +bool kvm_require_cpl (struct kvm_vcpu *vcpu,int required_cpl);bool kvm_require_dr (struct kvm_vcpu *vcpu,int dr);
arch/x86/kvm/mmu/paging_tmpl.h +1 -1
@@ -813,7 +813,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault*/ if (!r) {if (!fault->prefetch) -kvm_inject_emulated_page_fault (vcpu, &walker.fault); +__kvm_inject_emulated_page_fault (vcpu, &walker.fault, true);return RET_PF_RETRY ; }
arch/x86/kvm/svm/nested.c +2 -1
@@ -34,7 +34,8 @@#define CC KVM_NESTED_VMENTER_CONSISTENCY_CHECKstatic void nested_svm_inject_npf_exit (struct kvm_vcpu *vcpu, -struct x86_exception *fault) +struct x86_exception *fault, +bool from_hardware) {struct vcpu_svm *svm =to_svm (vcpu);struct vmcb *vmcb = svm->vmcb;
arch/x86/kvm/vmx/nested.c +2 -1
@@ -411,7 +411,8 @@ static void nested_ept_invalidate_addr(struct kvm_vcpu *vcpu, gpa_t eptp, }static void nested_ept_inject_page_fault (struct kvm_vcpu *vcpu, -struct x86_exception *fault) +struct x86_exception *fault, +bool from_hardware) {struct vmcs12 *vmcs12 =get_vmcs12 (vcpu);struct vcpu_vmx *vmx =to_vmx (vcpu);
arch/x86/kvm/x86.c +9 -7
@@ -969,7 +969,8 @@ static int complete_emulated_insn_gp(struct kvm_vcpu *vcpu, int err) EMULTYPE_COMPLETE_USER_EXIT); } -void kvm_inject_page_fault (struct kvm_vcpu *vcpu,struct x86_exception *fault) +void kvm_inject_page_fault (struct kvm_vcpu *vcpu,struct x86_exception *fault, +bool from_hardware) { ++vcpu->stat.pf_guest;
@@ -986,8 +987,9 @@ void kvm_inject_page_fault(struct kvm_vcpu *vcpu, struct x86_exception *fault) fault->address); } -void kvm_inject_emulated_page_fault (struct kvm_vcpu *vcpu, -struct x86_exception *fault) +void __kvm_inject_emulated_page_fault (struct kvm_vcpu *vcpu, +struct x86_exception *fault, +bool from_hardware) {struct kvm_mmu *fault_mmu;WARN_ON_ONCE (fault->vector !=PF_VECTOR );
@@ -1004,9 +1006,9 @@ void kvm_inject_emulated_page_fault(struct kvm_vcpu *vcpu,kvm_mmu_invalidate_addr (vcpu, fault_mmu, fault->address,KVM_MMU_ROOT_CURRENT ); - fault_mmu->inject_page_fault (vcpu, fault); + fault_mmu->inject_page_fault (vcpu, fault, from_hardware); } -EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_inject_emulated_page_fault); +EXPORT_SYMBOL_FOR_KVM_INTERNAL (__kvm_inject_emulated_page_fault);void kvm_inject_nmi (struct kvm_vcpu *vcpu) {
@@ -14065,7 +14067,7 @@ bool kvm_arch_async_page_not_present(struct kvm_vcpu *vcpu, fault.nested_page_fault = false; fault.address = work->arch.token; fault.async_page_fault = true; -kvm_inject_page_fault (vcpu, &fault); +kvm_inject_page_fault (vcpu, &fault, false);return true; }else {/*
@@ -14236,7 +14238,7 @@ void kvm_fixup_and_inject_pf_error(struct kvm_vcpu *vcpu, gva_t gva, u16 error_c fault.address = gva; fault.async_page_fault = false; } - vcpu->arch.walk_mmu->inject_page_fault (vcpu, &fault); + vcpu->arch.walk_mmu->inject_page_fault (vcpu, &fault, true); }EXPORT_SYMBOL_FOR_KVM_INTERNAL (kvm_fixup_and_inject_pf_error);
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
Re: [PATCH v4 2/5] KVM: x86: Tell ->inject_page_fault() whether or a fault came from hardware
Quoted 23 lines · Sean Christopherson
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_WALKvs.GUEST_FINALinformation 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 <[email protected]>--- 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(-)arch/x86/include/asm/kvm_host.h +0
-0
arch/x86/include/asm/kvm_host.h struct kvm_mmu { · line 488
Quoted 6 lines
arch/x86/include/asm/kvm_host.h +2
-1@@ -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?
Sean Christopherson
maintainerRe: [PATCH v4 2/5] KVM: x86: Tell ->inject_page_fault() whether or a fault came from hardware
Quoted 28 lines · Yosry Ahmed
Quoted 27 lines · Sean Christopherson
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_WALKvs.GUEST_FINALinformation 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 <[email protected]>--- 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(-)arch/x86/include/asm/kvm_host.h +0
-1@@ -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);
Quoted 8 lines
arch/x86/include/asm/kvm_host.h struct kvm_mmu { · line 488
Quoted 2 lines
arch/x86/include/asm/kvm_host.h +2
-0+struct x86_exception *fault, + bool from_hardware);Probably a bit late to ask this question, but why do we need
from_hardware(or the previoushardware_nested_page_fault) as opposed to just checkingexit_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.
Re: [PATCH v4 2/5] KVM: x86: Tell ->inject_page_fault() whether or a fault came from hardware
Quoted 39 lines · Sean Christopherson
Quoted 28 lines · Yosry Ahmed
Quoted 27 lines · Sean Christopherson
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_WALKvs.GUEST_FINALinformation 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 <[email protected]>--- 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(-)arch/x86/include/asm/kvm_host.h +0
-1@@ -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);Quoted 8 lines
arch/x86/include/asm/kvm_host.h struct kvm_mmu { · line 488
Quoted 2 lines
arch/x86/include/asm/kvm_host.h +2
-0+struct x86_exception *fault, + bool from_hardware);Probably a bit late to ask this question, but why do we need
from_hardware(or the previoushardware_nested_page_fault) as opposed to just checkingexit_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?
Quoted 7 lines
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?).
Sean Christopherson
maintainerRe: [PATCH v4 2/5] KVM: x86: Tell ->inject_page_fault() whether or a fault came from hardware
Quoted 48 lines · Yosry Ahmed
Quoted 39 lines · Sean Christopherson
Quoted 28 lines · Yosry Ahmed
Quoted 27 lines · Sean Christopherson
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_WALKvs.GUEST_FINALinformation 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 <[email protected]>--- 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(-)arch/x86/include/asm/kvm_host.h +0
-1@@ -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);Quoted 8 lines
arch/x86/include/asm/kvm_host.h struct kvm_mmu { · line 488
Quoted 2 lines
arch/x86/include/asm/kvm_host.h +2
-0+struct x86_exception *fault, + bool from_hardware);Probably a bit late to ask this question, but why do we need
from_hardware(or the previoushardware_nested_page_fault) as opposed to just checkingexit_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?Quoted 7 lines
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.
Quoted 2 lines
Interesting, thanks for the example. Probably worth documenting this somewhere (changelog? comment?).
I added a version of the above to the changelog.
Sean Christopherson
maintainerPATCH v4 3/5 KVM: SVM: Fix nested NPF injection of PFERR_GUEST_{PAGE,FINAL}_MASK bits
In reply to Sean ChristophersonFrom: Kevin Cheng <[email protected]>
Fix KVM's generation of PFERR_GUEST_{PAGE,FINAL}_MASK bits when injecting a Nested Page Fault into L1. Currently, KVM blindly stuffs GUEST_FINAL into L1, which is blatantly wrong given that KVM obviously generates NPFs for page table accesses.
There are two paths that trigger NPF injection: hardware NPF exits (from L2) and emulation-triggered faults, i.e. when KVM detects a NPF as part of emulating an L2 GVA access. For the hardware case, use the bits verbatim from the VMCB, as KVM is simply forwarding a NPF to L1. For the emulation case, propagate the GUEST_{PAGE,FINAL} bits from the access field (which were recently added for MBEC+GMET support).
To differentiate between the two cases, add "hardware_nested_page_fault" to "struct x86_exception", and set it when injecting a NPF in response to an NPF exit from L2.
To help guard against future goofs, assert that exactly one of GUEST_PAGE or GUEST_FINAL is set when injecting a NPF. Unlike VMX, there are no (known) cases where hardware doesn't set either bit, and KVM should always set one or the other when emulating a GVA access.
--- arch/x86/include/asm/kvm_host.h | 2 ++ arch/x86/kvm/mmu/paging_tmpl.h | 15 +++++--------- arch/x86/kvm/svm/nested.c | 35 ++++++++++++++++++++++----------- 3 files changed, 31 insertions(+), 21 deletions(-)
arch/x86/include/asm/kvm_host.h +2 -0
@@ -284,6 +284,8 @@ enum x86_intercept_stage;#define PFERR_GUEST_RMP_MASK BIT_ULL(31)#define PFERR_GUEST_FINAL_MASK BIT_ULL(32)#define PFERR_GUEST_PAGE_MASK BIT_ULL(33) +#define PFERR_GUEST_FAULT_STAGE_MASK \ + (PFERR_GUEST_FINAL_MASK | PFERR_GUEST_PAGE_MASK)#define PFERR_GUEST_ENC_MASK BIT_ULL(34)#define PFERR_GUEST_SIZEM_MASK BIT_ULL(35)#define PFERR_GUEST_VMPL_MASK BIT_ULL(36)
arch/x86/kvm/mmu/paging_tmpl.h +5 -10
@@ -397,16 +397,6 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, nested_access |PFERR_GUEST_PAGE_MASK , &walker->fault, 0); -/* -* FIXME: This can happen if emulation (for of an INS/OUTS -* instruction) triggers a nested page fault. The exit -* qualification / exit info field will incorrectly have -* "guest page access" as the nested page fault's cause, -* instead of "guest page structure access". To fix this, -* the x86_exception struct should be augmented with enough -* information to fix the exit_qualification or exit_info_1 -* fields. -*/ if (unlikely (real_gpa ==INVALID_GPA ))return 0 ;
@@ -548,6 +538,11 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, walker->fault.nested_page_fault = mmu != vcpu->arch.walk_mmu; walker->fault.async_page_fault = false; +#if PTTYPE !=PTTYPE_EPT +if (walker->fault.nested_page_fault) + walker->fault.error_code |= access &PFERR_GUEST_FAULT_STAGE_MASK ; +#endif +trace_kvm_mmu_walker_error (walker->fault.error_code);return 0 ; }
arch/x86/kvm/svm/nested.c +24 -11
@@ -39,19 +39,32 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, {struct vcpu_svm *svm =to_svm (vcpu);struct vmcb *vmcb = svm->vmcb; +u64 fault_stage; -if (vmcb->control.exit_code !=SVM_EXIT_NPF ) { -/* -* TODO: track the cause of the nested page fault, and -* correctly fill in the high bits of exit_info_1. -*/ - vmcb->control.exit_code =SVM_EXIT_NPF ; - vmcb->control.exit_info_1 = (1ULL <<32 ); - vmcb->control.exit_info_2 = fault->address; - } +/* +* For hardware NPF exits, the GUEST_FAULT_STAGE bits are only +* available in the hardware exit_info_1, since the guest_mmu +* walker doesn't know whether the faulting GPA was a page table +* page or final page from L2's perspective. +*/ +if (from_hardware) + fault_stage = vmcb->control.exit_info_1 & +PFERR_GUEST_FAULT_STAGE_MASK ; +else + fault_stage = fault->error_code &PFERR_GUEST_FAULT_STAGE_MASK ; - vmcb->control.exit_info_1 &= ~0xffffffffULL ; - vmcb->control.exit_info_1 |= fault->error_code; +/* +* All nested page faults should be annotated as occurring on the +* final translation *or* the page walk. Arbitrarily choose "final" +* if KVM is buggy and enumerated both or neither. +*/ +if (WARN_ON_ONCE (hweight64 (fault_stage) !=1 )) + fault_stage =PFERR_GUEST_FINAL_MASK ; + + vmcb->control.exit_code =SVM_EXIT_NPF ; + vmcb->control.exit_info_1 = fault_stage | + (fault->error_code & ~PFERR_GUEST_FAULT_STAGE_MASK ); + vmcb->control.exit_info_2 = fault->address;nested_svm_vmexit (svm); }
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
Re: [PATCH v4 3/5] KVM: SVM: Fix nested NPF injection of PFERR_GUEST_{PAGE,FINAL}_MASK bits
Quoted 15 lines · Sean Christopherson
From: Kevin Cheng <[email protected]>
Fix KVM's generation of PFERR_GUEST_{PAGE,FINAL}_MASK bits when injecting a Nested Page Fault into L1. Currently, KVM blindly stuffs
GUEST_FINALinto L1, which is blatantly wrong given that KVM obviously generates NPFs for page table accesses.There are two paths that trigger NPF injection: hardware NPF exits (from L2) and emulation-triggered faults, i.e. when KVM detects a NPF as part of emulating an L2 GVA access. For the hardware case, use the bits verbatim from the VMCB, as KVM is simply forwarding a NPF to L1. For the emulation case, propagate the GUEST_{PAGE,FINAL} bits from the access field (which were recently added for MBEC+GMET support).
Quoted 3 lines
To differentiate between the two cases, add "
hardware_nested_page_fault" to "structx86_exception", and set it when injecting a NPF in response to an NPF exit from L2.
hardware_nested_page_fault is no more.
Quoted 9 lines
To help guard against future goofs, assert that exactly one of
GUEST_PAGEorGUEST_FINALis set when injecting a NPF. Unlike VMX, there are no (known) cases where hardware doesn't set either bit, and KVM should always set one or the other when emulating a GVA access.Signed-off-by Kevin Cheng <[email protected]>[sean: use plumbed in @access bits, massage changelog]Signed-off-by Sean Christopherson <[email protected]>
[..]
Quoted 30 lines
arch/x86/kvm/svm/nested.c +13
-11@@ -39,19 +39,32 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, {struct vcpu_svm *svm =to_svm (vcpu);struct vmcb *vmcb = svm->vmcb; +u64 fault_stage; -if (vmcb->control.exit_code !=SVM_EXIT_NPF ) { -/* -* TODO: track the cause of the nested page fault, and -* correctly fill in the high bits of exit_info_1. -*/ - vmcb->control.exit_code =SVM_EXIT_NPF ; - vmcb->control.exit_info_1 = (1ULL <<32 ); - vmcb->control.exit_info_2 = fault->address; - } +/* +* For hardware NPF exits, the GUEST_FAULT_STAGE bits are only +* available in the hardware exit_info_1, since the guest_mmu +* walker doesn't know whether the faulting GPA was a page table +* page or final page from L2's perspective. +*/ +if (from_hardware) + fault_stage = vmcb->control.exit_info_1 & +PFERR_GUEST_FAULT_STAGE_MASK ; +else + fault_stage = fault->error_code &PFERR_GUEST_FAULT_STAGE_MASK ; - vmcb->control.exit_info_1 &= ~0xffffffffULL ; - vmcb->control.exit_info_1 |= fault->error_code; +/*
arch/x86/kvm/svm/nested.c static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, · line 66
Quoted 10 lines
arch/x86/kvm/svm/nested.c +10
-0+* All nested page faults should be annotated as occurring on the +* final translation *or* the page walk. Arbitrarily choose "final" +* if KVM is buggy and enumerated both or neither. +*/ +if (WARN_ON_ONCE (hweight64 (fault_stage) !=1 )) + fault_stage =PFERR_GUEST_FINAL_MASK ; + + vmcb->control.exit_code =SVM_EXIT_NPF ; + vmcb->control.exit_info_1 = fault_stage | + (fault->error_code & ~PFERR_GUEST_FAULT_STAGE_MASK );
Do we need to do this in the common path? If from_hardware=true, can the fault injected by KVM have different flags from the one produced by hardware? I guess the answer is yes, (e.g. if KVM is doing write-protection?). Might be worth a comment.
Quoted 8 lines
arch/x86/kvm/svm/nested.c +1
-1+ vmcb->control.exit_info_2 = fault->address;nested_svm_vmexit (svm); } --2.54.0.794.g4f17f83d09-goog
Sean Christopherson
maintainerRe: [PATCH v4 3/5] KVM: SVM: Fix nested NPF injection of PFERR_GUEST_{PAGE,FINAL}_MASK bits
Quoted 16 lines · Yosry Ahmed
Quoted 15 lines · Sean Christopherson
From: Kevin Cheng <[email protected]>
Fix KVM's generation of PFERR_GUEST_{PAGE,FINAL}_MASK bits when injecting a Nested Page Fault into L1. Currently, KVM blindly stuffs
GUEST_FINALinto L1, which is blatantly wrong given that KVM obviously generates NPFs for page table accesses.There are two paths that trigger NPF injection: hardware NPF exits (from L2) and emulation-triggered faults, i.e. when KVM detects a NPF as part of emulating an L2 GVA access. For the hardware case, use the bits verbatim from the VMCB, as KVM is simply forwarding a NPF to L1. For the emulation case, propagate the GUEST_{PAGE,FINAL} bits from the access field (which were recently added for MBEC+GMET support).
Quoted 5 lines
Quoted 3 lines
To differentiate between the two cases, add "
hardware_nested_page_fault" to "structx86_exception", and set it when injecting a NPF in response to an NPF exit from L2.
hardware_nested_page_faultis no more.
Hrm, I suspect I unintentionally discarded a changelog update, I distinctly remember rewriting this. *sigh*
Quoted 36 lines
Quoted 8 lines
To help guard against future goofs, assert that exactly one of
GUEST_PAGEorGUEST_FINALis set when injecting a NPF. Unlike VMX, there are no (known) cases where hardware doesn't set either bit, and KVM should always set one or the other when emulating a GVA access.Signed-off-by Kevin Cheng <[email protected]>[sean: use plumbed in @access bits, massage changelog]Signed-off-by Sean Christopherson <[email protected]>[..]
Quoted 27 lines
arch/x86/kvm/svm/nested.c +12
-9@@ -39,19 +39,32 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, {struct vcpu_svm *svm =to_svm (vcpu);struct vmcb *vmcb = svm->vmcb; +u64 fault_stage; -if (vmcb->control.exit_code !=SVM_EXIT_NPF ) { -/* -* TODO: track the cause of the nested page fault, and -* correctly fill in the high bits of exit_info_1. -*/ - vmcb->control.exit_code =SVM_EXIT_NPF ; - vmcb->control.exit_info_1 = (1ULL <<32 ); - vmcb->control.exit_info_2 = fault->address; - } +/* +* For hardware NPF exits, the GUEST_FAULT_STAGE bits are only +* available in the hardware exit_info_1, since the guest_mmu +* walker doesn't know whether the faulting GPA was a page table +* page or final page from L2's perspective. +*/ +if (from_hardware) + fault_stage = vmcb->control.exit_info_1 & +PFERR_GUEST_FAULT_STAGE_MASK ; +else + fault_stage = fault->error_code &PFERR_GUEST_FAULT_STAGE_MASK ;
Quoted 15 lines
arch/x86/kvm/svm/nested.c static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, · line 66
Quoted 13 lines
arch/x86/kvm/svm/nested.c +11
-2- vmcb->control.exit_info_1 &= ~0xffffffffULL ; - vmcb->control.exit_info_1 |= fault->error_code; +/* +* All nested page faults should be annotated as occurring on the +* final translation *or* the page walk. Arbitrarily choose "final" +* if KVM is buggy and enumerated both or neither. +*/ +if (WARN_ON_ONCE (hweight64 (fault_stage) !=1 )) + fault_stage =PFERR_GUEST_FINAL_MASK ; + + vmcb->control.exit_code =SVM_EXIT_NPF ; + vmcb->control.exit_info_1 = fault_stage | + (fault->error_code & ~PFERR_GUEST_FAULT_STAGE_MASK );Do we need to do this in the common path?
What do you mean by "this"? Pulling flags from fault->error_code?
Quoted 2 lines
If from_hardware=true, can the fault injected by KVM have different flags from the one produced by hardware?
Flags, yes. fault_stage, no.
Quoted 2 lines
I guess the answer is yes, (e.g. if KVM is doing write-protection?). Might be worth a comment.
Or if L1 has modified its TDP PTEs in memory, but hasn't yet flushed TLBs. In that case, KVM's software walker can see the updated PTEs, while hardware may have seen something else.
Re: [PATCH v4 3/5] KVM: SVM: Fix nested NPF injection of PFERR_GUEST_{PAGE,FINAL}_MASK bits
Quoted 7 lines
Quoted 5 lines
arch/x86/kvm/svm/nested.c static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, · line 66
Quoted 3 lines
arch/x86/kvm/svm/nested.c +3
-0+ vmcb->control.exit_code =SVM_EXIT_NPF ; + vmcb->control.exit_info_1 = fault_stage | + (fault->error_code & ~PFERR_GUEST_FAULT_STAGE_MASK );Do we need to do this in the common path?
What do you mean by "this"? Pulling flags from
fault->error_code?
Yes, sorry if that wasn't clear.
Quoted 5 lines
Quoted 3 lines
If from_hardware=true, can the fault injected by KVM have different flags from the one produced by hardware?
Flags, yes.
fault_stage, no.
Right, I meant the flags.
Quoted 7 lines
Quoted 3 lines
I guess the answer is yes, (e.g. if KVM is doing write-protection?). Might be worth a comment.
Or if L1 has modified its TDP PTEs in memory, but hasn't yet flushed TLBs. In that case, KVM's software walker can see the updated PTEs, while hardware may have seen something else.
Makes sense. A comment would be helpful for laymans like myself.
Sean Christopherson
maintainerRe: [PATCH v4 3/5] KVM: SVM: Fix nested NPF injection of PFERR_GUEST_{PAGE,FINAL}_MASK bits
Quoted 19 lines · Yosry Ahmed
Quoted 7 lines
Quoted 5 lines
arch/x86/kvm/svm/nested.c static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu, · line 66
Quoted 3 lines
arch/x86/kvm/svm/nested.c +3
-0+ vmcb->control.exit_code =SVM_EXIT_NPF ; + vmcb->control.exit_info_1 = fault_stage | + (fault->error_code & ~PFERR_GUEST_FAULT_STAGE_MASK );Do we need to do this in the common path?
What do you mean by "this"? Pulling flags from
fault->error_code?Yes, sorry if that wasn't clear.
Quoted 5 lines
Quoted 3 lines
If from_hardware=true, can the fault injected by KVM have different flags from the one produced by hardware?
Flags, yes.
fault_stage, no.Right, I meant the flags.
Quoted 1 line
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
I guess the answer is yes, (e.g. if KVM is doing write-protection?). Might be worth a comment.
Or if L1 has modified its TDP PTEs in memory, but hasn't yet flushed TLBs. In that case, KVM's software walker can see the updated PTEs, while hardware may have seen something else.
Makes sense. A comment would be helpful for laymans like myself.
I elected to not add a comment for now, because I'm not 100% confident the nSVM code is correct, and so didn't want to stealth in a comment that wasn't correct either. It's certainly much better than it was, but especially with GMET in play, I need to stare more to convince myself it handles all the edge cases correctly.
Sean Christopherson
maintainerPATCH v4 4/5 KVM: VMX: Synthesize nested EPT violation GVA_IS_VALID/GVA_TRANSLATED bits
In reply to Sean ChristophersonFrom: Kevin Cheng <[email protected]>
When injecting an EPT Violation into L2 in response to a fault detected while emulating an L2 GVA access, synthesize the GVA_IS_VALID and GVA_TRANSLATED bits using information provided by the walker, instead of pulling the bits from vmcs02.EXIT_QUALIFICATION. The information in vmcs02.EXIT_QUALIFICATION is valid/correct if and only if the fault being injected into L1 is the direct result of an EPT Violation VM-Exit from L2.
E.g. if KVM is emulating an I/O instruction and the memory operand's translation through L1's EPT fails, using vmcs02.EXIT_QUALIFICATION is wrong as the semantics for EXIT_QUALIFICATION would be for an I/O exit, not an EPT Violation exit.
Opportunistically clean up the formatting for creating the mask of bits to pull from vmcs02.EXIT_QUALIFICATION.
--- arch/x86/kvm/mmu/paging_tmpl.h | 13 ++++++++++++- arch/x86/kvm/vmx/nested.c | 26 +++++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-)
arch/x86/kvm/mmu/paging_tmpl.h +12 -1
@@ -502,7 +502,8 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,* [2:0] - Derive from the access bits. The exit_qualification might be * out of date if it is serving an EPT misconfiguration. * [5:3] - Calculated by the page walk of the guest EPT page tables -* [7:11] - Derived from [7:11] of real exit_qualification +* [7:8] - Derived from "fault stage" access bits +* [9:11] - Derived from [9:11] of real exit_qualification * * The other bits are set to 0. */
@@ -516,6 +517,14 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,else walker->fault.exit_qualification |=EPT_VIOLATION_ACC_READ ; +/* +* KVM doesn't emulate features that access GPAs directly, e.g. +* Intel Processor Trace. Assume the GVA is always valid; when +* propagating faults from hardware, KVM will discard this info +* and use the EXIT_QUALIFICATION bits from the VMCS. +*/ + walker->fault.exit_qualification |=EPT_VIOLATION_GVA_IS_VALID ; +/* * Accesses to guest paging structures are either "reads" or * "read+write" accesses, so consider them the latter if write_fault
@@ -523,6 +532,8 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,*/ if (access &PFERR_GUEST_PAGE_MASK ) walker->fault.exit_qualification |=EPT_VIOLATION_ACC_READ ; +else + walker->fault.exit_qualification |=EPT_VIOLATION_GVA_TRANSLATED ;/* * Note, pte_access holds the raw RWX bits from the EPTE, not
arch/x86/kvm/vmx/nested.c +21 -5
@@ -445,13 +445,29 @@ static void nested_ept_inject_page_fault(struct kvm_vcpu *vcpu, exit_qualification =0 ; }else {u64 mask =EPT_VIOLATION_GVA_IS_VALID | -EPT_VIOLATION_GVA_TRANSLATED ; +EPT_VIOLATION_GVA_TRANSLATED ; +if (vmx->nested.msrs.ept_caps &VMX_EPT_ADVANCED_VMEXIT_INFO_BIT ) mask |=EPT_VIOLATION_GVA_USER | -EPT_VIOLATION_GVA_WRITABLE | -EPT_VIOLATION_GVA_NX ; - exit_qualification = fault->exit_qualification; - exit_qualification |=vmx_get_exit_qual (vcpu) & mask; +EPT_VIOLATION_GVA_WRITABLE | +EPT_VIOLATION_GVA_NX ; + + exit_qualification = fault->exit_qualification & ~mask; + +/* +* Use the EXIT_QUALIFICATION from the VMCS if and only +* if the hardware VM-Exit from L2 was an EPT Violation. +* If the fault is synthesized, then EXIT_QUALIFICATION +* is stale and/or holds entirely different data. And +* conversely, KVM _must_ rely on EXIT_QUALIFICATION if +* the fault came from hardware, because KVM only sees +* and walks the faulting GPA. +*/ +if (from_hardware) + exit_qualification |=vmx_get_exit_qual (vcpu) & mask; +else + exit_qualification |= fault->exit_qualification & mask; + vm_exit_reason =EXIT_REASON_EPT_VIOLATION ; }
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
Re: [PATCH v4 4/5] KVM: VMX: Synthesize nested EPT violation GVA_IS_VALID/GVA_TRANSLATED bits
Review static int FNAME(walk_addr_generic)(struct guest_walker *walker, · line 527
Quoted 12 lines
(quoted diff) +8
-0@@ -516,6 +517,14 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker, else walker->fault.exit_qualification |= EPT_VIOLATION_ACC_READ; + /* + * KVM doesn't emulate features that access GPAs directly, e.g. + * Intel Processor Trace. Assume the GVA is always valid; when + * propagating faults from hardware, KVM will discard this info + * and use the EXIT_QUALIFICATION bits from the VMCS. + */ + walker->fault.exit_qualification |= EPT_VIOLATION_GVA_IS_VALID; +
Sashiko flagged this internally:
"Since this code asserts to L1 that the GVA is valid by setting EPT_VIOLATION_GVA_IS_VALID, does it also need to populate the access rights bits (EPT_VIOLATION_GVA_USER, EPT_VIOLATION_GVA_WRITABLE, and EPT_VIOLATION_GVA_NX)?"
The Intel SDM states that if bit 8 is set, bits 9-11 support advanced VM Exit information. Would a change like the following be needed to populate bits 9-11 of the exit qualification?
arch/x86/kvm/mmu/paging_tmpl.h +0 -0
@@ -449,8 +449,24 @@ static int FNAME(walk_addr_generic)(struct
guest_walker *walker,
real_gpa = kvm_translate_gpa(vcpu, mmu, gfn_to_gpa(gfn),
access | PFERR_GUEST_FINAL_MASK, &walker->fault);
- if (real_gpa == INVALID_GPA)
+ if (real_gpa == INVALID_GPA) {
+#if PTTYPE != PTTYPE_EPT
+ /*
+ * Architecturally, bits 11:9 are only valid if bit 8 + * (GVA_TRANSLATED) is set. If bit 8 is 0, bits 11:9 are + * undefined and must be 0. + */
+ if (walker->fault.exit_qualification &EPT_VIOLATION_GVA_TRANSLATED) {
+ if (walker->pte_access & ACC_USER_MASK)
+ walker->fault.exit_qualification |=EPT_VIOLATION_GVA_USER;
+ if (walker->pte_access & ACC_WRITE_MASK)
+ walker->fault.exit_qualification |=EPT_VIOLATION_GVA_WRITABLE;
+ if (!(walker->pte_access & ACC_EXEC_MASK))
+ walker->fault.exit_qualification |=EPT_VIOLATION_GVA_NX;
+ }
+#endif
return 0;
+ }
Re: [PATCH v4 4/5] KVM: VMX: Synthesize nested EPT violation GVA_IS_VALID/GVA_TRANSLATED bits
In reply to Sean ChristophersonQuoted 14 lines · Sean Christopherson
From: Kevin Cheng <[email protected]>
When injecting an EPT Violation into L2 in response to a fault detected while emulating an L2 GVA access, synthesize the
GVA_IS_VALIDandGVA_TRANSLATEDbits using information provided by the walker, instead of pulling the bits from vmcs02.EXIT_QUALIFICATION. The information in vmcs02.EXIT_QUALIFICATION is valid/correct if and only if the fault being injected into L1 is the direct result of an EPT Violation VM-Exit from L2.E.g. if KVM is emulating an I/O instruction and the memory operand's translation through L1's EPT fails, using vmcs02.EXIT_QUALIFICATION is wrong as the semantics for
EXIT_QUALIFICATIONwould be for an I/O exit, not an EPT Violation exit.
Quoted 6 lines
Opportunistically clean up the formatting for creating the mask of bits to pull from vmcs02.EXIT_QUALIFICATION.
Signed-off-by Kevin Cheng <[email protected]>[sean: use plumbed in @access bits, massage changelog]Signed-off-by Sean Christopherson <[email protected]>
I think this wants a Fixes: a9466078687f and backports to stable? Broke my testing environment on a 6.12-based distro.
Sean Christopherson
maintainerPATCH v4 5/5 KVM: selftests: Add nested page fault injection test
In reply to Sean ChristophersonFrom: Kevin Cheng <[email protected]>
Add a test that exercises nested page fault injection during L2 execution. L2 executes I/O string instructions (OUTSB/INSB) that access memory restricted in L1's nested page tables (NPT/EPT), triggering a nested page fault that L0 must inject to L1.
The test supports both AMD SVM (NPF) and Intel VMX (EPT violation) and verifies that:
- The exit reason is an NPF/EPT violation
- The access type and permission bits are correct
- The faulting GPA is correct
Three test cases are implemented:
- Unmap the final data page (final translation fault, OUTSB read)
- Unmap a PT page (page walk fault, OUTSB read)
- Write-protect the final data page (protection violation, INSB write)
- Write-protect a PT page (protection violation on A/D update, OUTSB read)
--- tools/testing/selftests/kvm/Makefile.kvm | 1 + .../selftests/kvm/include/x86/processor.h | 9 + .../selftests/kvm/x86/nested_tdp_fault_test.c | 313 ++++++++++++++++++ 3 files changed, 323 insertions(+) create mode 100644 tools/testing/selftests/kvm/x86/nested_tdp_fault_test.c
tools/testing/selftests/kvm/Makefile.kvm +1 -0
@@ -97,6 +97,7 @@ TEST_GEN_PROGS_x86 += x86/nested_emulation_test TEST_GEN_PROGS_x86 += x86/nested_exceptions_test TEST_GEN_PROGS_x86 += x86/nested_invalid_cr3_test TEST_GEN_PROGS_x86 += x86/nested_set_state_test +TEST_GEN_PROGS_x86 += x86/nested_tdp_fault_test TEST_GEN_PROGS_x86 += x86/nested_tsc_adjust_test TEST_GEN_PROGS_x86 += x86/nested_tsc_scaling_test TEST_GEN_PROGS_x86 += x86/nested_vmsave_vmload_test
tools/testing/selftests/kvm/include/x86/processor.h +9 -0
@@ -1573,6 +1573,15 @@ u64 *tdp_get_pte(struct kvm_vm *vm, u64 l2_gpa);#define PFERR_GUEST_PAGE_MASK BIT_ULL(PFERR_GUEST_PAGE_BIT)#define PFERR_IMPLICIT_ACCESS BIT_ULL(PFERR_IMPLICIT_ACCESS_BIT) +#define EPT_VIOLATION_ACC_READ BIT(0) +#define EPT_VIOLATION_ACC_WRITE BIT(1) +#define EPT_VIOLATION_ACC_INSTR BIT(2) +#define EPT_VIOLATION_PROT_READ BIT(3) +#define EPT_VIOLATION_PROT_WRITE BIT(4) +#define EPT_VIOLATION_PROT_EXEC BIT(5) +#define EPT_VIOLATION_GVA_IS_VALID BIT(7) +#define EPT_VIOLATION_GVA_TRANSLATED BIT(8) +bool sys_clocksource_is_based_on_tsc (void );#endif /* SELFTEST_KVM_PROCESSOR_H */
tools/testing/selftests/kvm/x86/nested_tdp_fault_test.c new file +313 -0
313 lines not on this page · raw message
Signature · 1 line
2.54.0.794.g4f17f83d09-goog
Quoted 6 lines · Sean Christopherson
Kevin's series to fix how KVM populates error information when injecting nested page faults (NPF on SVM, EPT violations on VMX) to L1 during instruction emulation.
See v3 for the full cover letter.
Quoted 8 lines
v4:
- Pass @from_hardware directly instead of stuff a flag inx86_exception.
- Use the bits in @access (thanks to MBEC+GMET) to get the fault stage.
- Check the entire PFEC/EXIT_QUAL in the selftest.
- Use hardware _or_ KVM information, never merge the two.
- Name the selftestnested_tdp_fault_test.[...]
Applied to kvm-x86 misc, thanks!
[1/5] KVM: x86: Widen x86_exception's error_code to 64 bits
https://github.com/kvm-x86/linux/commit/bb24edbb673f [2/5] KVM: x86: Tell ->inject_page_fault() whether or a fault came from hardware https://github.com/kvm-x86/linux/commit/fe0b872d7500 [3/5] KVM: SVM: Fix nested NPF injection of PFERR_GUEST_{PAGE,FINAL}_MASK bits https://github.com/kvm-x86/linux/commit/297c2fe249db [4/5] KVM: VMX: Synthesize nested EPT violation GVA_IS_VALID/GVA_TRANSLATED bits https://github.com/kvm-x86/linux/commit/96b067b59ad9 [5/5] KVM: selftests: Add nested page fault injection test https://github.com/kvm-x86/linux/commit/0de1020f7bbb