Skip to content

Commit bd0e96f

Browse files
Sean Christophersonbonzini
authored andcommitted
KVM: Explicitly free allocated-but-unused dirty bitmap
Explicitly free an allocated-but-unused dirty bitmap instead of relying on kvm_free_memslot() if an error occurs in __kvm_set_memory_region(). There is no longer a need to abuse kvm_free_memslot() to free arch specific resources as arch specific code is now called only after the common flow is guaranteed to succeed. Arch code can still fail, but it's responsible for its own cleanup in that case. Eliminating the error path's abuse of kvm_free_memslot() paves the way for simplifying kvm_free_memslot(), i.e. dropping its @dont param. Reviewed-by: Peter Xu <peterx@redhat.com> Signed-off-by: Sean Christopherson <sean.j.christopherson@intel.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
1 parent 414de7a commit bd0e96f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

virt/kvm/kvm_main.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
10931093

10941094
slots = kvzalloc(sizeof(struct kvm_memslots), GFP_KERNEL_ACCOUNT);
10951095
if (!slots)
1096-
goto out_free;
1096+
goto out_bitmap;
10971097
memcpy(slots, __kvm_memslots(kvm, as_id), sizeof(struct kvm_memslots));
10981098

10991099
if ((change == KVM_MR_DELETE) || (change == KVM_MR_MOVE)) {
@@ -1141,8 +1141,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
11411141
if (change == KVM_MR_DELETE || change == KVM_MR_MOVE)
11421142
slots = install_new_memslots(kvm, as_id, slots);
11431143
kvfree(slots);
1144-
out_free:
1145-
kvm_free_memslot(kvm, &new, &old);
1144+
out_bitmap:
1145+
if (new.dirty_bitmap && !old.dirty_bitmap)
1146+
kvm_destroy_dirty_bitmap(&new);
11461147
out:
11471148
return r;
11481149
}

0 commit comments

Comments
 (0)