KVM: set_memory_region: Don't check for overlaps unless we create or move a slot
authorTakuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
Fri, 11 Jan 2013 09:26:55 +0000 (18:26 +0900)
committerGleb Natapov <gleb@redhat.com>
Thu, 17 Jan 2013 12:27:50 +0000 (14:27 +0200)
Don't need the check for deleting an existing slot or just modifiying
the flags.

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>
virt/kvm/kvm_main.c

index 28eb160fd4870eacad52f0d901721d22e011a90c..fca64879f9672a4e262e6d4d19282d625f23667b 100644 (file)
@@ -782,14 +782,16 @@ int __kvm_set_memory_region(struct kvm *kvm,
        if (!npages && !old.npages)
                goto out;
 
-       /* Check for overlaps */
-       r = -EEXIST;
-       kvm_for_each_memslot(slot, kvm->memslots) {
-               if (slot->id >= KVM_USER_MEM_SLOTS || slot == memslot)
-                       continue;
-               if (!((base_gfn + npages <= slot->base_gfn) ||
-                     (base_gfn >= slot->base_gfn + slot->npages)))
-                       goto out;
+       if ((npages && !old.npages) || (base_gfn != old.base_gfn)) {
+               /* Check for overlaps */
+               r = -EEXIST;
+               kvm_for_each_memslot(slot, kvm->memslots) {
+                       if (slot->id >= KVM_USER_MEM_SLOTS || slot == memslot)
+                               continue;
+                       if (!((base_gfn + npages <= slot->base_gfn) ||
+                             (base_gfn >= slot->base_gfn + slot->npages)))
+                               goto out;
+               }
        }
 
        /* Free page dirty bitmap if unneeded */