[PATCH v2 8/8] KVM: Omit dirty log sync in log clear if initially all set

From: Keqian Zhu
Date: Thu Jul 02 2020 - 09:56:37 EST


Synchronizing dirty log during log clear is useful only when the dirty
bitmap of userspace contains dirty bits that memslot dirty bitmap does
not contain, because we can sync new dirty bits to memslot dirty bitmap,
then we can clear them by the way and avoid reporting them to userspace
later.

With dirty bitmap "initially all set" feature, the above situation will
not appear if userspace logic is normal, so we can omit dirty log sync in
log clear. This is valuable when dirty log sync is a high-cost operation,
such as arm64 DBM.

Signed-off-by: Keqian Zhu <zhukeqian1@xxxxxxxxxx>
---
virt/kvm/kvm_main.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
index a852af5c3214..3f9e51d52b7a 100644
--- a/virt/kvm/kvm_main.c
+++ b/virt/kvm/kvm_main.c
@@ -1554,7 +1554,8 @@ static int kvm_clear_dirty_log_protect(struct kvm *kvm,
(log->num_pages < memslot->npages - log->first_page && (log->num_pages & 63)))
return -EINVAL;

- kvm_arch_sync_dirty_log(kvm, memslot);
+ if (!kvm_dirty_log_manual_protect_and_init_set(kvm))
+ kvm_arch_sync_dirty_log(kvm, memslot);

flush = false;
dirty_bitmap_buffer = kvm_second_dirty_bitmap(memslot);
--
2.19.1