Skip to content

Commit e5f72cb

Browse files
khfengbjorn-helgaas
authored andcommitted
PCI: Validate window resource type in pbus_select_window_for_type()
After ebe091a ("PCI: Use pbus_select_window_for_type() during IO window sizing") and ae88d0b ("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: 74afce3 ("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
1 parent 1c2b4a4 commit e5f72cb

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

drivers/pci/setup-bus.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,21 @@ static struct resource *pbus_select_window_for_type(struct pci_bus *bus,
224224

225225
switch (iores_type) {
226226
case IORESOURCE_IO:
227-
return pci_bus_resource_n(bus, PCI_BUS_BRIDGE_IO_WINDOW);
227+
win = pci_bus_resource_n(bus, PCI_BUS_BRIDGE_IO_WINDOW);
228+
if (win && (win->flags & IORESOURCE_IO))
229+
return win;
230+
return NULL;
228231

229232
case IORESOURCE_MEM:
230233
mmio = pci_bus_resource_n(bus, PCI_BUS_BRIDGE_MEM_WINDOW);
231234
mmio_pref = pci_bus_resource_n(bus, PCI_BUS_BRIDGE_PREF_MEM_WINDOW);
232235

233-
if (!(type & IORESOURCE_PREFETCH) ||
234-
!(mmio_pref->flags & IORESOURCE_MEM))
236+
if (mmio && !(mmio->flags & IORESOURCE_MEM))
237+
mmio = NULL;
238+
if (mmio_pref && !(mmio_pref->flags & IORESOURCE_MEM))
239+
mmio_pref = NULL;
240+
241+
if (!(type & IORESOURCE_PREFETCH) || !mmio_pref)
235242
return mmio;
236243

237244
if ((type & IORESOURCE_MEM_64) ||

0 commit comments

Comments
 (0)