From: Jiang Liu <liuj97@gmail.com>
To: Alex Williamson <alex.williamson@redhat.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jiang Liu <jiang.liu@huawei.com>,
Joerg Roedel <joerg.roedel@amd.com>,
Yinghai Lu <yinghai@kernel.org>,
kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
Hanjun Guo <guohanjun@huawei.com>
Subject: [RFC PATCH 5/6] VFIO: simplify IOMMU group notification handler
Date: Sat, 10 Nov 2012 21:57:18 +0800 [thread overview]
Message-ID: <1352555839-18961-5-git-send-email-jiang.liu@huawei.com> (raw)
In-Reply-To: <1352555839-18961-1-git-send-email-jiang.liu@huawei.com>
From: Jiang Liu <jiang.liu@huawei.com>
Now we have a way to reject binding unsafe drivers to devices belonging
to active VFIO groups, so we could simplify IOMMU group notification
handler to only handle IOMMU_GROUP_NOTIFY_SOLICIT_BINDING event.
Signed-off-by: Jiang Liu <jiang.liu@huawei.com>
---
drivers/vfio/vfio.c | 90 ++++-----------------------------------------------
1 file changed, 6 insertions(+), 84 deletions(-)
diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 02da980..18714b9 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -538,57 +538,6 @@ static int vfio_dev_viable(struct device *dev, void *data)
/**
* Async device support
*/
-static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
-{
- struct vfio_device *device;
-
- /* Do we already know about it? We shouldn't */
- device = vfio_group_get_device(group, dev);
- if (WARN_ON_ONCE(device)) {
- vfio_device_put(device);
- return 0;
- }
-
- /* Nothing to do for idle groups */
- if (!atomic_read(&group->container_users))
- return 0;
-
- WARN("Device %s added to live group %d!\n", dev_name(dev),
- iommu_group_id(group->iommu_group));
-
- return 0;
-}
-
-static int vfio_group_nb_del_dev(struct vfio_group *group, struct device *dev)
-{
- struct vfio_device *device;
-
- /*
- * Expect to fall out here. If a device was in use, it would
- * have been bound to a vfio sub-driver, which would have blocked
- * in .remove at vfio_del_group_dev. Sanity check that we no
- * longer track the device, so it's safe to remove.
- */
- device = vfio_group_get_device(group, dev);
- if (likely(!device))
- return 0;
-
- WARN("Device %s removed from live group %d!\n", dev_name(dev),
- iommu_group_id(group->iommu_group));
-
- vfio_device_put(device);
- return 0;
-}
-
-static int vfio_group_nb_verify(struct vfio_group *group, struct device *dev)
-{
- /* We don't care what happens when the group isn't in use */
- if (!atomic_read(&group->container_users))
- return 0;
-
- return vfio_dev_viable(dev, group);
-}
-
static int vfio_group_nb_solicit_binding(struct vfio_group *group,
struct device *dev)
{
@@ -614,6 +563,9 @@ static int vfio_iommu_group_notifier(struct notifier_block *nb,
struct vfio_group *group = container_of(nb, struct vfio_group, nb);
struct device *dev = data;
+ if (action != IOMMU_GROUP_NOTIFY_SOLICIT_BINDING)
+ return NOTIFY_DONE;
+
/*
* Need to go through a group_lock lookup to get a reference or
* we risk racing a group being removed. Leave a WARN_ON for
@@ -624,41 +576,11 @@ static int vfio_iommu_group_notifier(struct notifier_block *nb,
if (WARN_ON(!group))
return NOTIFY_OK;
- switch (action) {
- case IOMMU_GROUP_NOTIFY_ADD_DEVICE:
- vfio_group_nb_add_dev(group, dev);
- break;
- case IOMMU_GROUP_NOTIFY_DEL_DEVICE:
- vfio_group_nb_del_dev(group, dev);
- break;
- case IOMMU_GROUP_NOTIFY_SOLICIT_BINDING:
- if (vfio_group_nb_solicit_binding(group, dev))
- ret = notifier_from_errno(-EBUSY);
- break;
- case IOMMU_GROUP_NOTIFY_BIND_DRIVER:
- pr_debug("%s: Device %s, group %d binding to driver\n",
- __func__, dev_name(dev),
- iommu_group_id(group->iommu_group));
- break;
- case IOMMU_GROUP_NOTIFY_BOUND_DRIVER:
- pr_debug("%s: Device %s, group %d bound to driver %s\n",
- __func__, dev_name(dev),
- iommu_group_id(group->iommu_group), dev->driver->name);
- BUG_ON(vfio_group_nb_verify(group, dev));
- break;
- case IOMMU_GROUP_NOTIFY_UNBIND_DRIVER:
- pr_debug("%s: Device %s, group %d unbinding from driver %s\n",
- __func__, dev_name(dev),
- iommu_group_id(group->iommu_group), dev->driver->name);
- break;
- case IOMMU_GROUP_NOTIFY_UNBOUND_DRIVER:
- pr_debug("%s: Device %s, group %d unbound from driver\n",
- __func__, dev_name(dev),
- iommu_group_id(group->iommu_group));
- break;
- }
+ if (vfio_group_nb_solicit_binding(group, dev))
+ ret = notifier_from_errno(-EBUSY);
vfio_group_put(group);
+
return ret;
}
--
1.7.9.5
next prev parent reply other threads:[~2012-11-10 13:59 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-11-10 13:57 [RFC PATCH 1/6] driver core: add a bus notification to temporarily reject driver binding Jiang Liu
2012-11-10 13:57 ` [RFC PATCH 2/6] iommu: pass on BUS_NOTIFY_QUERY_BINDING to iommu group notifier clients Jiang Liu
2012-11-10 13:57 ` [RFC PATCH 3/6] VFIO: unregister IOMMU notifier on error recovery path Jiang Liu
2012-11-13 18:15 ` Alex Williamson
2012-11-10 13:57 ` [RFC PATCH 4/6] VFIO: reject binding driver to devices belonging to active VFIO groups Jiang Liu
2012-11-10 13:57 ` Jiang Liu [this message]
2012-11-10 13:57 ` [RFC PATCH 6/6] VFIO: use ACCESS_ONCE() to guard access to dev->driver Jiang Liu
2012-11-11 5:21 ` [RFC PATCH 1/6] driver core: add a bus notification to temporarily reject driver binding Greg Kroah-Hartman
2012-11-13 16:02 ` Jiang Liu
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=1352555839-18961-5-git-send-email-jiang.liu@huawei.com \
--to=liuj97@gmail.com \
--cc=alex.williamson@redhat.com \
--cc=gregkh@linuxfoundation.org \
--cc=guohanjun@huawei.com \
--cc=jiang.liu@huawei.com \
--cc=joerg.roedel@amd.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yinghai@kernel.org \
/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).