[PATCH v2 3/3] PCI/IOV: Restore initial VF ReBAR sizes on PF driver remove
From: Marcin Bernatowicz
Date: Mon Aug 03 2026 - 06:39:20 EST
sriov_disable() and sriov_enable() error paths restore the per-VF BAR
sizes saved at probe time. They do not cover the case where the PF
driver is detached while VF BARs were resized but SR-IOV was never
enabled (or was already disabled).
Restore the initial sizes from pci_iov_remove() as well. That hook runs
on driver detach while the device is still live, unlike sriov_release()
which runs later from the pci_dev release path.
Skip the restore when the PF driver leaves SR-IOV enabled; in that case
VF memory decoding is still active and pci_iov_vf_bar_set_size() cannot
safely change the VF BAR size.
Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@xxxxxxxxxxxxxxx>
---
drivers/pci/iov.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 999938163ce9..3739825c84e9 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -1085,8 +1085,12 @@ void pci_iov_remove(struct pci_dev *dev)
return;
iov->driver_max_VFs = iov->total_VFs;
- if (iov->num_VFs)
+ if (iov->num_VFs) {
pci_warn(dev, "driver left SR-IOV enabled after remove\n");
+ return;
+ }
+
+ sriov_restore_vf_rebar_initial_sizes(dev);
}
/**
--
2.43.0