Re: [v3 5/5] KVM: set/clear kvm to/from vfio group during add/delete

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> With VFIO being capable of carrying usrdata, we can extend the
> existing interfaces between KVM and VFIO, whenever a group is
> added to or deleted from KVM, set/clear KVM instance to/from
> this group. That enables 3rd-party users of vfio_group to know
> which KVM it attached to, if there is one.
> 
> Signed-off-by: Jike Song <jike.song@xxxxxxxxx>
> ---
>  virt/kvm/vfio.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
> 
> diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
> index 1dd087d..62da226 100644
> --- a/virt/kvm/vfio.c
> +++ b/virt/kvm/vfio.c
> @@ -60,6 +60,34 @@ static void kvm_vfio_group_put_external_user(struct
> vfio_group *vfio_group)
>  	symbol_put(vfio_group_put_external_user);
>  }
>  
> +static void kvm_vfio_group_set_kvm(struct vfio_group *group, struct kvm
> *kvm)
> +{
> +	void (*fn)(struct vfio_group *, struct kvm *);
> +
> +	fn = symbol_get(vfio_group_set_kvm);
> +	if (!fn)
> +		return;
> +
> +	fn(group, kvm);
> +	kvm_get_kvm(kvm);
> +
> +	symbol_put(vfio_group_set_kvm);
> +}
> +
> +static void kvm_vfio_group_clear_kvm(struct vfio_group *group, struct kvm
> *kvm)
> +{
> +	void (*fn)(struct vfio_group *, struct kvm *);
> +
> +	fn = symbol_get(vfio_group_set_kvm);
> +	if (!fn)
> +		return;
> +
> +	fn(group, NULL);
> +	kvm_put_kvm(kvm);
> +
> +	symbol_put(vfio_group_set_kvm);
> +}
> +
>  static bool kvm_vfio_group_is_coherent(struct vfio_group *vfio_group)
>  {
>  	long (*fn)(struct vfio_group *, unsigned long);
> @@ -155,6 +183,8 @@ static int kvm_vfio_set_group(struct kvm_device *dev,
> long attr, u64 arg)
>  		list_add_tail(&kvg->node, &kv->group_list);
>  		kvg->vfio_group = vfio_group;
>  
> +		kvm_vfio_group_set_kvm(vfio_group, dev->kvm);
> +
>  		kvm_arch_start_assignment(dev->kvm);
>  
>  		mutex_unlock(&kv->lock);
> @@ -196,6 +226,8 @@ static int kvm_vfio_set_group(struct kvm_device *dev,
> long attr, u64 arg)
>  
>  		mutex_unlock(&kv->lock);
>  
> +		kvm_vfio_group_clear_kvm(vfio_group, dev->kvm);
> +
>  		kvm_vfio_group_put_external_user(vfio_group);
>  
>  		kvm_vfio_update_coherency(dev);
> @@ -240,6 +272,7 @@ static void kvm_vfio_destroy(struct kvm_device *dev)
>  	struct kvm_vfio_group *kvg, *tmp;
>  
>  	list_for_each_entry_safe(kvg, tmp, &kv->group_list, node) {
> +		kvm_vfio_group_clear_kvm(kvg->vfio_group, dev->kvm);
>  		kvm_vfio_group_put_external_user(kvg->vfio_group);
>  		list_del(&kvg->node);
>  		kfree(kvg);
> --
> 1.9.1
> 
> 
Acked-by: Paolo Bonzini <pbonzini@xxxxxxxxxx>
--
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



[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux