From: Cam Miller <cam@linux.ibm.com>
To: jpb@kernel.org, joro@8bytes.org, will@kernel.org
Cc: robin.murphy@arm.com, iommu@lists.linux.dev,
virtualization@lists.linux.dev, linux-kernel@vger.kernel.org,
schnelle@linux.ibm.com, mjrosato@linux.ibm.com
Subject: [RFC linux v1 3/3] iommu/virtio: Add device links for endpoints
Date: Tue, 24 Nov 2026 10:54:10 -0500 [thread overview]
Message-ID: <20261124155410.768743-4-cam@linux.ibm.com> (raw)
In-Reply-To: <20261124155410.768743-1-cam@linux.ibm.com>
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@kernel.org>
Signed-off-by: Cam Miller <cam@linux.ibm.com>
---
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
prev parent reply other threads:[~2026-11-24 15:54 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-24 15:54 [RFC linux v1 0/3] iommu/virtio: fix remove Cam Miller
2026-11-24 15:54 ` [RFC linux v1 1/3] iommu/virtio: Fix out-of-order teardown in viommu_remove() Cam Miller
2026-11-24 15:54 ` [RFC linux v1 2/3] iommu/virtio: Prevent driver unbind via sysfs Cam Miller
2026-11-24 15:54 ` Cam Miller [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261124155410.768743-4-cam@linux.ibm.com \
--to=cam@linux.ibm.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=jpb@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mjrosato@linux.ibm.com \
--cc=robin.murphy@arm.com \
--cc=schnelle@linux.ibm.com \
--cc=virtualization@lists.linux.dev \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®