[PATCH v5 03/14] PCI: Don't size or assign disabled BARs

From: Ilpo Järvinen

Date: Fri Nov 06 2026 - 08:50:18 EST


When a 64-bit BAR is larger than 4GB but pci_bus_addr_t or
resource_size_t is 32-bit, __pci_read_base() marks the BAR with
IORESOURCE_UNSET | IORESOURCE_DISABLED and sets its size to zero while
retaining the type flags. pdev_resource_assignable() only excludes
disabled bridge windows so such a BAR is still included in resource
sizing.

pbus_size_mem() then calls __ffs() on its zero alignment, which is
undefined behavior. pdev_sort_resources() catches the zero alignment but
logs a bogus "alignment must not be zero" warning.

Exclude all IORESOURCE_DISABLED resources in pdev_resource_assignable().

A disabled expansion ROM is still assigned because ROM disabling is
tracked with IORESOURCE_ROM_ENABLE, not with IORESOURCE_DISABLED.

Fixes: 23b13bc76f35 ("PCI: Fail safely if we can't handle BARs larger than 4GB")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@xxxxxxxxxxxxxxx>
---
drivers/pci/setup-bus.c | 16 +++++++---------
1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index ed16ef7c26fa..0c27cec83c0d 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -301,20 +301,18 @@ static bool pdev_resources_assignable(struct pci_dev *dev)
return true;
}

-static bool pdev_resource_assignable(struct pci_dev *dev, struct resource *res)
+static bool pdev_resource_assignable(struct resource *res)
{
- int idx = pci_resource_num(dev, res);
-
if (!res->flags)
return false;

- if (pci_resource_is_bridge_win(idx) && res->flags & IORESOURCE_DISABLED)
+ if (res->flags & IORESOURCE_DISABLED)
return false;

return true;
}

-static bool pdev_resource_should_fit(struct pci_dev *dev, struct resource *res)
+static bool pdev_resource_should_fit(struct resource *res)
{
if (resource_assigned(res))
return false;
@@ -322,7 +320,7 @@ static bool pdev_resource_should_fit(struct pci_dev *dev, struct resource *res)
if (res->flags & IORESOURCE_PCI_FIXED)
return false;

- return pdev_resource_assignable(dev, res);
+ return pdev_resource_assignable(res);
}

/* Sort resources by alignment */
@@ -340,7 +338,7 @@ static void pdev_sort_resources(struct pci_dev *dev, struct list_head *head)
resource_size_t r_align;
struct list_head *n;

- if (!pdev_resource_should_fit(dev, r))
+ if (!pdev_resource_should_fit(r))
continue;

r_align = pci_resource_alignment(dev, r);
@@ -1094,7 +1092,7 @@ static void pbus_size_io(struct pci_bus *bus, resource_size_t add_size,
if (resource_assigned(r) || !(r->flags & IORESOURCE_IO))
continue;

- if (!pdev_resource_assignable(dev, r))
+ if (!pdev_resource_assignable(r))
continue;

r_size = resource_size(r);
@@ -1305,7 +1303,7 @@ static void pbus_size_mem(struct pci_bus *bus, struct resource *b_res,
resource_size_t r_size;

if (!pdev_resources_assignable(dev) ||
- !pdev_resource_should_fit(dev, r))
+ !pdev_resource_should_fit(r))
continue;
if (b_res != pbus_select_window(bus, r))
continue;
--
2.47.3