From: Alex Williamson <alex.williamson@redhat.com>
To: Jike Song <jike.song@intel.com>
Cc: pbonzini@redhat.com, guangrong.xiao@linux.intel.com,
kwankhede@nvidia.com, cjia@nvidia.com, kevin.tian@intel.com,
kvm@vger.kernel.org
Subject: Re: [v3 4/5] vfio: implement APIs to set/put kvm to/from vfio group
Date: Mon, 7 Nov 2016 11:04:12 -0700 [thread overview]
Message-ID: <20161107110412.5db26fd4@t450s.home> (raw)
In-Reply-To: <1477895706-22824-5-git-send-email-jike.song@intel.com>
On Mon, 31 Oct 2016 14:35:05 +0800
Jike Song <jike.song@intel.com> wrote:
Patch title is "set/put" but there is no "put".
> A vfio_group may be or may not be attached to a KVM instance,
> if it is, the user of vfio_group might also want to know which
> KVM instance it is attached to, to utilize features provided
> by KVM. In VFIO there are already external APIs for KVM to
> get/put the vfio_group, by extending that, KVM can set or clear
> itself to/from the vfio_group, for external users to use.
>
> Signed-off-by: Jike Song <jike.song@intel.com>
> ---
> drivers/vfio/vfio.c | 30 ++++++++++++++++++++++++++++++
> include/linux/vfio.h | 4 ++++
> 2 files changed, 34 insertions(+)
>
> diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
> index e3e58e3..41611cc 100644
> --- a/drivers/vfio/vfio.c
> +++ b/drivers/vfio/vfio.c
> @@ -34,6 +34,7 @@
> #include <linux/uaccess.h>
> #include <linux/vfio.h>
> #include <linux/wait.h>
> +#include <linux/kvm_host.h>
>
> #define DRIVER_VERSION "0.3"
> #define DRIVER_AUTHOR "Alex Williamson <alex.williamson@redhat.com>"
> @@ -86,6 +87,10 @@ struct vfio_group {
> struct mutex unbound_lock;
> atomic_t opened;
> bool noiommu;
> + struct {
> + struct kvm *kvm;
> + struct mutex lock;
> + } udata;
> };
>
> struct vfio_device {
> @@ -333,6 +338,7 @@ static struct vfio_group *vfio_create_group(struct iommu_group *iommu_group)
> mutex_init(&group->device_lock);
> INIT_LIST_HEAD(&group->unbound_list);
> mutex_init(&group->unbound_lock);
> + mutex_init(&group->udata.lock);
> atomic_set(&group->container_users, 0);
> atomic_set(&group->opened, 0);
> group->iommu_group = iommu_group;
> @@ -1739,6 +1745,30 @@ long vfio_external_check_extension(struct vfio_group *group, unsigned long arg)
> }
> EXPORT_SYMBOL_GPL(vfio_external_check_extension);
>
> +void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm)
> +{
> + mutex_lock(&group->udata.lock);
> + group->udata.kvm = kvm;
> + mutex_unlock(&group->udata.lock);
> +}
> +EXPORT_SYMBOL_GPL(vfio_group_set_kvm);
> +
> +struct kvm *vfio_group_get_kvm(struct vfio_group *group)
> +{
> + struct kvm *kvm = NULL;
Unnecessary initialization.
> +
> + mutex_lock(&group->udata.lock);
> +
> + kvm = group->udata.kvm;
> + if (kvm)
> + kvm_get_kvm(kvm);
> +
> + mutex_unlock(&group->udata.lock);
> +
> + return kvm;
> +}
> +EXPORT_SYMBOL_GPL(vfio_group_get_kvm);
> +
How are kvm references acquired through vfio_group_get_kvm() ever
released? Can the reference become invalid? The caller may still hold
a kvm references, but couldn't the group be detached from one kvm
instance and re-attached to another? This seems like an ad-hoc
reference that doesn't impose any usage semantics on the caller or
release mechanism. Thanks,
Alex
> /**
> * Sub-module support
> */
> diff --git a/include/linux/vfio.h b/include/linux/vfio.h
> index ad9b857..3abd690 100644
> --- a/include/linux/vfio.h
> +++ b/include/linux/vfio.h
> @@ -95,6 +95,10 @@ extern long vfio_external_check_extension(struct vfio_group *group,
> extern struct vfio_group *vfio_group_get_from_dev(struct device *dev);
> extern void vfio_group_put(struct vfio_group *group);
>
> +struct kvm;
> +extern void vfio_group_set_kvm(struct vfio_group *group, struct kvm *kvm);
> +extern struct kvm *vfio_group_get_kvm(struct vfio_group *group);
> +
> /*
> * Sub-module helpers
> */
next prev parent reply other threads:[~2016-11-07 18:05 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-31 6:35 [v3 0/5] plumb kvm/vfio to allow getting kvm from vfio_group Jike Song
2016-10-31 6:35 ` [v3 1/5] vfio: Rearrange functions to get vfio_group from dev Jike Song
2016-10-31 6:35 ` [v3 2/5] vfio: export functions to get vfio_group from device and put it Jike Song
2016-10-31 6:35 ` [v3 3/5] KVM: move kvm_get_kvm to kvm_host.h Jike Song
2016-10-31 8:33 ` Paolo Bonzini
2016-10-31 6:35 ` [v3 4/5] vfio: implement APIs to set/put kvm to/from vfio group Jike Song
2016-11-07 18:04 ` Alex Williamson [this message]
2016-11-07 18:10 ` Paolo Bonzini
2016-11-07 18:28 ` Alex Williamson
2016-11-07 20:45 ` Paolo Bonzini
2016-11-09 12:49 ` Jike Song
2016-11-09 13:06 ` Xiao Guangrong
2016-11-09 13:31 ` Paolo Bonzini
2016-11-09 14:00 ` Xiao Guangrong
2016-11-09 14:28 ` Paolo Bonzini
2016-11-10 4:13 ` Jike Song
2016-11-09 17:53 ` Alex Williamson
2016-11-10 4:10 ` Jike Song
2016-11-10 6:04 ` Jike Song
2016-11-10 15:37 ` Alex Williamson
2016-11-11 7:29 ` Jike Song
2016-11-14 10:19 ` Jike Song
2016-11-14 15:52 ` Alex Williamson
2016-11-09 2:28 ` Jike Song
2016-11-09 2:52 ` Xiao Guangrong
2016-11-09 3:07 ` Jike Song
2016-10-31 6:35 ` [v3 5/5] KVM: set/clear kvm to/from vfio group during add/delete Jike Song
2016-10-31 8:33 ` Paolo Bonzini
2016-10-31 7:06 ` [v3 0/5] plumb kvm/vfio to allow getting kvm from vfio_group Xiao Guangrong
2016-10-31 7:24 ` Jike Song
2016-10-31 7:24 ` Xiao Guangrong
2016-10-31 7:30 ` Jike Song
2016-10-31 7:35 ` Xiao Guangrong
2016-11-02 1:06 ` Jike Song
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=20161107110412.5db26fd4@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).