On Sat, Nov 05, 2022 at 05:57:33AM +0800, Gavin Shan wrote: > On 11/5/22 4:12 AM, Oliver Upton wrote: > > I agree that we should address (1) like this, but in (2) requiring that > > no memslots were created before enabling the existing capabilities would > > be a change in ABI. If we can get away with that, great, but otherwise > > we may need to delete the bitmaps associated with all memslots when the > > cap is enabled. > > > > I had the assumption QEMU and kvm/selftests are the only consumers to > use DIRTY_RING. In this case, requiring that no memslots were created > to enable DIRTY_RING won't break userspace. > Following your thoughts, the tracked dirty pages in the bitmap also > need to be synchronized to the per-vcpu-ring before the bitmap can be > destroyed. Eh, I don't think we'd need to go that far. No matter what, any dirty bits that were present in the bitmap could never be read again anyway, as we reject KVM_GET_DIRTY_LOG if kvm->dirty_ring_size != 0. > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > > index 91cf51a25394..420cc101a16e 100644 > > --- a/virt/kvm/kvm_main.c > > +++ b/virt/kvm/kvm_main.c > > @@ -4588,6 +4588,32 @@ static int kvm_vm_ioctl_enable_cap_generic(struct kvm *kvm, > > return -EINVAL; > > return kvm_vm_ioctl_enable_dirty_log_ring(kvm, cap->args[0]); > > + > > + case KVM_CAP_DIRTY_LOG_RING_WITH_BITMAP: { > > + struct kvm_memslots *slots; > > + int r = -EINVAL; > > + > > + if (!IS_ENABLED(CONFIG_HAVE_KVM_DIRTY_RING_WITH_BITMAP) || > > + !kvm->dirty_ring_size) > > + return r; > > + > > + mutex_lock(&kvm->slots_lock); > > + > > + slots = kvm_memslots(kvm); > > + > > + /* > > + * Avoid a race between memslot creation and enabling the ring + > > + * bitmap capability to guarantee that no memslots have been > > + * created without a bitmap. > > + */ > > + if (kvm_memslots_empty(slots)) { > > + kvm->dirty_ring_with_bitmap = cap->args[0]; > > + r = 0; > > + } > > + > > + mutex_unlock(&kvm->slots_lock); > > + return r; > > + } > > default: > > return kvm_vm_ioctl_enable_cap(kvm, cap); > > } > > > > The proposed changes look good to me. It will be integrated to PATCH[v8 4/9]. > By the way, v8 will be posted shortly. Excellent, thanks! -- Best, Oliver _______________________________________________ kvmarm mailing list kvmarm@xxxxxxxxxxxxxxxxxxxxx https://lists.cs.columbia.edu/mailman/listinfo/kvmarm