linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/1] PCI: Do not size non-existing prefetchable window
@ 2025-10-27 13:24 Ilpo Järvinen
  2025-10-27 17:45 ` Klaus Kudielka
  2025-10-27 23:12 ` Bjorn Helgaas
  0 siblings, 2 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2025-10-27 13:24 UTC (permalink / raw)
  To: Klaus Kudielka, Bjorn Helgaas, Ilpo Järvinen, linux-pci,
	linux-kernel

pbus_size_mem() should only be called for bridge windows that exist but
__pci_bus_size_bridges() may point 'pref' to a resource that does not
exist (has zero flags) in case of non-root buses.

When prefetchable bridge window does not exist, the same
non-prefetchable bridge window is sized more than once which may result
in duplicating entries into the realloc_head list. Duplicated entries
are shown in this log and trigger a WARN_ON() because realloc_head had
residual entries after the resource assignment algorithm:

pci 0000:00:03.0: [11ab:6820] type 01 class 0x060400 PCIe Root Port
pci 0000:00:03.0: PCI bridge to [bus 00]
pci 0000:00:03.0:   bridge window [io  0x0000-0x0fff]
pci 0000:00:03.0:   bridge window [mem 0x00000000-0x000fffff]
pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
pci 0000:00:03.0: bridge window [mem 0xe0000000-0xe03fffff]: assigned
pci 0000:00:03.0: PCI bridge to [bus 02]
pci 0000:00:03.0:   bridge window [mem 0xe0000000-0xe03fffff]
------------[ cut here ]------------
WARNING: CPU: 0 PID: 1 at drivers/pci/setup-bus.c:2373 pci_assign_unassigned_root_bus_resources+0x1bc/0x234

Check resource flags of 'pref' and only size the prefetchable window if
the resource has the IORESOURCE_PREFETCH flag.

Fixes: ae88d0b9c57f ("PCI: Use pbus_select_window_for_type() during mem window sizing")
Link: https://lore.kernel.org/linux-pci/51e8cf1c62b8318882257d6b5a9de7fdaaecc343.camel@gmail.com/
Reported-by: Klaus Kudielka <klaus.kudielka@gmail.com>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/pci/setup-bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
index 362ad108794d..7cb6071cff7a 100644
--- a/drivers/pci/setup-bus.c
+++ b/drivers/pci/setup-bus.c
@@ -1604,7 +1604,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
 		pbus_size_io(bus, realloc_head ? 0 : additional_io_size,
 			     additional_io_size, realloc_head);
 
