diff mbox series

[v2,2/7] iommufd: Add iommufd_lock_obj() around the auto-domains hwpts

Message ID 2-v2-406f7ac07936+6a-iommufd_hwpt_jgg@nvidia.com (mailing list archive)
State Accepted
Commit 7214c1c85fe464929e9c32f90f81d65cd44b8ff6
Headers show
Series Revise the hwpt lifetime model | expand

Commit Message

Jason Gunthorpe Feb. 22, 2023, 9:02 p.m. UTC
A later patch will require this locking - currently under the ioas mutex
the hwpt can not have a 0 reference and be on the list.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 drivers/iommu/iommufd/device.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Tian, Kevin Feb. 24, 2023, 6:12 a.m. UTC | #1
> From: Jason Gunthorpe <jgg@nvidia.com>
> Sent: Thursday, February 23, 2023 5:03 AM
> 
> A later patch will require this locking - currently under the ioas mutex
> the hwpt can not have a 0 reference and be on the list.
> 
> Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

Reviewed-by: Kevin Tian <kevin.tian@intel.com>
diff mbox series

Patch

diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c
index dcfaf6567420e0..0a80ff7b2e0d79 100644
--- a/drivers/iommu/iommufd/device.c
+++ b/drivers/iommu/iommufd/device.c
@@ -282,7 +282,10 @@  static int iommufd_device_auto_get_domain(struct iommufd_device *idev,
 		if (!hwpt->auto_domain)
 			continue;
 
+		if (!iommufd_lock_obj(&hwpt->obj))
+			continue;
 		rc = iommufd_device_do_attach(idev, hwpt);
+		iommufd_put_object(&hwpt->obj);
 
 		/*
 		 * -EINVAL means the domain is incompatible with the device.