From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=148.163.156.1 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795970849; b=KgzsQv2D+ZujLh4n1FERjVPNZcKOrbxMzCQUOdW6Ak+OkSVdEsJpULZRiTJzO7YDLgpX WmciujtcYMf5lFou+ObJbBr5Aoe5iEzjxwK9C130JzRYgsn1WgEzSgagRjfL8sZHa43od Zh3AkEQ/Yl8Yzzcnttexy/B+O5xWG0qD9L5l2OguIh2WSxei7cOPlRGEt9r1bdhdtwWut YMPamqZr0lEDgMfgu4FEi06k+A42mOIxMpQIcW7n1WVlHlyoQNgk9L6MMeC5zlc0JAFYb DSNICVPUsbPIbj+v7YmyIgeoaatt70NGv3pSmPXmHUhfxQkuurwnCWOyhg8RUsfWejg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795970849; h=DMARC-Filter:Received:DKIM-Signature:Received:Received:Received: Received:Received:Received:Received:From:To:Cc:Subject:Date: Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding: X-TM-AS-GCONF:X-Proofpoint-GUID:X-Proofpoint-Spam-Info: X-Proofpoint-Spam-Details-Enc:X-Authority-Analysis: X-Proofpoint-ORIG-GUID:X-Proofpoint-Virus-Version: X-Proofpoint-Spam-Details; bh=Y61URKZB/FfAtHytLRD2ZLSq8HpXdfMZ4XWRdgHAd/o=; b=nBGHEeXhaW6f4u8T/8RVse5tDLx20IUU7/GYhKt5Gj2w9bm2qwNYE5oH2IV0Vydbe212 RJ/79eCBpDazBmFpM7PsVe5fIddnAqtX+I3tnOKiPAjgeWnwkEBfxjCVh+X5SOFyD1dY+ 5WZwr2S4bujgUE0FTa/a91/Bwm0fqzLJHjGSPqIc/TpxHo2JkjACP8Q/O0sf21liJqFfD 8NfG25guQ7UJ7q4k5jogEAKNvUy8jIvvvmz+1lk7dfP5DUkhbg2JNZH96W3rtAZzDOCSj LeZXAl7w0Xdu1yHZRo6iPk/uzNjic03Xr4ZdmY1is/rZBoZu3+Hc3G+QcMnbkPbR9vA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.ibm.com; spf=pass smtp.mailfrom=linux.ibm.com; dkim=pass header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b="m/+BWS+Y"; arc=none smtp.remote-ip=148.163.156.1 Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B284606A696; Sun, 29 Nov 2026 16:47:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5B284606A696 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.ibm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=m/+BWS+Y Received: from pps.filterd (m0356517.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.11/8.18.1.11) with ESMTP id 6ATCo5nG364760; Sun, 29 Nov 2026 16:47:08 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:message-id:mime-version :subject:to; s=pp1; bh=Y61URKZB/FfAtHytLRD2ZLSq8HpXdfMZ4XWRdgHAd /o=; b=m/+BWS+Yiv1xXwWXo9x02aPQb7AOjDkaFMktxdZH8gKqFbiJdX1uCYc09 BUBbFlWWH3hQP050ij1w3rIhe9XALIoHeEhmrOUOF3uOShbUNHloa4v5YrQ0CA21 DCC3Ss3URrL9UWmVpBfK2gNAkvXlupkbg8hRbaPDMO9mzjQhfICu0Ctuh80cO9J7 h8NfYKTSl/gjhBsxc8Mj5WVrCppmCUuQuudcVmRyTXlLqEB3w7YIcr/5aqOgOX1A 1ViMvUQT7KmzNhdBKfwdgis76xN4ajrKM7o9JzdbC3oPa30DosRRf7mYcBvwNPG9 9apYFDWDGfTICcXLBXCx/1R9VTYaQ== Received: from ppma23.wdc07v.mail.ibm.com (5d.69.3da9.ip4.static.sl-reverse.com [169.61.105.93]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 4j7pp5mpfg-1 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Sun, 29 Nov 2026 16:47:07 +0000 (GMT) Received: from pps.filterd (ppma23.wdc07v.mail.ibm.com [127.0.0.1]) by ppma23.wdc07v.mail.ibm.com (8.18.1.11/8.18.1.11) with ESMTP id 6ATALRm63643108; Sun, 29 Nov 2026 16:47:06 GMT Received: from smtprelay03.dal12v.mail.ibm.com ([172.16.1.5]) by ppma23.wdc07v.mail.ibm.com (PPS) with ESMTPS id 4j8asghuvp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sun, 29 Nov 2026 16:47:06 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (smtpav03.dal12v.mail.ibm.com [10.241.53.102]) by smtprelay03.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 6ATGl5IO32375512 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sun, 29 Nov 2026 16:47:05 GMT Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9654958056; Sun, 29 Nov 2026 16:47:05 +0000 (GMT) Received: from smtpav03.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DD0BF5803F; Sun, 29 Nov 2026 16:47:04 +0000 (GMT) Received: from li-505aefcc-3230-11b2-a85c-f1e8e6da9e06.ibm.com.com (unknown [9.61.147.237]) by smtpav03.dal12v.mail.ibm.com (Postfix) with ESMTP; Sun, 29 Nov 2026 16:47:04 +0000 (GMT) From: Cam Miller 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 v2 0/3] iommu/virtio: Fix remove Date: Sun, 29 Nov 2026 11:47:01 -0500 Message-ID: <20261129164704.279261-1-cam@linux.ibm.com> X-Mailer: git-send-email 2.54.0 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TM-AS-GCONF: 00 X-Proofpoint-GUID: g6uYbj8c33h5GrxmFBBwXVG-nFha0mCz X-Proofpoint-Spam-Info: AW1haW4tMjYxMTI5MDA2NiBTYWx0ZWRfX6TOf9iFwlnrR e966vTaAeaxIbnIl3oKQPnZJgqmRbgvo851nVRI/IfU44alHZTOL+MNKNWRmDd2JcKbO84cdcOE RJ+gWcep4drdWtTQhDXWk3uDc7r134o= X-Proofpoint-Spam-Details-Enc: AW1haW4tMjYxMTI5MDA2NiBTYWx0ZWRfX1TyYW8i3Ncb/ 690pc7YIuxXLsvSt0zyjf2pgY1w50Ozq/69qK/2oed6w7n36sQCYqNNDxUvpbucPEA5CXbrR/a3 t9AfpBcMJ+y4T+FuQVE1vMc4geqjIO+r+78pOSoFVhD36Od+i/U8+Th9pgiPZe96XEpOktVVCTK iUTb1R0TLFYuJIkutBfqZv6pNNVSOc2muswUz4Y8oyulnh6i9W9kanWPvLvXjBdJwK+3eSpDAPP 9+AU1DBF7wTFhZcrBatSCGv/ccRB3PMACsfDGGAsMzTaS0GiStiKhrmhGSFunJuw3DaoEstOlbz LyG0Szc6cV3+YJyzBToicmKQc2zdX9VVVvgtrI5MTkxyuIRfgvqqxistyAn30EJGPQJcNerq/4w 2o5MnuWKmOOqAoDfdYIdRAcSgzeXLBzVM5JoW9Y2IjNWXvGXk1vBIJOVOsvrwdE4VOKxkyINGkK h0EaMkOmZ5iPwXkT84Q== X-Authority-Analysis: v=2.4 cv=Ae8kjHXG c=1 sm=1 tr=0 ts=6b0c570b cx=c_pps a=3Bg1Hr4SwmMryq2xdFQyZA==:117 a=3Bg1Hr4SwmMryq2xdFQyZA==:17 a=zJRp6_cAMcgA:10 a=VkNPw1HP01LnGYTKEx00:22 a=RnoormkPH1_aCDwRdu11:22 a=U7nrCbtTmkRpXpFmAIza:22 a=SqMvC5kiAAAA:8 a=Ad2mtP5WQe4-xdD8JBkA:9 a=_o8VnCo6Hb5Oqlm6Mk7M:22 X-Proofpoint-ORIG-GUID: g6uYbj8c33h5GrxmFBBwXVG-nFha0mCz X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1176,Hydra:6.1.138,FMLib:17.12.100.49 definitions=2026-11-29_03,2026-11-27_03,2025-10-01_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 spamscore=0 malwarescore=0 phishscore=0 lowpriorityscore=0 bulkscore=0 priorityscore=1501 impostorscore=0 clxscore=1015 classifier=typeunknown authscore=0 authtc= authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.22.0-2611040001 definitions=main-2611290066 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. 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: 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