public inbox for linux-nvme@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH V1] nvme-pci: disable SR-IOV VFs on driver unbind
@ 2026-01-27  7:33 Qinyun Tan
  2026-01-27  8:48 ` Christoph Hellwig
  0 siblings, 1 reply; 10+ messages in thread
From: Qinyun Tan @ 2026-01-27  7:33 UTC (permalink / raw)
  To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg
  Cc: linux-nvme, Xunlei Pang, Guixin Liu, oliver.yang, Guanghui Feng,
	Qinyun Tan

The NVMe PCI driver exports the sriov_configure callback via
pci_sriov_configure_simple(), which allows userspace to enable SR-IOV
VFs through sysfs. However, when the PF driver is unbound, the driver
does not disable SR-IOV, leaving VFs orphaned in the system.

This causes the PCI core to emit a warning in pci_iov_remove():
  "driver left SR-IOV enabled after remove"

According to Documentation/PCI/pci-iov-howto.rst, PCI drivers that
support SR-IOV should call pci_disable_sriov() in their remove callback
to properly clean up VFs before the driver is unloaded.

Fix this by disabling SR-IOV in nvme_remove(). If VFs are not assigned
to a guest, disable SR-IOV. If VFs are still assigned, emit a warning
since forcibly disabling would disrupt the guest.

Signed-off-by: Qinyun Tan <qinyuntan@linux.alibaba.com>
Reviewed-by: Xunlei Pang <xlpang@linux.alibaba.com>
Reviewed-by: Guixin Liu <kanie@linux.alibaba.com>
---
 drivers/nvme/host/pci.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 58f3097888a7..4f2dc13de48b 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -3666,6 +3666,15 @@ static void nvme_remove(struct pci_dev *pdev)
 	nvme_stop_ctrl(&dev->ctrl);
 	nvme_remove_namespaces(&dev->ctrl);
 	nvme_dev_disable(dev, true);
+
+	if (pci_num_vf(pdev)) {
+		if (pci_vfs_assigned(pdev))
+			dev_warn(&pdev->dev,
+				 "WARNING: Removing PF while VFs are assigned - VFs will not be deallocated!\n");
+		else
+			pci_disable_sriov(pdev);
+	}
+
 	nvme_free_host_mem(dev);
 	nvme_dev_remove_admin(dev);
 	nvme_dbbuf_dma_free(dev);
-- 
2.43.5



^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2026-02-06 22:28 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-27  7:33 [PATCH V1] nvme-pci: disable SR-IOV VFs on driver unbind Qinyun Tan
2026-01-27  8:48 ` Christoph Hellwig
2026-01-27 14:31   ` Leon Romanovsky
2026-01-27 16:06     ` Keith Busch
2026-01-27 18:00       ` Leon Romanovsky
2026-01-27 23:09         ` Bjorn Helgaas
2026-01-27 23:43           ` Jakub Kicinski
2026-01-28  8:44           ` Leon Romanovsky
2026-01-30  4:53   ` qinyuntan
2026-02-06 22:28     ` Bjorn Helgaas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox