public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PCI: Fix BAR resizing when VF BARs are assigned
@ 2024-11-12 13:42 Ilpo Järvinen
       [not found] ` <a22a321a-0e60-474b-971c-8512189a69ca@amd.com>
  0 siblings, 1 reply; 3+ messages in thread
From: Ilpo Järvinen @ 2024-11-12 13:42 UTC (permalink / raw)
  To: Michał Winiarski, Bjorn Helgaas, Christian König,
	linux-pci, linux-kernel
  Cc: 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 makes
pci_resize_resource() to detect an error and abort the resize.

Similarly, an assigned Expansion ROM resource prevents the resize.

Change the release loop to cover both the VF BARs and Expansion ROM
which allows the resize operation to release the bridge windows and
attempt to assigned them again with the different size.

As __resource_resize_store() checks first that no driver is bound to
the PCI device before resizing is allowed, SR-IOV cannot be enabled
during resize so it is safe to release also the IOV resources.

Fixes: 8bb705e3e79d ("PCI: Add pci_resize_resource() for resizing BARs")
Reported-by: Michał Winiarski <michal.winiarski@intel.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/pci/pci-sysfs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
index 5d0f4db1cab7..80b01087d3ef 100644
--- a/drivers/pci/pci-sysfs.c
+++ b/drivers/pci/pci-sysfs.c
@@ -1440,7 +1440,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);
-- 
2.39.5


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

end of thread, other threads:[~2024-11-12 16:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-11-12 13:42 [PATCH] PCI: Fix BAR resizing when VF BARs are assigned Ilpo Järvinen
     [not found] ` <a22a321a-0e60-474b-971c-8512189a69ca@amd.com>
2024-11-12 14:28   ` Ilpo Järvinen
     [not found]     ` <9e3b6a38-6f23-45cc-ac3d-d0ebc929dee3@amd.com>
2024-11-12 16:16       ` Ilpo Järvinen

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