aboutsummaryrefslogtreecommitdiffstats
path: root/arch/x86/kvm/x86.c
diff options
context:
space:
mode:
authorXiao Guangrong <xiaoguangrong.eric@gmail.com>2011-11-24 06:04:35 -0500
committerAvi Kivity <avi@redhat.com>2011-12-27 04:17:39 -0500
commit28a37544fb0223eb9805d2567b88f7360edec52a (patch)
tree83afb64f8448303f9486eb6c87980695611275ab /arch/x86/kvm/x86.c
parentbe6ba0f0962a39091c52eb9167ddea201fe80716 (diff)
KVM: introduce id_to_memslot function
Introduce id_to_memslot to get memslot by slot id Signed-off-by: Xiao Guangrong <xiaoguangrong@linux.vnet.ibm.com> Signed-off-by: Avi Kivity <avi@redhat.com>
Diffstat (limited to 'arch/x86/kvm/x86.c')
-rw-r--r--arch/x86/kvm/x86.c18
1 files changed, 9 insertions, 9 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index 917a287d21c..b6776c613e6 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3520,7 +3520,7 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
3520 if (log->slot >= KVM_MEMORY_SLOTS) 3520 if (log->slot >= KVM_MEMORY_SLOTS)
3521 goto out; 3521 goto out;
3522 3522
3523 memslot = &kvm->memslots->memslots[log->slot]; 3523 memslot = id_to_memslot(kvm->memslots, log->slot);
3524 r = -ENOENT; 3524 r = -ENOENT;
3525 if (!memslot->dirty_bitmap) 3525 if (!memslot->dirty_bitmap)
3526 goto out; 3526 goto out;
@@ -3531,27 +3531,27 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
3531 /* If nothing is dirty, don't bother messing with page tables. */ 3531 /* If nothing is dirty, don't bother messing with page tables. */
3532 if (nr_dirty_pages) { 3532 if (nr_dirty_pages) {
3533 struct kvm_memslots *slots, *old_slots; 3533 struct kvm_memslots *slots, *old_slots;
3534 unsigned long *dirty_bitmap; 3534 unsigned long *dirty_bitmap, *dirty_bitmap_head;
3535 3535
3536 dirty_bitmap = memslot->dirty_bitmap_head; 3536 dirty_bitmap = memslot->dirty_bitmap;
3537 if (memslot->dirty_bitmap == dirty_bitmap) 3537 dirty_bitmap_head = memslot->dirty_bitmap_head;
3538 dirty_bitmap += n / sizeof(long); 3538 if (dirty_bitmap == dirty_bitmap_head)
3539 memset(dirty_bitmap, 0, n); 3539 dirty_bitmap_head += n / sizeof(long);
3540 memset(dirty_bitmap_head, 0, n);
3540 3541
3541 r = -ENOMEM; 3542 r = -ENOMEM;
3542 slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL); 3543 slots = kzalloc(sizeof(struct kvm_memslots), GFP_KERNEL);
3543 if (!slots) 3544 if (!slots)
3544 goto out; 3545 goto out;
3545 memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots)); 3546 memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots));
3546 memslot = &slots->memslots[log->slot]; 3547 memslot = id_to_memslot(slots, log->slot);
3547 memslot->dirty_bitmap = dirty_bitmap;
3548 memslot->nr_dirty_pages = 0; 3548 memslot->nr_dirty_pages = 0;
3549 memslot->dirty_bitmap = dirty_bitmap_head;
3549 update_memslots(slots, NULL); 3550 update_memslots(slots, NULL);
3550 3551
3551 old_slots = kvm->memslots; 3552 old_slots = kvm->memslots;
3552 rcu_assign_pointer(kvm->memslots, slots); 3553 rcu_assign_pointer(kvm->memslots, slots);
3553 synchronize_srcu_expedited(&kvm->srcu); 3554 synchronize_srcu_expedited(&kvm->srcu);
3554 dirty_bitmap = old_slots->memslots[log->slot].dirty_bitmap;
3555 kfree(old_slots); 3555 kfree(old_slots);
3556 3556
3557 write_protect_slot(kvm, memslot, dirty_bitmap, nr_dirty_pages); 3557 write_protect_slot(kvm, memslot, dirty_bitmap, nr_dirty_pages);