All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jike Song <jike.song@intel.com>
To: pbonzini@redhat.com, alex.williamson@redhat.com,
	guangrong.xiao@linux.intel.com
Cc: kwankhede@nvidia.com, cjia@nvidia.com, kevin.tian@intel.com,
	jike.song@intel.com, kvm@vger.kernel.org
Subject: [v3 4/5] vfio: implement APIs to set/put kvm to/from vfio group
Date: Mon, 31 Oct 2016 14:35:05 +0800	[thread overview]
Message-ID: <1477895706-22824-5-git-send-email-jike.song@intel.com> (raw)
In-Reply-To: <1477895706-22824-1-git-send-email-jike.song@intel.com>

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;
+
+	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);
+
 /**
  * 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
  */
-- 
1.9.1


  parent reply	other threads:[~2016-10-31  6:40 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 ` Jike Song [this message]
2016-11-07 18:04   ` [v3 4/5] vfio: implement APIs to set/put kvm to/from vfio group Alex Williamson
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=1477895706-22824-5-git-send-email-jike.song@intel.com \
    --to=jike.song@intel.com \
    --cc=alex.williamson@redhat.com \
    --cc=cjia@nvidia.com \
    --cc=guangrong.xiao@linux.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.