From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796043788; b=QWOmfDbOtskQ6a/eWxCibTPEGg8iJ19Ccowv2nZw8/DEko4OHq1r/VkyOnP5Y1uuX0vW YE27ddHDElw5rYnJ0Y0BcwKFj9sGkcMTuwBkxxax+XcZ0Qut7SDQDrai6/KHRQl2RHPmq pvdEcwmCy44aiy13ej38HDITO68HABEZtnzRmSXze1K3azNXdvkXxlWUFKUVD5KCg0LMS IelvRpCzuEeRDnTxHbk9C6Y//CeAIojUB0xMsg6onDLzn2rxfRfJA5V7Lgrj3maOfjvaB f4JVj/WJHGebPG6LHenetb0y8ti4YIkFd3Nj6r1p3cw/WFxeyfrY6iTaoiruz6rMYvg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796043788; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=c76O/j3rxkYk5RgrInOt/ow2rfNPBHFRNUOLuglsFyE=; b=glXMUzstWDHppvtudDd1Fw/BqXyysGbe3Xf5cYhkq+7D9KxOZaOwc9tDRwSi5dm1HOoz hQ038wbfjIEI8dpAmnfFZV3vBMXKvRBWP3xH6u+AjJSwSXuYNv7hJF7Kl40vJ7NDKJVwB TZigKeFXJK/2VZQNpkB5ZcoZ5J/fkbTeSCrsj2dLMW2pBb2QH9mnq8fe0bOGogyxUglvV 72zruVpJu9uWnNdaeakRMTNHW1xDXtbg7yRA4sz0RhmqUdrW3Bq9yJO2XKD42cyAvMru9 BxW5OPZwbZ3Ldl3QPUIOjdpI4mhFOZ1lu4rXR7hYzXQRCKtH/MfPb1CPhgmAmeXo4rw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b="QnfhyKT/"; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2C290606A31C; Mon, 30 Nov 2026 13:03:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=QnfhyKT/ Received: by smtp.kernel.org (Postfix) with ESMTPSA id 95ECF1F00899; Mon, 30 Nov 2026 13:03:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796043787; bh=c76O/j3rxkYk5RgrInOt/ow2rfNPBHFRNUOLuglsFyE=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=QnfhyKT/q83KTGIVnrRdMenMuBqWf/+iRx8YRQONeDIP2q3x+r0qTiSsMAFihmqX8 +Io+BB7mUfnbqpHTU1j6VSo9Mkxb5wsO7rSVrjxkDMedsEcn7eeGNAPoETOUGQXOc1 kVp17M7lVbF/RU+Y+9NYG6WDAFtrEDCw4660Pq5ji8aduyMOphx1uU2JTfxa3cwJ1Q 9RqfOGQzk2Xk4QQp6MsGVzCPOFahD6CzqoEfhW40BZaZlg/RcDQdf9XUGAYtzEVoq1 HVYwAP7NdBD83mzxdOBP8dCQixwAOogJTcrIL59Au4TzvEgTbuOdiyT8wrAg/kilsX qsw20ICdQ8imA== Date: Mon, 30 Nov 2026 13:03:39 +0000 From: Jean-Philippe Brucker To: Cam Miller 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 Message-ID: <20261130130339.GA2216821@myrica> References: <20261129164704.279261-1-cam@linux.ibm.com> X-Mailing-List: virtualization@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 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: > > --- 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: > > __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: > > __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: > > xmlns:qemu='http://libvirt.org/schemas/domain/qemu/1.0'> > hvm > ... > > > > > >
> > > > >
> > >
> > > > > > > > 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 >