Re: [PATCH v13 01/12] iommu: Pass in NULL old_domain when attaching a deferred device
From: Baolu Lu
Date: Sat Dec 05 2026 - 02:42:36 EST
On 11/18/2026 3:21 AM, Nicolin Chen wrote:
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@xxxxxxxxxx>
---
drivers/iommu/iommu.c | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
Reviewed-by: Lu Baolu <baolu.lu@xxxxxxxxxxxxxxx>