Skip to content

Commit 31a6cd7

Browse files
committed
Merge tag 'kvm-x86-vmx-6.10' of https://github.com/kvm-x86/linux into HEAD
KVM VMX changes for 6.10: - Clear vmcs.EXIT_QUALIFICATION when synthesizing an EPT Misconfig VM-Exit to L1, as per the SDM. - Move kvm_vcpu_arch's exit_qualification into x86_exception, as the field is used only when synthesizing nested EPT violation, i.e. it's not the vCPU's "real" exit_qualification, which is tracked elsewhere. - Add a sanity check to assert that EPT Violations are the only sources of nested PML Full VM-Exits.
2 parents 56f4070 + 23ffe4b commit 31a6cd7

File tree

5 files changed

+34
-16
lines changed

5 files changed

+34
-16
lines changed

arch/x86/include/asm/kvm_host.h

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

998998
u64 msr_kvm_poll_control;
999999

1000-
/* set at EPT violation at this point */
1001-
unsigned long exit_qualification;
1002-
10031000
/* pv related host specific info */
10041001
struct {
10051002
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: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,40 @@ 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+
* It should be impossible to trigger a nested PML Full VM-Exit
421+
* for anything other than an EPT Violation from L2. KVM *can*
422+
* trigger nEPT page fault injection in response to an EPT
423+
* Misconfig, e.g. if the MMIO SPTE was stale and L1's EPT
424+
* tables also changed, but KVM should not treat EPT Misconfig
425+
* VM-Exits as writes.
426+
*/
427+
WARN_ON_ONCE(vmx->exit_reason.basic != EXIT_REASON_EPT_VIOLATION);
428+
429+
/*
430+
* PML Full and EPT Violation VM-Exits both use bit 12 to report
431+
* "NMI unblocking due to IRET", i.e. the bit can be propagated
432+
* as-is from the original EXIT_QUALIFICATION.
433+
*/
434+
exit_qualification = vmx_get_exit_qual(vcpu) & INTR_INFO_UNBLOCK_NMI;
419435
} else {
420-
if (fault->error_code & PFERR_RSVD_MASK)
436+
if (fault->error_code & PFERR_RSVD_MASK) {
421437
vm_exit_reason = EXIT_REASON_EPT_MISCONFIG;
422-
else
438+
exit_qualification = 0;
439+
} else {
440+
exit_qualification = fault->exit_qualification;
441+
exit_qualification |= vmx_get_exit_qual(vcpu) &
442+
(EPT_VIOLATION_GVA_IS_VALID |
443+
EPT_VIOLATION_GVA_TRANSLATED);
423444
vm_exit_reason = EXIT_REASON_EPT_VIOLATION;
445+
}
424446

425447
/*
426448
* Although the caller (kvm_inject_emulated_page_fault) would

arch/x86/kvm/vmx/vmx.c

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

5786-
vcpu->arch.exit_qualification = exit_qualification;
5787-
57885786
/*
57895787
* Check that the GPA doesn't exceed physical memory limits, as that is
57905788
* a guest page fault. We have to emulate the instruction here, because

0 commit comments

Comments
 (0)