On Fri, Nov 18, 2022, Paolo Bonzini wrote: > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 43bbe4fde078..5d85f1a61793 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -1603,6 +1603,8 @@ static int kvm_prepare_memory_region(struct kvm *kvm, > struct kvm_memory_slot *new, > enum kvm_mr_change change) > { > + int old_flags = old ? old->flags : 0; > + int new_flags = new ? new->flags : 0; > int r; > > /* > @@ -1627,6 +1629,11 @@ static int kvm_prepare_memory_region(struct kvm *kvm, > } > } > > + if ((old_flags ^ new_flags) & KVM_MEM_LOG_DIRTY_PAGES) { > + int change = (new_flags & KVM_MEM_LOG_DIRTY_PAGES) ? 1 : -1; > + atomic_set(&kvm->nr_memslots_dirty_logging, > + atomic_read(&kvm->nr_memslots_dirty_logging) + change); Again, this needs to be done in the "commit" stage, and IMO should be x86-only. https://lore.kernel.org/all/Y3bTu4%2FnUfpX+Enm@xxxxxxxxxx > + } > r = kvm_arch_prepare_memory_region(kvm, old, new, change); > > /* Free the bitmap on failure if it was allocated above. */ > -- > 2.31.1 >