Skip to content

Commit

Permalink
KVM: Explicitly free allocated-but-unused dirty bitmap
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Sean Christopherson <[email protected]>
Signed-off-by: Paolo Bonzini <[email protected]>
  • Loading branch information
Sean Christopherson authored and bonzini committed Mar 16, 2020
1 parent 414de7a commit bd0e96f
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions virt/kvm/kvm_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1093,7 +1093,7 @@ int __kvm_set_memory_region(struct kvm *kvm,

slots = kvzalloc(sizeof(struct kvm_memslots), GFP_KERNEL_ACCOUNT);
if (!slots)
goto out_free;
goto out_bitmap;
memcpy(slots, __kvm_memslots(kvm, as_id), sizeof(struct kvm_memslots));

if ((change == KVM_MR_DELETE) || (change == KVM_MR_MOVE)) {
Expand Down Expand Up @@ -1141,8 +1141,9 @@ int __kvm_set_memory_region(struct kvm *kvm,
if (change == KVM_MR_DELETE || change == KVM_MR_MOVE)
slots = install_new_memslots(kvm, as_id, slots);
kvfree(slots);
out_free:
kvm_free_memslot(kvm, &new, &old);
out_bitmap:
if (new.dirty_bitmap && !old.dirty_bitmap)
kvm_destroy_dirty_bitmap(&new);
out:
return r;
}
Expand Down

0 comments on commit bd0e96f

Please sign in to comment.