PCI: Fix BAR resizing when VF BARs are assigned
PATCH v3 1/1 PCI: Fix BAR resizing when VF BARs are assigned
__resource_resize_store() attempts to release all resources of the device before attempting the resize. The loop, however, only covers standard BARs (< PCI_STD_NUM_BARS). If a device has VF BARs that are assigned, pci_reassign_bridge_resources() finds the bridge window still has some assigned child resources and returns -NOENT which makes pci_resize_resource() to detect an error and abort the resize.
Change the release loop to cover all resources up to VF BARs which allows the resize operation to release the bridge windows and attempt to assigned them again with the different size.
If SR-IOV is enabled, disallow resize as it requires releasing also IOV resources.
---
v3:
- Check that SR-IOV is not enabled before resizing
v2:
- Removed language about expansion ROMs
drivers/pci/pci-sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pci-sysfs.c +2 -2
@@ -1556,7 +1556,7 @@ static ssize_t __resource_resize_store(struct device *dev, int n,return -EINVAL ;device_lock (dev); -if (dev->driver) { +if (dev->driver ||pci_num_vf (pdev)) { ret = -EBUSY ; goto unlock; }
@@ -1578,7 +1578,7 @@ static ssize_t __resource_resize_store(struct device *dev, int n,pci_remove_resource_files (pdev); -for (i =0 ; i <PCI_STD_NUM_BARS ; i++) { +for (i =0 ; i <PCI_BRIDGE_RESOURCES ; i++) {if (pci_resource_len (pdev, i) &&pci_resource_flags (pdev, i) == flags)pci_release_resource (pdev, i);
base-commit: 2014c95afecee3e76ca4a56956a936e23283f05b
Signature · 1 line
2.39.5
Quoted 51 lines · On Thu, 20 Mar 2025 16:28:37 +0200 Ilpo Järvinen…
__resource_resize_store()attempts to release all resources of the device before attempting the resize. The loop, however, only covers standard BARs (<PCI_STD_NUM_BARS). If a device has VF BARs that are assigned,pci_reassign_bridge_resources()finds the bridge window still has some assigned child resources and returns -NOENT which makespci_resize_resource()to detect an error and abort the resize.Change the release loop to cover all resources up to VF BARs which allows the resize operation to release the bridge windows and attempt to assigned them again with the different size.
If SR-IOV is enabled, disallow resize as it requires releasing also IOV resources.
Fixes 91fa127794ac ("PCI: Expose PCIe Resizable BAR support via sysfs")Reported-by Michał Winiarski <[email protected]>Signed-off-by Ilpo Järvinen <[email protected]>---
v3:
- Check that SR-IOV is not enabled before resizingv2:
- Removed language about expansion ROMsdrivers/pci/pci-sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/pci-sysfs.c +2
-2@@ -1556,7 +1556,7 @@ static ssize_t __resource_resize_store(struct device *dev, int n,return -EINVAL ;device_lock (dev); -if (dev->driver) { +if (dev->driver ||pci_num_vf (pdev)) { ret = -EBUSY ; goto unlock; }@@ -1578,7 +1578,7 @@ static ssize_t __resource_resize_store(struct device *dev, int n,pci_remove_resource_files (pdev); -for (i =0 ; i <PCI_STD_NUM_BARS ; i++) { +for (i =0 ; i <PCI_BRIDGE_RESOURCES ; i++) {if (pci_resource_len (pdev, i) &&pci_resource_flags (pdev, i) == flags)pci_release_resource (pdev, i);
Quoted 1 line
base-commit:
2014c95afecee3e76ca4a56956a936e23283f05b
Quoted 11 lines · Ilpo Järvinen
__resource_resize_store()attempts to release all resources of the device before attempting the resize. The loop, however, only covers standard BARs (<PCI_STD_NUM_BARS). If a device has VF BARs that are assigned,pci_reassign_bridge_resources()finds the bridge window still has some assigned child resources and returns -NOENT which makespci_resize_resource()to detect an error and abort the resize.Change the release loop to cover all resources up to VF BARs which allows the resize operation to release the bridge windows and attempt to assigned them again with the different size.
Quoted 6 lines
If SR-IOV is enabled, disallow resize as it requires releasing also IOV resources.
Fixes 91fa127794ac ("PCI: Expose PCIe Resizable BAR support via sysfs")Reported-by Michał Winiarski <[email protected]>Signed-off-by Ilpo Järvinen <[email protected]>
Replaced the v2 patch [1] on pci/resource, headed for v6.15, thanks!
[1] https://lore.kernel.org/r/[email protected]
Quoted 38 lines
---
v3:
- Check that SR-IOV is not enabled before resizingv2:
- Removed language about expansion ROMsdrivers/pci/pci-sysfs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/pci/pci-sysfs.c +2
-2@@ -1556,7 +1556,7 @@ static ssize_t __resource_resize_store(struct device *dev, int n,return -EINVAL ;device_lock (dev); -if (dev->driver) { +if (dev->driver ||pci_num_vf (pdev)) { ret = -EBUSY ; goto unlock; }@@ -1578,7 +1578,7 @@ static ssize_t __resource_resize_store(struct device *dev, int n,pci_remove_resource_files (pdev); -for (i =0 ; i <PCI_STD_NUM_BARS ; i++) { +for (i =0 ; i <PCI_BRIDGE_RESOURCES ; i++) {if (pci_resource_len (pdev, i) &&pci_resource_flags (pdev, i) == flags)pci_release_resource (pdev, i);base-commit:
2014c95afecee3e76ca4a56956a936e23283f05bSignature · 1 line
2.39.5