Skip to content

Commit a946607

Browse files
committed
KVM: x86: Move nEPT exit_qualification field from kvm_vcpu_arch to x86_exception
Move the exit_qualification field that is used to track information about in-flight nEPT violations from "struct kvm_vcpu_arch" to "x86_exception", i.e. associate the information with the actual nEPT violation instead of the vCPU. To handle bits that are pulled from vmcs.EXIT_QUALIFICATION, i.e. that are propagated from the "original" EPT violation VM-Exit, simply grab them from the VMCS on-demand when injecting a nEPT Violation or a PML Full VM-exit. Aside from being ugly, having an exit_qualification field in kvm_vcpu_arch is outright dangerous, e.g. see commit d7f0a00 ("KVM: VMX: Report up-to-date exit qualification to userspace"). Opportunstically add a comment to call out that PML Full and EPT Violation VM-Exits use the same bit to report NMI blocking information. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Sean Christopherson <[email protected]>
1 parent 0c47651 commit a946607

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

arch/x86/include/asm/kvm_host.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -993,9 +993,6 @@ struct kvm_vcpu_arch {
993993

994994
u64 msr_kvm_poll_control;
995995

996-
/* set at EPT violation at this point */
997-
unsigned long exit_qualification;
998-
999996
/* pv related host specific info */
1000997
struct {
1001998
bool pv_unhalted;

arch/x86/kvm/kvm_emulate.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ struct x86_exception {
2626
bool nested_page_fault;
2727
u64 address; /* cr2 or nested page fault gpa */
2828
u8 async_page_fault;
29+
unsigned long exit_qualification;
2930
};
3031

3132
/*

arch/x86/kvm/mmu/paging_tmpl.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -497,21 +497,21 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
497497
* The other bits are set to 0.
498498
*/
499499
if (!(errcode & PFERR_RSVD_MASK)) {
500-
vcpu->arch.exit_qualification &= (EPT_VIOLATION_GVA_IS_VALID |
501-
EPT_VIOLATION_GVA_TRANSLATED);
500+
walker->fault.exit_qualification = 0;
501+
502502
if (write_fault)
503-
vcpu->arch.exit_qualification |= EPT_VIOLATION_ACC_WRITE;
503+
walker->fault.exit_qualification |= EPT_VIOLATION_ACC_WRITE;
504504
if (user_fault)
505-
vcpu->arch.exit_qualification |= EPT_VIOLATION_ACC_READ;
505+
walker->fault.exit_qualification |= EPT_VIOLATION_ACC_READ;
506506
if (fetch_fault)
507-
vcpu->arch.exit_qualification |= EPT_VIOLATION_ACC_INSTR;
507+
walker->fault.exit_qualification |= EPT_VIOLATION_ACC_INSTR;
508508

509509
/*
510510
* Note, pte_access holds the raw RWX bits from the EPTE, not
511511
* ACC_*_MASK flags!
512512
*/
513-
vcpu->arch.exit_qualification |= (pte_access & VMX_EPT_RWX_MASK) <<
514-
EPT_VIOLATION_RWX_SHIFT;
513+
walker->fault.exit_qualification |= (pte_access & VMX_EPT_RWX_MASK) <<
514+
EPT_VIOLATION_RWX_SHIFT;
515515
}
516516
#endif
517517
walker->fault.address = addr;

arch/x86/kvm/vmx/nested.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,28 @@ static void nested_ept_inject_page_fault(struct kvm_vcpu *vcpu,
409409
{
410410
struct vmcs12 *vmcs12 = get_vmcs12(vcpu);
411411
struct vcpu_vmx *vmx = to_vmx(vcpu);
412+
unsigned long exit_qualification;
412413
u32 vm_exit_reason;
413-
unsigned long exit_qualification = vcpu->arch.exit_qualification;
414414

415415
if (vmx->nested.pml_full) {
416416
vm_exit_reason = EXIT_REASON_PML_FULL;
417417
vmx->nested.pml_full = false;
418-
exit_qualification &= INTR_INFO_UNBLOCK_NMI;
418+
419+
/*
420+
* PML Full and EPT Violation VM-Exits both use bit 12 to report
421+
* "NMI unblocking due to IRET", i.e. the bit can be propagated
422+
* as-is from the original EXIT_QUALIFICATION.
423+
*/
424+
exit_qualification = vmx_get_exit_qual(vcpu) & INTR_INFO_UNBLOCK_NMI;
419425
} else {
420426
if (fault->error_code & PFERR_RSVD_MASK) {
421427
vm_exit_reason = EXIT_REASON_EPT_MISCONFIG;
422428
exit_qualification = 0;
423429
} else {
430+
exit_qualification = fault->exit_qualification;
431+
exit_qualification |= vmx_get_exit_qual(vcpu) &
432+
(EPT_VIOLATION_GVA_IS_VALID |
433+
EPT_VIOLATION_GVA_TRANSLATED);
424434
vm_exit_reason = EXIT_REASON_EPT_VIOLATION;
425435
}
426436

arch/x86/kvm/vmx/vmx.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5768,8 +5768,6 @@ static int handle_ept_violation(struct kvm_vcpu *vcpu)
57685768
error_code |= (exit_qualification & EPT_VIOLATION_GVA_TRANSLATED) != 0 ?
57695769
PFERR_GUEST_FINAL_MASK : PFERR_GUEST_PAGE_MASK;
57705770

5771-
vcpu->arch.exit_qualification = exit_qualification;
5772-
57735771
/*
57745772
* Check that the GPA doesn't exceed physical memory limits, as that is
57755773
* a guest page fault. We have to emulate the instruction here, because

0 commit comments

Comments
 (0)