On Mon, Feb 17, 2025 at 03:00:46PM +0000, Robin Murphy wrote: > On 14/02/2025 8:14 pm, Jason Gunthorpe wrote: > > On Thu, Feb 13, 2025 at 11:49:00PM +0000, Robin Murphy wrote: > > > > > much just calling the same path twice. At client driver probe time, > > > dev->driver is obviously set; conversely at device_add(), or a > > > subsequent bus_iommu_probe(), any device waiting for an IOMMU really > > > > Could you put the dev->driver test into iommu_device_use_default_domain()? > > > > It looks like many of the cases are just guarding that call. > > > > > should *not* have a driver already, so we can use that as a condition to > > > disambiguate the two cases, and avoid recursing back into the IOMMU core > > > at the wrong times. > > > > Which sounds like this: > > > > > + mutex_unlock(&iommu_probe_device_lock); > > > + dev->bus->dma_configure(dev); > > > + mutex_lock(&iommu_probe_device_lock); > > > + } > > > > Shouldn't call iommu_device_use_default_domain() ? > > Semantically it shouldn't really be called at this stage, but it won't be > anyway since "to_<x>_driver(NULL)->driver_managed_dma" is not false - > trouble is it's also not true ;) That case in PCI I understood, but the other cases seemed like they would be OK, especially if group is NULL > > This is the test I mean, if iommu_group is set then > > dev->iommu->iommu_dev->ops is supposed to be valid too. It seems like > > it should be done earlier.. > > Yeah, looking at it now I'm really not sure why this ended up in this order > - I guess I was effectively adding the dma_configure() call to the front of > the existing iommu_fwspec_ops() check, and then I moved the lockdep_assert() > up to make more sense. But then the ops check probably should have been > after the group check to begin with, for much the same reasoning as above. > I'll sort that out for v2. I guess check it at the top and then check it again after re-locking. > > > + * And if we do now see any replay calls, they would indicate someone > > > + * misusing the dma_configure path outside bus code. > > > + */ > > > + if (dev_iommu_fwspec_get(dev) && dev->driver) > > > + dev_WARN(dev, "late IOMMU probe at driver bind, something fishy here!\n"); > > > > WARN_ON_ONCE or dump_stack() to get the stack trace out? > > Indeed, hence dev_WARN() (!= dev_warn()) Oh, I've never seen that variation before! Jason