KVM: Make kvm_mmu_slot_remove_write_access() take mmu_lock by itself
authorTakuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
Tue, 8 Jan 2013 10:46:48 +0000 (19:46 +0900)
committerGleb Natapov <gleb@redhat.com>
Mon, 14 Jan 2013 09:14:17 +0000 (11:14 +0200)
Better to place mmu_lock handling and TLB flushing code together since
this is a self-contained function.

Reviewed-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
Signed-off-by: Gleb Natapov <gleb@redhat.com>
arch/x86/kvm/mmu.c
arch/x86/kvm/x86.c

index f5572804f5948fac4753b5e0ec76b882b2cd1b90..e5dcae31cebc85b90adc1fc40b6727f8b0694f40 100644 (file)
@@ -4173,6 +4173,8 @@ void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot)
        memslot = id_to_memslot(kvm->memslots, slot);
        last_gfn = memslot->base_gfn + memslot->npages - 1;
 
+       spin_lock(&kvm->mmu_lock);
+
        for (i = PT_PAGE_TABLE_LEVEL;
             i < PT_PAGE_TABLE_LEVEL + KVM_NR_PAGE_SIZES; ++i) {
                unsigned long *rmapp;
@@ -4188,6 +4190,7 @@ void kvm_mmu_slot_remove_write_access(struct kvm *kvm, int slot)
        }
 
        kvm_flush_remote_tlbs(kvm);
+       spin_unlock(&kvm->mmu_lock);
 }
 
 void kvm_mmu_zap_all(struct kvm *kvm)
index 080bbdcbf2eec3877eb123e4bbd7fb4b5a32415f..54832280cdef34d5993ff0d4e04e79e2738725ea 100644 (file)
@@ -6899,11 +6899,8 @@ void kvm_arch_commit_memory_region(struct kvm *kvm,
         * Existing largepage mappings are destroyed here and new ones will
         * not be created until the end of the logging.
         */
-       if (npages && (mem->flags & KVM_MEM_LOG_DIRTY_PAGES)) {
-               spin_lock(&kvm->mmu_lock);
+       if (npages && (mem->flags & KVM_MEM_LOG_DIRTY_PAGES))
                kvm_mmu_slot_remove_write_access(kvm, mem->slot);
-               spin_unlock(&kvm->mmu_lock);
-       }
        /*
         * If memory slot is created, or moved, we need to clear all
         * mmio sptes.