Skip to content

Commit f5e7f00

Browse files
sean-jcbonzini
authored andcommitted
KVM: x86/mmu: Account pf_{fixed,emulate,spurious} in callers of "do page fault"
Move the accounting of the result of kvm_mmu_do_page_fault() to its callers, as only pf_fixed is common to guest page faults and async #PFs, and upcoming support KVM_PRE_FAULT_MEMORY won't bump _any_ stats. Signed-off-by: Sean Christopherson <[email protected]> Signed-off-by: Paolo Bonzini <[email protected]>
1 parent 5186ec2 commit f5e7f00

File tree

2 files changed

+18
-14
lines changed

2 files changed

+18
-14
lines changed

arch/x86/kvm/mmu/mmu.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4291,7 +4291,16 @@ void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu, struct kvm_async_pf *work)
42914291
work->arch.cr3 != kvm_mmu_get_guest_pgd(vcpu, vcpu->arch.mmu))
42924292
return;
42934293

4294-
kvm_mmu_do_page_fault(vcpu, work->cr2_or_gpa, work->arch.error_code, true, NULL);
4294+
r = kvm_mmu_do_page_fault(vcpu, work->cr2_or_gpa, work->arch.error_code,
4295+
true, NULL);
4296+
4297+
/*
4298+
* Account fixed page faults, otherwise they'll never be counted, but
4299+
* ignore stats for all other return times. Page-ready "faults" aren't
4300+
* truly spurious and never trigger emulation
4301+
*/
4302+
if (r == RET_PF_FIXED)
4303+
vcpu->stat.pf_fixed++;
42954304
}
42964305

42974306
static inline u8 kvm_max_level_for_order(int order)
@@ -5935,6 +5944,14 @@ int noinline kvm_mmu_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa, u64 err
59355944

59365945
if (r < 0)
59375946
return r;
5947+
5948+
if (r == RET_PF_FIXED)
5949+
vcpu->stat.pf_fixed++;
5950+
else if (r == RET_PF_EMULATE)
5951+
vcpu->stat.pf_emulate++;
5952+
else if (r == RET_PF_SPURIOUS)
5953+
vcpu->stat.pf_spurious++;
5954+
59385955
if (r != RET_PF_EMULATE)
59395956
return 1;
59405957

arch/x86/kvm/mmu/mmu_internal.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,6 @@ static inline int kvm_mmu_do_page_fault(struct kvm_vcpu *vcpu, gpa_t cr2_or_gpa,
337337
if (fault.write_fault_to_shadow_pgtable && emulation_type)
338338
*emulation_type |= EMULTYPE_WRITE_PF_TO_SP;
339339

340-
/*
341-
* Similar to above, prefetch faults aren't truly spurious, and the
342-
* async #PF path doesn't do emulation. Do count faults that are fixed
343-
* by the async #PF handler though, otherwise they'll never be counted.
344-
*/
345-
if (r == RET_PF_FIXED)
346-
vcpu->stat.pf_fixed++;
347-
else if (prefetch)
348-
;
349-
else if (r == RET_PF_EMULATE)
350-
vcpu->stat.pf_emulate++;
351-
else if (r == RET_PF_SPURIOUS)
352-
vcpu->stat.pf_spurious++;
353340
return r;
354341
}
355342

0 commit comments

Comments
 (0)