From: Jean-Philippe Brucker <jpb@kernel.org>
To: Cam Miller <cam@linux.ibm.com>
Cc: joro@8bytes.org, will@kernel.org, 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: Re: [RFC linux v2 0/3] iommu/virtio: Fix remove
Date: Mon, 30 Nov 2026 13:03:39 +0000 [thread overview]
Message-ID: <20261130130339.GA2216821@myrica> (raw)
In-Reply-To: <20261129164704.279261-1-cam@linux.ibm.com>
On Sun, Nov 29, 2026 at 11:47:01AM -0500, Cam Miller wrote:
> This series allows for hot-removing a virtio-iommu device via sysfs to
> succeed, by fixing 2 separate day 1 bugs.
>
> Patch 1 addresses a NULL pointer dereference due to a pair of
> out-of-order calls. Patch 2 prevents driver unbind via
> suppress_bind_attrs. Patch 3 unbinds IOMMU endpoint drivers before
> removing the IOMMU.
Reviewed-by: Jean-Philippe Brucker <jpb@kernel.org>
Thank you!
>
>
> Change log
> ==========
>
> v1 -> v2
> --------
> - Failed device_link_add() call will now lead to return on -ENODEV.
>
>
> Bugs
> ====
>
> Before patch 1, attempting a removal caused the following kernel crash
> on x86.
>
> 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 ---
>
> After resolving this bug with patch 1, a 2nd bug was exposed. Live
> endpoints remain active after unregistering the IOMMU. All their IOVAs
> become stale, causing page faults.
>
> The following warning catches this case.
>
> WARNING: drivers/iommu/iommu.c:743 at __iommu_group_free_device.constprop.0+0xb9/0xe0, CPU#1:
> bash/1250
> --- snip ---
> Call Trace:
> <TASK>
> __iommu_group_remove_device+0x95/0xe0
> ? __pfx_remove_iommu_group+0x10/0x10
> remove_iommu_group+0x39/0x60
> bus_for_each_dev+0x85/0xd0
> iommu_device_unregister+0x3d/0xb0
> viommu_remove+0x1d/0x60
> --- snip ---
>
> As a consequence, endpoint drivers attempting IO hang.
>
> igb 0000:01:00.0 enp1s0: NETDEV WATCHDOG: CPU: 5: transmit queue 2 timed out 5120 ms
> igb 0000:01:00.0 enp1s0: Reset adapter
> igb 0000:01:00.0 enp1s0: igb: enp1s0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX/TX
> clocksource: Watchdog remote CPU 7 read timed out
> igb 0000:01:00.0: Detected Tx Unit Hang
>
> Shutting down the system at this point leads to a kernel panic.
>
> BUG: unable to handle page fault for address: ffffee9903ffffc0
> --- snip ---
> RIP: 0010:dma_free_contiguous+0x59/0xb0
> --- snip ---
> Call Trace:
> <TASK>
> __igb_close.isra.0+0xb0/0x1c0 [igb]
> __igb_shutdown.isra.0+0x27a/0x310 [igb]
> igb_shutdown+0x2f/0x90 [igb]
> pci_device_shutdown+0x35/0x60
> device_shutdown+0x118/0x1b0
> kernel_power_off+0x35/0x80
> __do_sys_reboot+0x1d4/0x240
> do_syscall_64+0xbe/0x470
> ? vfs_writev+0xe8/0x3c0
> ? do_writev+0x7f/0x110
> ? do_writev+0x7f/0x110
> ? do_syscall_64+0xfa/0x470
> ? do_user_addr_fault+0x2ae/0x7b0
> ? irqentry_exit+0x40/0x730
> ? do_syscall_64+0x37/0x470
> ? __irq_exit_rcu+0x4c/0x110
> entry_SYSCALL_64_after_hwframe+0x76/0x7e
> --- snip ---
>
> Patch 3 resolves this bug using device links. These links ensure that
> the IOMMU endpoints get unbound before viommu_remove() runs.
>
>
> Testing
> =======
>
> I tested this patch using a libvirt-managed q35 qemu machine (i.e. x86 guest).
>
> I used default-bus-bypass-iommu=true and placed root disk (as well as
> other devices) on the default bus. This way, access to the root
> filesystem was not affected by the IOMMU removal.
>
> Libvirt domain XML:
>
> <domain type='kvm'
> xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'>
> <os><type arch='x86_64' machine='pc-q35-9.2'>hvm</type></os>
> ...
> <!-- second host bridge, not bypassed -->
> <controller type='pci' index='15' model='pcie-expander-bus'>
> <target busNr='32'/>
> </controller>
> <controller type='pci' index='16' model='pcie-root-port'>
> <address type='pci' bus='0x0f' slot='0x00' function='0x0'/>
> </controller>
> <!-- test endpoint, behind the root port -->
> <interface type='user'>
> <model type='igb'/>
> <address type='pci' bus='0x10' slot='0x00' function='0x0'/>
> </interface>
> <iommu model='virtio'>
> <address type='pci' bus='0x00' slot='0x04' function='0x0'/>
> </iommu>
> <qemu:commandline>
> <qemu:arg value='-machine'/>
> <qemu:arg value='default-bus-bypass-iommu=true'/>
> </qemu:commandline>
> </domain>
>
> Guest topology (abridged `lspci -tv`):
>
> -+-[0000:00]-+-00.0 Intel Corporation 82G33/G31/P35/P31 Express DRAM Controller
> | +-01.0 Red Hat, Inc. QEMU PCIe Expander bridge
> | +-02.3-[04]----00.0 Red Hat, Inc. Virtio 1.0 block device <- root disk
> | +-04.0 Red Hat, Inc. Virtio 1.0 IOMMU
> | ...
> \-[0000:20]---00.0-[21]----00.0 Intel Corporation 82576 Gigabit Network Connection
>
> Device links created:
>
> # ls /sys/class/devlink/ | grep virtio0
> virtio:virtio0--pci:0000:20:00.0
> virtio:virtio0--pci:0000:21:00.0
> # cat /sys/class/devlink/virtio:virtio0--pci:0000:21:00.0/status
> active
>
> Removal:
>
> # echo 1 > /sys/bus/pci/devices/0000:00:04.0/remove
> [ 146.791872] igb 0000:21:00.0: removed PHC on enp33s0
> [ 147.538710] virtio_iommu virtio0: device removed
>
> I also tested removal with DMA in-flight. I removed the IOMMU while running
> iperf3 from the guest to the host (SLIRP backend).
>
> # iperf3 -c 10.0.2.2 -t 120 -i 5 &
> ...
> [ 5] 10.01-15.01 sec 109 MBytes 183 Mbits/sec 0 68.4 KBytes
> [ 5] 15.01-20.01 sec 110 MBytes 184 Mbits/sec 0 68.4 KBytes
> # echo 1 > /sys/bus/pci/devices/0000:00:04.0/remove
> [ 5] 30.00-35.01 sec 65.1 MBytes 109 Mbits/sec 1 1.43 KBytes
> [ 5] 35.01-40.01 sec 0.00 Bytes 0.00 bits/sec 0 1.43 KBytes
> ...
> # dmesg | tail -n4
> [ 234.227669] clocksource: Watchdog remote CPU 15 read timed out
> [ 260.920027] igb 0000:21:00.0: removed PHC on enp33s0
> [ 261.578453] virtio_iommu virtio0: device removed
>
> The transfer stops because the NIC is unbound, as expected.
>
> Rebinding an endpoint after the removal succeeds.
>
> # echo 0000:21:00.0 > /sys/bus/pci/drivers/igb/bind
> igb 0000:21:00.0: deferred probe timeout, ignoring dependency
> igb 0000:21:00.0: added PHC on eth0
> igb 0000:21:00.0 enp33s0: igb: enp33s0 NIC Link is Up 1000 Mbps Full Duplex
>
> Rebooting after removal completes cleanly, resolving the oops. After
> reboot, the links are active again and everything works.
>
>
> Thank you
> =========
>
>
> Cam Miller (3):
> iommu/virtio: Fix out-of-order teardown in viommu_remove()
> iommu/virtio: Prevent driver unbind via sysfs
> iommu/virtio: Add device links for endpoints
>
> drivers/iommu/virtio-iommu.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> --
> 2.54.0
>
prev parent reply other threads:[~2026-11-30 13:03 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-29 16:47 [RFC linux v2 0/3] iommu/virtio: Fix remove Cam Miller
2026-11-29 16:47 ` [RFC linux v2 1/3] iommu/virtio: Fix out-of-order teardown in viommu_remove() Cam Miller
2026-11-30 12:51 ` Cam Miller
2026-11-29 16:47 ` [RFC linux v2 2/3] iommu/virtio: Prevent driver unbind via sysfs Cam Miller
2026-11-29 16:47 ` [RFC linux v2 3/3] iommu/virtio: Add device links for endpoints Cam Miller
2026-11-29 16:52 ` [RFC linux v2 0/3] iommu/virtio: Fix remove sashiko-bot
2026-11-30 13:03 ` Jean-Philippe Brucker [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=20261130130339.GA2216821@myrica \
--to=jpb@kernel.org \
--cc=cam@linux.ibm.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.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