KVM: set_memory_region: Refactor commit_memory_region()
authorTakuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
Wed, 27 Feb 2013 10:45:25 +0000 (19:45 +0900)
committerMarcelo Tosatti <mtosatti@redhat.com>
Mon, 4 Mar 2013 23:21:08 +0000 (20:21 -0300)
This patch makes the parameter old a const pointer to the old memory
slot and adds a new parameter named change to know the change being
requested: the former is for removing extra copying and the latter is
for cleaning up the code.

Signed-off-by: Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
arch/arm/kvm/arm.c
arch/ia64/kvm/kvm-ia64.c
arch/powerpc/include/asm/kvm_ppc.h
arch/powerpc/kvm/book3s_hv.c
arch/powerpc/kvm/book3s_pr.c
arch/powerpc/kvm/booke.c
arch/powerpc/kvm/powerpc.c
arch/s390/kvm/kvm-s390.c
arch/x86/kvm/x86.c
include/linux/kvm_host.h
virt/kvm/kvm_main.c

index 96ebab7a19594c93169fa81ae6f6a1d527c3a11b..b32dc446e8024f1a4e5a17bec2205975d8a89bd2 100644 (file)
@@ -238,7 +238,8 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
 
 void kvm_arch_commit_memory_region(struct kvm *kvm,
                                   struct kvm_userspace_memory_region *mem,
-                                  struct kvm_memory_slot old)
+                                  const struct kvm_memory_slot *old,
+                                  enum kvm_mr_change change)
 {
 }
 
index 5c2b07e8c3d63da31a61c4a65fe713a01d28998e..7a54455dde39bc1f9493ddced8103714a7374658 100644 (file)
@@ -1591,7 +1591,8 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
 
 void kvm_arch_commit_memory_region(struct kvm *kvm,
                struct kvm_userspace_memory_region *mem,
-               struct kvm_memory_slot old)
+               const struct kvm_memory_slot *old,
+               enum kvm_mr_change change)
 {
        return;
 }
