diff options
author | Jason Gunthorpe <jgg@nvidia.com> | 2023-03-01 15:30:20 -0400 |
---|---|---|
committer | Jason Gunthorpe <jgg@nvidia.com> | 2023-03-06 10:51:57 -0400 |
commit | 342b9cab8e0cb6d35821ded00769a1172d171771 (patch) | |
tree | 42c068bd9373f0c64bdd9004f1b5e1f9df240f8a /drivers/iommu/iommufd | |
parent | 7214c1c85fe464929e9c32f90f81d65cd44b8ff6 (diff) |
iommufd: Consistently manage hwpt_item
This should be added immediately after every iopt_table_add_domain(), and
deleted after every iopt_table_remove_domain() under the ioas->mutex.
Tidy things to be consistent.
Link: https://lore.kernel.org/r/3-v3-ae9c2975a131+2e1e8-iommufd_hwpt_jgg@nvidia.com
Reviewed-by: Kevin Tian <kevin.tian@intel.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
Diffstat (limited to 'drivers/iommu/iommufd')
-rw-r--r-- | drivers/iommu/iommufd/device.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 0a80ff7b2e0d..adb73539b39c 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -243,6 +243,7 @@ static int iommufd_device_do_attach(struct iommufd_device *idev, hwpt->domain); if (rc) goto out_detach; + list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list); } } @@ -307,7 +308,6 @@ static int iommufd_device_auto_get_domain(struct iommufd_device *idev, rc = iommufd_device_do_attach(idev, hwpt); if (rc) goto out_abort; - list_add_tail(&hwpt->hwpt_item, &ioas->hwpt_list); mutex_unlock(&ioas->mutex); iommufd_object_finalize(idev->ictx, &hwpt->obj); @@ -753,6 +753,10 @@ iommufd_device_selftest_attach(struct iommufd_ctx *ictx, if (rc) goto out_hwpt; + mutex_lock(&ioas->mutex); + list_add_tail(&hwpt->hwpt_item, &hwpt->ioas->hwpt_list); + mutex_unlock(&ioas->mutex); + refcount_inc(&hwpt->obj.users); iommufd_object_finalize(ictx, &hwpt->obj); return hwpt; @@ -765,7 +769,10 @@ out_hwpt: void iommufd_device_selftest_detach(struct iommufd_ctx *ictx, struct iommufd_hw_pagetable *hwpt) { + mutex_lock(&hwpt->ioas->mutex); iopt_table_remove_domain(&hwpt->ioas->iopt, hwpt->domain); + list_del(&hwpt->hwpt_item); + mutex_unlock(&hwpt->ioas->mutex); refcount_dec(&hwpt->obj.users); } #endif |