[RFC linux v1 3/3] iommu/virtio: Add device links for endpoints
From: Cam Miller
Date: Tue Nov 24 2026 - 10:55:16 EST
Make each endpoint a consumer of the virtio-iommu device, so that the
driver core unbinds each endpoint driver before viommu_remove() runs.
Before this change, removing a virtio-iommu (for example via "echo 1 >
/sys/bus/pci/devices/<dev>/remove") tears down the IOMMU groups of all
its endpoints while their drivers are still bound. The endpoints keep
stale IOVAs and their later dma_free_contiguous() leads to WARNs in
__iommu_group_free_device(), endpoint IO hanging, and crash at shutdown.
Make each endpoint a consumer of the viommu with device_link_add(), as
arm-smmu and other IOMMU drivers do. The driver core then unbinds the
endpoint drivers before viommu_remove() runs, so that their DMA teardown
will still see an intact domain.
Fixes: edcd69ab9a32 ("iommu: Add virtio-iommu driver")
Suggested-by: Jean-Philippe Brucker <jpb@xxxxxxxxxx>
Signed-off-by: Cam Miller <cam@xxxxxxxxxxxxx>
---
drivers/iommu/virtio-iommu.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index dd10c3e98a3d..a84a653f269e 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -1044,6 +1044,9 @@ static struct iommu_device *viommu_probe_device(struct device *dev)
goto err_free_dev;
}
+ if (!device_link_add(dev, viommu->dev, DL_FLAG_AUTOREMOVE_SUPPLIER))
+ dev_dbg(dev, "could not add device link\n");
+
return &viommu->iommu;
err_free_dev:
--
2.54.0