Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

KVM: Fix user memslot overlap check

commit 5419369 upstream.

Prior to memory slot sorting this loop compared all of the user memory
slots for overlap with new entries.  With memory slot sorting, we're
just checking some number of entries in the array that may or may not
be user slots.  Instead, walk all the slots with kvm_for_each_memslot,
which has the added benefit of terminating early when we hit the first
empty slot, and skip comparison to private slots.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
Signed-off-by: Marcelo Tosatti <mtosatti@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information...
commit 9d4c74b86237ac64376b92c54cf7b471e7e75f76 1 parent 91534f7
Alex Williamson awilliam authored gregkh committed

Showing 1 changed file with 5 additions and 8 deletions. Show diff stats Hide diff stats

  1. +5 8 virt/kvm/kvm_main.c
13 virt/kvm/kvm_main.c
@@ -693,8 +693,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
693 693 int r;
694 694 gfn_t base_gfn;
695 695 unsigned long npages;
696   - unsigned long i;
697   - struct kvm_memory_slot *memslot;
  696 + struct kvm_memory_slot *memslot, *slot;
698 697 struct kvm_memory_slot old, new;
699 698 struct kvm_memslots *slots, *old_memslots;
700 699
@@ -741,13 +740,11 @@ int __kvm_set_memory_region(struct kvm *kvm,
741 740
742 741 /* Check for overlaps */
743 742 r = -EEXIST;
744   - for (i = 0; i < KVM_MEMORY_SLOTS; ++i) {
745   - struct kvm_memory_slot *s = &kvm->memslots->memslots[i];
746   -
747   - if (s == memslot || !s->npages)
  743 + kvm_for_each_memslot(slot, kvm->memslots) {
  744 + if (slot->id >= KVM_MEMORY_SLOTS || slot == memslot)
748 745 continue;
749   - if (!((base_gfn + npages <= s->base_gfn) ||
750   - (base_gfn >= s->base_gfn + s->npages)))
  746 + if (!((base_gfn + npages <= slot->base_gfn) ||
  747 + (base_gfn >= slot->base_gfn + slot->npages)))
751 748 goto out_free;
752 749 }
753 750

0 comments on commit 9d4c74b

Please sign in to comment.
Something went wrong with that request. Please try again.