All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: Jike Song <jike.song@intel.com>
Cc: pbonzini@redhat.com, guangrong.xiao@linux.intel.com,
	kevin.tian@intel.com, kwankhede@nvidia.com, cjia@nvidia.com,
	kvm@vger.kernel.org
Subject: Re: [v7 3/3] kvm: set/clear kvm to/from vfio_group when group add/delete
Date: Wed, 30 Nov 2016 10:02:39 -0700	[thread overview]
Message-ID: <20161130100239.6689cf7f@t450s.home> (raw)
In-Reply-To: <1479794973-11910-4-git-send-email-jike.song@intel.com>

On Tue, 22 Nov 2016 14:09:33 +0800
Jike Song <jike.song@intel.com> wrote:

> Sometimes users need to be aware when a vfio_group attaches to a
> KVM or detaches from it. KVM already calls get/put method from vfio to
> manipulate the vfio_group reference, it can notify vfio_group in
> a similar way.
> 
> Cc: Alex Williamson <alex.williamson@redhat.com>
> Cc: Kirti Wankhede <kwankhede@nvidia.com>
> Cc: Paolo Bonzini <pbonzini@redhat.com>
> Cc: Xiao Guangrong <guangrong.xiao@linux.intel.com>
> Signed-off-by: Jike Song <jike.song@intel.com>
> ---
>  virt/kvm/vfio.c | 31 +++++++++++++++++++++++++++++++
>  1 file changed, 31 insertions(+)
> 
> diff --git a/virt/kvm/vfio.c b/virt/kvm/vfio.c
> index 1dd087d..ea5b4bb 100644
> --- a/virt/kvm/vfio.c
> +++ b/virt/kvm/vfio.c
> @@ -60,6 +60,32 @@ 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);
> +
> +	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);
> +
> +	symbol_put(vfio_group_set_kvm);
> +}


Why do we need this function?  Can't we simply call
kvm_vfio_group_set_kvm(vfio_group, NULL)?  Not to mention that the
struct kvm arg is unused here otherwise.

> +
>  static bool kvm_vfio_group_is_coherent(struct vfio_group *vfio_group)
>  {
>  	long (*fn)(struct vfio_group *, unsigned long);
> @@ -155,6 +181,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 +224,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);
> +


Why did we set_kvm within kv->lock, but clear it outside of kv->lock?
I'm not sure kv->lock is particularly relevant to us but we might as
well be consistent.

>  		kvm_vfio_group_put_external_user(vfio_group);
>  
>  		kvm_vfio_update_coherency(dev);
> @@ -240,6 +270,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);


  reply	other threads:[~2016-11-30 17:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-22  6:09 [v7 0/3] plumb kvm/vfio to notify kvm:group attach/detach Jike Song
2016-11-22  6:09 ` [v7 1/3] vfio: vfio_register_notifier: classify iommu notifier Jike Song
2016-11-23  8:50   ` [UPDATE v7 " Jike Song
2016-11-22  6:09 ` [v7 2/3] vfio: support notifier chain in vfio_group Jike Song
2016-11-22 13:35   ` Kirti Wankhede
2016-11-22 14:02     ` Alex Williamson
2016-11-22 14:39       ` Kirti Wankhede
2016-11-22 14:50         ` Alex Williamson
2016-11-23  3:20           ` Jike Song
2016-11-23  4:52             ` Kirti Wankhede
2016-11-23  5:56               ` Alex Williamson
2016-11-23  6:29                 ` Jike Song
2016-11-23  6:33                   ` Tian, Kevin
2016-11-23  7:53                     ` Jike Song
2016-11-23 12:45                       ` Alex Williamson
2016-11-22  6:09 ` [v7 3/3] kvm: set/clear kvm to/from vfio_group when group add/delete Jike Song
2016-11-30 17:02   ` Alex Williamson [this message]
2016-12-01  2:47     ` Jike Song
2016-11-29  3:02 ` [v7 0/3] plumb kvm/vfio to notify kvm:group attach/detach Jike Song
2016-11-30 17:06   ` Alex Williamson
2016-12-01  2:27     ` Jike Song
2016-12-01  4:42       ` Kirti Wankhede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161130100239.6689cf7f@t450s.home \
    --to=alex.williamson@redhat.com \
    --cc=cjia@nvidia.com \
    --cc=guangrong.xiao@linux.intel.com \
    --cc=jike.song@intel.com \
    --cc=kevin.tian@intel.com \
    --cc=kvm@vger.kernel.org \
    --cc=kwankhede@nvidia.com \
    --cc=pbonzini@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.