On Tue, Feb 11, 2025 at 02:16:20PM -0400, Jason Gunthorpe wrote: > On Sat, Feb 08, 2025 at 01:02:39AM -0800, Nicolin Chen wrote: > > > +static struct iommufd_attach_handle * > > +iommu_group_get_iommufd_handle(struct iommu_group *group) > > +{ > > + struct iommu_attach_handle *handle; > > + > > + handle = iommu_attach_handle_get(group, IOMMU_NO_PASID, 0); > > + if (IS_ERR(handle)) > > + return NULL; > > + return to_iommufd_handle(handle); > > +} > > + > > +/* > > + * Called by the irq code if the platform translates the MSI address through the > > + * IOMMU. msi_addr is the physical address of the MSI page. iommufd will > > + * allocate a fd global iova for the physical page that is the same on all > > + * domains and devices. > > + */ > > +#ifdef CONFIG_IRQ_MSI_IOMMU > > +int iommufd_sw_msi(struct iommu_domain *domain, struct msi_desc *desc, > > + phys_addr_t msi_addr) > > +{ > > + struct device *dev = msi_desc_to_dev(desc); > > + struct iommufd_hwpt_paging *hwpt_paging; > > + struct iommufd_attach_handle *handle; > > + struct iommufd_sw_msi_map *msi_map; > > + struct iommufd_ctx *ictx; > > + unsigned long iova; > > + int rc; > > + > > + handle = iommu_group_get_iommufd_handle(dev->iommu_group); > > + if (!handle) > > + return 0; > > I think you should open code this and leave the other function > alone. The locking rules are different here. > > iommufd_device_get_attach_handle() should be locked under the > igroup->lock > > While in this context we are locked under the iommu core group mutex. > > A comment will help > > /* > * It is safe to call iommu_attach_handle_get() here because the iommu > * core code invokes this under the group mutex which also prevents any > * change of the attach handle for the duration of this function. > */ > iommu_group_mutex_assert(dev); Ack. I reverted that part and added this piece. Thanks Nicolin