]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
PCI: Validate window resource type in pbus_select_window_for_type()
authorKai-Heng Feng <kaihengf@nvidia.com>
Tue, 10 Feb 2026 14:20:57 +0000 (22:20 +0800)
committerBjorn Helgaas <bhelgaas@google.com>
Thu, 12 Feb 2026 17:08:34 +0000 (11:08 -0600)
After ebe091ad81e1 ("PCI: Use pbus_select_window_for_type() during IO
window sizing") and ae88d0b9c57f ("PCI: Use pbus_select_window_for_type()
during mem window sizing"), many bridge windows can't get resources
assigned:

  pci 0006:05:00.0: bridge window [??? 0x00001000-0x00001fff flags 0x20080000]: can't assign; no space
  pci 0006:05:00.0: bridge window [??? 0x00001000-0x00001fff flags 0x20080000]: failed to assign

Those commits replace find_bus_resource_of_type() with
pbus_select_window_for_type(), and the latter lacks resource type
validation.

Add the resource type validation back to pbus_select_window_for_type() to
match the original behavior.

Fixes: 74afce3dfcba ("PCI: Add bridge window selection functions")
Link: https://bugzilla.kernel.org/show_bug.cgi?id=221072
Signed-off-by: Kai-Heng Feng <kaihengf@nvidia.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
Link: https://patch.msgid.link/20260210142058.82701-1-kaihengf@nvidia.com
drivers/pci/setup-bus.c

index 32aa72456a4449d21cea8d3676ad12ea4058d0a1..f30d1f7f023a7078f5552c4179615553460c9faa 100644 (file)
@@ -224,14 +224,21 @@ static struct resource *pbus_select_window_for_type(struct pci_bus *bus,
 
        switch (iores_type) {
        case IORESOURCE_IO:
-               return pci_bus_resource_n(bus, PCI_BUS_BRIDGE_IO_WINDOW);
+               win = pci_bus_resource_n(bus, PCI_BUS_BRIDGE_IO_WINDOW);
+               if (win && (win->flags & IORESOURCE_IO))
+                       return win;
+               return NULL;
 
        case IORESOURCE_MEM:
                mmio = pci_bus_resource_n(bus, PCI_BUS_BRIDGE_MEM_WINDOW);
                mmio_pref = pci_bus_resource_n(bus, PCI_BUS_BRIDGE_PREF_MEM_WINDOW);
 
-               if (!(type & IORESOURCE_PREFETCH) ||
-                   !(mmio_pref->flags & IORESOURCE_MEM))
+               if (mmio && !(mmio->flags & IORESOURCE_MEM))
+                       mmio = NULL;
+               if (mmio_pref && !(mmio_pref->flags & IORESOURCE_MEM))
+                       mmio_pref = NULL;
+
+               if (!(type & IORESOURCE_PREFETCH) || !mmio_pref)
                        return mmio;
 
                if ((type & IORESOURCE_MEM_64) ||