diff options
author | Xiao Guangrong <xiaoguangrong@cn.fujitsu.com> | 2011-03-09 02:43:00 -0500 |
---|---|---|
committer | Marcelo Tosatti <mtosatti@redhat.com> | 2011-03-17 12:08:34 -0400 |
commit | 5d163b1c9d6e5562dcdfd6cd471f237f1502bb35 (patch) | |
tree | 84a2a5de608b00f22e3b79c86cef700019f6e9d9 /arch/x86/kvm/mmu.c | |
parent | 40dcaa9f69fa303ddcb5ea65baf4efefed3aec4b (diff) |
KVM: MMU: introduce a common function to get no-dirty-logged slot
Cleanup the code of pte_prefetch_gfn_to_memslot and mapping_level_dirty_bitmap
Signed-off-by: Xiao Guangrong <xiaoguangrong@cn.fujitsu.com>
Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/mmu.c')
-rw-r--r-- | arch/x86/kvm/mmu.c | 37 |
1 files changed, 17 insertions, 20 deletions
diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 88d36890f420..83171fdd38a7 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c | |||
@@ -549,13 +549,23 @@ static int host_mapping_level(struct kvm *kvm, gfn_t gfn) | |||
549 | return ret; | 549 | return ret; |
550 | } | 550 | } |
551 | 551 | ||
552 | static bool mapping_level_dirty_bitmap(struct kvm_vcpu *vcpu, gfn_t large_gfn) | 552 | static struct kvm_memory_slot * |
553 | gfn_to_memslot_dirty_bitmap(struct kvm_vcpu *vcpu, gfn_t gfn, | ||
554 | bool no_dirty_log) | ||
553 | { | 555 | { |
554 | struct kvm_memory_slot *slot; | 556 | struct kvm_memory_slot *slot; |
555 | slot = gfn_to_memslot(vcpu->kvm, large_gfn); | 557 | |
556 | if (slot && slot->dirty_bitmap) | 558 | slot = gfn_to_memslot(vcpu->kvm, gfn); |
557 | return true; | 559 | if (!slot || slot->flags & KVM_MEMSLOT_INVALID || |
558 | return false; | 560 | (no_dirty_log && slot->dirty_bitmap)) |
561 | slot = NULL; | ||
562 | |||
563 | return slot; | ||
564 | } | ||
565 | |||
566 | static bool mapping_level_dirty_bitmap(struct kvm_vcpu *vcpu, gfn_t large_gfn) | ||
567 | { | ||
568 | return gfn_to_memslot_dirty_bitmap(vcpu, large_gfn, true); | ||
559 | } | 569 | } |
560 | 570 | ||
561 | static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn) | 571 | static int mapping_level(struct kvm_vcpu *vcpu, gfn_t large_gfn) |
@@ -2145,26 +2155,13 @@ static void nonpaging_new_cr3(struct kvm_vcpu *vcpu) | |||
2145 | { | 2155 | { |
2146 | } | 2156 | } |
2147 | 2157 | ||
2148 | static struct kvm_memory_slot * | ||
2149 | pte_prefetch_gfn_to_memslot(struct kvm_vcpu *vcpu, gfn_t gfn, bool no_dirty_log) | ||
2150 | { | ||
2151 | struct kvm_memory_slot *slot; | ||
2152 | |||
2153 | slot = gfn_to_memslot(vcpu->kvm, gfn); | ||
2154 | if (!slot || slot->flags & KVM_MEMSLOT_INVALID || | ||
2155 | (no_dirty_log && slot->dirty_bitmap)) | ||
2156 | slot = NULL; | ||
2157 | |||
2158 | return slot; | ||
2159 | } | ||
2160 | |||
2161 | static pfn_t pte_prefetch_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, | 2158 | static pfn_t pte_prefetch_gfn_to_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, |
2162 | bool no_dirty_log) | 2159 | bool no_dirty_log) |
2163 | { | 2160 | { |
2164 | struct kvm_memory_slot *slot; | 2161 | struct kvm_memory_slot *slot; |
2165 | unsigned long hva; | 2162 | unsigned long hva; |
2166 | 2163 | ||
2167 | slot = pte_prefetch_gfn_to_memslot(vcpu, gfn, no_dirty_log); | 2164 | slot = gfn_to_memslot_dirty_bitmap(vcpu, gfn, no_dirty_log); |
2168 | if (!slot) { | 2165 | if (!slot) { |
2169 | get_page(bad_page); | 2166 | get_page(bad_page); |
2170 | return page_to_pfn(bad_page); | 2167 | return page_to_pfn(bad_page); |
@@ -2185,7 +2182,7 @@ static int direct_pte_prefetch_many(struct kvm_vcpu *vcpu, | |||
2185 | gfn_t gfn; | 2182 | gfn_t gfn; |
2186 | 2183 | ||
2187 | gfn = kvm_mmu_page_get_gfn(sp, start - sp->spt); | 2184 | gfn = kvm_mmu_page_get_gfn(sp, start - sp->spt); |
2188 | if (!pte_prefetch_gfn_to_memslot(vcpu, gfn, access & ACC_WRITE_MASK)) | 2185 | if (!gfn_to_memslot_dirty_bitmap(vcpu, gfn, access & ACC_WRITE_MASK)) |
2189 | return -1; | 2186 | return -1; |
2190 | 2187 | ||
2191 | ret = gfn_to_page_many_atomic(vcpu->kvm, gfn, pages, end - start); | 2188 | ret = gfn_to_page_many_atomic(vcpu->kvm, gfn, pages, end - start); |