From: Yi Liu Date: Fri, 21 Mar 2025 17:19:28 +0000 (-0700) Subject: iommufd/device: Add helper to detect the first attach of a group X-Git-Tag: v6.15-rc1~69^2~22 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ba1de6cd41d0654245864640b62ae45a1bc01bcd;p=thirdparty%2Flinux.git 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/20250321171940.7213-7-yi.l.liu@intel.com Reviewed-by: Jason Gunthorpe Reviewed-by: Lu Baolu Reviewed-by: Nicolin Chen Signed-off-by: Yi Liu Tested-by: Nicolin Chen Signed-off-by: Jason Gunthorpe --- diff --git a/drivers/iommu/iommufd/device.c b/drivers/iommu/iommufd/device.c index 15733b316b707..2cc3c12d301d6 100644 --- a/drivers/iommu/iommufd/device.c +++ b/drivers/iommu/iommufd/device.c @@ -329,6 +329,13 @@ iommufd_group_setup_msi(struct iommufd_group *igroup, } #endif +static bool +iommufd_group_first_attach(struct iommufd_group *igroup, ioasid_t pasid) +{ + lockdep_assert_held(&igroup->lock); + return !igroup->hwpt; +} + static int iommufd_device_attach_reserved_iova(struct iommufd_device *idev, struct iommufd_hwpt_paging *hwpt_paging) @@ -344,7 +351,7 @@ iommufd_device_attach_reserved_iova(struct iommufd_device *idev, if (rc) return rc; - if (list_empty(&igroup->device_list)) { + if (iommufd_group_first_attach(igroup, IOMMU_NO_PASID)) { rc = iommufd_group_setup_msi(igroup, hwpt_paging); if (rc) { iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, @@ -508,7 +515,7 @@ int iommufd_hw_pagetable_attach(struct iommufd_hw_pagetable *hwpt, * reserved regions are only updated during individual device * attachment. */ - if (list_empty(&igroup->device_list)) { + if (iommufd_group_first_attach(igroup, pasid)) { rc = iommufd_hwpt_attach_device(hwpt, idev, pasid); if (rc) goto err_unresv;