diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2014-11-14 04:46:45 -0500 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2014-11-17 06:15:34 -0500 |
commit | f2a81036516e2b97c07c49dd6d51d36bfa43593d (patch) | |
tree | 2a8c0874af9f00cf323d8aa95738a596c5dfdd22 /virt | |
parent | 8593176c677226ead5b4effbd667dd19d5cba5ea (diff) |
kvm: commonize allocation of the new memory slots
The two kmemdup invocations can be unified. I find that the new
placement of the comment makes it easier to see what happens.
Reviewed-by: Igor Mammedov <imammedo@redhat.com>
Reviewed-by: Takuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'virt')
-rw-r--r-- | virt/kvm/kvm_main.c | 28 |
1 files changed, 11 insertions, 17 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index eae07f97ecf7..7fc77c0f98fb 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c | |||
@@ -866,11 +866,12 @@ int __kvm_set_memory_region(struct kvm *kvm, | |||
866 | goto out_free; | 866 | goto out_free; |
867 | } | 867 | } |
868 | 868 | ||
869 | slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots), | ||
870 | GFP_KERNEL); | ||
871 | if (!slots) | ||
872 | goto out_free; | ||
873 | |||
869 | if ((change == KVM_MR_DELETE) || (change == KVM_MR_MOVE)) { | 874 | if ((change == KVM_MR_DELETE) || (change == KVM_MR_MOVE)) { |
870 | slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots), | ||
871 | GFP_KERNEL); | ||
872 | if (!slots) | ||
873 | goto out_free; | ||
874 | slot = id_to_memslot(slots, mem->slot); | 875 | slot = id_to_memslot(slots, mem->slot); |
875 | slot->flags |= KVM_MEMSLOT_INVALID; | 876 | slot->flags |= KVM_MEMSLOT_INVALID; |
876 | 877 | ||
@@ -886,6 +887,12 @@ int __kvm_set_memory_region(struct kvm *kvm, | |||
886 | * - kvm_is_visible_gfn (mmu_check_roots) | 887 | * - kvm_is_visible_gfn (mmu_check_roots) |
887 | */ | 888 | */ |
888 | kvm_arch_flush_shadow_memslot(kvm, slot); | 889 | kvm_arch_flush_shadow_memslot(kvm, slot); |
890 | |||
891 | /* | ||
892 | * We can re-use the old_memslots from above, the only difference | ||
893 | * from the currently installed memslots is the invalid flag. This | ||
894 | * will get overwritten by update_memslots anyway. | ||
895 | */ | ||
889 | slots = old_memslots; | 896 | slots = old_memslots; |
890 | } | 897 | } |
891 | 898 | ||
@@ -893,19 +900,6 @@ int __kvm_set_memory_region(struct kvm *kvm, | |||
893 | if (r) | 900 | if (r) |
894 | goto out_slots; | 901 | goto out_slots; |
895 | 902 | ||
896 | r = -ENOMEM; | ||
897 | /* | ||
898 | * We can re-use the old_memslots from above, the only difference | ||
899 | * from the currently installed memslots is the invalid flag. This | ||
900 | * will get overwritten by update_memslots anyway. | ||
901 | */ | ||
902 | if (!slots) { | ||
903 | slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots), | ||
904 | GFP_KERNEL); | ||
905 | if (!slots) | ||
906 | goto out_free; | ||
907 | } | ||
908 | |||
909 | /* actual memory is freed via old in kvm_free_physmem_slot below */ | 903 | /* actual memory is freed via old in kvm_free_physmem_slot below */ |
910 | if (change == KVM_MR_DELETE) { | 904 | if (change == KVM_MR_DELETE) { |
911 | new.dirty_bitmap = NULL; | 905 | new.dirty_bitmap = NULL; |