提交 5419369e 编写于 作者: A Alex Williamson 提交者: Marcelo Tosatti

KVM: Fix user memslot overlap check

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.

Cc: stable@vger.kernel.org
Signed-off-by: NAlex Williamson <alex.williamson@redhat.com>
Signed-off-by: NMarcelo Tosatti <mtosatti@redhat.com>
上级 5a560f8b
...@@ -714,8 +714,7 @@ int __kvm_set_memory_region(struct kvm *kvm, ...@@ -714,8 +714,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
int r; int r;
gfn_t base_gfn; gfn_t base_gfn;
unsigned long npages; unsigned long npages;
unsigned long i; struct kvm_memory_slot *memslot, *slot;
struct kvm_memory_slot *memslot;
struct kvm_memory_slot old, new; struct kvm_memory_slot old, new;
struct kvm_memslots *slots, *old_memslots; struct kvm_memslots *slots, *old_memslots;
...@@ -766,13 +765,11 @@ int __kvm_set_memory_region(struct kvm *kvm, ...@@ -766,13 +765,11 @@ int __kvm_set_memory_region(struct kvm *kvm,
/* Check for overlaps */ /* Check for overlaps */
r = -EEXIST; r = -EEXIST;
for (i = 0; i < KVM_MEMORY_SLOTS; ++i) { kvm_for_each_memslot(slot, kvm->memslots) {
struct kvm_memory_slot *s = &kvm->memslots->memslots[i]; if (slot->id >= KVM_MEMORY_SLOTS || slot == memslot)
if (s == memslot || !s->npages)
continue; continue;
if (!((base_gfn + npages <= s->base_gfn) || if (!((base_gfn + npages <= slot->base_gfn) ||
(base_gfn >= s->base_gfn + s->npages))) (base_gfn >= slot->base_gfn + slot->npages)))
goto out_free; goto out_free;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册