Skip to content

Commit ba1de6c

Browse files
yiliu1765jgunthorpe
authored andcommitted
iommufd/device: Add helper to detect the first attach of a group
The existing code detects the first attach by checking the igroup->device_list. However, the igroup->hwpt can also be used to detect the first attach. In future modifications, it is better to check the igroup->hwpt instead of the device_list. To improve readbility and also prepare for further modifications on this part, this adds a helper for it. Link: https://patch.msgid.link/r/[email protected] Reviewed-by: Jason Gunthorpe <[email protected]> Reviewed-by: Lu Baolu <[email protected]> Reviewed-by: Nicolin Chen <[email protected]> Signed-off-by: Yi Liu <[email protected]> Tested-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 2eaa7f8 commit ba1de6c

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

drivers/iommu/iommufd/device.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,13 @@ iommufd_group_setup_msi(struct iommufd_group *igroup,
329329
}
330330
#endif
331331

332+
static bool
333+
iommufd_group_first_attach(struct iommufd_group *igroup, ioasid_t pasid)
334+
{
335+
lockdep_assert_held(&igroup->lock);
336+
return !igroup->hwpt;
337+
}
338+
332339
static int
333340
iommufd_device_attach_reserved_iova(struct iommufd_device *idev,
334341
struct iommufd_hwpt_paging *hwpt_paging)
@@ -344,7 +351,7 @@ iommufd_device_attach_reserved_iova(struct iommufd_device *idev,
344351
if (rc)
345352
return rc;
346353

347-
if (list_empty(&igroup->device_list)) {
354+
if (iommufd_group_first_attach(igroup, IOMMU_NO_PASID)) {
348355
rc = iommufd_group_setup_msi(igroup, hwpt_paging);
349356
if (rc) {
350357
iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt,
@@ -508,7 +515,7 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt,
508515
* reserved regions are only updated during individual device
509516
* attachment.
510517
*/
511-
if (list_empty(&igroup->device_list)) {
518+
if (iommufd_group_first_attach(igroup, pasid)) {
512519
rc = iommufd_hwpt_attach_device(hwpt, idev, pasid);
513520
if (rc)
514521
goto err_unresv;

0 commit comments

Comments
 (0)