[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v13 04/22] vfio: Common function to increment contai
From: |
Kirti Wankhede |
Subject: |
[Qemu-devel] [PATCH v13 04/22] vfio: Common function to increment container_users |
Date: |
Tue, 15 Nov 2016 20:59:47 +0530 |
This change rearrange functions to have common function to increment
container_users
Signed-off-by: Kirti Wankhede <address@hidden>
Signed-off-by: Neo Jia <address@hidden>
Reviewed-by: Jike Song <address@hidden>
Change-Id: I8bdeb352bc8439b107ffd519480fd4dc238677f2
---
drivers/vfio/vfio.c | 34 +++++++++++++++++++++-------------
1 file changed, 21 insertions(+), 13 deletions(-)
diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
index 23bc86c1d05d..2e83bdf007fe 100644
--- a/drivers/vfio/vfio.c
+++ b/drivers/vfio/vfio.c
@@ -1385,6 +1385,23 @@ static bool vfio_group_viable(struct vfio_group *group)
group, vfio_dev_viable) == 0);
}
+static int vfio_group_add_container_user(struct vfio_group *group)
+{
+ if (!atomic_inc_not_zero(&group->container_users))
+ return -EINVAL;
+
+ if (group->noiommu) {
+ atomic_dec(&group->container_users);
+ return -EPERM;
+ }
+ if (!group->container->iommu_driver || !vfio_group_viable(group)) {
+ atomic_dec(&group->container_users);
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
static const struct file_operations vfio_device_fops;
static int vfio_group_get_device_fd(struct vfio_group *group, char *buf)
@@ -1694,23 +1711,14 @@ static const struct file_operations vfio_device_fops = {
struct vfio_group *vfio_group_get_external_user(struct file *filep)
{
struct vfio_group *group = filep->private_data;
+ int ret;
if (filep->f_op != &vfio_group_fops)
return ERR_PTR(-EINVAL);
- if (!atomic_inc_not_zero(&group->container_users))
- return ERR_PTR(-EINVAL);
-
- if (group->noiommu) {
- atomic_dec(&group->container_users);
- return ERR_PTR(-EPERM);
- }
-
- if (!group->container->iommu_driver ||
- !vfio_group_viable(group)) {
- atomic_dec(&group->container_users);
- return ERR_PTR(-EINVAL);
- }
+ ret = vfio_group_add_container_user(group);
+ if (ret)
+ return ERR_PTR(ret);
vfio_group_get(group);
--
2.7.0
- [Qemu-devel] [PATCH v13 00/22] Add Mediated device support, Kirti Wankhede, 2016/11/15
- [Qemu-devel] [PATCH v13 01/22] vfio: Mediated device Core driver, Kirti Wankhede, 2016/11/15
- [Qemu-devel] [PATCH v13 03/22] vfio: Rearrange functions to get vfio_group from dev, Kirti Wankhede, 2016/11/15
- [Qemu-devel] [PATCH v13 02/22] vfio: VFIO based driver for Mediated devices, Kirti Wankhede, 2016/11/15
- [Qemu-devel] [PATCH v13 04/22] vfio: Common function to increment container_users,
Kirti Wankhede <=
- [Qemu-devel] [PATCH v13 05/22] vfio iommu: Added pin and unpin callback functions to vfio_iommu_driver_ops, Kirti Wankhede, 2016/11/15
- [Qemu-devel] [PATCH v13 06/22] vfio iommu type1: Update arguments of vfio_lock_acct, Kirti Wankhede, 2016/11/15
- [Qemu-devel] [PATCH v13 08/22] vfio iommu type1: Add find_iommu_group() function, Kirti Wankhede, 2016/11/15
- [Qemu-devel] [PATCH v13 07/22] vfio iommu type1: Update argument of vaddr_get_pfn(), Kirti Wankhede, 2016/11/15
- [Qemu-devel] [PATCH v13 09/22] vfio iommu type1: Add task structure to vfio_dma, Kirti Wankhede, 2016/11/15
- [Qemu-devel] [PATCH v13 10/22] vfio iommu type1: Add support for mediated devices, Kirti Wankhede, 2016/11/15