index 44a657adf41606c3219a0577ac78952ee6b9c64a..44fa9ad1d62c82d911b0cba53a5d0ab4dc5ebd06 100644 (file)
@@ -152,7 +152,7 @@ extern int kvmppc_core_prepare_memory_region(struct kvm *kvm,
                                struct kvm_userspace_memory_region *mem);
 extern void kvmppc_core_commit_memory_region(struct kvm *kvm,
                                struct kvm_userspace_memory_region *mem,
-                               struct kvm_memory_slot old);
+                               const struct kvm_memory_slot *old);
 extern int kvm_vm_ioctl_get_smmu_info(struct kvm *kvm,
                                      struct kvm_ppc_smmu_info *info);
 extern void kvmppc_core_flush_memslot(struct kvm *kvm,
index 80dcc53a1abaf813659cf2102b9e701c30fc16cf..1e521baf9a7d30612d976e90af663a521172a328 100644 (file)
@@ -1639,12 +1639,12 @@ int kvmppc_core_prepare_memory_region(struct kvm *kvm,
 
 void kvmppc_core_commit_memory_region(struct kvm *kvm,
                                      struct kvm_userspace_memory_region *mem,
-                                     struct kvm_memory_slot old)
+                                     const struct kvm_memory_slot *old)
 {
        unsigned long npages = mem->memory_size >> PAGE_SHIFT;
        struct kvm_memory_slot *memslot;
 
-       if (npages && old.npages) {
+       if (npages && old->npages) {
                /*
                 * If modifying a memslot, reset all the rmap dirty bits.
                 * If this is a new memslot, we don't need to do anything
index 5e93438afb068c89b27062cec2bb772d4e77ce4c..286e23e6b92dd01cf6587559d05a74d76a9bedd7 100644 (file)
@@ -1283,7 +1283,7 @@ int kvmppc_core_prepare_memory_region(struct kvm *kvm,
 
 void kvmppc_core_commit_memory_region(struct kvm *kvm,
                                struct kvm_userspace_memory_region *mem,
-                               struct kvm_memory_slot old)
+                               const struct kvm_memory_slot *old)
 {
 }
 
index 020923e4313490445130517f220325f7485a4fa2..eb88fa6210732169a1785cd0d0c9ce0529022a4d 100644 (file)
@@ -1531,7 +1531,7 @@ int kvmppc_core_prepare_memory_region(struct kvm *kvm,
 
 void kvmppc_core_commit_memory_region(struct kvm *kvm,
                                struct kvm_userspace_memory_region *mem,
-                               struct kvm_memory_slot old)
+                               const struct kvm_memory_slot *old)
 {
 }
 
index 8aa51cd67c28e5d863c7d7a4089e2ad14f7162bc..7b5d4d20cdc56943643ff96a921ae7a6bfa4c0ca 100644 (file)
@@ -420,7 +420,8 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
 
 void kvm_arch_commit_memory_region(struct kvm *kvm,
                                   struct kvm_userspace_memory_region *mem,
-                                  struct kvm_memory_slot old)
+                                  const struct kvm_memory_slot *old,
+                                  enum kvm_mr_change change)
 {
        kvmppc_core_commit_memory_region(kvm, mem, old);
 }
index 4288780c86b8c6d9d6441002b3f7c360e4af39dd..6cae4ad647a9b86a614d66c78421073b3291eaf2 100644 (file)
@@ -1001,7 +1001,8 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
 
 void kvm_arch_commit_memory_region(struct kvm *kvm,
                                struct kvm_userspace_memory_region *mem,
-                               struct kvm_memory_slot old)
+                               const struct kvm_memory_slot *old,
+                               enum kvm_mr_change change)
 {
        int rc;
 
index 7198234fa08807dc5daf3e6dafb8744bf63e064e..35b491229c3aac9b763b02766ee04c5e4d762216 100644 (file)
@@ -6935,16 +6935,17 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
 
 void kvm_arch_commit_memory_region(struct kvm *kvm,
                                struct kvm_userspace_memory_region *mem,
-                               struct kvm_memory_slot old)
+                               const struct kvm_memory_slot *old,
+                               enum kvm_mr_change change)
 {
 
-       int nr_mmu_pages = 0, npages = mem->memory_size >> PAGE_SHIFT;
+       int nr_mmu_pages = 0;
 
-       if ((mem->slot >= KVM_USER_MEM_SLOTS) && old.npages && !npages) {
+       if ((mem->slot >= KVM_USER_MEM_SLOTS) && (change == KVM_MR_DELETE)) {
                int ret;
 
-               ret = vm_munmap(old.userspace_addr,
-                               old.npages * PAGE_SIZE);
+               ret = vm_munmap(old->userspace_addr,
+                               old->npages * PAGE_SIZE);
                if (ret < 0)
                        printk(KERN_WARNING
                               "kvm_vm_ioctl_set_memory_region: "
@@ -6961,13 +6962,13 @@ 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))
+       if ((change != KVM_MR_DELETE) && (mem->flags & KVM_MEM_LOG_DIRTY_PAGES))
                kvm_mmu_slot_remove_write_access(kvm, mem->slot);
        /*
         * If memory slot is created, or moved, we need to clear all
         * mmio sptes.
         */
-       if (npages && old.base_gfn != mem->guest_phys_addr >> PAGE_SHIFT) {
+       if ((change == KVM_MR_CREATE) || (change == KVM_MR_MOVE)) {
                kvm_mmu_zap_all(kvm);
                kvm_reload_remote_mmus(kvm);
        }
index caa72cf7e8e7ff5cf1f5ebdc348949d7e25a1d1e..ac584cc5358182f7d966efc647f84f40209b6c13 100644 (file)
@@ -483,7 +483,8 @@ int kvm_arch_prepare_memory_region(struct kvm *kvm,
                                enum kvm_mr_change change);
 void kvm_arch_commit_memory_region(struct kvm *kvm,
                                struct kvm_userspace_memory_region *mem,
-                               struct kvm_memory_slot old);
+                               const struct kvm_memory_slot *old,
+                               enum kvm_mr_change change);
 bool kvm_largepages_enabled(void);
 void kvm_disable_largepages(void);
 /* flush all memory translations */
index 8f85bae862c7c32f007086c20aafb396ada71f70..0e919a1d4d56d8aeeced2b59a13241b481c54e02 100644 (file)
@@ -896,7 +896,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
 
        old_memslots = install_new_memslots(kvm, slots, &new);
 
-       kvm_arch_commit_memory_region(kvm, mem, old);
+       kvm_arch_commit_memory_region(kvm, mem, &old, change);
 
        kvm_free_physmem_slot(&old, &new);
        kfree(old_memslots);