[PATCH 3/3] PCI/IOV: Restore initial VF ReBAR sizes on PF release
From: Marcin Bernatowicz
Date: Tue May 05 2026 - 13:01:43 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 unbound while VF BARs were resized but SR-IOV was never
enabled (or was already disabled).
On the next bind, sriov_init() re-reads the SR-IOV capability and
captures the current (inflated) BAR registers as the new initial sizes
in iov->barsz_orig[]. The restore logic becomes a no-op for that boot
and the kernel may reserve MMIO for the inflated VF aperture multiplied
by TotalVFs.
Restore the initial sizes from sriov_release() as well. At this point
num_VFs is 0 (BUG_ON enforces it) and VF Memory Space is therefore
disabled, satisfying the precondition of pci_iov_vf_bar_set_size().
Signed-off-by: Marcin Bernatowicz <marcin.bernatowicz@xxxxxxxxxxxxxxx>
---
drivers/pci/iov.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index 42b935265b3c..d9e745e23add 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -969,6 +969,8 @@ static void sriov_release(struct pci_dev *dev)
{
BUG_ON(dev->sriov->num_VFs);
+ sriov_restore_vf_rebar_initial_sizes(dev);
+
if (dev != dev->sriov->dev)
pci_dev_put(dev->sriov->dev);
--
2.43.0