aboutsummaryrefslogtreecommitdiffstats
path: root/virt/kvm/kvm_main.c
diff options
context:
space:
mode:
authorGleb Natapov <gleb@redhat.com>2012-12-24 10:49:30 -0500
committerGleb Natapov <gleb@redhat.com>2012-12-24 10:49:30 -0500
commit7ec4fb44962f611241bcb974fa97c5f49ddcb2f1 (patch)
tree28400ae97788c508e723bc84f2bd6e42e6515815 /virt/kvm/kvm_main.c
parentf924d66d278d5da890f3098805b0450a4ef66c32 (diff)
KVM: move the code that installs new slots array to a separate function.
Move repetitive code sequence to a separate function. Reviewed-by: Alex Williamson <alex.williamson@redhat.com> Signed-off-by: Gleb Natapov <gleb@redhat.com>
Diffstat (limited to 'virt/kvm/kvm_main.c')
-rw-r--r--virt/kvm/kvm_main.c21
1 files changed, 13 insertions, 8 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 14cbae83be64..e45c20ca422a 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -702,6 +702,17 @@ static int check_memory_region_flags(struct kvm_userspace_memory_region *mem)
702 return 0; 702 return 0;
703} 703}
704 704
705static struct kvm_memslots *install_new_memslots(struct kvm *kvm,
706 struct kvm_memslots *slots, struct kvm_memory_slot *new)
707{
708 struct kvm_memslots *old_memslots = kvm->memslots;
709
710 update_memslots(slots, new, kvm->memslots->generation);
711 rcu_assign_pointer(kvm->memslots, slots);
712 synchronize_srcu_expedited(&kvm->srcu);
713 return old_memslots;
714}
715
705/* 716/*
706 * Allocate some memory and give it an address in the guest physical address 717 * Allocate some memory and give it an address in the guest physical address
707 * space. 718 * space.
@@ -820,11 +831,8 @@ int __kvm_set_memory_region(struct kvm *kvm,
820 slot = id_to_memslot(slots, mem->slot); 831 slot = id_to_memslot(slots, mem->slot);
821 slot->flags |= KVM_MEMSLOT_INVALID; 832 slot->flags |= KVM_MEMSLOT_INVALID;
822 833
823 update_memslots(slots, NULL, kvm->memslots->generation); 834 old_memslots = install_new_memslots(kvm, slots, NULL);
824 835
825 old_memslots = kvm->memslots;
826 rcu_assign_pointer(kvm->memslots, slots);
827 synchronize_srcu_expedited(&kvm->srcu);
828 /* slot was deleted or moved, clear iommu mapping */ 836 /* slot was deleted or moved, clear iommu mapping */
829 kvm_iommu_unmap_pages(kvm, &old); 837 kvm_iommu_unmap_pages(kvm, &old);
830 /* From this point no new shadow pages pointing to a deleted, 838 /* From this point no new shadow pages pointing to a deleted,
@@ -868,10 +876,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
868 memset(&new.arch, 0, sizeof(new.arch)); 876 memset(&new.arch, 0, sizeof(new.arch));
869 } 877 }
870 878
871 update_memslots(slots, &new, kvm->memslots->generation); 879 old_memslots = install_new_memslots(kvm, slots, &new);
872 old_memslots = kvm->memslots;
873 rcu_assign_pointer(kvm->memslots, slots);
874 synchronize_srcu_expedited(&kvm->srcu);
875 880
876 kvm_arch_commit_memory_region(kvm, mem, old, user_alloc); 881 kvm_arch_commit_memory_region(kvm, mem, old, user_alloc);
877 882