@@ -265,6 +265,8 @@ enum x86_intercept_stage;
PFERR_WRITE_MASK | \
PFERR_PRESENT_MASK)
+#define PFERR_GUEST_MASK (PFERR_GUEST_FINAL_MASK | PFERR_GUEST_PAGE_MASK)
+
/* apic attention bits */
#define KVM_APIC_CHECK_VAPIC 0
/*
@@ -24,8 +24,9 @@ struct x86_exception {
bool error_code_valid;
u16 error_code;
bool nested_page_fault;
- u64 address; /* cr2 or nested page fault gpa */
u8 async_page_fault;
+ u64 nested_pfec; /* nested page fault error code */
+ u64 address; /* cr2 or nested page fault gpa */
};
/*
@@ -383,7 +383,8 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
* by the MOV to CR instruction are treated as reads and do not cause the
* processor to set the dirty flag in any EPT paging-structure entry.
*/
- nested_access = (have_ad ? PFERR_WRITE_MASK : 0) | PFERR_USER_MASK;
+ nested_access = (have_ad ? PFERR_WRITE_MASK : 0) | PFERR_USER_MASK |
+ PFERR_GUEST_PAGE_MASK;
pte_access = ~0;
++walker->level;
@@ -466,7 +467,8 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
if (PTTYPE == 32 && walker->level > PG_LEVEL_4K && is_cpuid_PSE36())
gfn += pse36_gfn_delta(pte);
- real_gpa = kvm_translate_gpa(vcpu, mmu, gfn_to_gpa(gfn), access, &walker->fault);
+ real_gpa = kvm_translate_gpa(vcpu, mmu, gfn_to_gpa(gfn),
+ access | PFERR_GUEST_FINAL_MASK, &walker->fault);
if (real_gpa == UNMAPPED_GVA)
return 0;
@@ -534,6 +536,8 @@ static int FNAME(walk_addr_generic)(struct guest_walker *walker,
walker->fault.address = addr;
walker->fault.nested_page_fault = mmu != vcpu->arch.walk_mmu;
walker->fault.async_page_fault = false;
+ if (walker->fault.nested_page_fault)
+ walker->fault.nested_pfec = errcode | (access & PFERR_GUEST_MASK);
trace_kvm_mmu_walker_error(walker->fault.error_code);
return 0;
@@ -38,18 +38,12 @@ static void nested_svm_inject_npf_exit(struct kvm_vcpu *vcpu,
struct vcpu_svm *svm = to_svm(vcpu);
if (svm->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.
- */
svm->vmcb->control.exit_code = SVM_EXIT_NPF;
svm->vmcb->control.exit_code_hi = 0;
- svm->vmcb->control.exit_info_1 = (1ULL << 32);
- svm->vmcb->control.exit_info_2 = fault->address;
}
- svm->vmcb->control.exit_info_1 &= ~0xffffffffULL;
- svm->vmcb->control.exit_info_1 |= fault->error_code;
+ svm->vmcb->control.exit_info_1 = fault->nested_pfec;
+ svm->vmcb->control.exit_info_2 = fault->address;
nested_svm_vmexit(svm);
}
@@ -372,6 +372,17 @@ static void nested_ept_inject_page_fault(struct kvm_vcpu *vcpu,
u32 vm_exit_reason;
unsigned long exit_qualification = vcpu->arch.exit_qualification;
+ exit_qualification &= ~(EPT_VIOLATION_ACC_READ | EPT_VIOLATION_ACC_WRITE |
+ EPT_VIOLATION_ACC_INSTR | EPT_VIOLATION_GVA_TRANSLATED);
+ exit_qualification |= fault->nested_pfec & PFERR_USER_MASK ?
+ EPT_VIOLATION_ACC_READ : 0;
+ exit_qualification |= fault->nested_pfec & PFERR_WRITE_MASK ?
+ EPT_VIOLATION_ACC_WRITE : 0;
+ exit_qualification |= fault->nested_pfec & PFERR_FETCH_MASK ?
+ EPT_VIOLATION_ACC_INSTR : 0;
+ exit_qualification |= fault->nested_pfec & PFERR_GUEST_FINAL_MASK ?
+ EPT_VIOLATION_GVA_TRANSLATED : 0;
+
if (vmx->nested.pml_full) {
vm_exit_reason = EXIT_REASON_PML_FULL;
vmx->nested.pml_full = false;