Commit 8c85ac1c authored by Takuya Yoshikawa's avatar Takuya Yoshikawa Committed by Paolo Bonzini

KVM: x86: MMU: Initialize force_pt_level before calling mapping_level()

Commit fd136902 ("KVM: x86: MMU: Move mapping_level_dirty_bitmap()
call in mapping_level()") forgot to initialize force_pt_level to false
in FNAME(page_fault)() before calling mapping_level() like
nonpaging_map() does.  This can sometimes result in forcing page table
level mapping unnecessarily.

Fix this and move the first *force_pt_level check in mapping_level()
before kvm_vcpu_gfn_to_memslot() call to make it a bit clearer that
the variable must be initialized before mapping_level() gets called.

This change can also avoid calling kvm_vcpu_gfn_to_memslot() when
!check_hugepage_cache_consistency() check in tdp_page_fault() forces
page table level mapping.
Signed-off-by: default avatarTakuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 5690891b
...@@ -886,9 +886,10 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn, ...@@ -886,9 +886,10 @@ static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn,
int host_level, level, max_level; int host_level, level, max_level;
struct kvm_memory_slot *slot; struct kvm_memory_slot *slot;
slot = kvm_vcpu_gfn_to_memslot(vcpu, large_gfn); if (unlikely(*force_pt_level))
return PT_PAGE_TABLE_LEVEL;
if (likely(!*force_pt_level)) slot = kvm_vcpu_gfn_to_memslot(vcpu, large_gfn);
*force_pt_level = !memslot_valid_for_gpte(slot, true); *force_pt_level = !memslot_valid_for_gpte(slot, true);
if (unlikely(*force_pt_level)) if (unlikely(*force_pt_level))
return PT_PAGE_TABLE_LEVEL; return PT_PAGE_TABLE_LEVEL;
......
...@@ -698,7 +698,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, u32 error_code, ...@@ -698,7 +698,7 @@ static int FNAME(page_fault)(struct kvm_vcpu *vcpu, gva_t addr, u32 error_code,
int r; int r;
pfn_t pfn; pfn_t pfn;
int level = PT_PAGE_TABLE_LEVEL; int level = PT_PAGE_TABLE_LEVEL;
bool force_pt_level; bool force_pt_level = false;
unsigned long mmu_seq; unsigned long mmu_seq;
bool map_writable, is_self_change_mapping; bool map_writable, is_self_change_mapping;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment