lkml.org 
[lkml]   [2023]   [Oct]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
    Patch in this message
    /
    From
    Subject[RFC 2/7] iommufd: Introduce iommufd_alloc_device()
    Date
    From: Kevin Tian <kevin.tian@intel.com>

    This abstracts the common logic used in the iommufd_device_bind() and the
    later iommufd_device_bind_pasid() to be helper.

    Signed-off-by: Kevin Tian <kevin.tian@intel.com>
    Signed-off-by: Yi Liu <yi.l.liu@intel.com>
    ---
    drivers/iommu/iommufd/device.c | 34 +++++++++++++++++++++++-----------
    1 file changed, 23 insertions(+), 11 deletions(-)

    diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
    index ca3919fecc89..9dd76d92b7f6 100644
    --- a/drivers/iommu/iommufd/device.c
    +++ b/drivers/iommu/iommufd/device.c
    @@ -164,6 +164,27 @@ static int iommufd_allow_unsafe_interrupts(struct device *dev)
    return 0;
    }

    +static struct iommufd_device *iommufd_alloc_device(struct iommufd_ctx *ictx,
    + struct device *dev)
    +{
    + struct iommufd_device *idev;
    +
    + idev = iommufd_object_alloc(ictx, idev, IOMMUFD_OBJ_DEVICE);
    + if (IS_ERR(idev))
    + return idev;
    + idev->ictx = ictx;
    + if (!iommufd_selftest_is_mock_dev(dev))
    + iommufd_ctx_get(ictx);
    + idev->dev = dev;
    + idev->enforce_cache_coherency =
    + device_iommu_capable(dev, IOMMU_CAP_ENFORCE_CACHE_COHERENCY);
    + xa_init(&idev->pasid_hwpts);
    +
    + /* The calling driver is a user until iommufd_device_unbind() */
    + refcount_inc(&idev->obj.users);
    + return idev;
    +}
    +
    /**
    * iommufd_device_bind - Bind a physical device to an iommu fd
    * @ictx: iommufd file descriptor
    @@ -209,24 +230,15 @@ struct iommufd_device *iommufd_device_bind(struct iommufd_ctx *ictx,
    if (rc)
    goto out_group_put;

    - idev = iommufd_object_alloc(ictx, idev, IOMMUFD_OBJ_DEVICE);
    + idev = iommufd_alloc_device(ictx, dev);
    if (IS_ERR(idev)) {
    rc = PTR_ERR(idev);
    goto out_release_owner;
    }
    - idev->ictx = ictx;
    - if (!iommufd_selftest_is_mock_dev(dev))
    - iommufd_ctx_get(ictx);
    - idev->dev = dev;
    - idev->enforce_cache_coherency =
    - device_iommu_capable(dev, IOMMU_CAP_ENFORCE_CACHE_COHERENCY);
    - /* The calling driver is a user until iommufd_device_unbind() */
    - refcount_inc(&idev->obj.users);
    +
    /* igroup refcount moves into iommufd_device */
    idev->igroup = igroup;

    - xa_init(&idev->pasid_hwpts);
    -
    /*
    * If the caller fails after this success it must call
    * iommufd_unbind_device() which is safe since we hold this refcount.
    --
    2.34.1
    \
     
     \ /
      Last update: 2023-10-09 10:53    [W:2.689 / U:1.812 seconds]
    ©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site