Re: [RFC linux v1 3/3] iommu/virtio: Add device links for endpoints

From: Niklas Schnelle

Date: Wed Nov 25 2026 - 15:33:14 EST


On Tue, 2026-11-24 at 10:54 -0500, Cam Miller wrote:
> 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:

Looks good to me and like the unbind suppression is also already used
by other IOMMU drivers in this case e.g. arm-smmu in a similar fashion.

Reviewed-by: Niklas Schnelle <schnelle@xxxxxxxxxxxxx>

Thanks,
Niklas