-		if (pref) {
+		if (pref && (pref->flags & IORESOURCE_PREFETCH)) {
 			pbus_size_mem(bus,
 				      IORESOURCE_MEM | IORESOURCE_PREFETCH |
 				      (pref->flags & IORESOURCE_MEM_64),

base-commit: 2f2c7254931f41b5736e3ba12aaa9ac1bbeeeb92
-- 
2.39.5


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

* Re: [PATCH 1/1] PCI: Do not size non-existing prefetchable window
  2025-10-27 13:24 [PATCH 1/1] PCI: Do not size non-existing prefetchable window Ilpo Järvinen
@ 2025-10-27 17:45 ` Klaus Kudielka
  2025-10-27 17:55   ` Ilpo Järvinen
  2025-10-27 23:12 ` Bjorn Helgaas
  1 sibling, 1 reply; 5+ messages in thread
From: Klaus Kudielka @ 2025-10-27 17:45 UTC (permalink / raw)
  To: Ilpo Järvinen, Bjorn Helgaas, linux-pci, linux-kernel

On Mon, 2025-10-27 at 15:24 +0200, Ilpo Järvinen wrote:
> pbus_size_mem() should only be called for bridge windows that exist but
> __pci_bus_size_bridges() may point 'pref' to a resource that does not
> exist (has zero flags) in case of non-root buses.
> 
> When prefetchable bridge window does not exist, the same
> non-prefetchable bridge window is sized more than once which may result
> in duplicating entries into the realloc_head list. Duplicated entries
> are shown in this log and trigger a WARN_ON() because realloc_head had
> residual entries after the resource assignment algorithm:
> 
> pci 0000:00:03.0: [11ab:6820] type 01 class 0x060400 PCIe Root Port
> pci 0000:00:03.0: PCI bridge to [bus 00]
> pci 0000:00:03.0:   bridge window [io  0x0000-0x0fff]
> pci 0000:00:03.0:   bridge window [mem 0x00000000-0x000fffff]
> pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
> pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
> pci 0000:00:03.0: bridge window [mem 0xe0000000-0xe03fffff]: assigned
> pci 0000:00:03.0: PCI bridge to [bus 02]
> pci 0000:00:03.0:   bridge window [mem 0xe0000000-0xe03fffff]
> ------------[ cut here ]------------
> WARNING: CPU: 0 PID: 1 at drivers/pci/setup-bus.c:2373 pci_assign_unassigned_root_bus_resources+0x1bc/0x234

With this patch on top of v6.18-rc3, the boot log looks clean again:

pci 0000:00:03.0: [11ab:6820] type 01 class 0x060400 PCIe Root Port
pci 0000:00:03.0: PCI bridge to [bus 00]
pci 0000:00:03.0:   bridge window [io  0x0000-0x0fff]
pci 0000:00:03.0:   bridge window [mem 0x00000000-0x000fffff]
pci 0000:00:03.0: bridge configuration invalid ([bus 00-00]), reconfiguring
pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
pci 0000:00:03.0: bridge window [mem 0xe0000000-0xe03fffff]: assigned
pci 0000:00:03.0: PCI bridge to [bus 02]
pci 0000:00:03.0:   bridge window [mem 0xe0000000-0xe03fffff]

(and no WARNING thereafter)
Thanks a lot!

Tested-by: Klaus Kudielka <klaus.kudielka@gmail.com>

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

* Re: [PATCH 1/1] PCI: Do not size non-existing prefetchable window
  2025-10-27 17:45 ` Klaus Kudielka
@ 2025-10-27 17:55   ` Ilpo Järvinen
  0 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2025-10-27 17:55 UTC (permalink / raw)
  To: Klaus Kudielka; +Cc: Bjorn Helgaas, linux-pci, LKML

[-- Attachment #1: Type: text/plain, Size: 2326 bytes --]

On Mon, 27 Oct 2025, Klaus Kudielka wrote:

> On Mon, 2025-10-27 at 15:24 +0200, Ilpo Järvinen wrote:
> > pbus_size_mem() should only be called for bridge windows that exist but
> > __pci_bus_size_bridges() may point 'pref' to a resource that does not
> > exist (has zero flags) in case of non-root buses.
> > 
> > When prefetchable bridge window does not exist, the same
> > non-prefetchable bridge window is sized more than once which may result
> > in duplicating entries into the realloc_head list. Duplicated entries
> > are shown in this log and trigger a WARN_ON() because realloc_head had
> > residual entries after the resource assignment algorithm:
> > 
> > pci 0000:00:03.0: [11ab:6820] type 01 class 0x060400 PCIe Root Port
> > pci 0000:00:03.0: PCI bridge to [bus 00]
> > pci 0000:00:03.0:   bridge window [io  0x0000-0x0fff]
> > pci 0000:00:03.0:   bridge window [mem 0x00000000-0x000fffff]
> > pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
> > pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
> > pci 0000:00:03.0: bridge window [mem 0xe0000000-0xe03fffff]: assigned
> > pci 0000:00:03.0: PCI bridge to [bus 02]
> > pci 0000:00:03.0:   bridge window [mem 0xe0000000-0xe03fffff]
> > ------------[ cut here ]------------
> > WARNING: CPU: 0 PID: 1 at drivers/pci/setup-bus.c:2373 pci_assign_unassigned_root_bus_resources+0x1bc/0x234
> 
> With this patch on top of v6.18-rc3, the boot log looks clean again:
> 
> pci 0000:00:03.0: [11ab:6820] type 01 class 0x060400 PCIe Root Port
> pci 0000:00:03.0: PCI bridge to [bus 00]
> pci 0000:00:03.0:   bridge window [io  0x0000-0x0fff]
> pci 0000:00:03.0:   bridge window [mem 0x00000000-0x000fffff]
> pci 0000:00:03.0: bridge configuration invalid ([bus 00-00]), reconfiguring
> pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
> pci 0000:00:03.0: bridge window [mem 0xe0000000-0xe03fffff]: assigned
> pci 0000:00:03.0: PCI bridge to [bus 02]
> pci 0000:00:03.0:   bridge window [mem 0xe0000000-0xe03fffff]
> 
> (and no WARNING thereafter)
> Thanks a lot!
> 
> Tested-by: Klaus Kudielka <klaus.kudielka@gmail.com>

Thanks for testing.

-- 
 i.

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

* Re: [PATCH 1/1] PCI: Do not size non-existing prefetchable window
  2025-10-27 13:24 [PATCH 1/1] PCI: Do not size non-existing prefetchable window Ilpo Järvinen
  2025-10-27 17:45 ` Klaus Kudielka
@ 2025-10-27 23:12 ` Bjorn Helgaas
  2025-10-27 23:15   ` Ilpo Järvinen
  1 sibling, 1 reply; 5+ messages in thread
From: Bjorn Helgaas @ 2025-10-27 23:12 UTC (permalink / raw)
  To: Ilpo Järvinen; +Cc: Klaus Kudielka, Bjorn Helgaas, linux-pci, linux-kernel

On Mon, Oct 27, 2025 at 03:24:23PM +0200, Ilpo Järvinen wrote:
> pbus_size_mem() should only be called for bridge windows that exist but
> __pci_bus_size_bridges() may point 'pref' to a resource that does not
> exist (has zero flags) in case of non-root buses.
> 
> When prefetchable bridge window does not exist, the same
> non-prefetchable bridge window is sized more than once which may result
> in duplicating entries into the realloc_head list. Duplicated entries
> are shown in this log and trigger a WARN_ON() because realloc_head had
> residual entries after the resource assignment algorithm:
> 
> pci 0000:00:03.0: [11ab:6820] type 01 class 0x060400 PCIe Root Port
> pci 0000:00:03.0: PCI bridge to [bus 00]
> pci 0000:00:03.0:   bridge window [io  0x0000-0x0fff]
> pci 0000:00:03.0:   bridge window [mem 0x00000000-0x000fffff]
> pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
> pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
> pci 0000:00:03.0: bridge window [mem 0xe0000000-0xe03fffff]: assigned
> pci 0000:00:03.0: PCI bridge to [bus 02]
> pci 0000:00:03.0:   bridge window [mem 0xe0000000-0xe03fffff]
> ------------[ cut here ]------------
> WARNING: CPU: 0 PID: 1 at drivers/pci/setup-bus.c:2373 pci_assign_unassigned_root_bus_resources+0x1bc/0x234
> 
> Check resource flags of 'pref' and only size the prefetchable window if
> the resource has the IORESOURCE_PREFETCH flag.
> 
> Fixes: ae88d0b9c57f ("PCI: Use pbus_select_window_for_type() during mem window sizing")
> Link: https://lore.kernel.org/linux-pci/51e8cf1c62b8318882257d6b5a9de7fdaaecc343.camel@gmail.com/
> Reported-by: Klaus Kudielka <klaus.kudielka@gmail.com>
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

Since ae88d0b9c57f appeared in v6.18-rc1, this looks like v6.18
material, right?

Applied to pci/for-linus for v6.18 on that assumption, thanks!

> ---
>  drivers/pci/setup-bus.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
> index 362ad108794d..7cb6071cff7a 100644
> --- a/drivers/pci/setup-bus.c
> +++ b/drivers/pci/setup-bus.c
> @@ -1604,7 +1604,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
>  		pbus_size_io(bus, realloc_head ? 0 : additional_io_size,
>  			     additional_io_size, realloc_head);
>  
> -		if (pref) {
> +		if (pref && (pref->flags & IORESOURCE_PREFETCH)) {
>  			pbus_size_mem(bus,
>  				      IORESOURCE_MEM | IORESOURCE_PREFETCH |
>  				      (pref->flags & IORESOURCE_MEM_64),
> 
> base-commit: 2f2c7254931f41b5736e3ba12aaa9ac1bbeeeb92
> -- 
> 2.39.5
> 

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

* Re: [PATCH 1/1] PCI: Do not size non-existing prefetchable window
  2025-10-27 23:12 ` Bjorn Helgaas
@ 2025-10-27 23:15   ` Ilpo Järvinen
  0 siblings, 0 replies; 5+ messages in thread
From: Ilpo Järvinen @ 2025-10-27 23:15 UTC (permalink / raw)
  To: Bjorn Helgaas; +Cc: Klaus Kudielka, Bjorn Helgaas, linux-pci, LKML

[-- Attachment #1: Type: text/plain, Size: 2977 bytes --]

On Mon, 27 Oct 2025, Bjorn Helgaas wrote:

> On Mon, Oct 27, 2025 at 03:24:23PM +0200, Ilpo Järvinen wrote:
> > pbus_size_mem() should only be called for bridge windows that exist but
> > __pci_bus_size_bridges() may point 'pref' to a resource that does not
> > exist (has zero flags) in case of non-root buses.
> > 
> > When prefetchable bridge window does not exist, the same
> > non-prefetchable bridge window is sized more than once which may result
> > in duplicating entries into the realloc_head list. Duplicated entries
> > are shown in this log and trigger a WARN_ON() because realloc_head had
> > residual entries after the resource assignment algorithm:
> > 
> > pci 0000:00:03.0: [11ab:6820] type 01 class 0x060400 PCIe Root Port
> > pci 0000:00:03.0: PCI bridge to [bus 00]
> > pci 0000:00:03.0:   bridge window [io  0x0000-0x0fff]
> > pci 0000:00:03.0:   bridge window [mem 0x00000000-0x000fffff]
> > pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
> > pci 0000:00:03.0: bridge window [mem 0x00200000-0x003fffff] to [bus 02] add_size 200000 add_align 200000
> > pci 0000:00:03.0: bridge window [mem 0xe0000000-0xe03fffff]: assigned
> > pci 0000:00:03.0: PCI bridge to [bus 02]
> > pci 0000:00:03.0:   bridge window [mem 0xe0000000-0xe03fffff]
> > ------------[ cut here ]------------
> > WARNING: CPU: 0 PID: 1 at drivers/pci/setup-bus.c:2373 pci_assign_unassigned_root_bus_resources+0x1bc/0x234
> > 
> > Check resource flags of 'pref' and only size the prefetchable window if
> > the resource has the IORESOURCE_PREFETCH flag.
> > 
> > Fixes: ae88d0b9c57f ("PCI: Use pbus_select_window_for_type() during mem window sizing")
> > Link: https://lore.kernel.org/linux-pci/51e8cf1c62b8318882257d6b5a9de7fdaaecc343.camel@gmail.com/
> > Reported-by: Klaus Kudielka <klaus.kudielka@gmail.com>
> > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> 
> Since ae88d0b9c57f appeared in v6.18-rc1, this looks like v6.18
> material, right?
>
> Applied to pci/for-linus for v6.18 on that assumption, thanks!

Yes, it's for-linus material.

-- 
 i.

> >  drivers/pci/setup-bus.c | 2 +-
> >  1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/drivers/pci/setup-bus.c b/drivers/pci/setup-bus.c
> > index 362ad108794d..7cb6071cff7a 100644
> > --- a/drivers/pci/setup-bus.c
> > +++ b/drivers/pci/setup-bus.c
> > @@ -1604,7 +1604,7 @@ void __pci_bus_size_bridges(struct pci_bus *bus, struct list_head *realloc_head)
> >  		pbus_size_io(bus, realloc_head ? 0 : additional_io_size,
> >  			     additional_io_size, realloc_head);
> >  
> > -		if (pref) {
> > +		if (pref && (pref->flags & IORESOURCE_PREFETCH)) {
> >  			pbus_size_mem(bus,
> >  				      IORESOURCE_MEM | IORESOURCE_PREFETCH |
> >  				      (pref->flags & IORESOURCE_MEM_64),
> > 
> > base-commit: 2f2c7254931f41b5736e3ba12aaa9ac1bbeeeb92
> > -- 
> > 2.39.5
> > 
> 

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

end of thread, other threads:[~2025-10-27 23:15 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-10-27 13:24 [PATCH 1/1] PCI: Do not size non-existing prefetchable window Ilpo Järvinen
2025-10-27 17:45 ` Klaus Kudielka
2025-10-27 17:55   ` Ilpo Järvinen
2025-10-27 23:12 ` Bjorn Helgaas
2025-10-27 23:15   ` 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;
as well as URLs for NNTP newsgroup(s).