aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/x86/kvm/x86.c9
-rw-r--r--include/linux/kvm_host.h1
-rw-r--r--virt/kvm/kvm_main.c4
3 files changed, 7 insertions, 7 deletions
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index a3b25a524c9..220c83b0fbd 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -3466,10 +3466,9 @@ static int kvm_vm_ioctl_reinject(struct kvm *kvm,
3466int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm, 3466int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
3467 struct kvm_dirty_log *log) 3467 struct kvm_dirty_log *log)
3468{ 3468{
3469 int r, i; 3469 int r;
3470 struct kvm_memory_slot *memslot; 3470 struct kvm_memory_slot *memslot;
3471 unsigned long n; 3471 unsigned long n;
3472 unsigned long is_dirty = 0;
3473 3472
3474 mutex_lock(&kvm->slots_lock); 3473 mutex_lock(&kvm->slots_lock);
3475 3474
@@ -3484,11 +3483,8 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
3484 3483
3485 n = kvm_dirty_bitmap_bytes(memslot); 3484 n = kvm_dirty_bitmap_bytes(memslot);
3486 3485
3487 for (i = 0; !is_dirty && i < n/sizeof(long); i++)
3488 is_dirty = memslot->dirty_bitmap[i];
3489
3490 /* If nothing is dirty, don't bother messing with page tables. */ 3486 /* If nothing is dirty, don't bother messing with page tables. */
3491 if (is_dirty) { 3487 if (memslot->nr_dirty_pages) {
3492 struct kvm_memslots *slots, *old_slots; 3488 struct kvm_memslots *slots, *old_slots;
3493 unsigned long *dirty_bitmap; 3489 unsigned long *dirty_bitmap;
3494 3490
@@ -3503,6 +3499,7 @@ int kvm_vm_ioctl_get_dirty_log(struct kvm *kvm,
3503 goto out; 3499 goto out;
3504 memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots)); 3500 memcpy(slots, kvm->memslots, sizeof(struct kvm_memslots));
3505 slots->memslots[log->slot].dirty_bitmap = dirty_bitmap; 3501 slots->memslots[log->slot].dirty_bitmap = dirty_bitmap;
3502 slots->memslots[log->slot].nr_dirty_pages = 0;
3506 slots->generation++; 3503 slots->generation++;
3507 3504
3508 old_slots = kvm->memslots; 3505 old_slots = kvm->memslots;
diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
index c6a2ec92584..7c654aa46b6 100644
--- a/include/linux/kvm_host.h
+++ b/include/linux/kvm_host.h
@@ -181,6 +181,7 @@ struct kvm_memory_slot {
181 unsigned long *rmap; 181 unsigned long *rmap;
182 unsigned long *dirty_bitmap; 182 unsigned long *dirty_bitmap;
183 unsigned long *dirty_bitmap_head; 183 unsigned long *dirty_bitmap_head;
184 unsigned long nr_dirty_pages;
184 struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES - 1]; 185 struct kvm_lpage_info *lpage_info[KVM_NR_PAGE_SIZES - 1];
185 unsigned long userspace_addr; 186 unsigned long userspace_addr;
186 int user_alloc; 187 int user_alloc;
diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index 4c5b9a23967..af5c988cafc 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -625,6 +625,7 @@ static int kvm_create_dirty_bitmap(struct kvm_memory_slot *memslot)
625 return -ENOMEM; 625 return -ENOMEM;
626 626
627 memslot->dirty_bitmap_head = memslot->dirty_bitmap; 627 memslot->dirty_bitmap_head = memslot->dirty_bitmap;
628 memslot->nr_dirty_pages = 0;
628 return 0; 629 return 0;
629} 630}
630#endif /* !CONFIG_S390 */ 631#endif /* !CONFIG_S390 */
@@ -1491,7 +1492,8 @@ void mark_page_dirty_in_slot(struct kvm *kvm, struct kvm_memory_slot *memslot,
1491 if (memslot && memslot->dirty_bitmap) { 1492 if (memslot && memslot->dirty_bitmap) {
1492 unsigned long rel_gfn = gfn - memslot->base_gfn; 1493 unsigned long rel_gfn = gfn - memslot->base_gfn;
1493 1494
1494 __set_bit_le(rel_gfn, memslot->dirty_bitmap); 1495 if (!__test_and_set_bit_le(rel_gfn, memslot->dirty_bitmap))
1496 memslot->nr_dirty_pages++;
1495 } 1497 }
1496} 1498}
1497 1499