Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f2a81036 authored by Paolo Bonzini's avatar Paolo Bonzini
Browse files

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: default avatarIgor Mammedov <imammedo@redhat.com>
Reviewed-by: default avatarTakuya Yoshikawa <yoshikawa_takuya_b1@lab.ntt.co.jp>
Signed-off-by: default avatarPaolo Bonzini <pbonzini@redhat.com>
parent 8593176c
Loading
Loading
Loading
Loading
+11 −17
Original line number Original line Diff line number Diff line
@@ -866,11 +866,12 @@ int __kvm_set_memory_region(struct kvm *kvm,
			goto out_free;
			goto out_free;
	}
	}


	if ((change == KVM_MR_DELETE) || (change == KVM_MR_MOVE)) {
	slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
	slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
			GFP_KERNEL);
			GFP_KERNEL);
	if (!slots)
	if (!slots)
		goto out_free;
		goto out_free;

	if ((change == KVM_MR_DELETE) || (change == KVM_MR_MOVE)) {
		slot = id_to_memslot(slots, mem->slot);
		slot = id_to_memslot(slots, mem->slot);
		slot->flags |= KVM_MEMSLOT_INVALID;
		slot->flags |= KVM_MEMSLOT_INVALID;


@@ -886,26 +887,19 @@ int __kvm_set_memory_region(struct kvm *kvm,
		 * 	- kvm_is_visible_gfn (mmu_check_roots)
		 * 	- kvm_is_visible_gfn (mmu_check_roots)
		 */
		 */
		kvm_arch_flush_shadow_memslot(kvm, slot);
		kvm_arch_flush_shadow_memslot(kvm, slot);
		slots = old_memslots;
	}


	r = kvm_arch_prepare_memory_region(kvm, &new, mem, change);
	if (r)
		goto out_slots;

	r = -ENOMEM;
		/*
		/*
		 * We can re-use the old_memslots from above, the only difference
		 * We can re-use the old_memslots from above, the only difference
		 * from the currently installed memslots is the invalid flag.  This
		 * from the currently installed memslots is the invalid flag.  This
		 * will get overwritten by update_memslots anyway.
		 * will get overwritten by update_memslots anyway.
		 */
		 */
	if (!slots) {
		slots = old_memslots;
		slots = kmemdup(kvm->memslots, sizeof(struct kvm_memslots),
				GFP_KERNEL);
		if (!slots)
			goto out_free;
	}
	}


	r = kvm_arch_prepare_memory_region(kvm, &new, mem, change);
	if (r)
		goto out_slots;

	/* actual memory is freed via old in kvm_free_physmem_slot below */
	/* actual memory is freed via old in kvm_free_physmem_slot below */
	if (change == KVM_MR_DELETE) {
	if (change == KVM_MR_DELETE) {
		new.dirty_bitmap = NULL;
		new.dirty_bitmap = NULL;