On 10/21/2016 01:19 AM, Xiao, Guangrong wrote: >> On 10/19/2016 10:14 PM, Paolo Bonzini wrote: >>> On 19/10/2016 15:39, Xiao Guangrong wrote: >>> >>> >>> I understood that KVM side is safe, however, vfio side is independent >>> with kvm and the user of usrdata can fetch kvm struct at any time, >>> consider this scenario: >>> >>> CPU 0 CPU 1 >>> KVM: VFIO/userdata user >>> kvm_ioctl_create_device >>> get_kvm() >>> vfio_group_get_usrdata(vfio_group) >>> kvm_device_release >>> put_kvm() >>> !!! kvm refcount has gone >>> use KVM struct >>> >>> Then, the user of userdata have fetched kvm struct but the refcount >>> has already gone. >> >> vfio_group_set_usrdata (actually) kvm_vfio_group_set_kvm has called >>kvm_get_kvm too, however. What you need is a mutex that is taken by >>vfio_group_set_usrdata and by the callers of vfio_group_get_usrdata. > > Yes, mutex can fix it and is good to me. :) Thanks everyone, I'll cook another patch according to your guidance. -- Thanks, Jike -- To unsubscribe from this list: send the line "unsubscribe kvm" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html