aboutsummaryrefslogtreecommitdiffstats
path: root/virt/kvm/kvm_main.c
diff options
context:
space:
mode:
Diffstat (limited to 'virt/kvm/kvm_main.c')
-rw-r--r--virt/kvm/kvm_main.c13
1 files changed, 9 insertions, 4 deletions
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 4c2900c5d81d..7b6084999424 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -634,8 +634,9 @@ void update_memslots(struct kvm_memslots *slots, struct kvm_memory_slot *new)
634{ 634{
635 if (new) { 635 if (new) {
636 int id = new->id; 636 int id = new->id;
637 struct kvm_memory_slot *old = id_to_memslot(slots, id);
637 638
638 slots->memslots[id] = *new; 639 *old = *new;
639 if (id >= slots->nmemslots) 640 if (id >= slots->nmemslots)
640 slots->nmemslots = id + 1; 641 slots->nmemslots = id + 1;
641 } 642 }
@@ -681,7 +682,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
681 if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr) 682 if (mem->guest_phys_addr + mem->memory_size < mem->guest_phys_addr)
682 goto out; 683 goto out;
683 684
684 memslot = &kvm->memslots->memslots[mem->slot]; 685 memslot = id_to_memslot(kvm->memslots, mem->slot);
685 base_gfn = mem->guest_phys_addr >> PAGE_SHIFT; 686 base_gfn = mem->guest_phys_addr >> PAGE_SHIFT;
686 npages = mem->memory_size >> PAGE_SHIFT; 687 npages = mem->memory_size >> PAGE_SHIFT;
687 688
@@ -788,12 +789,16 @@ skip_lpage:
788#endif /* not defined CONFIG_S390 */ 789#endif /* not defined CONFIG_S390 */
789 790
790 if (!npages) { 791 if (!npages) {
792 struct kvm_memory_slot *slot;
793
791 r = -ENOMEM; 794 r = -ENOMEM;
792 slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots), 795 slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
793 GFP_KERNEL); 796 GFP_KERNEL);
794 if (!slots) 797 if (!slots)
795 goto out_free; 798 goto out_free;
796 slots->memslots[mem->slot].flags |= KVM_MEMSLOT_INVALID; 799 slot = id_to_memslot(slots, mem->slot);
800 slot->flags |= KVM_MEMSLOT_INVALID;
801
797 update_memslots(slots, NULL); 802 update_memslots(slots, NULL);
798 803
799 old_memslots = kvm->memslots; 804 old_memslots = kvm->memslots;
@@ -897,7 +902,7 @@ int kvm_get_dirty_log(struct kvm *kvm,
897 if (log->slot >= KVM_MEMORY_SLOTS) 902 if (log->slot >= KVM_MEMORY_SLOTS)
898 goto out; 903 goto out;
899 904
900 memslot = &kvm->memslots->memslots[log->slot]; 905 memslot = id_to_memslot(kvm->memslots, log->slot);
901 r = -ENOENT; 906 r = -ENOENT;
902 if (!memslot->dirty_bitmap) 907 if (!memslot->dirty_bitmap)
903 goto out; 908 goto out;