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 5/5] KVM: set/clear kvm to/from vfio group during add/delete
Date: Mon, 31 Oct 2016 14:35:06 +0800	[thread overview]
Message-ID: <1477895706-22824-6-git-send-email-jike.song@intel.com> (raw)
In-Reply-To: <1477895706-22824-1-git-send-email-jike.song@intel.com>

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@intel.com>
---
 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


  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 ` [v3 4/5] vfio: implement APIs to set/put kvm to/from vfio group Jike Song
2016-11-07 18:04   ` 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 ` Jike Song [this message]
2016-10-31  8:33   ` [v3 5/5] KVM: set/clear kvm to/from vfio group during add/delete 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-6-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.