* [PATCH v2] kvm: Fix user memslot overlap check
@ 2012-11-29 21:07 Alex Williamson
2012-11-30 20:18 ` Marcelo Tosatti
0 siblings, 1 reply; 2+ messages in thread
From: Alex Williamson @ 2012-11-29 21:07 UTC (permalink / raw)
To: mtosatti, gleb; +Cc: linux-kernel, kvm, xiaoguangrong
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>
Cc: stable@vger.kernel.org
---
v2: Remove unused variable i
virt/kvm/kvm_main.c | 13 +++++--------
1 file changed, 5 insertions(+), 8 deletions(-)
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index be70035..6e8fa7e 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -709,8 +709,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
int r;
gfn_t base_gfn;
unsigned long npages;
- unsigned long i;
- struct kvm_memory_slot *memslot;
+ struct kvm_memory_slot *memslot, *slot;
struct kvm_memory_slot old, new;
struct kvm_memslots *slots, *old_memslots;
@@ -761,13 +760,11 @@ int __kvm_set_memory_region(struct kvm *kvm,
/* Check for overlaps */
r = -EEXIST;
- for (i = 0; i < KVM_MEMORY_SLOTS; ++i) {
- struct kvm_memory_slot *s = &kvm->memslots->memslots[i];
-
- if (s == memslot || !s->npages)
+ kvm_for_each_memslot(slot, kvm->memslots) {
+ if (slot->id >= KVM_MEMORY_SLOTS || slot == memslot)
continue;
- if (!((base_gfn + npages <= s->base_gfn) ||
- (base_gfn >= s->base_gfn + s->npages)))
+ if (!((base_gfn + npages <= slot->base_gfn) ||
+ (base_gfn >= slot->base_gfn + slot->npages)))
goto out_free;
}
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH v2] kvm: Fix user memslot overlap check
2012-11-29 21:07 [PATCH v2] kvm: Fix user memslot overlap check Alex Williamson
@ 2012-11-30 20:18 ` Marcelo Tosatti
0 siblings, 0 replies; 2+ messages in thread
From: Marcelo Tosatti @ 2012-11-30 20:18 UTC (permalink / raw)
To: Alex Williamson; +Cc: gleb, linux-kernel, kvm, xiaoguangrong
On Thu, Nov 29, 2012 at 02:07:59PM -0700, Alex Williamson wrote:
> 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>
> Cc: stable@vger.kernel.org
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-11-30 20:31 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-29 21:07 [PATCH v2] kvm: Fix user memslot overlap check Alex Williamson
2012-11-30 20:18 ` Marcelo Tosatti
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox