From: Jike Song <jike.song@intel.com>
To: alex.williamson@redhat.com, pbonzini@redhat.com,
guangrong.xiao@linux.intel.com
Cc: kwankhede@nvidia.com, cjia@nvidia.com, kevin.tian@intel.com,
kvm@vger.kernel.org, jike.song@intel.com
Subject: [v4 3/3] kvm: notify vfio on attaching and detaching
Date: Tue, 15 Nov 2016 19:35:47 +0800 [thread overview]
Message-ID: <1479209747-5564-4-git-send-email-jike.song@intel.com> (raw)
In-Reply-To: <1479209747-5564-1-git-send-email-jike.song@intel.com>
Sometimes vfio needs to be aware when a group attaches to a KVM or
detaches from it. KVM already calls get/put method from vfio to
manipulate the reference, now it can notify vfio in a similar way.
Cc: Xiao Guangrong <guangrong.xiao@linux.intel.com>
Cc: Paolo Bonzini <pbonzini@redhat.com>
Cc: Alex Williamson <alex.williamson@redhat.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..104082b 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_attach_kvm(struct vfio_group *group, struct kvm *kvm)
+{
+ void (*fn)(struct vfio_group *, struct kvm *);
+
+ fn = symbol_get(vfio_group_notify);
+ if (!fn)
+ return;
+
+ fn(group, kvm);
+
+ symbol_put(vfio_group_notify);
+}
+
+static void kvm_vfio_group_detach_kvm(struct vfio_group *group, struct kvm *kvm)
+{
+ void (*fn)(struct vfio_group *, struct kvm *);
+
+ fn = symbol_get(vfio_group_notify);
+ if (!fn)
+ return;
+
+ fn(group, NULL);
+
+ symbol_put(vfio_group_notify);
+}
+
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_attach_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_detach_kvm(vfio_group, dev->kvm);
+
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_detach_kvm(kvg->vfio_group, dev->kvm);
kvm_vfio_group_put_external_user(kvg->vfio_group);
list_del(&kvg->node);
kfree(kvg);
--
1.9.1
prev parent reply other threads:[~2016-11-15 11:42 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-15 11:35 [v4 0/3] plumb kvm/vfio to notify kvm:group attaching/detaching Jike Song
2016-11-15 11:35 ` [v4 1/3] vfio: add vfio_group_notify support Jike Song
2016-11-15 23:11 ` Alex Williamson
2016-11-16 3:02 ` Jike Song
2016-11-15 11:35 ` [v4 2/3] vfio_register_notifier: also register on the group notifier Jike Song
2016-11-15 23:11 ` Alex Williamson
2016-11-16 3:01 ` Jike Song
2016-11-16 3:43 ` Alex Williamson
2016-11-16 9:14 ` Kirti Wankhede
2016-11-16 9:37 ` Jike Song
2016-11-16 10:44 ` Kirti Wankhede
2016-11-16 17:48 ` Alex Williamson
2016-11-16 19:12 ` Kirti Wankhede
2016-11-16 19:45 ` Alex Williamson
2016-11-17 5:24 ` Jike Song
2016-11-17 6:03 ` Alex Williamson
2016-11-17 6:27 ` Jike Song
2016-11-17 12:31 ` Jike Song
2016-11-17 16:22 ` Alex Williamson
2016-11-18 10:39 ` Jike Song
2016-11-15 11:35 ` Jike Song [this message]
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=1479209747-5564-4-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 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).