Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <jgg@nvidia.com>
Reviewed-by: Lu Baolu <baolu.lu@linux.intel.com>
Reviewed-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Tested-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>

authored by

Yi Liu and committed by
Jason Gunthorpe
ba1de6cd 2eaa7f84

+9 -2
+9 -2
drivers/iommu/iommufd/device.c
··· 329 329 } 330 330 #endif 331 331 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 + 332 339 static int 333 340 iommufd_device_attach_reserved_iova(struct iommufd_device *idev, 334 341 struct iommufd_hwpt_paging *hwpt_paging) ··· 351 344 if (rc) 352 345 return rc; 353 346 354 - if (list_empty(&igroup->device_list)) { 347 + if (iommufd_group_first_attach(igroup, IOMMU_NO_PASID)) { 355 348 rc = iommufd_group_setup_msi(igroup, hwpt_paging); 356 349 if (rc) { 357 350 iopt_remove_reserved_iova(&hwpt_paging->ioas->iopt, ··· 515 508 * reserved regions are only updated during individual device 516 509 * attachment. 517 510 */ 518 - if (list_empty(&igroup->device_list)) { 511 + if (iommufd_group_first_attach(igroup, pasid)) { 519 512 rc = iommufd_hwpt_attach_device(hwpt, idev, pasid); 520 513 if (rc) 521 514 goto err_unresv;