* [PATCH v3 1/1] PCI: Fix BAR resizing when VF BARs are assigned
@ 2025-03-20 14:28 Ilpo Järvinen
2025-03-20 15:10 ` Alex Williamson
2025-03-20 21:45 ` Bjorn Helgaas
0 siblings, 2 replies; 3+ messages in thread
From: Ilpo Järvinen @ 2025-03-20 14:28 UTC (permalink / raw)
To: Bjorn Helgaas, Christian König, Alex Williamson, linux-pci,
linux-kernel
Cc: Ilpo Järvinen, Michał Winiarski
__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.
Fixes: 91fa127794ac ("PCI: Expose PCIe Resizable BAR support via sysfs")
Reported-by: Michał Winiarski <michal.winiarski@intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
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(-)
diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index b46ce1a2c554..0e7eb2a42d88 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -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
--
2.39.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v3 1/1] PCI: Fix BAR resizing when VF BARs are assigned
2025-03-20 14:28 [PATCH v3 1/1] PCI: Fix BAR resizing when VF BARs are assigned Ilpo Järvinen
@ 2025-03-20 15:10 ` Alex Williamson
2025-03-20 21:45 ` Bjorn Helgaas
1 sibling, 0 replies; 3+ messages in thread
From: Alex Williamson @ 2025-03-20 15:10 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Bjorn Helgaas, Christian König, linux-pci, linux-kernel,
Michał Winiarski
On Thu, 20 Mar 2025 16:28:37 +0200
Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> wrote:
> __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.
>
> Fixes: 91fa127794ac ("PCI: Expose PCIe Resizable BAR support via sysfs")
> Reported-by: Michał Winiarski <michal.winiarski@intel.com>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
>
> 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(-)
>
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index b46ce1a2c554..0e7eb2a42d88 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -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
Reviewed-by: Alex Williamson <alex.williamson@redhat.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v3 1/1] PCI: Fix BAR resizing when VF BARs are assigned
2025-03-20 14:28 [PATCH v3 1/1] PCI: Fix BAR resizing when VF BARs are assigned Ilpo Järvinen
2025-03-20 15:10 ` Alex Williamson
@ 2025-03-20 21:45 ` Bjorn Helgaas
1 sibling, 0 replies; 3+ messages in thread
From: Bjorn Helgaas @ 2025-03-20 21:45 UTC (permalink / raw)
To: Ilpo Järvinen
Cc: Bjorn Helgaas, Christian König, Alex Williamson, linux-pci,
linux-kernel, Michał Winiarski
On Thu, Mar 20, 2025 at 04:28:37PM +0200, Ilpo Järvinen wrote:
> __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.
>
> Fixes: 91fa127794ac ("PCI: Expose PCIe Resizable BAR support via sysfs")
> Reported-by: Michał Winiarski <michal.winiarski@intel.com>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Replaced the v2 patch [1] on pci/resource, headed for v6.15, thanks!
[1] https://lore.kernel.org/r/20250307140349.5634-1-ilpo.jarvinen@linux.intel.com
> ---
>
> 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(-)
>
> diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
> index b46ce1a2c554..0e7eb2a42d88 100644
> --- a/drivers/pci/pci-sysfs.c
> +++ b/drivers/pci/pci-sysfs.c
> @@ -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
> --
> 2.39.5
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-03-20 21:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-20 14:28 [PATCH v3 1/1] PCI: Fix BAR resizing when VF BARs are assigned Ilpo Järvinen
2025-03-20 15:10 ` Alex Williamson
2025-03-20 21:45 ` Bjorn Helgaas
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox