Linux virtualization list
 help / color / mirror / Atom feed
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 1/3] iommu/virtio: Fix out-of-order teardown in viommu_remove()
Date: Tue, 24 Nov 2026 10:54:08 -0500	[thread overview]
Message-ID: <20261124155410.768743-2-cam@linux.ibm.com> (raw)
In-Reply-To: <20261124155410.768743-1-cam@linux.ibm.com>

Fix bug in viommu_remove() by swapping out-of-order IOMMU unregistration
and sysfs removal steps.

Other IOMMU drivers all call iommu_device_unregister() before
iommu_device_sysfs_remove(). Before this change, viommu_remove() had
incorrectly reversed this ordering, leading to the following kernel
oops.

  BUG: kernel NULL pointer dereference, address: 0000000000000030
  ...snip...
  RIP: 0010:sysfs_remove_link_from_group+0x10/0x40
  ...snip..
  Call Trace:
   <TASK>
  ...snip...
   ? sysfs_remove_link_from_group+0x10/0x40
   iommu_deinit_device+0x2a/0xe0
   __iommu_group_remove_device+0xb0/0xe0
   ? __pfx_remove_iommu_group+0x10/0x10
   remove_iommu_group+0x35/0x60
   bus_for_each_dev+0x83/0xd0
   iommu_device_unregister+0x3d/0xb0
   viommu_remove+0x25/0x60
   virtio_dev_remove+0x3c/0x90
  ...snip...

iommu_device_sysfs_remove() will set iommu->dev = NULL after tearing
down the corresponding sysfs entry. Then iommu_device_unregister() will
iterate over every endpoint device attached to the IOMMU and reference
the null iommu->dev pointer, specifically via call
sysfs_remove_link_from_group(&iommu->dev->kobj, ...).

Fixes: edcd69ab9a32 ("iommu: Add virtio-iommu driver")
Signed-off-by: Cam Miller <cam@linux.ibm.com>
---
 drivers/iommu/virtio-iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/virtio-iommu.c b/drivers/iommu/virtio-iommu.c
index 587fc13197f1..a08474eeed58 100644
--- a/drivers/iommu/virtio-iommu.c
+++ b/drivers/iommu/virtio-iommu.c
@@ -1254,8 +1254,8 @@ static void viommu_remove(struct virtio_device *vdev)
 {
 	struct viommu_dev *viommu = vdev->priv;
 
-	iommu_device_sysfs_remove(&viommu->iommu);
 	iommu_device_unregister(&viommu->iommu);
+	iommu_device_sysfs_remove(&viommu->iommu);
 
 	/* Stop all virtqueues */
 	virtio_reset_device(vdev);
-- 
2.54.0


  reply	other threads:[~2026-11-24 15:54 UTC|newest]

Thread overview: 5+ 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 ` Cam Miller [this message]
2026-11-24 15:54 ` [RFC linux v1 2/3] iommu/virtio: Prevent driver unbind via sysfs Cam Miller
2026-11-24 15:54 ` [RFC linux v1 3/3] iommu/virtio: Add device links for endpoints Cam Miller
2026-11-24 16:04 ` [RFC linux v1 0/3] iommu/virtio: fix remove sashiko-bot

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-2-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