[PATCH v13 01/12] iommu: Pass in NULL old_domain when attaching a deferred device

Jason Gunthorpe jgg at nvidia.com
Wed Dec 2 09:31:41 PST 2026


> When a driver defers the default domain attachment of a device, the IOMMU
> core skips the attachment in __iommu_device_set_domain() but still sets the
> group->domain to the group->default_domain. Since the driver has not seen
> this attachment, iommu_deferred_attach() later finalizes it by passing in a
> NULL old_domain.
> 
> However, two other paths pass in the group->domain as the old_domain for a
> deferred device:
>  - __iommu_device_set_domain(), when attaching a non-default domain
>  - pci_dev_reset_iommu_prepare(), when attaching the group->blocking_domain
> 
> A driver uses the given old_domain to clean up the device's state in that
> domain. However, a deferred device has no state in the group->domain, since
> the driver has never attached the device to it. So, the driver would end up
> cleaning up a state that does not exist.
> 
> In practice, the first path is unlikely, since it requires the device to be
> attached to a non-default domain before its first DMA mapping. The second
> path is reachable when an ATS supported device gets reset before its first
> DMA mapping.
> 
> Pass in a NULL old_domain on both paths for a deferred device.
> 
> Note that pci_dev_reset_iommu_done() can keep using the group->domain for
> recovering the device, because pci_dev_reset_iommu_prepare() has unset the
> attach_deferred flag.
> 
> This will be needed for the SMMUv3 driver to support the kdump mode, where
> it relies on the given old_domain to unreference the invalidation entries
> of a master.
> 
> Signed-off-by: Nicolin Chen <nicolinc at nvidia.com>
> ---
>  drivers/iommu/iommu.c | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)

This makes alot of sense, I would have mentioned that the initial
attach already passes NULL, ie:

	if (group->domain) {
		ret = __iommu_device_set_domain(group, dev, group->domain, NULL,
						0);
		if (ret)

So there is no risk that a driver will have a problem with it.

Reviewed-by: Jason Gunthorpe <jgg at nvidia.com>

-- 
Jason



More information about the linux-arm-kernel mailing list