[PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET

Ilpo Järvinen posted 2 patches 4 months, 2 weeks ago
[PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Ilpo Järvinen 4 months, 2 weeks ago
PNP resources are checked for conflicts with the other resource in the
system by quirk_system_pci_resources() that walks through all PCI
resources. quirk_system_pci_resources() correctly filters out resource
with IORESOURCE_UNSET.

Resources that do not reside within their bridge window, however, are
not properly initialized with IORESOURCE_UNSET resulting in bogus
conflicts detected in quirk_system_pci_resources():

pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
...
pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
...
pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]

Mark resources that are not contained within their bridge window with
IORESOURCE_UNSET in __pci_read_base() which resolves the false
positives for the overlap check in quirk_system_pci_resources().

Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---

This change uses resource_contains() which will reject partial overlaps.
I don't know for sure if partial overlaps should be allowed or not (but
they feel as something FW didn't set things up properly so I chose to
mark them UNSET as well).

 drivers/pci/probe.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 7f9da8c41620..097389f25853 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -205,6 +205,26 @@ static void __pci_size_rom(struct pci_dev *dev, unsigned int pos, u32 *sizes)
 	__pci_size_bars(dev, 1, pos, sizes, true);
 }
 
+static struct resource *pbus_select_window_for_res_addr(
+					const struct pci_bus *bus,
+					const struct resource *res)
+{
+	unsigned long type = res->flags & IORESOURCE_TYPE_BITS;
+	struct resource *r;
+
+	pci_bus_for_each_resource(bus, r) {
+		if (!r || r == &ioport_resource || r == &iomem_resource)
+			continue;
+
+		if ((r->flags & IORESOURCE_TYPE_BITS) != type)
+			continue;
+
+		if (resource_contains(r, res))
+			return r;
+	}
+	return NULL;
+}
+
 /**
  * __pci_read_base - Read a PCI BAR
  * @dev: the PCI device
@@ -329,6 +349,18 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
 			 res_name, (unsigned long long)region.start);
 	}
 
+	if (!(res->flags & IORESOURCE_UNSET)) {
+		struct resource *b_res;
+
+		b_res = pbus_select_window_for_res_addr(dev->bus, res);
+		if (!b_res ||
+		    b_res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) {
+			pci_dbg(dev, "%s %pR: no initial claim (no window)\n",
+				res_name, res);
+			res->flags |= IORESOURCE_UNSET;
+		}
+	}
+
 	goto out;
 
 
-- 
2.39.5

Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Geert Uytterhoeven 4 months, 1 week ago
Hi Ilpo,

On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
> PNP resources are checked for conflicts with the other resource in the
> system by quirk_system_pci_resources() that walks through all PCI
> resources. quirk_system_pci_resources() correctly filters out resource
> with IORESOURCE_UNSET.
>
> Resources that do not reside within their bridge window, however, are
> not properly initialized with IORESOURCE_UNSET resulting in bogus
> conflicts detected in quirk_system_pci_resources():
>
> pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> ...
> pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> ...
> pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
>
> Mark resources that are not contained within their bridge window with
> IORESOURCE_UNSET in __pci_read_base() which resolves the false
> positives for the overlap check in quirk_system_pci_resources().
>
> Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>

Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
Mark resources IORESOURCE_UNSET when outside bridge windows") in
linux-next/master next-20250929 pci/next

This replaces the actual resources by their sizes in the boot log on
e.g. on R-Car M2-W:

     pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
     pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff
-> 0x00ee080000
     pci-rcar-gen2 ee090000.pci: PCI: revision 11
     pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
     pci_bus 0000:00: root bus resource [bus 00]
     pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
     pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
PCI endpoint
    -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
    -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
    +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
    +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
     pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
PCI endpoint
    -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
    +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
     pci 0000:00:01.0: supports D1 D2
     pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
     pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
PCI endpoint
    -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
    +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
     pci 0000:00:02.0: supports D1 D2
     pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
     PCI: bus0: Fast back to back transfers disabled
     pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
     pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
     pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]

Is that intentional?

> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -205,6 +205,26 @@ static void __pci_size_rom(struct pci_dev *dev, unsigned int pos, u32 *sizes)
>         __pci_size_bars(dev, 1, pos, sizes, true);
>  }
>
> +static struct resource *pbus_select_window_for_res_addr(
> +                                       const struct pci_bus *bus,
> +                                       const struct resource *res)
> +{
> +       unsigned long type = res->flags & IORESOURCE_TYPE_BITS;
> +       struct resource *r;
> +
> +       pci_bus_for_each_resource(bus, r) {
> +               if (!r || r == &ioport_resource || r == &iomem_resource)
> +                       continue;
> +
> +               if ((r->flags & IORESOURCE_TYPE_BITS) != type)
> +                       continue;
> +
> +               if (resource_contains(r, res))
> +                       return r;
> +       }
> +       return NULL;
> +}
> +
>  /**
>   * __pci_read_base - Read a PCI BAR
>   * @dev: the PCI device
> @@ -329,6 +349,18 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
>                          res_name, (unsigned long long)region.start);
>         }
>
> +       if (!(res->flags & IORESOURCE_UNSET)) {
> +               struct resource *b_res;
> +
> +               b_res = pbus_select_window_for_res_addr(dev->bus, res);
> +               if (!b_res ||
> +                   b_res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) {
> +                       pci_dbg(dev, "%s %pR: no initial claim (no window)\n",
> +                               res_name, res);
> +                       res->flags |= IORESOURCE_UNSET;
> +               }
> +       }
> +
>         goto out;
>
>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Ilpo Järvinen 4 months, 1 week ago
On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
> > PNP resources are checked for conflicts with the other resource in the
> > system by quirk_system_pci_resources() that walks through all PCI
> > resources. quirk_system_pci_resources() correctly filters out resource
> > with IORESOURCE_UNSET.
> >
> > Resources that do not reside within their bridge window, however, are
> > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > conflicts detected in quirk_system_pci_resources():
> >
> > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > ...
> > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > ...
> > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> >
> > Mark resources that are not contained within their bridge window with
> > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > positives for the overlap check in quirk_system_pci_resources().
> >
> > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> 
> Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> Mark resources IORESOURCE_UNSET when outside bridge windows") in
> linux-next/master next-20250929 pci/next

Hi Geert,

I really appreciate you paying attention!!

> This replaces the actual resources by their sizes in the boot log on
> e.g. on R-Car M2-W:
> 
>      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
>      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff
> -> 0x00ee080000
>      pci-rcar-gen2 ee090000.pci: PCI: revision 11
>      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
>      pci_bus 0000:00: root bus resource [bus 00]
>      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
>      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
> PCI endpoint
>     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
>     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]

What is going to be the parent of these resources? They don't seem to fall
under the root bus resource above in which case the output change is 
intentional so they don't appear as if address range would be "okay".

When IORESOURCE_UNSET is set in a resource, %pR does not print the start 
and end addresses.

>     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
>     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
>      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> PCI endpoint
>     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
>     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]

For this resource, it's very much intentional. It's a zero-based BAR which 
was left without IORESOURCE_UNSET prior to my patch leading to others part 
of the kernel to think that resource range valid and in use (in your 
case it's so small it wouldn't collide with anything but it wasn't 
properly set up resource, nonetheless).

>      pci 0000:00:01.0: supports D1 D2
>      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
>      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
> PCI endpoint
>     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
>     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]

And this as well is very much intentional.

>      pci 0000:00:02.0: supports D1 D2
>      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
>      PCI: bus0: Fast back to back transfers disabled
>      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
>      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
>      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> 
> Is that intentional?

There's also that pci_dbg() in the patch which would show the original 
addresses (print the resource before setting IORESOURCE_UNSET) but to see 
it one would need to enable it with dyndbg=... Bjorn was thinking of 
making that pci_info() though so it would appear always.

Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs 
getting assigned anywhere.

You didn't report any issues beyond textual changes in the log, I suppose 
there were none beyond the log differences?

-- 
 i.

> > --- a/drivers/pci/probe.c
> > +++ b/drivers/pci/probe.c
> > @@ -205,6 +205,26 @@ static void __pci_size_rom(struct pci_dev *dev, unsigned int pos, u32 *sizes)
> >         __pci_size_bars(dev, 1, pos, sizes, true);
> >  }
> >
> > +static struct resource *pbus_select_window_for_res_addr(
> > +                                       const struct pci_bus *bus,
> > +                                       const struct resource *res)
> > +{
> > +       unsigned long type = res->flags & IORESOURCE_TYPE_BITS;
> > +       struct resource *r;
> > +
> > +       pci_bus_for_each_resource(bus, r) {
> > +               if (!r || r == &ioport_resource || r == &iomem_resource)
> > +                       continue;
> > +
> > +               if ((r->flags & IORESOURCE_TYPE_BITS) != type)
> > +                       continue;
> > +
> > +               if (resource_contains(r, res))
> > +                       return r;
> > +       }
> > +       return NULL;
> > +}
> > +
> >  /**
> >   * __pci_read_base - Read a PCI BAR
> >   * @dev: the PCI device
> > @@ -329,6 +349,18 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
> >                          res_name, (unsigned long long)region.start);
> >         }
> >
> > +       if (!(res->flags & IORESOURCE_UNSET)) {
> > +               struct resource *b_res;
> > +
> > +               b_res = pbus_select_window_for_res_addr(dev->bus, res);
> > +               if (!b_res ||
> > +                   b_res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) {
> > +                       pci_dbg(dev, "%s %pR: no initial claim (no window)\n",
> > +                               res_name, res);
> > +                       res->flags |= IORESOURCE_UNSET;
> > +               }
> > +       }
> > +
> >         goto out;
> >
> >
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> 
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Geert Uytterhoeven 4 months, 1 week ago
Hi Ilpo,

On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
> On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > <ilpo.jarvinen@linux.intel.com> wrote:
> > > PNP resources are checked for conflicts with the other resource in the
> > > system by quirk_system_pci_resources() that walks through all PCI
> > > resources. quirk_system_pci_resources() correctly filters out resource
> > > with IORESOURCE_UNSET.
> > >
> > > Resources that do not reside within their bridge window, however, are
> > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > conflicts detected in quirk_system_pci_resources():
> > >
> > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > ...
> > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > ...
> > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > >
> > > Mark resources that are not contained within their bridge window with
> > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > positives for the overlap check in quirk_system_pci_resources().
> > >
> > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> >
> > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > linux-next/master next-20250929 pci/next

> > This replaces the actual resources by their sizes in the boot log on
> > e.g. on R-Car M2-W:
> >
> >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> >      pci_bus 0000:00: root bus resource [bus 00]
> >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
>
> What is going to be the parent of these resources? They don't seem to fall
> under the root bus resource above in which case the output change is
> intentional so they don't appear as if address range would be "okay".

From /proc/iomem:

    ee080000-ee08ffff : pci@ee090000
      ee080000-ee080fff : 0000:00:01.0
        ee080000-ee080fff : ohci_hcd
      ee081000-ee0810ff : 0000:00:02.0
        ee081000-ee0810ff : ehci_hcd
    ee090000-ee090bff : ee090000.pci pci@ee090000
    ee0c0000-ee0cffff : pci@ee0d0000
      ee0c0000-ee0c0fff : 0001:01:01.0
        ee0c0000-ee0c0fff : ohci_hcd
      ee0c1000-ee0c10ff : 0001:01:02.0
        ee0c1000-ee0c10ff : ehci_hcd

> When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> and end addresses.

Yeah, that's how I found this commit, without bisecting ;-)

> >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
>
> For this resource, it's very much intentional. It's a zero-based BAR which
> was left without IORESOURCE_UNSET prior to my patch leading to others part
> of the kernel to think that resource range valid and in use (in your
> case it's so small it wouldn't collide with anything but it wasn't
> properly set up resource, nonetheless).
>
> >      pci 0000:00:01.0: supports D1 D2
> >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
>
> And this as well is very much intentional.
>
> >      pci 0000:00:02.0: supports D1 D2
> >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> >      PCI: bus0: Fast back to back transfers disabled
> >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> >
> > Is that intentional?
>
> There's also that pci_dbg() in the patch which would show the original
> addresses (print the resource before setting IORESOURCE_UNSET) but to see
> it one would need to enable it with dyndbg=... Bjorn was thinking of
> making that pci_info() though so it would appear always.
>
> Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> getting assigned anywhere.

The above log is almost complete (lacked enabling the device afterwards).

AFAIU, the BARs come from the reg and ranges properties in the
PCI controller nodes;
https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562

The full related log for this device, for both instances, with the pci_dbg()
changes to pci_info():

     pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
     pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff
-> 0x00ee080000
     pci-rcar-gen2 ee090000.pci: PCI: revision 11
     pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
     pci_bus 0000:00: root bus resource [bus 00]
     pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
     pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
PCI endpoint
    -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
    -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
    +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
claim (no window)
    +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
    +pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
initial claim (no window)
    +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
     pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
PCI endpoint
    -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
    +pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
claim (no window)
    +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
     pci 0000:00:01.0: supports D1 D2
     pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
     pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
PCI endpoint
    -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
    +pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
claim (no window)
    +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
     pci 0000:00:02.0: supports D1 D2
     pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
     PCI: bus0: Fast back to back transfers disabled
     pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
     pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
     pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
     pci 0000:00:01.0: enabling device (0140 -> 0142)
     pci 0000:00:02.0: enabling device (0140 -> 0142)
     pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
     pci-rcar-gen2 ee0d0000.pci:      MEM 0x00ee0c0000..0x00ee0cffff
-> 0x00ee0c0000
     pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
     pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
     pci_bus 0001:01: root bus resource [bus 01]
     pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
     pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional
PCI endpoint
    -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
    -pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
    +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial
claim (no window)
    +pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
    +pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
initial claim (no window)
    +pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
     pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional
PCI endpoint
    -pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]
    +pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
claim (no window)
    +pci 0001:01:01.0: BAR 0 [mem size 0x00001000]
     pci 0001:01:01.0: supports D1 D2
     pci 0001:01:01.0: PME# supported from D0 D1 D2 D3hot
     pci 0001:01:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
PCI endpoint
    -pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]
    +pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
claim (no window)
    +pci 0001:01:02.0: BAR 0 [mem size 0x00000100]
     pci 0001:01:02.0: supports D1 D2
     pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
     PCI: bus1: Fast back to back transfers disabled
     pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
     pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
     pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
     pci 0001:01:01.0: enabling device (0140 -> 0142)
     pci 0001:01:02.0: enabling device (0140 -> 0142)

> You didn't report any issues beyond textual changes in the log, I suppose
> there were none beyond the log differences?

Sorry, I should have done a little bit more testing.  This is the funny
on-chip Renesas R-Car Gen2 PCI host controller with integrated OHCI/EHCI
PCI devices.  I don't have any USB devices connected, but "lspci -v"
output is the same before/after, and the OHCI/EHCI drivers probe fine.

BTW, I am seeing similar changes on rts7751r2d (qemu SuperH target r2d):

     PCI host bridge to bus 0000:00
     pci_bus 0000:00: root bus resource [io  0x1000-0x3fffff]
     pci_bus 0000:00: root bus resource [mem 0xfd000000-0xfdffffff]
     pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
     pci 0000:00:00.0: [1054:350e] type 00 class 0x060000 conventional
PCI endpoint
     pci 0000:00:00.0: [Firmware Bug]: BAR 0: invalid; can't size
     pci 0000:00:00.0: [Firmware Bug]: BAR 1: invalid; can't size
     pci 0000:00:00.0: [Firmware Bug]: BAR 2: invalid; can't size
     pci 0000:00:02.0: [10ec:8139] type 00 class 0x020000 conventional
PCI endpoint
    -pci 0000:00:02.0: BAR 0 [io  0x0000-0x00ff]
    -pci 0000:00:02.0: BAR 1 [mem 0x00000000-0x000000ff]
    -pci 0000:00:02.0: ROM [mem 0x00000000-0x0007ffff pref]
    +pci 0000:00:02.0: BAR 0 [io  0x0000-0x00ff]: no initial claim (no window)
    +pci 0000:00:02.0: BAR 0 [io  size 0x0100]
    +pci 0000:00:02.0: BAR 1 [mem 0x00000000-0x000000ff]: no initial
claim (no window)
    +pci 0000:00:02.0: BAR 1 [mem size 0x00000100]
    +pci 0000:00:02.0: ROM [mem 0x00000000-0x0007ffff pref]: no
initial claim (no window)
    +pci 0000:00:02.0: ROM [mem size 0x00080000 pref]
     pci_bus 0000:00: busn_res: [bus 00-ff] end is updated to 00
     pci 0000:00:02.0: ROM [mem 0xfd000000-0xfd07ffff pref]: assigned
     pci 0000:00:02.0: BAR 0 [io  0x1000-0x10ff]: assigned
     pci 0000:00:02.0: BAR 1 [mem 0xfd080000-0xfd0800ff]: assigned

All of these look legitimate to me, as they all start at zero.

Thanks!


Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Ilpo Järvinen 4 months, 1 week ago
On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
> > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > PNP resources are checked for conflicts with the other resource in the
> > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > with IORESOURCE_UNSET.
> > > >
> > > > Resources that do not reside within their bridge window, however, are
> > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > conflicts detected in quirk_system_pci_resources():
> > > >
> > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > ...
> > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > ...
> > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > >
> > > > Mark resources that are not contained within their bridge window with
> > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > positives for the overlap check in quirk_system_pci_resources().
> > > >
> > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > >
> > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > linux-next/master next-20250929 pci/next
> 
> > > This replaces the actual resources by their sizes in the boot log on
> > > e.g. on R-Car M2-W:
> > >
> > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > >      pci_bus 0000:00: root bus resource [bus 00]
> > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> >
> > What is going to be the parent of these resources? They don't seem to fall
> > under the root bus resource above in which case the output change is
> > intentional so they don't appear as if address range would be "okay".
> 
> >From /proc/iomem:
> 
>     ee080000-ee08ffff : pci@ee090000
>       ee080000-ee080fff : 0000:00:01.0
>         ee080000-ee080fff : ohci_hcd
>       ee081000-ee0810ff : 0000:00:02.0
>         ee081000-ee0810ff : ehci_hcd
>     ee090000-ee090bff : ee090000.pci pci@ee090000

Okay, so this seem to appear in the resource tree but not among the root 
bus resources.

>     ee0c0000-ee0cffff : pci@ee0d0000
>       ee0c0000-ee0c0fff : 0001:01:01.0
>         ee0c0000-ee0c0fff : ohci_hcd
>       ee0c1000-ee0c10ff : 0001:01:02.0
>         ee0c1000-ee0c10ff : ehci_hcd
> 
> > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > and end addresses.
> 
> Yeah, that's how I found this commit, without bisecting ;-)
> 
> > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> >
> > For this resource, it's very much intentional. It's a zero-based BAR which
> > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > of the kernel to think that resource range valid and in use (in your
> > case it's so small it wouldn't collide with anything but it wasn't
> > properly set up resource, nonetheless).
> >
> > >      pci 0000:00:01.0: supports D1 D2
> > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> >
> > And this as well is very much intentional.
> >
> > >      pci 0000:00:02.0: supports D1 D2
> > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > >      PCI: bus0: Fast back to back transfers disabled
> > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > >
> > > Is that intentional?
> >
> > There's also that pci_dbg() in the patch which would show the original
> > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > making that pci_info() though so it would appear always.
> >
> > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > getting assigned anywhere.
> 
> The above log is almost complete (lacked enabling the device afterwards).
> 
> AFAIU, the BARs come from the reg and ranges properties in the
> PCI controller nodes;
> https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562

Thanks, although I had already found this line by grep. I was just 
expecting the address appear among root bus resources too.

Curiously enough, pci_register_host_bridge() seems to try to add some 
resource from that list into bus and it's what prints those "root bus 
resource" lines and ee090000 is not among the printed lines despite 
appearing in /proc/iomem. As is, the resource tree and PCI bus view on the 
resources seems to be in disagreement and I'm not sure what to make of it.

But before considering going into that direction or figuring out why this 
ee090000 resource does not appear among root bus resources, could you 
check if the attached patch changes behavior for the resource which are 
non-zero based?

-- 
 i.

> The full related log for this device, for both instances, with the pci_dbg()
> changes to pci_info():
> 
>      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
>      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff
> -> 0x00ee080000
>      pci-rcar-gen2 ee090000.pci: PCI: revision 11
>      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
>      pci_bus 0000:00: root bus resource [bus 00]
>      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
>      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
> PCI endpoint
>     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
>     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
>     +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
> claim (no window)
>     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
>     +pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
> initial claim (no window)
>     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
>      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> PCI endpoint
>     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
>     +pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
> claim (no window)
>     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
>      pci 0000:00:01.0: supports D1 D2
>      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
>      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
> PCI endpoint
>     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
>     +pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
> claim (no window)
>     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
>      pci 0000:00:02.0: supports D1 D2
>      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
>      PCI: bus0: Fast back to back transfers disabled
>      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
>      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
>      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
>      pci 0000:00:01.0: enabling device (0140 -> 0142)
>      pci 0000:00:02.0: enabling device (0140 -> 0142)
>      pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
>      pci-rcar-gen2 ee0d0000.pci:      MEM 0x00ee0c0000..0x00ee0cffff
> -> 0x00ee0c0000
>      pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
>      pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
>      pci_bus 0001:01: root bus resource [bus 01]
>      pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
>      pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional
> PCI endpoint
>     -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
>     -pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
>     +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial
> claim (no window)
>     +pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
>     +pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
> initial claim (no window)
>     +pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
>      pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> PCI endpoint
>     -pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]
>     +pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
> claim (no window)
>     +pci 0001:01:01.0: BAR 0 [mem size 0x00001000]
>      pci 0001:01:01.0: supports D1 D2
>      pci 0001:01:01.0: PME# supported from D0 D1 D2 D3hot
>      pci 0001:01:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
> PCI endpoint
>     -pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]
>     +pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
> claim (no window)
>     +pci 0001:01:02.0: BAR 0 [mem size 0x00000100]
>      pci 0001:01:02.0: supports D1 D2
>      pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
>      PCI: bus1: Fast back to back transfers disabled
>      pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
>      pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
>      pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
>      pci 0001:01:01.0: enabling device (0140 -> 0142)
>      pci 0001:01:02.0: enabling device (0140 -> 0142)
> 
> > You didn't report any issues beyond textual changes in the log, I suppose
> > there were none beyond the log differences?
> 
> Sorry, I should have done a little bit more testing.  This is the funny
> on-chip Renesas R-Car Gen2 PCI host controller with integrated OHCI/EHCI
> PCI devices.  I don't have any USB devices connected, but "lspci -v"
> output is the same before/after, and the OHCI/EHCI drivers probe fine.
> 
> BTW, I am seeing similar changes on rts7751r2d (qemu SuperH target r2d):
> 
>      PCI host bridge to bus 0000:00
>      pci_bus 0000:00: root bus resource [io  0x1000-0x3fffff]
>      pci_bus 0000:00: root bus resource [mem 0xfd000000-0xfdffffff]
>      pci_bus 0000:00: No busn resource found for root bus, will use [bus 00-ff]
>      pci 0000:00:00.0: [1054:350e] type 00 class 0x060000 conventional
> PCI endpoint
>      pci 0000:00:00.0: [Firmware Bug]: BAR 0: invalid; can't size
>      pci 0000:00:00.0: [Firmware Bug]: BAR 1: invalid; can't size
>      pci 0000:00:00.0: [Firmware Bug]: BAR 2: invalid; can't size
>      pci 0000:00:02.0: [10ec:8139] type 00 class 0x020000 conventional
> PCI endpoint
>     -pci 0000:00:02.0: BAR 0 [io  0x0000-0x00ff]
>     -pci 0000:00:02.0: BAR 1 [mem 0x00000000-0x000000ff]
>     -pci 0000:00:02.0: ROM [mem 0x00000000-0x0007ffff pref]
>     +pci 0000:00:02.0: BAR 0 [io  0x0000-0x00ff]: no initial claim (no window)
>     +pci 0000:00:02.0: BAR 0 [io  size 0x0100]
>     +pci 0000:00:02.0: BAR 1 [mem 0x00000000-0x000000ff]: no initial
> claim (no window)
>     +pci 0000:00:02.0: BAR 1 [mem size 0x00000100]
>     +pci 0000:00:02.0: ROM [mem 0x00000000-0x0007ffff pref]: no
> initial claim (no window)
>     +pci 0000:00:02.0: ROM [mem size 0x00080000 pref]
>      pci_bus 0000:00: busn_res: [bus 00-ff] end is updated to 00
>      pci 0000:00:02.0: ROM [mem 0xfd000000-0xfd07ffff pref]: assigned
>      pci 0000:00:02.0: BAR 0 [io  0x1000-0x10ff]: assigned
>      pci 0000:00:02.0: BAR 1 [mem 0xfd080000-0xfd0800ff]: assigned
> 
> All of these look legitimate to me, as they all start at zero.
> 
> Thanks!
> 
> 
> Gr{oetje,eeting}s,
> 
>                         Geert
> 
> --
> Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
> 
> In personal conversations with technical people, I call myself a hacker. But
> when I'm talking to journalists I just say "programmer" or something like that.
>                                 -- Linus Torvalds
> 
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Geert Uytterhoeven 4 months, 1 week ago
Hi Ilpo,

On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
> On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> > <ilpo.jarvinen@linux.intel.com> wrote:
> > > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > PNP resources are checked for conflicts with the other resource in the
> > > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > > with IORESOURCE_UNSET.
> > > > >
> > > > > Resources that do not reside within their bridge window, however, are
> > > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > > conflicts detected in quirk_system_pci_resources():
> > > > >
> > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > > ...
> > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > > ...
> > > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > >
> > > > > Mark resources that are not contained within their bridge window with
> > > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > > positives for the overlap check in quirk_system_pci_resources().
> > > > >
> > > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > >
> > > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > > linux-next/master next-20250929 pci/next
> >
> > > > This replaces the actual resources by their sizes in the boot log on
> > > > e.g. on R-Car M2-W:
> > > >
> > > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> > >
> > > What is going to be the parent of these resources? They don't seem to fall
> > > under the root bus resource above in which case the output change is
> > > intentional so they don't appear as if address range would be "okay".
> >
> > >From /proc/iomem:
> >
> >     ee080000-ee08ffff : pci@ee090000
> >       ee080000-ee080fff : 0000:00:01.0
> >         ee080000-ee080fff : ohci_hcd
> >       ee081000-ee0810ff : 0000:00:02.0
> >         ee081000-ee0810ff : ehci_hcd
> >     ee090000-ee090bff : ee090000.pci pci@ee090000
>
> Okay, so this seem to appear in the resource tree but not among the root
> bus resources.
>
> >     ee0c0000-ee0cffff : pci@ee0d0000
> >       ee0c0000-ee0c0fff : 0001:01:01.0
> >         ee0c0000-ee0c0fff : ohci_hcd
> >       ee0c1000-ee0c10ff : 0001:01:02.0
> >         ee0c1000-ee0c10ff : ehci_hcd
> >
> > > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > > and end addresses.
> >
> > Yeah, that's how I found this commit, without bisecting ;-)
> >
> > > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > >
> > > For this resource, it's very much intentional. It's a zero-based BAR which
> > > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > > of the kernel to think that resource range valid and in use (in your
> > > case it's so small it wouldn't collide with anything but it wasn't
> > > properly set up resource, nonetheless).
> > >
> > > >      pci 0000:00:01.0: supports D1 D2
> > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > >
> > > And this as well is very much intentional.
> > >
> > > >      pci 0000:00:02.0: supports D1 D2
> > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > >      PCI: bus0: Fast back to back transfers disabled
> > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > >
> > > > Is that intentional?
> > >
> > > There's also that pci_dbg() in the patch which would show the original
> > > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > > making that pci_info() though so it would appear always.
> > >
> > > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > > getting assigned anywhere.
> >
> > The above log is almost complete (lacked enabling the device afterwards).
> >
> > AFAIU, the BARs come from the reg and ranges properties in the
> > PCI controller nodes;
> > https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
>
> Thanks, although I had already found this line by grep. I was just
> expecting the address appear among root bus resources too.
>
> Curiously enough, pci_register_host_bridge() seems to try to add some
> resource from that list into bus and it's what prints those "root bus
> resource" lines and ee090000 is not among the printed lines despite
> appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
> resources seems to be in disagreement and I'm not sure what to make of it.
>
> But before considering going into that direction or figuring out why this
> ee090000 resource does not appear among root bus resources, could you
> check if the attached patch changes behavior for the resource which are
> non-zero based?

This patch has no impact on dmesg, lspci output, or /proc/iomem
for pci-rcar-gen2.

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Ilpo Järvinen 4 months, 1 week ago
On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
> > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > PNP resources are checked for conflicts with the other resource in the
> > > > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > > > with IORESOURCE_UNSET.
> > > > > >
> > > > > > Resources that do not reside within their bridge window, however, are
> > > > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > > > conflicts detected in quirk_system_pci_resources():
> > > > > >
> > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > > > ...
> > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > > > ...
> > > > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > >
> > > > > > Mark resources that are not contained within their bridge window with
> > > > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > > > positives for the overlap check in quirk_system_pci_resources().
> > > > > >
> > > > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > > >
> > > > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > > > linux-next/master next-20250929 pci/next
> > >
> > > > > This replaces the actual resources by their sizes in the boot log on
> > > > > e.g. on R-Car M2-W:
> > > > >
> > > > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > > > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> > > >
> > > > What is going to be the parent of these resources? They don't seem to fall
> > > > under the root bus resource above in which case the output change is
> > > > intentional so they don't appear as if address range would be "okay".
> > >
> > > >From /proc/iomem:
> > >
> > >     ee080000-ee08ffff : pci@ee090000
> > >       ee080000-ee080fff : 0000:00:01.0
> > >         ee080000-ee080fff : ohci_hcd
> > >       ee081000-ee0810ff : 0000:00:02.0
> > >         ee081000-ee0810ff : ehci_hcd
> > >     ee090000-ee090bff : ee090000.pci pci@ee090000
> >
> > Okay, so this seem to appear in the resource tree but not among the root
> > bus resources.
> >
> > >     ee0c0000-ee0cffff : pci@ee0d0000
> > >       ee0c0000-ee0c0fff : 0001:01:01.0
> > >         ee0c0000-ee0c0fff : ohci_hcd
> > >       ee0c1000-ee0c10ff : 0001:01:02.0
> > >         ee0c1000-ee0c10ff : ehci_hcd
> > >
> > > > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > > > and end addresses.
> > >
> > > Yeah, that's how I found this commit, without bisecting ;-)
> > >
> > > > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > > > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > >
> > > > For this resource, it's very much intentional. It's a zero-based BAR which
> > > > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > > > of the kernel to think that resource range valid and in use (in your
> > > > case it's so small it wouldn't collide with anything but it wasn't
> > > > properly set up resource, nonetheless).
> > > >
> > > > >      pci 0000:00:01.0: supports D1 D2
> > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > > > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > >
> > > > And this as well is very much intentional.
> > > >
> > > > >      pci 0000:00:02.0: supports D1 D2
> > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > >
> > > > > Is that intentional?
> > > >
> > > > There's also that pci_dbg() in the patch which would show the original
> > > > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > > > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > > > making that pci_info() though so it would appear always.
> > > >
> > > > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > > > getting assigned anywhere.
> > >
> > > The above log is almost complete (lacked enabling the device afterwards).
> > >
> > > AFAIU, the BARs come from the reg and ranges properties in the
> > > PCI controller nodes;
> > > https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
> >
> > Thanks, although I had already found this line by grep. I was just
> > expecting the address appear among root bus resources too.
> >
> > Curiously enough, pci_register_host_bridge() seems to try to add some
> > resource from that list into bus and it's what prints those "root bus
> > resource" lines and ee090000 is not among the printed lines despite
> > appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
> > resources seems to be in disagreement and I'm not sure what to make of it.
> >
> > But before considering going into that direction or figuring out why this
> > ee090000 resource does not appear among root bus resources, could you
> > check if the attached patch changes behavior for the resource which are
> > non-zero based?
> 
> This patch has no impact on dmesg, lspci output, or /proc/iomem
> for pci-rcar-gen2.

It would have been too easy... :-(

I'm sorry I don't really know these platform well and I'm currently trying 
to understand what adds that ee090000 resource into the resource tree
and so far I've not been very successful.

Perhaps it would be easiest to print a stacktrace when the resource is 
added but there are many possible functions. I think all of them 
converge in __request_resource() so I suggest adding:

WARN_ON(new->start == 0xee090000);

before __request_resource() does anything.


-- 
 i.
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Geert Uytterhoeven 4 months, 1 week ago
Hi Ilpo,

On Thu, 2 Oct 2025 at 16:54, Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
> On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
> > <ilpo.jarvinen@linux.intel.com> wrote:
> > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > > > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > PNP resources are checked for conflicts with the other resource in the
> > > > > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > > > > with IORESOURCE_UNSET.
> > > > > > >
> > > > > > > Resources that do not reside within their bridge window, however, are
> > > > > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > > > > conflicts detected in quirk_system_pci_resources():
> > > > > > >
> > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > > > > ...
> > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > > > > ...
> > > > > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > >
> > > > > > > Mark resources that are not contained within their bridge window with
> > > > > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > > > > positives for the overlap check in quirk_system_pci_resources().
> > > > > > >
> > > > > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > > > >
> > > > > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > > > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > > > > linux-next/master next-20250929 pci/next
> > > >
> > > > > > This replaces the actual resources by their sizes in the boot log on
> > > > > > e.g. on R-Car M2-W:
> > > > > >
> > > > > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > > > > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> > > > >
> > > > > What is going to be the parent of these resources? They don't seem to fall
> > > > > under the root bus resource above in which case the output change is
> > > > > intentional so they don't appear as if address range would be "okay".
> > > >
> > > > >From /proc/iomem:
> > > >
> > > >     ee080000-ee08ffff : pci@ee090000
> > > >       ee080000-ee080fff : 0000:00:01.0
> > > >         ee080000-ee080fff : ohci_hcd
> > > >       ee081000-ee0810ff : 0000:00:02.0
> > > >         ee081000-ee0810ff : ehci_hcd
> > > >     ee090000-ee090bff : ee090000.pci pci@ee090000
> > >
> > > Okay, so this seem to appear in the resource tree but not among the root
> > > bus resources.
> > >
> > > >     ee0c0000-ee0cffff : pci@ee0d0000
> > > >       ee0c0000-ee0c0fff : 0001:01:01.0
> > > >         ee0c0000-ee0c0fff : ohci_hcd
> > > >       ee0c1000-ee0c10ff : 0001:01:02.0
> > > >         ee0c1000-ee0c10ff : ehci_hcd
> > > >
> > > > > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > > > > and end addresses.
> > > >
> > > > Yeah, that's how I found this commit, without bisecting ;-)
> > > >
> > > > > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > > > > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > > >
> > > > > For this resource, it's very much intentional. It's a zero-based BAR which
> > > > > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > > > > of the kernel to think that resource range valid and in use (in your
> > > > > case it's so small it wouldn't collide with anything but it wasn't
> > > > > properly set up resource, nonetheless).
> > > > >
> > > > > >      pci 0000:00:01.0: supports D1 D2
> > > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > > > > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > > >
> > > > > And this as well is very much intentional.
> > > > >
> > > > > >      pci 0000:00:02.0: supports D1 D2
> > > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > > > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > > >
> > > > > > Is that intentional?
> > > > >
> > > > > There's also that pci_dbg() in the patch which would show the original
> > > > > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > > > > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > > > > making that pci_info() though so it would appear always.
> > > > >
> > > > > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > > > > getting assigned anywhere.
> > > >
> > > > The above log is almost complete (lacked enabling the device afterwards).
> > > >
> > > > AFAIU, the BARs come from the reg and ranges properties in the
> > > > PCI controller nodes;
> > > > https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
> > >
> > > Thanks, although I had already found this line by grep. I was just
> > > expecting the address appear among root bus resources too.
> > >
> > > Curiously enough, pci_register_host_bridge() seems to try to add some
> > > resource from that list into bus and it's what prints those "root bus
> > > resource" lines and ee090000 is not among the printed lines despite
> > > appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
> > > resources seems to be in disagreement and I'm not sure what to make of it.
> > >
> > > But before considering going into that direction or figuring out why this
> > > ee090000 resource does not appear among root bus resources, could you
> > > check if the attached patch changes behavior for the resource which are
> > > non-zero based?
> >
> > This patch has no impact on dmesg, lspci output, or /proc/iomem
> > for pci-rcar-gen2.
>
> It would have been too easy... :-(
>
> I'm sorry I don't really know these platform well and I'm currently trying
> to understand what adds that ee090000 resource into the resource tree
> and so far I've not been very successful.
>
> Perhaps it would be easiest to print a stacktrace when the resource is
> added but there are many possible functions. I think all of them
> converge in __request_resource() so I suggest adding:
>
> WARN_ON(new->start == 0xee090000);
>
> before __request_resource() does anything.

    Call trace:
     unwind_backtrace from show_stack+0x10/0x14
     show_stack from dump_stack_lvl+0x7c/0xb0
     dump_stack_lvl from __warn+0x80/0x198
     __warn from warn_slowpath_fmt+0xc0/0x124
     warn_slowpath_fmt from __request_resource+0x38/0xc8
     __request_resource from __request_region+0xc4/0x1e8
     __request_region from __devm_request_region+0x80/0xac
     __devm_request_region from __devm_ioremap_resource+0xcc/0x160
     __devm_ioremap_resource from rcar_pci_probe+0x58/0x350
     rcar_pci_probe from platform_probe+0x58/0x90

I.e. the call to devm_platform_get_and_ioremap_resource() in
drivers/pci/controller/pci-rcar-gen2.c:rcar_pci_probe().

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Ilpo Järvinen 4 months, 1 week ago
On Thu, 2 Oct 2025, Geert Uytterhoeven wrote:

> Hi Ilpo,
> 
> On Thu, 2 Oct 2025 at 16:54, Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
> > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
> > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > > > > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > PNP resources are checked for conflicts with the other resource in the
> > > > > > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > > > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > > > > > with IORESOURCE_UNSET.
> > > > > > > >
> > > > > > > > Resources that do not reside within their bridge window, however, are
> > > > > > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > > > > > conflicts detected in quirk_system_pci_resources():
> > > > > > > >
> > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > > > > > ...
> > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > > > > > ...
> > > > > > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > > > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > >
> > > > > > > > Mark resources that are not contained within their bridge window with
> > > > > > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > > > > > positives for the overlap check in quirk_system_pci_resources().
> > > > > > > >
> > > > > > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > > > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > > > > >
> > > > > > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > > > > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > > > > > linux-next/master next-20250929 pci/next
> > > > >
> > > > > > > This replaces the actual resources by their sizes in the boot log on
> > > > > > > e.g. on R-Car M2-W:
> > > > > > >
> > > > > > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > > > > > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > > > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > > > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> > > > > >
> > > > > > What is going to be the parent of these resources? They don't seem to fall
> > > > > > under the root bus resource above in which case the output change is
> > > > > > intentional so they don't appear as if address range would be "okay".
> > > > >
> > > > > >From /proc/iomem:
> > > > >
> > > > >     ee080000-ee08ffff : pci@ee090000
> > > > >       ee080000-ee080fff : 0000:00:01.0
> > > > >         ee080000-ee080fff : ohci_hcd
> > > > >       ee081000-ee0810ff : 0000:00:02.0
> > > > >         ee081000-ee0810ff : ehci_hcd
> > > > >     ee090000-ee090bff : ee090000.pci pci@ee090000
> > > >
> > > > Okay, so this seem to appear in the resource tree but not among the root
> > > > bus resources.
> > > >
> > > > >     ee0c0000-ee0cffff : pci@ee0d0000
> > > > >       ee0c0000-ee0c0fff : 0001:01:01.0
> > > > >         ee0c0000-ee0c0fff : ohci_hcd
> > > > >       ee0c1000-ee0c10ff : 0001:01:02.0
> > > > >         ee0c1000-ee0c10ff : ehci_hcd
> > > > >
> > > > > > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > > > > > and end addresses.
> > > > >
> > > > > Yeah, that's how I found this commit, without bisecting ;-)
> > > > >
> > > > > > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > > > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > > > > > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > > > >
> > > > > > For this resource, it's very much intentional. It's a zero-based BAR which
> > > > > > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > > > > > of the kernel to think that resource range valid and in use (in your
> > > > > > case it's so small it wouldn't collide with anything but it wasn't
> > > > > > properly set up resource, nonetheless).
> > > > > >
> > > > > > >      pci 0000:00:01.0: supports D1 D2
> > > > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > > > > > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > > > >
> > > > > > And this as well is very much intentional.
> > > > > >
> > > > > > >      pci 0000:00:02.0: supports D1 D2
> > > > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > > > > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > > > >
> > > > > > > Is that intentional?
> > > > > >
> > > > > > There's also that pci_dbg() in the patch which would show the original
> > > > > > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > > > > > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > > > > > making that pci_info() though so it would appear always.
> > > > > >
> > > > > > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > > > > > getting assigned anywhere.
> > > > >
> > > > > The above log is almost complete (lacked enabling the device afterwards).
> > > > >
> > > > > AFAIU, the BARs come from the reg and ranges properties in the
> > > > > PCI controller nodes;
> > > > > https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
> > > >
> > > > Thanks, although I had already found this line by grep. I was just
> > > > expecting the address appear among root bus resources too.
> > > >
> > > > Curiously enough, pci_register_host_bridge() seems to try to add some
> > > > resource from that list into bus and it's what prints those "root bus
> > > > resource" lines and ee090000 is not among the printed lines despite
> > > > appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
> > > > resources seems to be in disagreement and I'm not sure what to make of it.
> > > >
> > > > But before considering going into that direction or figuring out why this
> > > > ee090000 resource does not appear among root bus resources, could you
> > > > check if the attached patch changes behavior for the resource which are
> > > > non-zero based?
> > >
> > > This patch has no impact on dmesg, lspci output, or /proc/iomem
> > > for pci-rcar-gen2.
> >
> > It would have been too easy... :-(
> >
> > I'm sorry I don't really know these platform well and I'm currently trying
> > to understand what adds that ee090000 resource into the resource tree
> > and so far I've not been very successful.
> >
> > Perhaps it would be easiest to print a stacktrace when the resource is
> > added but there are many possible functions. I think all of them
> > converge in __request_resource() so I suggest adding:
> >
> > WARN_ON(new->start == 0xee090000);
> >
> > before __request_resource() does anything.
> 
>     Call trace:
>      unwind_backtrace from show_stack+0x10/0x14
>      show_stack from dump_stack_lvl+0x7c/0xb0
>      dump_stack_lvl from __warn+0x80/0x198
>      __warn from warn_slowpath_fmt+0xc0/0x124
>      warn_slowpath_fmt from __request_resource+0x38/0xc8
>      __request_resource from __request_region+0xc4/0x1e8
>      __request_region from __devm_request_region+0x80/0xac
>      __devm_request_region from __devm_ioremap_resource+0xcc/0x160
>      __devm_ioremap_resource from rcar_pci_probe+0x58/0x350
>      rcar_pci_probe from platform_probe+0x58/0x90
> 
> I.e. the call to devm_platform_get_and_ioremap_resource() in
> drivers/pci/controller/pci-rcar-gen2.c:rcar_pci_probe().

Thanks, the patch below might help BAR0 (but I'm not sure if it's the 
correct solution due to being so unfamiliar with these kind of platforms 
and how they're initialized).

If this works, we'll also have to decide what to do with the BAR1 (it 
didn't appear in your (partial?) /proc/iomem quote so I'm left unsure how 
to approach it).

I also noticed that || COMPILE_TEST is made ineffective for this driver by 
the depends on ARM on the other line but it built just fine on x86 after 
changing the depends on to:

depends on (ARCH_RENESAS && ARM) || COMPILE_TEST


--
[PATCH 1/1] PCI: rcar-gen2: Add BAR0 into host bridge resources

On R-Car M2-W, 0000:00:00.0 has BAR0 address that does not fall under
any root bus resource.

 pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
 pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
 pci-rcar-gen2 ee090000.pci: PCI: revision 11
 pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
 pci_bus 0000:00: root bus resource [bus 00]
 pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
 pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
 pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]

The same resource, however, appears in the resource tree (from
/proc/iomem):

ee090000-ee090bff : ee090000.pci pci@ee090000

This discrepancy between the resource tree and PCI bus resources for
the root bus causes issues with the commit 06b77d5647a4 ("PCI: Mark
resources IORESOURCE_UNSET when outside bridge windows") as BAR0 is
outside of any bus resource, and therefore marked with
IORESOURCE_UNSET.

The resource is added into the resource tree by rcar_pci_probe().
Add the resource also into host bridge resources.

Reported-by: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/pci/controller/pci-rcar-gen2.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/pci/controller/pci-rcar-gen2.c b/drivers/pci/controller/pci-rcar-gen2.c
index d29866485361..72ed44fdcde4 100644
--- a/drivers/pci/controller/pci-rcar-gen2.c
+++ b/drivers/pci/controller/pci-rcar-gen2.c
@@ -294,6 +294,8 @@ static int rcar_pci_probe(struct platform_device *pdev)
 	if (IS_ERR(reg))
 		return PTR_ERR(reg);
 
+	pci_add_resource(&bridge->windows, cfg_res);
+
 	mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
 	if (!mem_res || !mem_res->start)
 		return -ENODEV;

base-commit: 8f5ae30d69d7543eee0d70083daf4de8fe15d585
-- 
2.39.5
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Geert Uytterhoeven 4 months, 1 week ago
Hi Ilpo,

On Thu, 2 Oct 2025 at 18:59, Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
> On Thu, 2 Oct 2025, Geert Uytterhoeven wrote:
> > On Thu, 2 Oct 2025 at 16:54, Ilpo Järvinen
> > <ilpo.jarvinen@linux.intel.com> wrote:
> > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
> > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > > > > > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > PNP resources are checked for conflicts with the other resource in the
> > > > > > > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > > > > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > > > > > > with IORESOURCE_UNSET.
> > > > > > > > >
> > > > > > > > > Resources that do not reside within their bridge window, however, are
> > > > > > > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > > > > > > conflicts detected in quirk_system_pci_resources():
> > > > > > > > >
> > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > > > > > > ...
> > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > > > > > > ...
> > > > > > > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > > > > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > >
> > > > > > > > > Mark resources that are not contained within their bridge window with
> > > > > > > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > > > > > > positives for the overlap check in quirk_system_pci_resources().
> > > > > > > > >
> > > > > > > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > > > > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > > > > > >
> > > > > > > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > > > > > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > > > > > > linux-next/master next-20250929 pci/next
> > > > > >
> > > > > > > > This replaces the actual resources by their sizes in the boot log on
> > > > > > > > e.g. on R-Car M2-W:
> > > > > > > >
> > > > > > > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > > > > > > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > > > > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> > > > > > >
> > > > > > > What is going to be the parent of these resources? They don't seem to fall
> > > > > > > under the root bus resource above in which case the output change is
> > > > > > > intentional so they don't appear as if address range would be "okay".
> > > > > >
> > > > > > >From /proc/iomem:
> > > > > >
> > > > > >     ee080000-ee08ffff : pci@ee090000
> > > > > >       ee080000-ee080fff : 0000:00:01.0
> > > > > >         ee080000-ee080fff : ohci_hcd
> > > > > >       ee081000-ee0810ff : 0000:00:02.0
> > > > > >         ee081000-ee0810ff : ehci_hcd
> > > > > >     ee090000-ee090bff : ee090000.pci pci@ee090000
> > > > >
> > > > > Okay, so this seem to appear in the resource tree but not among the root
> > > > > bus resources.
> > > > >
> > > > > >     ee0c0000-ee0cffff : pci@ee0d0000
> > > > > >       ee0c0000-ee0c0fff : 0001:01:01.0
> > > > > >         ee0c0000-ee0c0fff : ohci_hcd
> > > > > >       ee0c1000-ee0c10ff : 0001:01:02.0
> > > > > >         ee0c1000-ee0c10ff : ehci_hcd
> > > > > >
> > > > > > > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > > > > > > and end addresses.
> > > > > >
> > > > > > Yeah, that's how I found this commit, without bisecting ;-)
> > > > > >
> > > > > > > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > > > > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > > > > > > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > > > > >
> > > > > > > For this resource, it's very much intentional. It's a zero-based BAR which
> > > > > > > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > > > > > > of the kernel to think that resource range valid and in use (in your
> > > > > > > case it's so small it wouldn't collide with anything but it wasn't
> > > > > > > properly set up resource, nonetheless).
> > > > > > >
> > > > > > > >      pci 0000:00:01.0: supports D1 D2
> > > > > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > > > > > > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > > > > >
> > > > > > > And this as well is very much intentional.
> > > > > > >
> > > > > > > >      pci 0000:00:02.0: supports D1 D2
> > > > > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > > > > > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > > > > >
> > > > > > > > Is that intentional?
> > > > > > >
> > > > > > > There's also that pci_dbg() in the patch which would show the original
> > > > > > > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > > > > > > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > > > > > > making that pci_info() though so it would appear always.
> > > > > > >
> > > > > > > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > > > > > > getting assigned anywhere.
> > > > > >
> > > > > > The above log is almost complete (lacked enabling the device afterwards).
> > > > > >
> > > > > > AFAIU, the BARs come from the reg and ranges properties in the
> > > > > > PCI controller nodes;
> > > > > > https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
> > > > >
> > > > > Thanks, although I had already found this line by grep. I was just
> > > > > expecting the address appear among root bus resources too.
> > > > >
> > > > > Curiously enough, pci_register_host_bridge() seems to try to add some
> > > > > resource from that list into bus and it's what prints those "root bus
> > > > > resource" lines and ee090000 is not among the printed lines despite
> > > > > appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
> > > > > resources seems to be in disagreement and I'm not sure what to make of it.
> > > > >
> > > > > But before considering going into that direction or figuring out why this
> > > > > ee090000 resource does not appear among root bus resources, could you
> > > > > check if the attached patch changes behavior for the resource which are
> > > > > non-zero based?
> > > >
> > > > This patch has no impact on dmesg, lspci output, or /proc/iomem
> > > > for pci-rcar-gen2.
> > >
> > > It would have been too easy... :-(
> > >
> > > I'm sorry I don't really know these platform well and I'm currently trying
> > > to understand what adds that ee090000 resource into the resource tree
> > > and so far I've not been very successful.
> > >
> > > Perhaps it would be easiest to print a stacktrace when the resource is
> > > added but there are many possible functions. I think all of them
> > > converge in __request_resource() so I suggest adding:
> > >
> > > WARN_ON(new->start == 0xee090000);
> > >
> > > before __request_resource() does anything.
> >
> >     Call trace:
> >      unwind_backtrace from show_stack+0x10/0x14
> >      show_stack from dump_stack_lvl+0x7c/0xb0
> >      dump_stack_lvl from __warn+0x80/0x198
> >      __warn from warn_slowpath_fmt+0xc0/0x124
> >      warn_slowpath_fmt from __request_resource+0x38/0xc8
> >      __request_resource from __request_region+0xc4/0x1e8
> >      __request_region from __devm_request_region+0x80/0xac
> >      __devm_request_region from __devm_ioremap_resource+0xcc/0x160
> >      __devm_ioremap_resource from rcar_pci_probe+0x58/0x350
> >      rcar_pci_probe from platform_probe+0x58/0x90
> >
> > I.e. the call to devm_platform_get_and_ioremap_resource() in
> > drivers/pci/controller/pci-rcar-gen2.c:rcar_pci_probe().
>
> Thanks, the patch below might help BAR0 (but I'm not sure if it's the
> correct solution due to being so unfamiliar with these kind of platforms
> and how they're initialized).

Thanks, that has the following impact on dmesg:

     pci-rcar-gen2 ee090000.pci: PCI: revision 11
     pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
     pci_bus 0000:00: root bus resource [bus 00]
    -pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
    +pci_bus 0000:00: root bus resource [mem 0xee080000-0xee090bff]
     pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
PCI endpoint
    -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
claim (no window)
    -pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
    -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
initial claim (no window)
    +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
     pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
     pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
PCI endpoint
    -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
claim (no window)
     pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
     pci 0000:00:01.0: supports D1 D2
     pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
     pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
PCI endpoint
    -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
claim (no window)
     pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
     pci 0000:00:02.0: supports D1 D2
     pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
     PCI: bus0: Fast back to back transfers disabled
     pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
     pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
    -pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
    +pci_bus 0000:00: resource 4 [mem 0xee080000-0xee090bff]
     pci-rcar-gen2 ee0d0000.pci: adding to PM domain always-on
     PM: genpd_add_device: Add ee0d0000.pci to always-on
     pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
    @@ -414,26 +416,22 @@ PM: ==== always-on/ee0d0000.pci: start
     pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
     pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
     pci_bus 0001:01: root bus resource [bus 01]
    -pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
    +pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0d0bff]
     pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional
PCI endpoint
    -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial
claim (no window)
    -pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
    -pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
initial claim (no window)
    +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
     pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
     pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional
PCI endpoint
    -pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
claim (no window)
     pci 0001:01:01.0: BAR 0 [mem size 0x00001000]
     pci 0001:01:01.0: supports D1 D2
     pci 0001:01:01.0: PME# supported from D0 D1 D2 D3hot
     pci 0001:01:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
PCI endpoint
    -pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
claim (no window)
     pci 0001:01:02.0: BAR 0 [mem size 0x00000100]
     pci 0001:01:02.0: supports D1 D2
     pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
     PCI: bus1: Fast back to back transfers disabled
     pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
     pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
    -pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
    +pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0d0bff]
     rcar-pcie fe000000.pcie: adding to PM domain always-on
     PM: genpd_add_device: Add fe000000.pcie to always-on
     rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:

and on /proc/iomem (I used "diff -w" to reduce clutter):

     ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
     ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
     ec740000-ec7401ff : ec500000.sound audmapp
    -ee080000-ee08ffff : pci@ee090000
    -  ee080000-ee080fff : 0000:00:01.0
         ee080000-ee080fff : ohci_hcd
    -  ee081000-ee0810ff : 0000:00:02.0
         ee081000-ee0810ff : ehci_hcd
     ee090000-ee090bff : ee090000.pci pci@ee090000
    -ee0c0000-ee0cffff : pci@ee0d0000
    -  ee0c0000-ee0c0fff : 0001:01:01.0
         ee0c0000-ee0c0fff : ohci_hcd
    -  ee0c1000-ee0c10ff : 0001:01:02.0
         ee0c1000-ee0c10ff : ehci_hcd
     ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
     ee100000-ee100327 : ee100000.mmc mmc@ee100000

Removing the pci@ee0x0000 and 000x:0x:0x.0 entries doesn't look
right to me? Or am I missing something?

> If this works, we'll also have to decide what to do with the BAR1 (it
> didn't appear in your (partial?) /proc/iomem quote so I'm left unsure how
> to approach it).

That is indeed not visible in /proc/iomem.

I tried the following (whitespace-damaged):

--- a/drivers/pci/controller/pci-rcar-gen2.c
+++ b/drivers/pci/controller/pci-rcar-gen2.c
@@ -179,6 +179,7 @@ static void rcar_pci_setup(struct rcar_pci *priv)
        unsigned long window_size;
        unsigned long window_addr;
        unsigned long window_pci;
+       struct resource res;
        u32 val;

        entry = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM);
@@ -191,6 +192,8 @@ static void rcar_pci_setup(struct rcar_pci *priv)
                window_pci = entry->res->start - entry->offset;
                window_size = resource_size(entry->res);
        }
+       resource_set_range(&res, window_addr, window_size);
+       pci_add_resource(&bridge->windows, &res);

        pm_runtime_enable(dev);
        pm_runtime_get_sync(dev);

and only got:

     pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
     pci_bus 0000:00: root bus resource [bus 00]
     pci_bus 0000:00: root bus resource [mem 0xee080000-0xee090bff]
    +pci_bus 0000:00: busn_res: can not insert [bus 00-7fffffff] under
domain [bus 00-ff] (conflicts with (null) [bus 00-ff])
    +pci_bus 0000:00: root bus resource [mem size 0x40000000 64bit
pref window disabled]
     pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
PCI endpoint
     pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
     pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
    @@ -417,6 +419,8 @@ pci-rcar-gen2 ee0d0000.pci: PCI: revisio
     pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
     pci_bus 0001:01: root bus resource [bus 01]
     pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0d0bff]
    +pci_bus 0001:01: busn_res: can not insert [bus 01-7fffffff] under
domain [bus 00-ff] (conflicts with (null) [bus 00-ff])
    +pci_bus 0001:01: root bus resource [mem size 0x40000000 64bit
pref window disabled]
     pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional
PCI endpoint
     pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
     pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]

but no impact on /proc/iomem.

> I also noticed that || COMPILE_TEST is made ineffective for this driver by
> the depends on ARM on the other line but it built just fine on x86 after
> changing the depends on to:
>
> depends on (ARCH_RENESAS && ARM) || COMPILE_TEST

Thanks, that is a relic from the past, when the driver failed to build
on other architectures. I have submitted a fix.


Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Ilpo Järvinen 4 months, 1 week ago
On Fri, 3 Oct 2025, Geert Uytterhoeven wrote:
> On Thu, 2 Oct 2025 at 18:59, Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
> > On Thu, 2 Oct 2025, Geert Uytterhoeven wrote:
> > > On Thu, 2 Oct 2025 at 16:54, Ilpo Järvinen
> > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
> > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > > > > > > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > PNP resources are checked for conflicts with the other resource in the
> > > > > > > > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > > > > > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > > > > > > > with IORESOURCE_UNSET.
> > > > > > > > > >
> > > > > > > > > > Resources that do not reside within their bridge window, however, are
> > > > > > > > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > > > > > > > conflicts detected in quirk_system_pci_resources():
> > > > > > > > > >
> > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > > > > > > > ...
> > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > > > > > > > ...
> > > > > > > > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > > > > > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > >
> > > > > > > > > > Mark resources that are not contained within their bridge window with
> > > > > > > > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > > > > > > > positives for the overlap check in quirk_system_pci_resources().
> > > > > > > > > >
> > > > > > > > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > > > > > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > > > > > > >
> > > > > > > > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > > > > > > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > > > > > > > linux-next/master next-20250929 pci/next
> > > > > > >
> > > > > > > > > This replaces the actual resources by their sizes in the boot log on
> > > > > > > > > e.g. on R-Car M2-W:
> > > > > > > > >
> > > > > > > > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > > > > > > > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > > > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > > > > > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > > > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > > > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > > > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> > > > > > > >
> > > > > > > > What is going to be the parent of these resources? They don't seem to fall
> > > > > > > > under the root bus resource above in which case the output change is
> > > > > > > > intentional so they don't appear as if address range would be "okay".
> > > > > > >
> > > > > > > >From /proc/iomem:
> > > > > > >
> > > > > > >     ee080000-ee08ffff : pci@ee090000
> > > > > > >       ee080000-ee080fff : 0000:00:01.0
> > > > > > >         ee080000-ee080fff : ohci_hcd
> > > > > > >       ee081000-ee0810ff : 0000:00:02.0
> > > > > > >         ee081000-ee0810ff : ehci_hcd
> > > > > > >     ee090000-ee090bff : ee090000.pci pci@ee090000
> > > > > >
> > > > > > Okay, so this seem to appear in the resource tree but not among the root
> > > > > > bus resources.
> > > > > >
> > > > > > >     ee0c0000-ee0cffff : pci@ee0d0000
> > > > > > >       ee0c0000-ee0c0fff : 0001:01:01.0
> > > > > > >         ee0c0000-ee0c0fff : ohci_hcd
> > > > > > >       ee0c1000-ee0c10ff : 0001:01:02.0
> > > > > > >         ee0c1000-ee0c10ff : ehci_hcd
> > > > > > >
> > > > > > > > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > > > > > > > and end addresses.
> > > > > > >
> > > > > > > Yeah, that's how I found this commit, without bisecting ;-)
> > > > > > >
> > > > > > > > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > > > > > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > > > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > > > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > > > > > > > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > > > > > >
> > > > > > > > For this resource, it's very much intentional. It's a zero-based BAR which
> > > > > > > > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > > > > > > > of the kernel to think that resource range valid and in use (in your
> > > > > > > > case it's so small it wouldn't collide with anything but it wasn't
> > > > > > > > properly set up resource, nonetheless).
> > > > > > > >
> > > > > > > > >      pci 0000:00:01.0: supports D1 D2
> > > > > > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > > > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > > > > > > > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > > > > > >
> > > > > > > > And this as well is very much intentional.
> > > > > > > >
> > > > > > > > >      pci 0000:00:02.0: supports D1 D2
> > > > > > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > > > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > > > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > > > > > > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > > > > > >
> > > > > > > > > Is that intentional?
> > > > > > > >
> > > > > > > > There's also that pci_dbg() in the patch which would show the original
> > > > > > > > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > > > > > > > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > > > > > > > making that pci_info() though so it would appear always.
> > > > > > > >
> > > > > > > > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > > > > > > > getting assigned anywhere.
> > > > > > >
> > > > > > > The above log is almost complete (lacked enabling the device afterwards).
> > > > > > >
> > > > > > > AFAIU, the BARs come from the reg and ranges properties in the
> > > > > > > PCI controller nodes;
> > > > > > > https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
> > > > > >
> > > > > > Thanks, although I had already found this line by grep. I was just
> > > > > > expecting the address appear among root bus resources too.
> > > > > >
> > > > > > Curiously enough, pci_register_host_bridge() seems to try to add some
> > > > > > resource from that list into bus and it's what prints those "root bus
> > > > > > resource" lines and ee090000 is not among the printed lines despite
> > > > > > appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
> > > > > > resources seems to be in disagreement and I'm not sure what to make of it.
> > > > > >
> > > > > > But before considering going into that direction or figuring out why this
> > > > > > ee090000 resource does not appear among root bus resources, could you
> > > > > > check if the attached patch changes behavior for the resource which are
> > > > > > non-zero based?
> > > > >
> > > > > This patch has no impact on dmesg, lspci output, or /proc/iomem
> > > > > for pci-rcar-gen2.
> > > >
> > > > It would have been too easy... :-(
> > > >
> > > > I'm sorry I don't really know these platform well and I'm currently trying
> > > > to understand what adds that ee090000 resource into the resource tree
> > > > and so far I've not been very successful.
> > > >
> > > > Perhaps it would be easiest to print a stacktrace when the resource is
> > > > added but there are many possible functions. I think all of them
> > > > converge in __request_resource() so I suggest adding:
> > > >
> > > > WARN_ON(new->start == 0xee090000);
> > > >
> > > > before __request_resource() does anything.
> > >
> > >     Call trace:
> > >      unwind_backtrace from show_stack+0x10/0x14
> > >      show_stack from dump_stack_lvl+0x7c/0xb0
> > >      dump_stack_lvl from __warn+0x80/0x198
> > >      __warn from warn_slowpath_fmt+0xc0/0x124
> > >      warn_slowpath_fmt from __request_resource+0x38/0xc8
> > >      __request_resource from __request_region+0xc4/0x1e8
> > >      __request_region from __devm_request_region+0x80/0xac
> > >      __devm_request_region from __devm_ioremap_resource+0xcc/0x160
> > >      __devm_ioremap_resource from rcar_pci_probe+0x58/0x350
> > >      rcar_pci_probe from platform_probe+0x58/0x90
> > >
> > > I.e. the call to devm_platform_get_and_ioremap_resource() in
> > > drivers/pci/controller/pci-rcar-gen2.c:rcar_pci_probe().
> >
> > Thanks, the patch below might help BAR0 (but I'm not sure if it's the
> > correct solution due to being so unfamiliar with these kind of platforms
> > and how they're initialized).
> 
> Thanks, that has the following impact on dmesg:
> 
>      pci-rcar-gen2 ee090000.pci: PCI: revision 11
>      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
>      pci_bus 0000:00: root bus resource [bus 00]
>     -pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
>     +pci_bus 0000:00: root bus resource [mem 0xee080000-0xee090bff]
>      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
> PCI endpoint
>     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
> claim (no window)
>     -pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
>     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
> initial claim (no window)
>     +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
>      pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
>      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> PCI endpoint
>     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
> claim (no window)
>      pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
>      pci 0000:00:01.0: supports D1 D2
>      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
>      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
> PCI endpoint
>     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
> claim (no window)

Did you e.g. forget to change pci_dbg() to pci_info() as these all went 
away, I cannot see why it should disappear because of my patch?

(No need to apologize if that was the case, just confirming if that 
explains it is enough. :-))

>      pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
>      pci 0000:00:02.0: supports D1 D2
>      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
>      PCI: bus0: Fast back to back transfers disabled
>      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
>      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned

Perhaps print here what's the parent resource of these resource.

>     -pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
>     +pci_bus 0000:00: resource 4 [mem 0xee080000-0xee090bff]
>      pci-rcar-gen2 ee0d0000.pci: adding to PM domain always-on
>      PM: genpd_add_device: Add ee0d0000.pci to always-on
>      pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
>     @@ -414,26 +416,22 @@ PM: ==== always-on/ee0d0000.pci: start
>      pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
>      pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
>      pci_bus 0001:01: root bus resource [bus 01]
>     -pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
>     +pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0d0bff]
>      pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional
> PCI endpoint
>     -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial
> claim (no window)
>     -pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
>     -pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
> initial claim (no window)
>     +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
>      pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
>      pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> PCI endpoint
>     -pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
> claim (no window)
>      pci 0001:01:01.0: BAR 0 [mem size 0x00001000]
>      pci 0001:01:01.0: supports D1 D2
>      pci 0001:01:01.0: PME# supported from D0 D1 D2 D3hot
>      pci 0001:01:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
> PCI endpoint
>     -pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
> claim (no window)
>      pci 0001:01:02.0: BAR 0 [mem size 0x00000100]
>      pci 0001:01:02.0: supports D1 D2
>      pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
>      PCI: bus1: Fast back to back transfers disabled
>      pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
>      pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
>     -pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
>     +pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0d0bff]
>      rcar-pcie fe000000.pcie: adding to PM domain always-on
>      PM: genpd_add_device: Add fe000000.pcie to always-on
>      rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
> 
> and on /proc/iomem (I used "diff -w" to reduce clutter):
> 
>      ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
>      ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
>      ec740000-ec7401ff : ec500000.sound audmapp
>     -ee080000-ee08ffff : pci@ee090000

So what did add this previous? (Maybe use the same WARN_ON() trick as 
previously to find out.)

It might have gotten broken because the coalesed resource 
ee080000-ee090bff overlaps with that other resource in the resource tree. 
But I don't see anything to that effect in the log so it's either silent 
failure or there's much filtered from the log.

>     -  ee080000-ee080fff : 0000:00:01.0
>          ee080000-ee080fff : ohci_hcd
>     -  ee081000-ee0810ff : 0000:00:02.0
>          ee081000-ee0810ff : ehci_hcd
>      ee090000-ee090bff : ee090000.pci pci@ee090000
>     -ee0c0000-ee0cffff : pci@ee0d0000
>     -  ee0c0000-ee0c0fff : 0001:01:01.0
>          ee0c0000-ee0c0fff : ohci_hcd
>     -  ee0c1000-ee0c10ff : 0001:01:02.0
>          ee0c1000-ee0c10ff : ehci_hcd
>      ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
>      ee100000-ee100327 : ee100000.mmc mmc@ee100000
> 
> Removing the pci@ee0x0000 and 000x:0x:0x.0 entries doesn't look
> right to me? Or am I missing something?

I cannot understand this output, these resources seem to have been now 
left without a parent and due to -w I don't know what's their real 
indentation level.

> > If this works, we'll also have to decide what to do with the BAR1 (it
> > didn't appear in your (partial?) /proc/iomem quote so I'm left unsure how
> > to approach it).
> 
> That is indeed not visible in /proc/iomem.

I meant before the commit 06b77d5647a4d6a7 ("PCI Mark resources 
IORESOURCE_UNSET when outside bridge windows"), was it present?

> I tried the following (whitespace-damaged):
> 
> --- a/drivers/pci/controller/pci-rcar-gen2.c
> +++ b/drivers/pci/controller/pci-rcar-gen2.c
> @@ -179,6 +179,7 @@ static void rcar_pci_setup(struct rcar_pci *priv)
>         unsigned long window_size;
>         unsigned long window_addr;
>         unsigned long window_pci;
> +       struct resource res;
>         u32 val;
> 
>         entry = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM);
> @@ -191,6 +192,8 @@ static void rcar_pci_setup(struct rcar_pci *priv)
>                 window_pci = entry->res->start - entry->offset;
>                 window_size = resource_size(entry->res);
>         }
> +       resource_set_range(&res, window_addr, window_size);

You need to set flags properly too as this now tried to insert BUS, not 
MEM resource (DEFINE_RES() might be the more appropriate in that case 
anyway). 

However, if there's not &bridge->dma_ranges ranges entry, rcar_pci_setup() 
seems to initialize the resource to 0x40000000-0x7fffffff and I'm not sure 
how it's supposed to work if there's more than one of these devices as per 
the log above.

> +       pci_add_resource(&bridge->windows, &res);

What would be the backing resource in the resource tree for this? I'm not 
sure if pci_add_resource() is going to result in adding one into the 
resource tree.

>         pm_runtime_enable(dev);
>         pm_runtime_get_sync(dev);
> 
> and only got:
> 
>      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
>      pci_bus 0000:00: root bus resource [bus 00]
>      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee090bff]
>     +pci_bus 0000:00: busn_res: can not insert [bus 00-7fffffff] under
> domain [bus 00-ff] (conflicts with (null) [bus 00-ff])
>     +pci_bus 0000:00: root bus resource [mem size 0x40000000 64bit
> pref window disabled]
>      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
> PCI endpoint
>      pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
>      pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
>     @@ -417,6 +419,8 @@ pci-rcar-gen2 ee0d0000.pci: PCI: revisio
>      pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
>      pci_bus 0001:01: root bus resource [bus 01]
>      pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0d0bff]
>     +pci_bus 0001:01: busn_res: can not insert [bus 01-7fffffff] under
> domain [bus 00-ff] (conflicts with (null) [bus 00-ff])
>     +pci_bus 0001:01: root bus resource [mem size 0x40000000 64bit
> pref window disabled]
>      pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional
> PCI endpoint
>      pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
>      pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
> 
> but no impact on /proc/iomem.
> 
> > I also noticed that || COMPILE_TEST is made ineffective for this driver by
> > the depends on ARM on the other line but it built just fine on x86 after
> > changing the depends on to:
> >
> > depends on (ARCH_RENESAS && ARM) || COMPILE_TEST
> 
> Thanks, that is a relic from the past, when the driver failed to build
> on other architectures. I have submitted a fix.

Thanks.

-- 
 i.
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Geert Uytterhoeven 4 months ago
Hi Ilpo,

On Fri, 3 Oct 2025 at 16:58, Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
> On Fri, 3 Oct 2025, Geert Uytterhoeven wrote:
> > On Thu, 2 Oct 2025 at 18:59, Ilpo Järvinen
> > <ilpo.jarvinen@linux.intel.com> wrote:
> > > On Thu, 2 Oct 2025, Geert Uytterhoeven wrote:
> > > > On Thu, 2 Oct 2025 at 16:54, Ilpo Järvinen
> > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
> > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > > On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > > > > > > > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > > PNP resources are checked for conflicts with the other resource in the
> > > > > > > > > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > > > > > > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > > > > > > > > with IORESOURCE_UNSET.
> > > > > > > > > > >
> > > > > > > > > > > Resources that do not reside within their bridge window, however, are
> > > > > > > > > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > > > > > > > > conflicts detected in quirk_system_pci_resources():
> > > > > > > > > > >
> > > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > > > > > > > > ...
> > > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > > > > > > > > ...
> > > > > > > > > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > > > > > > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > >
> > > > > > > > > > > Mark resources that are not contained within their bridge window with
> > > > > > > > > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > > > > > > > > positives for the overlap check in quirk_system_pci_resources().
> > > > > > > > > > >
> > > > > > > > > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > > > > > > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > > > > > > > >
> > > > > > > > > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > > > > > > > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > > > > > > > > linux-next/master next-20250929 pci/next
> > > > > > > >
> > > > > > > > > > This replaces the actual resources by their sizes in the boot log on
> > > > > > > > > > e.g. on R-Car M2-W:
> > > > > > > > > >
> > > > > > > > > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > > > > > > > > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > > > > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > > > > > > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > > > > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > > > > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > > > > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> > > > > > > > >
> > > > > > > > > What is going to be the parent of these resources? They don't seem to fall
> > > > > > > > > under the root bus resource above in which case the output change is
> > > > > > > > > intentional so they don't appear as if address range would be "okay".
> > > > > > > >
> > > > > > > > >From /proc/iomem:
> > > > > > > >
> > > > > > > >     ee080000-ee08ffff : pci@ee090000
> > > > > > > >       ee080000-ee080fff : 0000:00:01.0
> > > > > > > >         ee080000-ee080fff : ohci_hcd
> > > > > > > >       ee081000-ee0810ff : 0000:00:02.0
> > > > > > > >         ee081000-ee0810ff : ehci_hcd
> > > > > > > >     ee090000-ee090bff : ee090000.pci pci@ee090000
> > > > > > >
> > > > > > > Okay, so this seem to appear in the resource tree but not among the root
> > > > > > > bus resources.
> > > > > > >
> > > > > > > >     ee0c0000-ee0cffff : pci@ee0d0000
> > > > > > > >       ee0c0000-ee0c0fff : 0001:01:01.0
> > > > > > > >         ee0c0000-ee0c0fff : ohci_hcd
> > > > > > > >       ee0c1000-ee0c10ff : 0001:01:02.0
> > > > > > > >         ee0c1000-ee0c10ff : ehci_hcd
> > > > > > > >
> > > > > > > > > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > > > > > > > > and end addresses.
> > > > > > > >
> > > > > > > > Yeah, that's how I found this commit, without bisecting ;-)
> > > > > > > >
> > > > > > > > > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > > > > > > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > > > > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > > > > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > > > > > > > > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > > > > > > >
> > > > > > > > > For this resource, it's very much intentional. It's a zero-based BAR which
> > > > > > > > > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > > > > > > > > of the kernel to think that resource range valid and in use (in your
> > > > > > > > > case it's so small it wouldn't collide with anything but it wasn't
> > > > > > > > > properly set up resource, nonetheless).
> > > > > > > > >
> > > > > > > > > >      pci 0000:00:01.0: supports D1 D2
> > > > > > > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > > > > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > > > > > > > > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > > > > > > >
> > > > > > > > > And this as well is very much intentional.
> > > > > > > > >
> > > > > > > > > >      pci 0000:00:02.0: supports D1 D2
> > > > > > > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > > > > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > > > > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > > > > > > > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > > > > > > >
> > > > > > > > > > Is that intentional?
> > > > > > > > >
> > > > > > > > > There's also that pci_dbg() in the patch which would show the original
> > > > > > > > > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > > > > > > > > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > > > > > > > > making that pci_info() though so it would appear always.
> > > > > > > > >
> > > > > > > > > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > > > > > > > > getting assigned anywhere.
> > > > > > > >
> > > > > > > > The above log is almost complete (lacked enabling the device afterwards).
> > > > > > > >
> > > > > > > > AFAIU, the BARs come from the reg and ranges properties in the
> > > > > > > > PCI controller nodes;
> > > > > > > > https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
> > > > > > >
> > > > > > > Thanks, although I had already found this line by grep. I was just
> > > > > > > expecting the address appear among root bus resources too.
> > > > > > >
> > > > > > > Curiously enough, pci_register_host_bridge() seems to try to add some
> > > > > > > resource from that list into bus and it's what prints those "root bus
> > > > > > > resource" lines and ee090000 is not among the printed lines despite
> > > > > > > appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
> > > > > > > resources seems to be in disagreement and I'm not sure what to make of it.
> > > > > > >
> > > > > > > But before considering going into that direction or figuring out why this
> > > > > > > ee090000 resource does not appear among root bus resources, could you
> > > > > > > check if the attached patch changes behavior for the resource which are
> > > > > > > non-zero based?
> > > > > >
> > > > > > This patch has no impact on dmesg, lspci output, or /proc/iomem
> > > > > > for pci-rcar-gen2.
> > > > >
> > > > > It would have been too easy... :-(
> > > > >
> > > > > I'm sorry I don't really know these platform well and I'm currently trying
> > > > > to understand what adds that ee090000 resource into the resource tree
> > > > > and so far I've not been very successful.
> > > > >
> > > > > Perhaps it would be easiest to print a stacktrace when the resource is
> > > > > added but there are many possible functions. I think all of them
> > > > > converge in __request_resource() so I suggest adding:
> > > > >
> > > > > WARN_ON(new->start == 0xee090000);
> > > > >
> > > > > before __request_resource() does anything.
> > > >
> > > >     Call trace:
> > > >      unwind_backtrace from show_stack+0x10/0x14
> > > >      show_stack from dump_stack_lvl+0x7c/0xb0
> > > >      dump_stack_lvl from __warn+0x80/0x198
> > > >      __warn from warn_slowpath_fmt+0xc0/0x124
> > > >      warn_slowpath_fmt from __request_resource+0x38/0xc8
> > > >      __request_resource from __request_region+0xc4/0x1e8
> > > >      __request_region from __devm_request_region+0x80/0xac
> > > >      __devm_request_region from __devm_ioremap_resource+0xcc/0x160
> > > >      __devm_ioremap_resource from rcar_pci_probe+0x58/0x350
> > > >      rcar_pci_probe from platform_probe+0x58/0x90
> > > >
> > > > I.e. the call to devm_platform_get_and_ioremap_resource() in
> > > > drivers/pci/controller/pci-rcar-gen2.c:rcar_pci_probe().
> > >
> > > Thanks, the patch below might help BAR0 (but I'm not sure if it's the
> > > correct solution due to being so unfamiliar with these kind of platforms
> > > and how they're initialized).
> >
> > Thanks, that has the following impact on dmesg:
> >
> >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> >      pci_bus 0000:00: root bus resource [bus 00]
> >     -pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> >     +pci_bus 0000:00: root bus resource [mem 0xee080000-0xee090bff]
> >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
> > PCI endpoint
> >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
> > claim (no window)
> >     -pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
> > initial claim (no window)
> >     +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> >      pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> > PCI endpoint
> >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
> > claim (no window)
> >      pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> >      pci 0000:00:01.0: supports D1 D2
> >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
> > PCI endpoint
> >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
> > claim (no window)
>
> Did you e.g. forget to change pci_dbg() to pci_info() as these all went
> away, I cannot see why it should disappear because of my patch?
>
> (No need to apologize if that was the case, just confirming if that
> explains it is enough. :-))

I indeed dropped that change. Adding it back...

> >      pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> >      pci 0000:00:02.0: supports D1 D2
> >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> >      PCI: bus0: Fast back to back transfers disabled
> >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
>
> Perhaps print here what's the parent resource of these resource.

pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned (parent
[mem 0xee080000-0xee08ffff])
pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned (parent
[mem 0xee080000-0xee08ffff])

>
> >     -pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> >     +pci_bus 0000:00: resource 4 [mem 0xee080000-0xee090bff]
> >      pci-rcar-gen2 ee0d0000.pci: adding to PM domain always-on
> >      PM: genpd_add_device: Add ee0d0000.pci to always-on
> >      pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
> >     @@ -414,26 +416,22 @@ PM: ==== always-on/ee0d0000.pci: start
> >      pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
> >      pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
> >      pci_bus 0001:01: root bus resource [bus 01]
> >     -pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
> >     +pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0d0bff]
> >      pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> >     -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial claim (no window)
> >     -pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
> >     -pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no initial claim (no window)
> >     +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
> >      pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
> >      pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> >     -pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial claim (no window)
> >      pci 0001:01:01.0: BAR 0 [mem size 0x00001000]
> >      pci 0001:01:01.0: supports D1 D2
> >      pci 0001:01:01.0: PME# supported from D0 D1 D2 D3hot
> >      pci 0001:01:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> >     -pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial claim (no window)
> >      pci 0001:01:02.0: BAR 0 [mem size 0x00000100]
> >      pci 0001:01:02.0: supports D1 D2
> >      pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
> >      PCI: bus1: Fast back to back transfers disabled
> >      pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
> >      pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
> >     -pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
> >     +pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0d0bff]
> >      rcar-pcie fe000000.pcie: adding to PM domain always-on
> >      PM: genpd_add_device: Add fe000000.pcie to always-on
> >      rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
> >
> > and on /proc/iomem (I used "diff -w" to reduce clutter):
> >
> >      ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
> >      ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
> >      ec740000-ec7401ff : ec500000.sound audmapp
> >     -ee080000-ee08ffff : pci@ee090000
>
> So what did add this previous? (Maybe use the same WARN_ON() trick as
> previously to find out.)

First call:

    + __request_resource from request_resource_conflict+0x24/0x3c
    + request_resource_conflict from devm_request_resource+0x48/0x9c
    + devm_request_resource from devm_request_pci_bus_resources+0x5c/0x70
    + devm_request_pci_bus_resources from devm_of_pci_bridge_init+0x7c/0x1c0
    + devm_of_pci_bridge_init from devm_pci_alloc_host_bridge+0x44/0x6c
    + devm_pci_alloc_host_bridge from rcar_pci_probe+0x34/0x384
    + rcar_pci_probe from platform_probe+0x58/0x90

Second call:

    + __request_resource from allocate_resource+0x1b8/0x1d4
    + allocate_resource from pci_bus_alloc_from_region+0x1e0/0x220
    + pci_bus_alloc_from_region from pci_bus_alloc_resource+0x84/0xb8
    + pci_bus_alloc_resource from _pci_assign_resource+0x78/0x150
    + _pci_assign_resource from pci_assign_resource+0x10c/0x310
    + pci_assign_resource from assign_requested_resources_sorted+0x78/0xac
    + assign_requested_resources_sorted from
__assign_resources_sorted+0x74/0x5c4
    + __assign_resources_sorted from __pci_bus_assign_resources+0x50/0x1f0
    + __pci_bus_assign_resources from
pci_assign_unassigned_root_bus_resources+0xa8/0x190
    + pci_assign_unassigned_root_bus_resources from pci_host_probe+0x5c/0xb0
    + pci_host_probe from rcar_pci_probe+0x2e0/0x384
    + rcar_pci_probe from platform_probe+0x58/0x90

Third call:

    + __request_resource from __request_region+0xc4/0x1e8
    + __request_region from __devm_request_region+0x80/0xac
    + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
    + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
    + pci_device_probe from really_probe+0x128/0x28c

Fourth call:

    + __request_region from __devm_request_region+0x80/0xac
    + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
    + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
    + pci_device_probe from really_probe+0x128/0x28c

Fifth call:

    + __request_region from __devm_request_region+0x80/0xac
    + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
    + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
    + pci_device_probe from really_probe+0x128/0x28c

> It might have gotten broken because the coalesed resource
> ee080000-ee090bff overlaps with that other resource in the resource tree.
> But I don't see anything to that effect in the log so it's either silent
> failure or there's much filtered from the log.
>
> >     -  ee080000-ee080fff : 0000:00:01.0
> >          ee080000-ee080fff : ohci_hcd
> >     -  ee081000-ee0810ff : 0000:00:02.0
> >          ee081000-ee0810ff : ehci_hcd
> >      ee090000-ee090bff : ee090000.pci pci@ee090000
> >     -ee0c0000-ee0cffff : pci@ee0d0000
> >     -  ee0c0000-ee0c0fff : 0001:01:01.0
> >          ee0c0000-ee0c0fff : ohci_hcd
> >     -  ee0c1000-ee0c10ff : 0001:01:02.0
> >          ee0c1000-ee0c10ff : ehci_hcd
> >      ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
> >      ee100000-ee100327 : ee100000.mmc mmc@ee100000
> >
> > Removing the pci@ee0x0000 and 000x:0x:0x.0 entries doesn't look
> > right to me? Or am I missing something?
>
> I cannot understand this output, these resources seem to have been now
> left without a parent and due to -w I don't know what's their real
> indentation level.

The *_hcd resources are now at the top level.

     ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
     ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
     ec740000-ec7401ff : ec500000.sound audmapp
    -ee080000-ee08ffff : pci@ee090000
    -  ee080000-ee080fff : 0000:00:01.0
    -    ee080000-ee080fff : ohci_hcd
    -  ee081000-ee0810ff : 0000:00:02.0
    -    ee081000-ee0810ff : ehci_hcd
    +ee080000-ee080fff : ohci_hcd
    +ee081000-ee0810ff : ehci_hcd
     ee090000-ee090bff : ee090000.pci pci@ee090000
    -ee0c0000-ee0cffff : pci@ee0d0000
    -  ee0c0000-ee0c0fff : 0001:01:01.0
    -    ee0c0000-ee0c0fff : ohci_hcd
    -  ee0c1000-ee0c10ff : 0001:01:02.0
    -    ee0c1000-ee0c10ff : ehci_hcd
    +ee0c0000-ee0c0fff : ohci_hcd
    +ee0c1000-ee0c10ff : ehci_hcd
     ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
     ee100000-ee100327 : ee100000.mmc mmc@ee100000
     ee140000-ee1400ff : ee140000.mmc mmc@ee140000

I assume the others are gone because they now conflict with the *_hcd
resources at the top level.

> > > If this works, we'll also have to decide what to do with the BAR1 (it
> > > didn't appear in your (partial?) /proc/iomem quote so I'm left unsure how
> > > to approach it).
> >
> > That is indeed not visible in /proc/iomem.
>
> I meant before the commit 06b77d5647a4d6a7 ("PCI Mark resources
> IORESOURCE_UNSET when outside bridge windows"), was it present?

No, it was not present.

> > I tried the following (whitespace-damaged):
> >
> > --- a/drivers/pci/controller/pci-rcar-gen2.c
> > +++ b/drivers/pci/controller/pci-rcar-gen2.c
> > @@ -179,6 +179,7 @@ static void rcar_pci_setup(struct rcar_pci *priv)
> >         unsigned long window_size;
> >         unsigned long window_addr;
> >         unsigned long window_pci;
> > +       struct resource res;
> >         u32 val;
> >
> >         entry = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM);
> > @@ -191,6 +192,8 @@ static void rcar_pci_setup(struct rcar_pci *priv)
> >                 window_pci = entry->res->start - entry->offset;
> >                 window_size = resource_size(entry->res);
> >         }
> > +       resource_set_range(&res, window_addr, window_size);
>
> You need to set flags properly too as this now tried to insert BUS, not
> MEM resource (DEFINE_RES() might be the more appropriate in that case
> anyway).
>
> However, if there's not &bridge->dma_ranges ranges entry, rcar_pci_setup()
> seems to initialize the resource to 0x40000000-0x7fffffff and I'm not sure

I guess the not &bridge->dma_ranges case dates back to the time the
DTS didn't have dma-ranges yet.  However, upon closer look, the DTS
still doesn't have dma_ranges, thus always using the default.

> how it's supposed to work if there's more than one of these devices as per
> the log above.

Upon closer look, this is not a resource of the device, but an inbound
memory region.  Hence there is no issue if multiple devices use the
same region.

>
> > +       pci_add_resource(&bridge->windows, &res);
>
> What would be the backing resource in the resource tree for this? I'm not
> sure if pci_add_resource() is going to result in adding one into the
> resource tree.

Likewise, it should not appear in /proc/ioem.
Thanks!

Gr{oetje,eeting}s,

                        Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Ilpo Järvinen 4 months ago
On Mon, 6 Oct 2025, Geert Uytterhoeven wrote:
> On Fri, 3 Oct 2025 at 16:58, Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
> > On Fri, 3 Oct 2025, Geert Uytterhoeven wrote:
> > > On Thu, 2 Oct 2025 at 18:59, Ilpo Järvinen
> > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > On Thu, 2 Oct 2025, Geert Uytterhoeven wrote:
> > > > > On Thu, 2 Oct 2025 at 16:54, Ilpo Järvinen
> > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
> > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > > > On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > > > > > > > > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > > > PNP resources are checked for conflicts with the other resource in the
> > > > > > > > > > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > > > > > > > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > > > > > > > > > with IORESOURCE_UNSET.
> > > > > > > > > > > >
> > > > > > > > > > > > Resources that do not reside within their bridge window, however, are
> > > > > > > > > > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > > > > > > > > > conflicts detected in quirk_system_pci_resources():
> > > > > > > > > > > >
> > > > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > > > > > > > > > ...
> > > > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > > > > > > > > > ...
> > > > > > > > > > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > > > > > > > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > >
> > > > > > > > > > > > Mark resources that are not contained within their bridge window with
> > > > > > > > > > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > > > > > > > > > positives for the overlap check in quirk_system_pci_resources().
> > > > > > > > > > > >
> > > > > > > > > > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > > > > > > > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > > > > > > > > >
> > > > > > > > > > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > > > > > > > > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > > > > > > > > > linux-next/master next-20250929 pci/next
> > > > > > > > >
> > > > > > > > > > > This replaces the actual resources by their sizes in the boot log on
> > > > > > > > > > > e.g. on R-Car M2-W:
> > > > > > > > > > >
> > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > > > > > > > > > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > > > > > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > > > > > > > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > > > > > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > > > > > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > > > > > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> > > > > > > > > >
> > > > > > > > > > What is going to be the parent of these resources? They don't seem to fall
> > > > > > > > > > under the root bus resource above in which case the output change is
> > > > > > > > > > intentional so they don't appear as if address range would be "okay".
> > > > > > > > >
> > > > > > > > > >From /proc/iomem:
> > > > > > > > >
> > > > > > > > >     ee080000-ee08ffff : pci@ee090000
> > > > > > > > >       ee080000-ee080fff : 0000:00:01.0
> > > > > > > > >         ee080000-ee080fff : ohci_hcd
> > > > > > > > >       ee081000-ee0810ff : 0000:00:02.0
> > > > > > > > >         ee081000-ee0810ff : ehci_hcd
> > > > > > > > >     ee090000-ee090bff : ee090000.pci pci@ee090000
> > > > > > > >
> > > > > > > > Okay, so this seem to appear in the resource tree but not among the root
> > > > > > > > bus resources.
> > > > > > > >
> > > > > > > > >     ee0c0000-ee0cffff : pci@ee0d0000
> > > > > > > > >       ee0c0000-ee0c0fff : 0001:01:01.0
> > > > > > > > >         ee0c0000-ee0c0fff : ohci_hcd
> > > > > > > > >       ee0c1000-ee0c10ff : 0001:01:02.0
> > > > > > > > >         ee0c1000-ee0c10ff : ehci_hcd
> > > > > > > > >
> > > > > > > > > > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > > > > > > > > > and end addresses.
> > > > > > > > >
> > > > > > > > > Yeah, that's how I found this commit, without bisecting ;-)
> > > > > > > > >
> > > > > > > > > > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > > > > > > > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > > > > > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > > > > > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > > > > > > > > > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > > > > > > > >
> > > > > > > > > > For this resource, it's very much intentional. It's a zero-based BAR which
> > > > > > > > > > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > > > > > > > > > of the kernel to think that resource range valid and in use (in your
> > > > > > > > > > case it's so small it wouldn't collide with anything but it wasn't
> > > > > > > > > > properly set up resource, nonetheless).
> > > > > > > > > >
> > > > > > > > > > >      pci 0000:00:01.0: supports D1 D2
> > > > > > > > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > > > > > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > > > > > > > > > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > > > > > > > >
> > > > > > > > > > And this as well is very much intentional.
> > > > > > > > > >
> > > > > > > > > > >      pci 0000:00:02.0: supports D1 D2
> > > > > > > > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > > > > > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > > > > > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > > > > > > > > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > > > > > > > >
> > > > > > > > > > > Is that intentional?
> > > > > > > > > >
> > > > > > > > > > There's also that pci_dbg() in the patch which would show the original
> > > > > > > > > > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > > > > > > > > > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > > > > > > > > > making that pci_info() though so it would appear always.
> > > > > > > > > >
> > > > > > > > > > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > > > > > > > > > getting assigned anywhere.
> > > > > > > > >
> > > > > > > > > The above log is almost complete (lacked enabling the device afterwards).
> > > > > > > > >
> > > > > > > > > AFAIU, the BARs come from the reg and ranges properties in the
> > > > > > > > > PCI controller nodes;
> > > > > > > > > https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
> > > > > > > >
> > > > > > > > Thanks, although I had already found this line by grep. I was just
> > > > > > > > expecting the address appear among root bus resources too.
> > > > > > > >
> > > > > > > > Curiously enough, pci_register_host_bridge() seems to try to add some
> > > > > > > > resource from that list into bus and it's what prints those "root bus
> > > > > > > > resource" lines and ee090000 is not among the printed lines despite
> > > > > > > > appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
> > > > > > > > resources seems to be in disagreement and I'm not sure what to make of it.
> > > > > > > >
> > > > > > > > But before considering going into that direction or figuring out why this
> > > > > > > > ee090000 resource does not appear among root bus resources, could you
> > > > > > > > check if the attached patch changes behavior for the resource which are
> > > > > > > > non-zero based?
> > > > > > >
> > > > > > > This patch has no impact on dmesg, lspci output, or /proc/iomem
> > > > > > > for pci-rcar-gen2.
> > > > > >
> > > > > > It would have been too easy... :-(
> > > > > >
> > > > > > I'm sorry I don't really know these platform well and I'm currently trying
> > > > > > to understand what adds that ee090000 resource into the resource tree
> > > > > > and so far I've not been very successful.
> > > > > >
> > > > > > Perhaps it would be easiest to print a stacktrace when the resource is
> > > > > > added but there are many possible functions. I think all of them
> > > > > > converge in __request_resource() so I suggest adding:
> > > > > >
> > > > > > WARN_ON(new->start == 0xee090000);
> > > > > >
> > > > > > before __request_resource() does anything.
> > > > >
> > > > >     Call trace:
> > > > >      unwind_backtrace from show_stack+0x10/0x14
> > > > >      show_stack from dump_stack_lvl+0x7c/0xb0
> > > > >      dump_stack_lvl from __warn+0x80/0x198
> > > > >      __warn from warn_slowpath_fmt+0xc0/0x124
> > > > >      warn_slowpath_fmt from __request_resource+0x38/0xc8
> > > > >      __request_resource from __request_region+0xc4/0x1e8
> > > > >      __request_region from __devm_request_region+0x80/0xac
> > > > >      __devm_request_region from __devm_ioremap_resource+0xcc/0x160
> > > > >      __devm_ioremap_resource from rcar_pci_probe+0x58/0x350
> > > > >      rcar_pci_probe from platform_probe+0x58/0x90
> > > > >
> > > > > I.e. the call to devm_platform_get_and_ioremap_resource() in
> > > > > drivers/pci/controller/pci-rcar-gen2.c:rcar_pci_probe().
> > > >
> > > > Thanks, the patch below might help BAR0 (but I'm not sure if it's the
> > > > correct solution due to being so unfamiliar with these kind of platforms
> > > > and how they're initialized).
> > >
> > > Thanks, that has the following impact on dmesg:
> > >
> > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > >      pci_bus 0000:00: root bus resource [bus 00]
> > >     -pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > >     +pci_bus 0000:00: root bus resource [mem 0xee080000-0xee090bff]
> > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
> > > PCI endpoint
> > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
> > > claim (no window)
> > >     -pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
> > > initial claim (no window)
> > >     +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > >      pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> > > PCI endpoint
> > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
> > > claim (no window)
> > >      pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > >      pci 0000:00:01.0: supports D1 D2
> > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
> > > PCI endpoint
> > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
> > > claim (no window)
> >
> > Did you e.g. forget to change pci_dbg() to pci_info() as these all went
> > away, I cannot see why it should disappear because of my patch?
> >
> > (No need to apologize if that was the case, just confirming if that
> > explains it is enough. :-))
> 
> I indeed dropped that change. Adding it back...
> 
> > >      pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > >      pci 0000:00:02.0: supports D1 D2
> > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > >      PCI: bus0: Fast back to back transfers disabled
> > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> >
> > Perhaps print here what's the parent resource of these resource.
> 
> pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned (parent
> [mem 0xee080000-0xee08ffff])
> pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned (parent
> [mem 0xee080000-0xee08ffff])

Were these from a kernel without the problematic commit at all or with the 
problematic commit and my fix? They look like the former case. The full 
/proc/iomem also shows all the parent resources I think.

> > >     -pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > >     +pci_bus 0000:00: resource 4 [mem 0xee080000-0xee090bff]
> > >      pci-rcar-gen2 ee0d0000.pci: adding to PM domain always-on
> > >      PM: genpd_add_device: Add ee0d0000.pci to always-on
> > >      pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
> > >     @@ -414,26 +416,22 @@ PM: ==== always-on/ee0d0000.pci: start
> > >      pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
> > >      pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
> > >      pci_bus 0001:01: root bus resource [bus 01]
> > >     -pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
> > >     +pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0d0bff]
> > >      pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > >     -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial claim (no window)
> > >     -pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
> > >     -pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no initial claim (no window)
> > >     +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
> > >      pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
> > >      pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > >     -pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial claim (no window)
> > >      pci 0001:01:01.0: BAR 0 [mem size 0x00001000]
> > >      pci 0001:01:01.0: supports D1 D2
> > >      pci 0001:01:01.0: PME# supported from D0 D1 D2 D3hot
> > >      pci 0001:01:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > >     -pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial claim (no window)
> > >      pci 0001:01:02.0: BAR 0 [mem size 0x00000100]
> > >      pci 0001:01:02.0: supports D1 D2
> > >      pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
> > >      PCI: bus1: Fast back to back transfers disabled
> > >      pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
> > >      pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
> > >     -pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
> > >     +pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0d0bff]
> > >      rcar-pcie fe000000.pcie: adding to PM domain always-on
> > >      PM: genpd_add_device: Add fe000000.pcie to always-on
> > >      rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
> > >
> > > and on /proc/iomem (I used "diff -w" to reduce clutter):
> > >
> > >      ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
> > >      ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
> > >      ec740000-ec7401ff : ec500000.sound audmapp
> > >     -ee080000-ee08ffff : pci@ee090000
> >
> > So what did add this previous? (Maybe use the same WARN_ON() trick as
> > previously to find out.)
> 
> First call:
> 
>     + __request_resource from request_resource_conflict+0x24/0x3c
>     + request_resource_conflict from devm_request_resource+0x48/0x9c
>     + devm_request_resource from devm_request_pci_bus_resources+0x5c/0x70
>     + devm_request_pci_bus_resources from devm_of_pci_bridge_init+0x7c/0x1c0
>     + devm_of_pci_bridge_init from devm_pci_alloc_host_bridge+0x44/0x6c
>     + devm_pci_alloc_host_bridge from rcar_pci_probe+0x34/0x384
>     + rcar_pci_probe from platform_probe+0x58/0x90

Thanks. So this is the call of interest, the rest are just the childs of 
it with the same address.

I'm looking devm_of_pci_get_host_bridge_resources(), it seems to read 
"ranges" property but not "reg" at all.

I wonder if devm_of_pci_get_host_bridge_resources() should also loop 
through "reg" addresses and add those to host resources which are outside 
of the "ranges"? Or if there should be a "range" that covers all what's 
in "reg" to get them added into host bridge resources? That would seem the 
generic solution instead of trying to do this in rcar_pci_probe().

(Perhaps these are stupid questions, please excuse my lack of knowledge 
about OF things.)


While looking at another issue report, I also notice of_pci_prop_ranges() 
assumes there are only bridge windows or BARs, but not both (not sure if 
this relates to anything, just an observation while reading these code 
paths).


> Second call:
> 
>     + __request_resource from allocate_resource+0x1b8/0x1d4
>     + allocate_resource from pci_bus_alloc_from_region+0x1e0/0x220
>     + pci_bus_alloc_from_region from pci_bus_alloc_resource+0x84/0xb8
>     + pci_bus_alloc_resource from _pci_assign_resource+0x78/0x150
>     + _pci_assign_resource from pci_assign_resource+0x10c/0x310
>     + pci_assign_resource from assign_requested_resources_sorted+0x78/0xac
>     + assign_requested_resources_sorted from
> __assign_resources_sorted+0x74/0x5c4
>     + __assign_resources_sorted from __pci_bus_assign_resources+0x50/0x1f0
>     + __pci_bus_assign_resources from
> pci_assign_unassigned_root_bus_resources+0xa8/0x190
>     + pci_assign_unassigned_root_bus_resources from pci_host_probe+0x5c/0xb0
>     + pci_host_probe from rcar_pci_probe+0x2e0/0x384
>     + rcar_pci_probe from platform_probe+0x58/0x90
> 
> Third call:
> 
>     + __request_resource from __request_region+0xc4/0x1e8
>     + __request_region from __devm_request_region+0x80/0xac
>     + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
>     + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
>     + pci_device_probe from really_probe+0x128/0x28c
> 
> Fourth call:
> 
>     + __request_region from __devm_request_region+0x80/0xac
>     + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
>     + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
>     + pci_device_probe from really_probe+0x128/0x28c
> 
> Fifth call:
> 
>     + __request_region from __devm_request_region+0x80/0xac
>     + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
>     + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
>     + pci_device_probe from really_probe+0x128/0x28c
> 
> > It might have gotten broken because the coalesed resource
> > ee080000-ee090bff overlaps with that other resource in the resource tree.
> > But I don't see anything to that effect in the log so it's either silent
> > failure or there's much filtered from the log.
> >
> > >     -  ee080000-ee080fff : 0000:00:01.0
> > >          ee080000-ee080fff : ohci_hcd
> > >     -  ee081000-ee0810ff : 0000:00:02.0
> > >          ee081000-ee0810ff : ehci_hcd
> > >      ee090000-ee090bff : ee090000.pci pci@ee090000
> > >     -ee0c0000-ee0cffff : pci@ee0d0000
> > >     -  ee0c0000-ee0c0fff : 0001:01:01.0
> > >          ee0c0000-ee0c0fff : ohci_hcd
> > >     -  ee0c1000-ee0c10ff : 0001:01:02.0
> > >          ee0c1000-ee0c10ff : ehci_hcd
> > >      ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
> > >      ee100000-ee100327 : ee100000.mmc mmc@ee100000
> > >
> > > Removing the pci@ee0x0000 and 000x:0x:0x.0 entries doesn't look
> > > right to me? Or am I missing something?
> >
> > I cannot understand this output, these resources seem to have been now
> > left without a parent and due to -w I don't know what's their real
> > indentation level.
> 
> The *_hcd resources are now at the top level.
> 
>      ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
>      ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
>      ec740000-ec7401ff : ec500000.sound audmapp
>     -ee080000-ee08ffff : pci@ee090000
>     -  ee080000-ee080fff : 0000:00:01.0
>     -    ee080000-ee080fff : ohci_hcd
>     -  ee081000-ee0810ff : 0000:00:02.0
>     -    ee081000-ee0810ff : ehci_hcd
>     +ee080000-ee080fff : ohci_hcd
>     +ee081000-ee0810ff : ehci_hcd
>      ee090000-ee090bff : ee090000.pci pci@ee090000
>     -ee0c0000-ee0cffff : pci@ee0d0000
>     -  ee0c0000-ee0c0fff : 0001:01:01.0
>     -    ee0c0000-ee0c0fff : ohci_hcd
>     -  ee0c1000-ee0c10ff : 0001:01:02.0
>     -    ee0c1000-ee0c10ff : ehci_hcd
>     +ee0c0000-ee0c0fff : ohci_hcd
>     +ee0c1000-ee0c10ff : ehci_hcd
>      ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
>      ee100000-ee100327 : ee100000.mmc mmc@ee100000
>      ee140000-ee1400ff : ee140000.mmc mmc@ee140000
> 
> I assume the others are gone because they now conflict with the *_hcd
> resources at the top level.

Like you initially assumed, it is wrong (while it works as the resources 
themselves don't care that much about their parent they're under as long 
as the resource is assigned, it's still not intended to be that way).

It might be worth to see if the coalescing in pci_register_host_bridge() 
somehow messes these resources up either by not doing the coalesing loop 
at all or by adding:

		if (res->parent || next_res->parent) {
			if (res->parent)
				pr_info("Has parent %pR\n", res);
			if (next_res->parent)
				pr_info("Has parent %pR\n", next_res);
			continue;
		}

...into the coalescing loop in case one of them happens to have a parent
(this is to be tested with the rcar_probe() fix).

> > > > If this works, we'll also have to decide what to do with the BAR1 (it
> > > > didn't appear in your (partial?) /proc/iomem quote so I'm left unsure how
> > > > to approach it).
> > >
> > > That is indeed not visible in /proc/iomem.
> >
> > I meant before the commit 06b77d5647a4d6a7 ("PCI Mark resources
> > IORESOURCE_UNSET when outside bridge windows"), was it present?
> 
> No, it was not present.
> 
> > > I tried the following (whitespace-damaged):
> > >
> > > --- a/drivers/pci/controller/pci-rcar-gen2.c
> > > +++ b/drivers/pci/controller/pci-rcar-gen2.c
> > > @@ -179,6 +179,7 @@ static void rcar_pci_setup(struct rcar_pci *priv)
> > >         unsigned long window_size;
> > >         unsigned long window_addr;
> > >         unsigned long window_pci;
> > > +       struct resource res;
> > >         u32 val;
> > >
> > >         entry = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM);
> > > @@ -191,6 +192,8 @@ static void rcar_pci_setup(struct rcar_pci *priv)
> > >                 window_pci = entry->res->start - entry->offset;
> > >                 window_size = resource_size(entry->res);
> > >         }
> > > +       resource_set_range(&res, window_addr, window_size);
> >
> > You need to set flags properly too as this now tried to insert BUS, not
> > MEM resource (DEFINE_RES() might be the more appropriate in that case
> > anyway).
> >
> > However, if there's not &bridge->dma_ranges ranges entry, rcar_pci_setup()
> > seems to initialize the resource to 0x40000000-0x7fffffff and I'm not sure
> 
> I guess the not &bridge->dma_ranges case dates back to the time the
> DTS didn't have dma-ranges yet.  However, upon closer look, the DTS
> still doesn't have dma_ranges, thus always using the default.
> 
> > how it's supposed to work if there's more than one of these devices as per
> > the log above.
> 
> Upon closer look, this is not a resource of the device, but an inbound
> memory region.  Hence there is no issue if multiple devices use the
> same region.
> 
> >
> > > +       pci_add_resource(&bridge->windows, &res);
> >
> > What would be the backing resource in the resource tree for this? I'm not
> > sure if pci_add_resource() is going to result in adding one into the
> > resource tree.
> 
> Likewise, it should not appear in /proc/ioem.

Thanks for checking it out.

I wonder how it would be supposed to work if PCI resource fitting logic 
finds place for it and changes its address. I don't think it would ever 
happen because it should never fit...

...But the logic still is a bit fishy if rcar2 code expects that address 
to be fixed but doesn't flag the resource to have a fixed address.

-- 
 i.
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Geert Uytterhoeven 4 months ago
Hi Ilpo,

On Mon, 6 Oct 2025 at 14:37, Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
> On Mon, 6 Oct 2025, Geert Uytterhoeven wrote:
> > On Fri, 3 Oct 2025 at 16:58, Ilpo Järvinen
> > <ilpo.jarvinen@linux.intel.com> wrote:
> > > On Fri, 3 Oct 2025, Geert Uytterhoeven wrote:
> > > > On Thu, 2 Oct 2025 at 18:59, Ilpo Järvinen
> > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > On Thu, 2 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > On Thu, 2 Oct 2025 at 16:54, Ilpo Järvinen
> > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > > On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
> > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > > > > On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> > > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > > > > > > > > > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > > > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > > > > PNP resources are checked for conflicts with the other resource in the
> > > > > > > > > > > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > > > > > > > > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > > > > > > > > > > with IORESOURCE_UNSET.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Resources that do not reside within their bridge window, however, are
> > > > > > > > > > > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > > > > > > > > > > conflicts detected in quirk_system_pci_resources():
> > > > > > > > > > > > >
> > > > > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > > > > > > > > > > ...
> > > > > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > > > > > > > > > > ...
> > > > > > > > > > > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > >
> > > > > > > > > > > > > Mark resources that are not contained within their bridge window with
> > > > > > > > > > > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > > > > > > > > > > positives for the overlap check in quirk_system_pci_resources().
> > > > > > > > > > > > >
> > > > > > > > > > > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > > > > > > > > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > > > > > > > > > >
> > > > > > > > > > > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > > > > > > > > > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > > > > > > > > > > linux-next/master next-20250929 pci/next
> > > > > > > > > >
> > > > > > > > > > > > This replaces the actual resources by their sizes in the boot log on
> > > > > > > > > > > > e.g. on R-Car M2-W:
> > > > > > > > > > > >
> > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > > > > > > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > > > > > > > > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > > > > > > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > > > > > > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > > > > > > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> > > > > > > > > > >
> > > > > > > > > > > What is going to be the parent of these resources? They don't seem to fall
> > > > > > > > > > > under the root bus resource above in which case the output change is
> > > > > > > > > > > intentional so they don't appear as if address range would be "okay".
> > > > > > > > > >
> > > > > > > > > > >From /proc/iomem:
> > > > > > > > > >
> > > > > > > > > >     ee080000-ee08ffff : pci@ee090000
> > > > > > > > > >       ee080000-ee080fff : 0000:00:01.0
> > > > > > > > > >         ee080000-ee080fff : ohci_hcd
> > > > > > > > > >       ee081000-ee0810ff : 0000:00:02.0
> > > > > > > > > >         ee081000-ee0810ff : ehci_hcd
> > > > > > > > > >     ee090000-ee090bff : ee090000.pci pci@ee090000
> > > > > > > > >
> > > > > > > > > Okay, so this seem to appear in the resource tree but not among the root
> > > > > > > > > bus resources.
> > > > > > > > >
> > > > > > > > > >     ee0c0000-ee0cffff : pci@ee0d0000
> > > > > > > > > >       ee0c0000-ee0c0fff : 0001:01:01.0
> > > > > > > > > >         ee0c0000-ee0c0fff : ohci_hcd
> > > > > > > > > >       ee0c1000-ee0c10ff : 0001:01:02.0
> > > > > > > > > >         ee0c1000-ee0c10ff : ehci_hcd
> > > > > > > > > >
> > > > > > > > > > > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > > > > > > > > > > and end addresses.
> > > > > > > > > >
> > > > > > > > > > Yeah, that's how I found this commit, without bisecting ;-)
> > > > > > > > > >
> > > > > > > > > > > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > > > > > > > > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > > > > > > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > > > > > > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > > > > > > > > > > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > > > > > > > > >
> > > > > > > > > > > For this resource, it's very much intentional. It's a zero-based BAR which
> > > > > > > > > > > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > > > > > > > > > > of the kernel to think that resource range valid and in use (in your
> > > > > > > > > > > case it's so small it wouldn't collide with anything but it wasn't
> > > > > > > > > > > properly set up resource, nonetheless).
> > > > > > > > > > >
> > > > > > > > > > > >      pci 0000:00:01.0: supports D1 D2
> > > > > > > > > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > > > > > > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > > > > > > > > > > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > > > > > > > > >
> > > > > > > > > > > And this as well is very much intentional.
> > > > > > > > > > >
> > > > > > > > > > > >      pci 0000:00:02.0: supports D1 D2
> > > > > > > > > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > > > > > > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > > > > > > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > > > > > > > > > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > > > > > > > > >
> > > > > > > > > > > > Is that intentional?
> > > > > > > > > > >
> > > > > > > > > > > There's also that pci_dbg() in the patch which would show the original
> > > > > > > > > > > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > > > > > > > > > > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > > > > > > > > > > making that pci_info() though so it would appear always.
> > > > > > > > > > >
> > > > > > > > > > > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > > > > > > > > > > getting assigned anywhere.
> > > > > > > > > >
> > > > > > > > > > The above log is almost complete (lacked enabling the device afterwards).
> > > > > > > > > >
> > > > > > > > > > AFAIU, the BARs come from the reg and ranges properties in the
> > > > > > > > > > PCI controller nodes;
> > > > > > > > > > https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
> > > > > > > > >
> > > > > > > > > Thanks, although I had already found this line by grep. I was just
> > > > > > > > > expecting the address appear among root bus resources too.
> > > > > > > > >
> > > > > > > > > Curiously enough, pci_register_host_bridge() seems to try to add some
> > > > > > > > > resource from that list into bus and it's what prints those "root bus
> > > > > > > > > resource" lines and ee090000 is not among the printed lines despite
> > > > > > > > > appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
> > > > > > > > > resources seems to be in disagreement and I'm not sure what to make of it.
> > > > > > > > >
> > > > > > > > > But before considering going into that direction or figuring out why this
> > > > > > > > > ee090000 resource does not appear among root bus resources, could you
> > > > > > > > > check if the attached patch changes behavior for the resource which are
> > > > > > > > > non-zero based?
> > > > > > > >
> > > > > > > > This patch has no impact on dmesg, lspci output, or /proc/iomem
> > > > > > > > for pci-rcar-gen2.
> > > > > > >
> > > > > > > It would have been too easy... :-(
> > > > > > >
> > > > > > > I'm sorry I don't really know these platform well and I'm currently trying
> > > > > > > to understand what adds that ee090000 resource into the resource tree
> > > > > > > and so far I've not been very successful.
> > > > > > >
> > > > > > > Perhaps it would be easiest to print a stacktrace when the resource is
> > > > > > > added but there are many possible functions. I think all of them
> > > > > > > converge in __request_resource() so I suggest adding:
> > > > > > >
> > > > > > > WARN_ON(new->start == 0xee090000);
> > > > > > >
> > > > > > > before __request_resource() does anything.
> > > > > >
> > > > > >     Call trace:
> > > > > >      unwind_backtrace from show_stack+0x10/0x14
> > > > > >      show_stack from dump_stack_lvl+0x7c/0xb0
> > > > > >      dump_stack_lvl from __warn+0x80/0x198
> > > > > >      __warn from warn_slowpath_fmt+0xc0/0x124
> > > > > >      warn_slowpath_fmt from __request_resource+0x38/0xc8
> > > > > >      __request_resource from __request_region+0xc4/0x1e8
> > > > > >      __request_region from __devm_request_region+0x80/0xac
> > > > > >      __devm_request_region from __devm_ioremap_resource+0xcc/0x160
> > > > > >      __devm_ioremap_resource from rcar_pci_probe+0x58/0x350
> > > > > >      rcar_pci_probe from platform_probe+0x58/0x90
> > > > > >
> > > > > > I.e. the call to devm_platform_get_and_ioremap_resource() in
> > > > > > drivers/pci/controller/pci-rcar-gen2.c:rcar_pci_probe().
> > > > >
> > > > > Thanks, the patch below might help BAR0 (but I'm not sure if it's the
> > > > > correct solution due to being so unfamiliar with these kind of platforms
> > > > > and how they're initialized).
> > > >
> > > > Thanks, that has the following impact on dmesg:
> > > >
> > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > >     -pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > >     +pci_bus 0000:00: root bus resource [mem 0xee080000-0xee090bff]
> > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
> > > > PCI endpoint
> > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
> > > > claim (no window)
> > > >     -pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
> > > > initial claim (no window)
> > > >     +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > >      pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> > > > PCI endpoint
> > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
> > > > claim (no window)
> > > >      pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > >      pci 0000:00:01.0: supports D1 D2
> > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
> > > > PCI endpoint
> > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
> > > > claim (no window)
> > >
> > > Did you e.g. forget to change pci_dbg() to pci_info() as these all went
> > > away, I cannot see why it should disappear because of my patch?
> > >
> > > (No need to apologize if that was the case, just confirming if that
> > > explains it is enough. :-))
> >
> > I indeed dropped that change. Adding it back...
> >
> > > >      pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > >      pci 0000:00:02.0: supports D1 D2
> > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > >      PCI: bus0: Fast back to back transfers disabled
> > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > >
> > > Perhaps print here what's the parent resource of these resource.
> >
> > pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned (parent
> > [mem 0xee080000-0xee08ffff])
> > pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned (parent
> > [mem 0xee080000-0xee08ffff])
>
> Were these from a kernel without the problematic commit at all or with the
> problematic commit and my fix? They look like the former case. The full
> /proc/iomem also shows all the parent resources I think.

With commit 06b77d5647a4d6a7 ("PCI: Mark resources IORESOURCE_UNSET when
outside bridge windows"), but without adding
"pci_add_resource(&bridge->windows, cfg_res);" in .probe().

> > > >     -pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > >     +pci_bus 0000:00: resource 4 [mem 0xee080000-0xee090bff]
> > > >      pci-rcar-gen2 ee0d0000.pci: adding to PM domain always-on
> > > >      PM: genpd_add_device: Add ee0d0000.pci to always-on
> > > >      pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
> > > >     @@ -414,26 +416,22 @@ PM: ==== always-on/ee0d0000.pci: start
> > > >      pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
> > > >      pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
> > > >      pci_bus 0001:01: root bus resource [bus 01]
> > > >     -pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
> > > >     +pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0d0bff]
> > > >      pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > >     -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial claim (no window)
> > > >     -pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
> > > >     -pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no initial claim (no window)
> > > >     +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
> > > >      pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
> > > >      pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > >     -pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial claim (no window)
> > > >      pci 0001:01:01.0: BAR 0 [mem size 0x00001000]
> > > >      pci 0001:01:01.0: supports D1 D2
> > > >      pci 0001:01:01.0: PME# supported from D0 D1 D2 D3hot
> > > >      pci 0001:01:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > >     -pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial claim (no window)
> > > >      pci 0001:01:02.0: BAR 0 [mem size 0x00000100]
> > > >      pci 0001:01:02.0: supports D1 D2
> > > >      pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
> > > >      PCI: bus1: Fast back to back transfers disabled
> > > >      pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
> > > >      pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
> > > >     -pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
> > > >     +pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0d0bff]
> > > >      rcar-pcie fe000000.pcie: adding to PM domain always-on
> > > >      PM: genpd_add_device: Add fe000000.pcie to always-on
> > > >      rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
> > > >
> > > > and on /proc/iomem (I used "diff -w" to reduce clutter):
> > > >
> > > >      ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
> > > >      ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
> > > >      ec740000-ec7401ff : ec500000.sound audmapp
> > > >     -ee080000-ee08ffff : pci@ee090000
> > >
> > > So what did add this previous? (Maybe use the same WARN_ON() trick as
> > > previously to find out.)
> >
> > First call:
> >
> >     + __request_resource from request_resource_conflict+0x24/0x3c
> >     + request_resource_conflict from devm_request_resource+0x48/0x9c
> >     + devm_request_resource from devm_request_pci_bus_resources+0x5c/0x70
> >     + devm_request_pci_bus_resources from devm_of_pci_bridge_init+0x7c/0x1c0
> >     + devm_of_pci_bridge_init from devm_pci_alloc_host_bridge+0x44/0x6c
> >     + devm_pci_alloc_host_bridge from rcar_pci_probe+0x34/0x384
> >     + rcar_pci_probe from platform_probe+0x58/0x90
>
> Thanks. So this is the call of interest, the rest are just the childs of
> it with the same address.
>
> I'm looking devm_of_pci_get_host_bridge_resources(), it seems to read
> "ranges" property but not "reg" at all.
>
> I wonder if devm_of_pci_get_host_bridge_resources() should also loop
> through "reg" addresses and add those to host resources which are outside
> of the "ranges"? Or if there should be a "range" that covers all what's
> in "reg" to get them added into host bridge resources? That would seem the
> generic solution instead of trying to do this in rcar_pci_probe().
>
> (Perhaps these are stupid questions, please excuse my lack of knowledge
> about OF things.)
>
> While looking at another issue report, I also notice of_pci_prop_ranges()
> assumes there are only bridge windows or BARs, but not both (not sure if
> this relates to anything, just an observation while reading these code
> paths).

We still have Rob in CC...

> > Second call:
> >
> >     + __request_resource from allocate_resource+0x1b8/0x1d4
> >     + allocate_resource from pci_bus_alloc_from_region+0x1e0/0x220
> >     + pci_bus_alloc_from_region from pci_bus_alloc_resource+0x84/0xb8
> >     + pci_bus_alloc_resource from _pci_assign_resource+0x78/0x150
> >     + _pci_assign_resource from pci_assign_resource+0x10c/0x310
> >     + pci_assign_resource from assign_requested_resources_sorted+0x78/0xac
> >     + assign_requested_resources_sorted from
> > __assign_resources_sorted+0x74/0x5c4
> >     + __assign_resources_sorted from __pci_bus_assign_resources+0x50/0x1f0
> >     + __pci_bus_assign_resources from
> > pci_assign_unassigned_root_bus_resources+0xa8/0x190
> >     + pci_assign_unassigned_root_bus_resources from pci_host_probe+0x5c/0xb0
> >     + pci_host_probe from rcar_pci_probe+0x2e0/0x384
> >     + rcar_pci_probe from platform_probe+0x58/0x90
> >
> > Third call:
> >
> >     + __request_resource from __request_region+0xc4/0x1e8
> >     + __request_region from __devm_request_region+0x80/0xac
> >     + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
> >     + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
> >     + pci_device_probe from really_probe+0x128/0x28c
> >
> > Fourth call:
> >
> >     + __request_region from __devm_request_region+0x80/0xac
> >     + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
> >     + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
> >     + pci_device_probe from really_probe+0x128/0x28c
> >
> > Fifth call:
> >
> >     + __request_region from __devm_request_region+0x80/0xac
> >     + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
> >     + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
> >     + pci_device_probe from really_probe+0x128/0x28c
> >
> > > It might have gotten broken because the coalesed resource
> > > ee080000-ee090bff overlaps with that other resource in the resource tree.
> > > But I don't see anything to that effect in the log so it's either silent
> > > failure or there's much filtered from the log.
> > >
> > > >     -  ee080000-ee080fff : 0000:00:01.0
> > > >          ee080000-ee080fff : ohci_hcd
> > > >     -  ee081000-ee0810ff : 0000:00:02.0
> > > >          ee081000-ee0810ff : ehci_hcd
> > > >      ee090000-ee090bff : ee090000.pci pci@ee090000
> > > >     -ee0c0000-ee0cffff : pci@ee0d0000
> > > >     -  ee0c0000-ee0c0fff : 0001:01:01.0
> > > >          ee0c0000-ee0c0fff : ohci_hcd
> > > >     -  ee0c1000-ee0c10ff : 0001:01:02.0
> > > >          ee0c1000-ee0c10ff : ehci_hcd
> > > >      ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
> > > >      ee100000-ee100327 : ee100000.mmc mmc@ee100000
> > > >
> > > > Removing the pci@ee0x0000 and 000x:0x:0x.0 entries doesn't look
> > > > right to me? Or am I missing something?
> > >
> > > I cannot understand this output, these resources seem to have been now
> > > left without a parent and due to -w I don't know what's their real
> > > indentation level.
> >
> > The *_hcd resources are now at the top level.
> >
> >      ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
> >      ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
> >      ec740000-ec7401ff : ec500000.sound audmapp
> >     -ee080000-ee08ffff : pci@ee090000
> >     -  ee080000-ee080fff : 0000:00:01.0
> >     -    ee080000-ee080fff : ohci_hcd
> >     -  ee081000-ee0810ff : 0000:00:02.0
> >     -    ee081000-ee0810ff : ehci_hcd
> >     +ee080000-ee080fff : ohci_hcd
> >     +ee081000-ee0810ff : ehci_hcd
> >      ee090000-ee090bff : ee090000.pci pci@ee090000
> >     -ee0c0000-ee0cffff : pci@ee0d0000
> >     -  ee0c0000-ee0c0fff : 0001:01:01.0
> >     -    ee0c0000-ee0c0fff : ohci_hcd
> >     -  ee0c1000-ee0c10ff : 0001:01:02.0
> >     -    ee0c1000-ee0c10ff : ehci_hcd
> >     +ee0c0000-ee0c0fff : ohci_hcd
> >     +ee0c1000-ee0c10ff : ehci_hcd
> >      ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
> >      ee100000-ee100327 : ee100000.mmc mmc@ee100000
> >      ee140000-ee1400ff : ee140000.mmc mmc@ee140000
> >
> > I assume the others are gone because they now conflict with the *_hcd
> > resources at the top level.
>
> Like you initially assumed, it is wrong (while it works as the resources
> themselves don't care that much about their parent they're under as long
> as the resource is assigned, it's still not intended to be that way).
>
> It might be worth to see if the coalescing in pci_register_host_bridge()
> somehow messes these resources up either by not doing the coalesing loop
> at all or by adding:
>
>                 if (res->parent || next_res->parent) {
>                         if (res->parent)
>                                 pr_info("Has parent %pR\n", res);
>                         if (next_res->parent)
>                                 pr_info("Has parent %pR\n", next_res);
>                         continue;
>                 }
>
> ...into the coalescing loop in case one of them happens to have a parent
> (this is to be tested with the rcar_probe() fix).

The above restores the missing entries in /proc/iomem.
Changes to dmesg:

     pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
     pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff
-> 0x00ee080000
     pci-rcar-gen2 ee090000.pci: PCI: revision 11
     pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
    +Has parent [mem 0xee080000-0xee08ffff]
     pci_bus 0000:00: root bus resource [bus 00]
     pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
    +pci_bus 0000:00: root bus resource [mem 0xee090000-0xee090bff]
     pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
PCI endpoint
    -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
claim (no window)
    -pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
    +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
     pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
initial claim (no window)
     pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
     pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
PCI endpoint
    @@ -403,21 +397,24 @@ pci 0000:00:02.0: BAR 0 [mem size 0x0000
     pci 0000:00:02.0: supports D1 D2
     pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
     PCI: bus0: Fast back to back transfers disabled
     pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
     pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
     pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
    +pci_bus 0000:00: resource 5 [mem 0xee090000-0xee090bff]
     pci-rcar-gen2 ee0d0000.pci: adding to PM domain always-on
     pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
     pci-rcar-gen2 ee0d0000.pci:      MEM 0x00ee0c0000..0x00ee0cffff
-> 0x00ee0c0000
     pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
     pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
    +Has parent [mem 0xee0c0000-0xee0cffff]
     pci_bus 0001:01: root bus resource [bus 01]
     pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
    +pci_bus 0001:01: root bus resource [mem 0xee0d0000-0xee0d0bff]
     pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional
PCI endpoint
    -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial
claim (no window)
    -pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
    +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
     pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
initial claim (no window)
     pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
     pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional
PCI endpoint
    @@ -431,9 +428,10 @@ pci 0001:01:02.0: BAR 0 [mem size 0x0000
     pci 0001:01:02.0: supports D1 D2
     pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
     PCI: bus1: Fast back to back transfers disabled
     pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
     pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
     pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
    +pci_bus 0001:01: resource 5 [mem 0xee0d0000-0xee0d0bff]

> > > > > If this works, we'll also have to decide what to do with the BAR1 (it
> > > > > didn't appear in your (partial?) /proc/iomem quote so I'm left unsure how
> > > > > to approach it).
> > > >
> > > > That is indeed not visible in /proc/iomem.
> > >
> > > I meant before the commit 06b77d5647a4d6a7 ("PCI Mark resources
> > > IORESOURCE_UNSET when outside bridge windows"), was it present?
> >
> > No, it was not present.
> >
> > > > I tried the following (whitespace-damaged):
> > > >
> > > > --- a/drivers/pci/controller/pci-rcar-gen2.c
> > > > +++ b/drivers/pci/controller/pci-rcar-gen2.c
> > > > @@ -179,6 +179,7 @@ static void rcar_pci_setup(struct rcar_pci *priv)
> > > >         unsigned long window_size;
> > > >         unsigned long window_addr;
> > > >         unsigned long window_pci;
> > > > +       struct resource res;
> > > >         u32 val;
> > > >
> > > >         entry = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM);
> > > > @@ -191,6 +192,8 @@ static void rcar_pci_setup(struct rcar_pci *priv)
> > > >                 window_pci = entry->res->start - entry->offset;
> > > >                 window_size = resource_size(entry->res);
> > > >         }
> > > > +       resource_set_range(&res, window_addr, window_size);
> > >
> > > You need to set flags properly too as this now tried to insert BUS, not
> > > MEM resource (DEFINE_RES() might be the more appropriate in that case
> > > anyway).
> > >
> > > However, if there's not &bridge->dma_ranges ranges entry, rcar_pci_setup()
> > > seems to initialize the resource to 0x40000000-0x7fffffff and I'm not sure
> >
> > I guess the not &bridge->dma_ranges case dates back to the time the
> > DTS didn't have dma-ranges yet.  However, upon closer look, the DTS
> > still doesn't have dma_ranges, thus always using the default.
> >
> > > how it's supposed to work if there's more than one of these devices as per
> > > the log above.
> >
> > Upon closer look, this is not a resource of the device, but an inbound
> > memory region.  Hence there is no issue if multiple devices use the
> > same region.
> >
> > >
> > > > +       pci_add_resource(&bridge->windows, &res);
> > >
> > > What would be the backing resource in the resource tree for this? I'm not
> > > sure if pci_add_resource() is going to result in adding one into the
> > > resource tree.
> >
> > Likewise, it should not appear in /proc/ioem.
>
> Thanks for checking it out.
>
> I wonder how it would be supposed to work if PCI resource fitting logic
> finds place for it and changes its address. I don't think it would ever
> happen because it should never fit...
>
> ...But the logic still is a bit fishy if rcar2 code expects that address
> to be fixed but doesn't flag the resource to have a fixed address.

How can the PCI resource fitting logic change it? It is an inbound
memory region, not a normal BAR?

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Ilpo Järvinen 4 months ago
+ Kai-Heng

On Mon, 6 Oct 2025, Geert Uytterhoeven wrote:
> On Mon, 6 Oct 2025 at 14:37, Ilpo Järvinen
> <ilpo.jarvinen@linux.intel.com> wrote:
> > On Mon, 6 Oct 2025, Geert Uytterhoeven wrote:
> > > On Fri, 3 Oct 2025 at 16:58, Ilpo Järvinen
> > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > On Fri, 3 Oct 2025, Geert Uytterhoeven wrote:
> > > > > On Thu, 2 Oct 2025 at 18:59, Ilpo Järvinen
> > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > On Thu, 2 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > On Thu, 2 Oct 2025 at 16:54, Ilpo Järvinen
> > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > > > On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
> > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > > > > > On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> > > > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > > > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > > > > > > > > > > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > > > > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > > > > > PNP resources are checked for conflicts with the other resource in the
> > > > > > > > > > > > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > > > > > > > > > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > > > > > > > > > > > with IORESOURCE_UNSET.
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Resources that do not reside within their bridge window, however, are
> > > > > > > > > > > > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > > > > > > > > > > > conflicts detected in quirk_system_pci_resources():
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > > > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > > > > > > > > > > > ...
> > > > > > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > > > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > > > > > > > > > > > ...
> > > > > > > > > > > > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Mark resources that are not contained within their bridge window with
> > > > > > > > > > > > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > > > > > > > > > > > positives for the overlap check in quirk_system_pci_resources().
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > > > > > > > > > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > > > > > > > > > > >
> > > > > > > > > > > > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > > > > > > > > > > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > > > > > > > > > > > linux-next/master next-20250929 pci/next
> > > > > > > > > > >
> > > > > > > > > > > > > This replaces the actual resources by their sizes in the boot log on
> > > > > > > > > > > > > e.g. on R-Car M2-W:
> > > > > > > > > > > > >
> > > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > > > > > > > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > > > > > > > > > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > > > > > > > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > > > > > > > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > > > > > > > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> > > > > > > > > > > >
> > > > > > > > > > > > What is going to be the parent of these resources? They don't seem to fall
> > > > > > > > > > > > under the root bus resource above in which case the output change is
> > > > > > > > > > > > intentional so they don't appear as if address range would be "okay".
> > > > > > > > > > >
> > > > > > > > > > > >From /proc/iomem:
> > > > > > > > > > >
> > > > > > > > > > >     ee080000-ee08ffff : pci@ee090000
> > > > > > > > > > >       ee080000-ee080fff : 0000:00:01.0
> > > > > > > > > > >         ee080000-ee080fff : ohci_hcd
> > > > > > > > > > >       ee081000-ee0810ff : 0000:00:02.0
> > > > > > > > > > >         ee081000-ee0810ff : ehci_hcd
> > > > > > > > > > >     ee090000-ee090bff : ee090000.pci pci@ee090000
> > > > > > > > > >
> > > > > > > > > > Okay, so this seem to appear in the resource tree but not among the root
> > > > > > > > > > bus resources.
> > > > > > > > > >
> > > > > > > > > > >     ee0c0000-ee0cffff : pci@ee0d0000
> > > > > > > > > > >       ee0c0000-ee0c0fff : 0001:01:01.0
> > > > > > > > > > >         ee0c0000-ee0c0fff : ohci_hcd
> > > > > > > > > > >       ee0c1000-ee0c10ff : 0001:01:02.0
> > > > > > > > > > >         ee0c1000-ee0c10ff : ehci_hcd
> > > > > > > > > > >
> > > > > > > > > > > > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > > > > > > > > > > > and end addresses.
> > > > > > > > > > >
> > > > > > > > > > > Yeah, that's how I found this commit, without bisecting ;-)
> > > > > > > > > > >
> > > > > > > > > > > > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > > > > > > > > > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > > > > > > > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > > > > > > > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > > > > > > > > > > > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > > > > > > > > > >
> > > > > > > > > > > > For this resource, it's very much intentional. It's a zero-based BAR which
> > > > > > > > > > > > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > > > > > > > > > > > of the kernel to think that resource range valid and in use (in your
> > > > > > > > > > > > case it's so small it wouldn't collide with anything but it wasn't
> > > > > > > > > > > > properly set up resource, nonetheless).
> > > > > > > > > > > >
> > > > > > > > > > > > >      pci 0000:00:01.0: supports D1 D2
> > > > > > > > > > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > > > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > > > > > > > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > > > > > > > > > > > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > > > > > > > > > >
> > > > > > > > > > > > And this as well is very much intentional.
> > > > > > > > > > > >
> > > > > > > > > > > > >      pci 0000:00:02.0: supports D1 D2
> > > > > > > > > > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > > > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > > > > > > > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > > > > > > > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > > > > > > > > > > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > > > > > > > > > >
> > > > > > > > > > > > > Is that intentional?
> > > > > > > > > > > >
> > > > > > > > > > > > There's also that pci_dbg() in the patch which would show the original
> > > > > > > > > > > > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > > > > > > > > > > > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > > > > > > > > > > > making that pci_info() though so it would appear always.
> > > > > > > > > > > >
> > > > > > > > > > > > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > > > > > > > > > > > getting assigned anywhere.
> > > > > > > > > > >
> > > > > > > > > > > The above log is almost complete (lacked enabling the device afterwards).
> > > > > > > > > > >
> > > > > > > > > > > AFAIU, the BARs come from the reg and ranges properties in the
> > > > > > > > > > > PCI controller nodes;
> > > > > > > > > > > https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
> > > > > > > > > >
> > > > > > > > > > Thanks, although I had already found this line by grep. I was just
> > > > > > > > > > expecting the address appear among root bus resources too.
> > > > > > > > > >
> > > > > > > > > > Curiously enough, pci_register_host_bridge() seems to try to add some
> > > > > > > > > > resource from that list into bus and it's what prints those "root bus
> > > > > > > > > > resource" lines and ee090000 is not among the printed lines despite
> > > > > > > > > > appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
> > > > > > > > > > resources seems to be in disagreement and I'm not sure what to make of it.
> > > > > > > > > >
> > > > > > > > > > But before considering going into that direction or figuring out why this
> > > > > > > > > > ee090000 resource does not appear among root bus resources, could you
> > > > > > > > > > check if the attached patch changes behavior for the resource which are
> > > > > > > > > > non-zero based?
> > > > > > > > >
> > > > > > > > > This patch has no impact on dmesg, lspci output, or /proc/iomem
> > > > > > > > > for pci-rcar-gen2.
> > > > > > > >
> > > > > > > > It would have been too easy... :-(
> > > > > > > >
> > > > > > > > I'm sorry I don't really know these platform well and I'm currently trying
> > > > > > > > to understand what adds that ee090000 resource into the resource tree
> > > > > > > > and so far I've not been very successful.
> > > > > > > >
> > > > > > > > Perhaps it would be easiest to print a stacktrace when the resource is
> > > > > > > > added but there are many possible functions. I think all of them
> > > > > > > > converge in __request_resource() so I suggest adding:
> > > > > > > >
> > > > > > > > WARN_ON(new->start == 0xee090000);
> > > > > > > >
> > > > > > > > before __request_resource() does anything.
> > > > > > >
> > > > > > >     Call trace:
> > > > > > >      unwind_backtrace from show_stack+0x10/0x14
> > > > > > >      show_stack from dump_stack_lvl+0x7c/0xb0
> > > > > > >      dump_stack_lvl from __warn+0x80/0x198
> > > > > > >      __warn from warn_slowpath_fmt+0xc0/0x124
> > > > > > >      warn_slowpath_fmt from __request_resource+0x38/0xc8
> > > > > > >      __request_resource from __request_region+0xc4/0x1e8
> > > > > > >      __request_region from __devm_request_region+0x80/0xac
> > > > > > >      __devm_request_region from __devm_ioremap_resource+0xcc/0x160
> > > > > > >      __devm_ioremap_resource from rcar_pci_probe+0x58/0x350
> > > > > > >      rcar_pci_probe from platform_probe+0x58/0x90
> > > > > > >
> > > > > > > I.e. the call to devm_platform_get_and_ioremap_resource() in
> > > > > > > drivers/pci/controller/pci-rcar-gen2.c:rcar_pci_probe().
> > > > > >
> > > > > > Thanks, the patch below might help BAR0 (but I'm not sure if it's the
> > > > > > correct solution due to being so unfamiliar with these kind of platforms
> > > > > > and how they're initialized).
> > > > >
> > > > > Thanks, that has the following impact on dmesg:
> > > > >
> > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > >     -pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > >     +pci_bus 0000:00: root bus resource [mem 0xee080000-0xee090bff]
> > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
> > > > > PCI endpoint
> > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
> > > > > claim (no window)
> > > > >     -pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
> > > > > initial claim (no window)
> > > > >     +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > >      pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> > > > > PCI endpoint
> > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
> > > > > claim (no window)
> > > > >      pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > > >      pci 0000:00:01.0: supports D1 D2
> > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
> > > > > PCI endpoint
> > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
> > > > > claim (no window)
> > > >
> > > > Did you e.g. forget to change pci_dbg() to pci_info() as these all went
> > > > away, I cannot see why it should disappear because of my patch?
> > > >
> > > > (No need to apologize if that was the case, just confirming if that
> > > > explains it is enough. :-))
> > >
> > > I indeed dropped that change. Adding it back...
> > >
> > > > >      pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > > >      pci 0000:00:02.0: supports D1 D2
> > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > >
> > > > Perhaps print here what's the parent resource of these resource.
> > >
> > > pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned (parent
> > > [mem 0xee080000-0xee08ffff])
> > > pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned (parent
> > > [mem 0xee080000-0xee08ffff])
> >
> > Were these from a kernel without the problematic commit at all or with the
> > problematic commit and my fix? They look like the former case. The full
> > /proc/iomem also shows all the parent resources I think.
> 
> With commit 06b77d5647a4d6a7 ("PCI: Mark resources IORESOURCE_UNSET when
> outside bridge windows"), but without adding
> "pci_add_resource(&bridge->windows, cfg_res);" in .probe().
> 
> > > > >     -pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > >     +pci_bus 0000:00: resource 4 [mem 0xee080000-0xee090bff]
> > > > >      pci-rcar-gen2 ee0d0000.pci: adding to PM domain always-on
> > > > >      PM: genpd_add_device: Add ee0d0000.pci to always-on
> > > > >      pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
> > > > >     @@ -414,26 +416,22 @@ PM: ==== always-on/ee0d0000.pci: start
> > > > >      pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
> > > > >      pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
> > > > >      pci_bus 0001:01: root bus resource [bus 01]
> > > > >     -pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
> > > > >     +pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0d0bff]
> > > > >      pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > >     -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial claim (no window)
> > > > >     -pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
> > > > >     -pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no initial claim (no window)
> > > > >     +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
> > > > >      pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > >      pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > >     -pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial claim (no window)
> > > > >      pci 0001:01:01.0: BAR 0 [mem size 0x00001000]
> > > > >      pci 0001:01:01.0: supports D1 D2
> > > > >      pci 0001:01:01.0: PME# supported from D0 D1 D2 D3hot
> > > > >      pci 0001:01:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > >     -pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial claim (no window)
> > > > >      pci 0001:01:02.0: BAR 0 [mem size 0x00000100]
> > > > >      pci 0001:01:02.0: supports D1 D2
> > > > >      pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
> > > > >      PCI: bus1: Fast back to back transfers disabled
> > > > >      pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
> > > > >      pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
> > > > >     -pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
> > > > >     +pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0d0bff]
> > > > >      rcar-pcie fe000000.pcie: adding to PM domain always-on
> > > > >      PM: genpd_add_device: Add fe000000.pcie to always-on
> > > > >      rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
> > > > >
> > > > > and on /proc/iomem (I used "diff -w" to reduce clutter):
> > > > >
> > > > >      ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
> > > > >      ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
> > > > >      ec740000-ec7401ff : ec500000.sound audmapp
> > > > >     -ee080000-ee08ffff : pci@ee090000
> > > >
> > > > So what did add this previous? (Maybe use the same WARN_ON() trick as
> > > > previously to find out.)
> > >
> > > First call:
> > >
> > >     + __request_resource from request_resource_conflict+0x24/0x3c
> > >     + request_resource_conflict from devm_request_resource+0x48/0x9c
> > >     + devm_request_resource from devm_request_pci_bus_resources+0x5c/0x70
> > >     + devm_request_pci_bus_resources from devm_of_pci_bridge_init+0x7c/0x1c0
> > >     + devm_of_pci_bridge_init from devm_pci_alloc_host_bridge+0x44/0x6c
> > >     + devm_pci_alloc_host_bridge from rcar_pci_probe+0x34/0x384
> > >     + rcar_pci_probe from platform_probe+0x58/0x90
> >
> > Thanks. So this is the call of interest, the rest are just the childs of
> > it with the same address.
> >
> > I'm looking devm_of_pci_get_host_bridge_resources(), it seems to read
> > "ranges" property but not "reg" at all.
> >
> > I wonder if devm_of_pci_get_host_bridge_resources() should also loop
> > through "reg" addresses and add those to host resources which are outside
> > of the "ranges"? Or if there should be a "range" that covers all what's
> > in "reg" to get them added into host bridge resources? That would seem the
> > generic solution instead of trying to do this in rcar_pci_probe().
> >
> > (Perhaps these are stupid questions, please excuse my lack of knowledge
> > about OF things.)
> >
> > While looking at another issue report, I also notice of_pci_prop_ranges()
> > assumes there are only bridge windows or BARs, but not both (not sure if
> > this relates to anything, just an observation while reading these code
> > paths).
> 
> We still have Rob in CC...

While we wait, can you simply try to make the "ranges" large enough to fit 
the BAR0 too?

I think it will results in making the larger "ranges" entry the parent of
ee090000-ee090bff : ee090000.pci pci@ee090000 entry in the resource tree
which would also avoid the coalescing issue.

Again, I'm not entirely sure if that would be an acceptable solution.

> > > Second call:
> > >
> > >     + __request_resource from allocate_resource+0x1b8/0x1d4
> > >     + allocate_resource from pci_bus_alloc_from_region+0x1e0/0x220
> > >     + pci_bus_alloc_from_region from pci_bus_alloc_resource+0x84/0xb8
> > >     + pci_bus_alloc_resource from _pci_assign_resource+0x78/0x150
> > >     + _pci_assign_resource from pci_assign_resource+0x10c/0x310
> > >     + pci_assign_resource from assign_requested_resources_sorted+0x78/0xac
> > >     + assign_requested_resources_sorted from
> > > __assign_resources_sorted+0x74/0x5c4
> > >     + __assign_resources_sorted from __pci_bus_assign_resources+0x50/0x1f0
> > >     + __pci_bus_assign_resources from
> > > pci_assign_unassigned_root_bus_resources+0xa8/0x190
> > >     + pci_assign_unassigned_root_bus_resources from pci_host_probe+0x5c/0xb0
> > >     + pci_host_probe from rcar_pci_probe+0x2e0/0x384
> > >     + rcar_pci_probe from platform_probe+0x58/0x90
> > >
> > > Third call:
> > >
> > >     + __request_resource from __request_region+0xc4/0x1e8
> > >     + __request_region from __devm_request_region+0x80/0xac
> > >     + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
> > >     + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
> > >     + pci_device_probe from really_probe+0x128/0x28c
> > >
> > > Fourth call:
> > >
> > >     + __request_region from __devm_request_region+0x80/0xac
> > >     + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
> > >     + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
> > >     + pci_device_probe from really_probe+0x128/0x28c
> > >
> > > Fifth call:
> > >
> > >     + __request_region from __devm_request_region+0x80/0xac
> > >     + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
> > >     + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
> > >     + pci_device_probe from really_probe+0x128/0x28c
> > >
> > > > It might have gotten broken because the coalesed resource
> > > > ee080000-ee090bff overlaps with that other resource in the resource tree.
> > > > But I don't see anything to that effect in the log so it's either silent
> > > > failure or there's much filtered from the log.
> > > >
> > > > >     -  ee080000-ee080fff : 0000:00:01.0
> > > > >          ee080000-ee080fff : ohci_hcd
> > > > >     -  ee081000-ee0810ff : 0000:00:02.0
> > > > >          ee081000-ee0810ff : ehci_hcd
> > > > >      ee090000-ee090bff : ee090000.pci pci@ee090000
> > > > >     -ee0c0000-ee0cffff : pci@ee0d0000
> > > > >     -  ee0c0000-ee0c0fff : 0001:01:01.0
> > > > >          ee0c0000-ee0c0fff : ohci_hcd
> > > > >     -  ee0c1000-ee0c10ff : 0001:01:02.0
> > > > >          ee0c1000-ee0c10ff : ehci_hcd
> > > > >      ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
> > > > >      ee100000-ee100327 : ee100000.mmc mmc@ee100000
> > > > >
> > > > > Removing the pci@ee0x0000 and 000x:0x:0x.0 entries doesn't look
> > > > > right to me? Or am I missing something?
> > > >
> > > > I cannot understand this output, these resources seem to have been now
> > > > left without a parent and due to -w I don't know what's their real
> > > > indentation level.
> > >
> > > The *_hcd resources are now at the top level.
> > >
> > >      ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
> > >      ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
> > >      ec740000-ec7401ff : ec500000.sound audmapp
> > >     -ee080000-ee08ffff : pci@ee090000
> > >     -  ee080000-ee080fff : 0000:00:01.0
> > >     -    ee080000-ee080fff : ohci_hcd
> > >     -  ee081000-ee0810ff : 0000:00:02.0
> > >     -    ee081000-ee0810ff : ehci_hcd
> > >     +ee080000-ee080fff : ohci_hcd
> > >     +ee081000-ee0810ff : ehci_hcd
> > >      ee090000-ee090bff : ee090000.pci pci@ee090000
> > >     -ee0c0000-ee0cffff : pci@ee0d0000
> > >     -  ee0c0000-ee0c0fff : 0001:01:01.0
> > >     -    ee0c0000-ee0c0fff : ohci_hcd
> > >     -  ee0c1000-ee0c10ff : 0001:01:02.0
> > >     -    ee0c1000-ee0c10ff : ehci_hcd
> > >     +ee0c0000-ee0c0fff : ohci_hcd
> > >     +ee0c1000-ee0c10ff : ehci_hcd
> > >      ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
> > >      ee100000-ee100327 : ee100000.mmc mmc@ee100000
> > >      ee140000-ee1400ff : ee140000.mmc mmc@ee140000
> > >
> > > I assume the others are gone because they now conflict with the *_hcd
> > > resources at the top level.
> >
> > Like you initially assumed, it is wrong (while it works as the resources
> > themselves don't care that much about their parent they're under as long
> > as the resource is assigned, it's still not intended to be that way).
> >
> > It might be worth to see if the coalescing in pci_register_host_bridge()
> > somehow messes these resources up either by not doing the coalesing loop
> > at all or by adding:
> >
> >                 if (res->parent || next_res->parent) {
> >                         if (res->parent)
> >                                 pr_info("Has parent %pR\n", res);
> >                         if (next_res->parent)
> >                                 pr_info("Has parent %pR\n", next_res);
> >                         continue;
> >                 }
> >
> > ...into the coalescing loop in case one of them happens to have a parent
> > (this is to be tested with the rcar_probe() fix).
> 
> The above restores the missing entries in /proc/iomem.
> Changes to dmesg:
> 
>      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
>      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff
> -> 0x00ee080000
>      pci-rcar-gen2 ee090000.pci: PCI: revision 11
>      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
>     +Has parent [mem 0xee080000-0xee08ffff]
>      pci_bus 0000:00: root bus resource [bus 00]
>      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
>     +pci_bus 0000:00: root bus resource [mem 0xee090000-0xee090bff]
>      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
> PCI endpoint
>     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
> claim (no window)
>     -pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
>     +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
>      pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
> initial claim (no window)
>      pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
>      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> PCI endpoint
>     @@ -403,21 +397,24 @@ pci 0000:00:02.0: BAR 0 [mem size 0x0000
>      pci 0000:00:02.0: supports D1 D2
>      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
>      PCI: bus0: Fast back to back transfers disabled
>      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
>      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
>      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
>     +pci_bus 0000:00: resource 5 [mem 0xee090000-0xee090bff]
>      pci-rcar-gen2 ee0d0000.pci: adding to PM domain always-on
>      pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
>      pci-rcar-gen2 ee0d0000.pci:      MEM 0x00ee0c0000..0x00ee0cffff
> -> 0x00ee0c0000
>      pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
>      pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
>     +Has parent [mem 0xee0c0000-0xee0cffff]

So this ended up locating another bug in the coalescing loop.

It's very dangerous to mess with resources like that as the backing 
struct resource is shared with whatever added that resource, which is 
different sites in this case.

I'm preparing a better approach to do the resource merge, however, I'm 
left unsure if the clean up of everything will happen "correctly" as this 
coalescing is removing resources from the resource tree which were added 
there by something else so it's then becomes very muddy who is responsible 
for releasing it in the end.

>      pci_bus 0001:01: root bus resource [bus 01]
>      pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
>     +pci_bus 0001:01: root bus resource [mem 0xee0d0000-0xee0d0bff]
>      pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional
> PCI endpoint
>     -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial
> claim (no window)
>     -pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
>     +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
>      pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
> initial claim (no window)
>      pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
>      pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> PCI endpoint
>     @@ -431,9 +428,10 @@ pci 0001:01:02.0: BAR 0 [mem size 0x0000
>      pci 0001:01:02.0: supports D1 D2
>      pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
>      PCI: bus1: Fast back to back transfers disabled
>      pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
>      pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
>      pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
>     +pci_bus 0001:01: resource 5 [mem 0xee0d0000-0xee0d0bff]
> 
> > > > > > If this works, we'll also have to decide what to do with the BAR1 (it
> > > > > > didn't appear in your (partial?) /proc/iomem quote so I'm left unsure how
> > > > > > to approach it).
> > > > >
> > > > > That is indeed not visible in /proc/iomem.
> > > >
> > > > I meant before the commit 06b77d5647a4d6a7 ("PCI Mark resources
> > > > IORESOURCE_UNSET when outside bridge windows"), was it present?
> > >
> > > No, it was not present.
> > >
> > > > > I tried the following (whitespace-damaged):
> > > > >
> > > > > --- a/drivers/pci/controller/pci-rcar-gen2.c
> > > > > +++ b/drivers/pci/controller/pci-rcar-gen2.c
> > > > > @@ -179,6 +179,7 @@ static void rcar_pci_setup(struct rcar_pci *priv)
> > > > >         unsigned long window_size;
> > > > >         unsigned long window_addr;
> > > > >         unsigned long window_pci;
> > > > > +       struct resource res;
> > > > >         u32 val;
> > > > >
> > > > >         entry = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM);
> > > > > @@ -191,6 +192,8 @@ static void rcar_pci_setup(struct rcar_pci *priv)
> > > > >                 window_pci = entry->res->start - entry->offset;
> > > > >                 window_size = resource_size(entry->res);
> > > > >         }
> > > > > +       resource_set_range(&res, window_addr, window_size);
> > > >
> > > > You need to set flags properly too as this now tried to insert BUS, not
> > > > MEM resource (DEFINE_RES() might be the more appropriate in that case
> > > > anyway).
> > > >
> > > > However, if there's not &bridge->dma_ranges ranges entry, rcar_pci_setup()
> > > > seems to initialize the resource to 0x40000000-0x7fffffff and I'm not sure
> > >
> > > I guess the not &bridge->dma_ranges case dates back to the time the
> > > DTS didn't have dma-ranges yet.  However, upon closer look, the DTS
> > > still doesn't have dma_ranges, thus always using the default.
> > >
> > > > how it's supposed to work if there's more than one of these devices as per
> > > > the log above.
> > >
> > > Upon closer look, this is not a resource of the device, but an inbound
> > > memory region.  Hence there is no issue if multiple devices use the
> > > same region.
> > >
> > > >
> > > > > +       pci_add_resource(&bridge->windows, &res);
> > > >
> > > > What would be the backing resource in the resource tree for this? I'm not
> > > > sure if pci_add_resource() is going to result in adding one into the
> > > > resource tree.
> > >
> > > Likewise, it should not appear in /proc/ioem.
> >
> > Thanks for checking it out.
> >
> > I wonder how it would be supposed to work if PCI resource fitting logic
> > finds place for it and changes its address. I don't think it would ever
> > happen because it should never fit...
> >
> > ...But the logic still is a bit fishy if rcar2 code expects that address
> > to be fixed but doesn't flag the resource to have a fixed address.
> 
> How can the PCI resource fitting logic change it? It is an inbound
> memory region, not a normal BAR?

I thought it can happen because it appears as BAR1, all resources from 
BARs are eligible for the normal assignment but now that I think it more, 
the underlying struct resource is going different for that BAR1 and the 
actual dma_ranges entry.

-- 
 i.
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Geert Uytterhoeven 4 months ago
Hi Ilpo,

On Tue, 7 Oct 2025 at 19:30, Ilpo Järvinen
<ilpo.jarvinen@linux.intel.com> wrote:
> On Mon, 6 Oct 2025, Geert Uytterhoeven wrote:
> > On Mon, 6 Oct 2025 at 14:37, Ilpo Järvinen
> > <ilpo.jarvinen@linux.intel.com> wrote:
> > > On Mon, 6 Oct 2025, Geert Uytterhoeven wrote:
> > > > On Fri, 3 Oct 2025 at 16:58, Ilpo Järvinen
> > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > On Fri, 3 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > On Thu, 2 Oct 2025 at 18:59, Ilpo Järvinen
> > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > On Thu, 2 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > > On Thu, 2 Oct 2025 at 16:54, Ilpo Järvinen
> > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > > > > On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
> > > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > > On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
> > > > > > > > > > > > On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
> > > > > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > > > > On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
> > > > > > > > > > > > > > On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
> > > > > > > > > > > > > > <ilpo.jarvinen@linux.intel.com> wrote:
> > > > > > > > > > > > > > > PNP resources are checked for conflicts with the other resource in the
> > > > > > > > > > > > > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > > > > > > > > > > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > > > > > > > > > > > > with IORESOURCE_UNSET.
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Resources that do not reside within their bridge window, however, are
> > > > > > > > > > > > > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > > > > > > > > > > > > conflicts detected in quirk_system_pci_resources():
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > > > > > > > > > > > > > > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > > > > > > > > > > > > > > ...
> > > > > > > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > > > > > > > > > > > > > > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > > > > > > > > > > > > > > ...
> > > > > > > > > > > > > > > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Mark resources that are not contained within their bridge window with
> > > > > > > > > > > > > > > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > > > > > > > > > > > > > > positives for the overlap check in quirk_system_pci_resources().
> > > > > > > > > > > > > > >
> > > > > > > > > > > > > > > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > > > > > > > > > > > > > > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
> > > > > > > > > > > > > > Mark resources IORESOURCE_UNSET when outside bridge windows") in
> > > > > > > > > > > > > > linux-next/master next-20250929 pci/next
> > > > > > > > > > > >
> > > > > > > > > > > > > > This replaces the actual resources by their sizes in the boot log on
> > > > > > > > > > > > > > e.g. on R-Car M2-W:
> > > > > > > > > > > > > >
> > > > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
> > > > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
> > > > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > > > > > > > > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > > > > > > > > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > > > > > > > > > > >      pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > > > > > > > > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > > > > > > > > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > > > > > > > > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
> > > > > > > > > > > > >
> > > > > > > > > > > > > What is going to be the parent of these resources? They don't seem to fall
> > > > > > > > > > > > > under the root bus resource above in which case the output change is
> > > > > > > > > > > > > intentional so they don't appear as if address range would be "okay".
> > > > > > > > > > > >
> > > > > > > > > > > > >From /proc/iomem:
> > > > > > > > > > > >
> > > > > > > > > > > >     ee080000-ee08ffff : pci@ee090000
> > > > > > > > > > > >       ee080000-ee080fff : 0000:00:01.0
> > > > > > > > > > > >         ee080000-ee080fff : ohci_hcd
> > > > > > > > > > > >       ee081000-ee0810ff : 0000:00:02.0
> > > > > > > > > > > >         ee081000-ee0810ff : ehci_hcd
> > > > > > > > > > > >     ee090000-ee090bff : ee090000.pci pci@ee090000
> > > > > > > > > > >
> > > > > > > > > > > Okay, so this seem to appear in the resource tree but not among the root
> > > > > > > > > > > bus resources.
> > > > > > > > > > >
> > > > > > > > > > > >     ee0c0000-ee0cffff : pci@ee0d0000
> > > > > > > > > > > >       ee0c0000-ee0c0fff : 0001:01:01.0
> > > > > > > > > > > >         ee0c0000-ee0c0fff : ohci_hcd
> > > > > > > > > > > >       ee0c1000-ee0c10ff : 0001:01:02.0
> > > > > > > > > > > >         ee0c1000-ee0c10ff : ehci_hcd
> > > > > > > > > > > >
> > > > > > > > > > > > > When IORESOURCE_UNSET is set in a resource, %pR does not print the start
> > > > > > > > > > > > > and end addresses.
> > > > > > > > > > > >
> > > > > > > > > > > > Yeah, that's how I found this commit, without bisecting ;-)
> > > > > > > > > > > >
> > > > > > > > > > > > > >     +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > > > > > > > > > > >     +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > > > > > > > > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > > > > > > > > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
> > > > > > > > > > > > > >     +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > > > > > > > > > > >
> > > > > > > > > > > > > For this resource, it's very much intentional. It's a zero-based BAR which
> > > > > > > > > > > > > was left without IORESOURCE_UNSET prior to my patch leading to others part
> > > > > > > > > > > > > of the kernel to think that resource range valid and in use (in your
> > > > > > > > > > > > > case it's so small it wouldn't collide with anything but it wasn't
> > > > > > > > > > > > > properly set up resource, nonetheless).
> > > > > > > > > > > > >
> > > > > > > > > > > > > >      pci 0000:00:01.0: supports D1 D2
> > > > > > > > > > > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > > > > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > > > > > > > > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
> > > > > > > > > > > > > >     +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > > > > > > > > > > >
> > > > > > > > > > > > > And this as well is very much intentional.
> > > > > > > > > > > > >
> > > > > > > > > > > > > >      pci 0000:00:02.0: supports D1 D2
> > > > > > > > > > > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > > > > > > > > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > > > > > > > > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > > > > > > > > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > > > > > > > > > > > >      pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > > > > > > > > > > >
> > > > > > > > > > > > > > Is that intentional?
> > > > > > > > > > > > >
> > > > > > > > > > > > > There's also that pci_dbg() in the patch which would show the original
> > > > > > > > > > > > > addresses (print the resource before setting IORESOURCE_UNSET) but to see
> > > > > > > > > > > > > it one would need to enable it with dyndbg=... Bjorn was thinking of
> > > > > > > > > > > > > making that pci_info() though so it would appear always.
> > > > > > > > > > > > >
> > > > > > > > > > > > > Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
> > > > > > > > > > > > > getting assigned anywhere.
> > > > > > > > > > > >
> > > > > > > > > > > > The above log is almost complete (lacked enabling the device afterwards).
> > > > > > > > > > > >
> > > > > > > > > > > > AFAIU, the BARs come from the reg and ranges properties in the
> > > > > > > > > > > > PCI controller nodes;
> > > > > > > > > > > > https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
> > > > > > > > > > >
> > > > > > > > > > > Thanks, although I had already found this line by grep. I was just
> > > > > > > > > > > expecting the address appear among root bus resources too.
> > > > > > > > > > >
> > > > > > > > > > > Curiously enough, pci_register_host_bridge() seems to try to add some
> > > > > > > > > > > resource from that list into bus and it's what prints those "root bus
> > > > > > > > > > > resource" lines and ee090000 is not among the printed lines despite
> > > > > > > > > > > appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
> > > > > > > > > > > resources seems to be in disagreement and I'm not sure what to make of it.
> > > > > > > > > > >
> > > > > > > > > > > But before considering going into that direction or figuring out why this
> > > > > > > > > > > ee090000 resource does not appear among root bus resources, could you
> > > > > > > > > > > check if the attached patch changes behavior for the resource which are
> > > > > > > > > > > non-zero based?
> > > > > > > > > >
> > > > > > > > > > This patch has no impact on dmesg, lspci output, or /proc/iomem
> > > > > > > > > > for pci-rcar-gen2.
> > > > > > > > >
> > > > > > > > > It would have been too easy... :-(
> > > > > > > > >
> > > > > > > > > I'm sorry I don't really know these platform well and I'm currently trying
> > > > > > > > > to understand what adds that ee090000 resource into the resource tree
> > > > > > > > > and so far I've not been very successful.
> > > > > > > > >
> > > > > > > > > Perhaps it would be easiest to print a stacktrace when the resource is
> > > > > > > > > added but there are many possible functions. I think all of them
> > > > > > > > > converge in __request_resource() so I suggest adding:
> > > > > > > > >
> > > > > > > > > WARN_ON(new->start == 0xee090000);
> > > > > > > > >
> > > > > > > > > before __request_resource() does anything.
> > > > > > > >
> > > > > > > >     Call trace:
> > > > > > > >      unwind_backtrace from show_stack+0x10/0x14
> > > > > > > >      show_stack from dump_stack_lvl+0x7c/0xb0
> > > > > > > >      dump_stack_lvl from __warn+0x80/0x198
> > > > > > > >      __warn from warn_slowpath_fmt+0xc0/0x124
> > > > > > > >      warn_slowpath_fmt from __request_resource+0x38/0xc8
> > > > > > > >      __request_resource from __request_region+0xc4/0x1e8
> > > > > > > >      __request_region from __devm_request_region+0x80/0xac
> > > > > > > >      __devm_request_region from __devm_ioremap_resource+0xcc/0x160
> > > > > > > >      __devm_ioremap_resource from rcar_pci_probe+0x58/0x350
> > > > > > > >      rcar_pci_probe from platform_probe+0x58/0x90
> > > > > > > >
> > > > > > > > I.e. the call to devm_platform_get_and_ioremap_resource() in
> > > > > > > > drivers/pci/controller/pci-rcar-gen2.c:rcar_pci_probe().
> > > > > > >
> > > > > > > Thanks, the patch below might help BAR0 (but I'm not sure if it's the
> > > > > > > correct solution due to being so unfamiliar with these kind of platforms
> > > > > > > and how they're initialized).
> > > > > >
> > > > > > Thanks, that has the following impact on dmesg:
> > > > > >
> > > > > >      pci-rcar-gen2 ee090000.pci: PCI: revision 11
> > > > > >      pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
> > > > > >      pci_bus 0000:00: root bus resource [bus 00]
> > > > > >     -pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
> > > > > >     +pci_bus 0000:00: root bus resource [mem 0xee080000-0xee090bff]
> > > > > >      pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
> > > > > > PCI endpoint
> > > > > >     -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
> > > > > > claim (no window)
> > > > > >     -pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
> > > > > >     -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
> > > > > > initial claim (no window)
> > > > > >     +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
> > > > > >      pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > > >      pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
> > > > > > PCI endpoint
> > > > > >     -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
> > > > > > claim (no window)
> > > > > >      pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
> > > > > >      pci 0000:00:01.0: supports D1 D2
> > > > > >      pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
> > > > > >      pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
> > > > > > PCI endpoint
> > > > > >     -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
> > > > > > claim (no window)
> > > > >
> > > > > Did you e.g. forget to change pci_dbg() to pci_info() as these all went
> > > > > away, I cannot see why it should disappear because of my patch?
> > > > >
> > > > > (No need to apologize if that was the case, just confirming if that
> > > > > explains it is enough. :-))
> > > >
> > > > I indeed dropped that change. Adding it back...
> > > >
> > > > > >      pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
> > > > > >      pci 0000:00:02.0: supports D1 D2
> > > > > >      pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
> > > > > >      PCI: bus0: Fast back to back transfers disabled
> > > > > >      pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
> > > > > >      pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
> > > > >
> > > > > Perhaps print here what's the parent resource of these resource.
> > > >
> > > > pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned (parent
> > > > [mem 0xee080000-0xee08ffff])
> > > > pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned (parent
> > > > [mem 0xee080000-0xee08ffff])
> > >
> > > Were these from a kernel without the problematic commit at all or with the
> > > problematic commit and my fix? They look like the former case. The full
> > > /proc/iomem also shows all the parent resources I think.
> >
> > With commit 06b77d5647a4d6a7 ("PCI: Mark resources IORESOURCE_UNSET when
> > outside bridge windows"), but without adding
> > "pci_add_resource(&bridge->windows, cfg_res);" in .probe().
> >
> > > > > >     -pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
> > > > > >     +pci_bus 0000:00: resource 4 [mem 0xee080000-0xee090bff]
> > > > > >      pci-rcar-gen2 ee0d0000.pci: adding to PM domain always-on
> > > > > >      PM: genpd_add_device: Add ee0d0000.pci to always-on
> > > > > >      pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
> > > > > >     @@ -414,26 +416,22 @@ PM: ==== always-on/ee0d0000.pci: start
> > > > > >      pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
> > > > > >      pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
> > > > > >      pci_bus 0001:01: root bus resource [bus 01]
> > > > > >     -pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
> > > > > >     +pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0d0bff]
> > > > > >      pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
> > > > > >     -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial claim (no window)
> > > > > >     -pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
> > > > > >     -pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no initial claim (no window)
> > > > > >     +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
> > > > > >      pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
> > > > > >      pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
> > > > > >     -pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial claim (no window)
> > > > > >      pci 0001:01:01.0: BAR 0 [mem size 0x00001000]
> > > > > >      pci 0001:01:01.0: supports D1 D2
> > > > > >      pci 0001:01:01.0: PME# supported from D0 D1 D2 D3hot
> > > > > >      pci 0001:01:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
> > > > > >     -pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial claim (no window)
> > > > > >      pci 0001:01:02.0: BAR 0 [mem size 0x00000100]
> > > > > >      pci 0001:01:02.0: supports D1 D2
> > > > > >      pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
> > > > > >      PCI: bus1: Fast back to back transfers disabled
> > > > > >      pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
> > > > > >      pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
> > > > > >     -pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
> > > > > >     +pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0d0bff]
> > > > > >      rcar-pcie fe000000.pcie: adding to PM domain always-on
> > > > > >      PM: genpd_add_device: Add fe000000.pcie to always-on
> > > > > >      rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
> > > > > >
> > > > > > and on /proc/iomem (I used "diff -w" to reduce clutter):
> > > > > >
> > > > > >      ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
> > > > > >      ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
> > > > > >      ec740000-ec7401ff : ec500000.sound audmapp
> > > > > >     -ee080000-ee08ffff : pci@ee090000
> > > > >
> > > > > So what did add this previous? (Maybe use the same WARN_ON() trick as
> > > > > previously to find out.)
> > > >
> > > > First call:
> > > >
> > > >     + __request_resource from request_resource_conflict+0x24/0x3c
> > > >     + request_resource_conflict from devm_request_resource+0x48/0x9c
> > > >     + devm_request_resource from devm_request_pci_bus_resources+0x5c/0x70
> > > >     + devm_request_pci_bus_resources from devm_of_pci_bridge_init+0x7c/0x1c0
> > > >     + devm_of_pci_bridge_init from devm_pci_alloc_host_bridge+0x44/0x6c
> > > >     + devm_pci_alloc_host_bridge from rcar_pci_probe+0x34/0x384
> > > >     + rcar_pci_probe from platform_probe+0x58/0x90
> > >
> > > Thanks. So this is the call of interest, the rest are just the childs of
> > > it with the same address.
> > >
> > > I'm looking devm_of_pci_get_host_bridge_resources(), it seems to read
> > > "ranges" property but not "reg" at all.
> > >
> > > I wonder if devm_of_pci_get_host_bridge_resources() should also loop
> > > through "reg" addresses and add those to host resources which are outside
> > > of the "ranges"? Or if there should be a "range" that covers all what's
> > > in "reg" to get them added into host bridge resources? That would seem the
> > > generic solution instead of trying to do this in rcar_pci_probe().
> > >
> > > (Perhaps these are stupid questions, please excuse my lack of knowledge
> > > about OF things.)
> > >
> > > While looking at another issue report, I also notice of_pci_prop_ranges()
> > > assumes there are only bridge windows or BARs, but not both (not sure if
> > > this relates to anything, just an observation while reading these code
> > > paths).
> >
> > We still have Rob in CC...
>
> While we wait, can you simply try to make the "ranges" large enough to fit
> the BAR0 too?

Sure, so I changed:

    --- a/arch/arm/boot/dts/renesas/r8a7791.dtsi
    +++ b/arch/arm/boot/dts/renesas/r8a7791.dtsi
    @@ -1577,7 +1577,7 @@ pci0: pci@ee090000 {
                            #address-cells = <3>;
                            #size-cells = <2>;
                            #interrupt-cells = <1>;
    -                       ranges = <0x02000000 0 0xee080000 0
0xee080000 0 0x00010000>;
    +                       ranges = <0x02000000 0 0xee080000 0
0xee080000 0 0x00020000>;
                            interrupt-map-mask = <0xf800 0 0 0x7>;
                            interrupt-map = <0x0000 0 0 1 &gic GIC_SPI
108 IRQ_TYPE_LEVEL_HIGH>,
                                            <0x0800 0 0 1 &gic GIC_SPI
108 IRQ_TYPE_LEVEL_HIGH>,

> I think it will results in making the larger "ranges" entry the parent of
> ee090000-ee090bff : ee090000.pci pci@ee090000 entry in the resource tree

Correct!

Impact on dmesg:

     pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
    -pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff
-> 0x00ee080000
    +pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee09ffff
-> 0x00ee080000
     rcar_pci_setup:187: No dma_ranges, using default!
     pci-rcar-gen2 ee090000.pci: PCI: revision 11
     pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
    -Has parent [mem 0xee080000-0xee08ffff]
    +Has parent [mem 0xee080000-0xee09ffff]
     pci_bus 0000:00: root bus resource [bus 00]
    -pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
    +pci_bus 0000:00: root bus resource [mem 0xee080000-0xee09ffff]
     pci_bus 0000:00: root bus resource [mem 0xee090000-0xee090bff]
     pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
PCI endpoint
     pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
    @@ -397,9 +398,9 @@ pci 0000:00:02.0: BAR 0 [mem size 0x0000
     pci 0000:00:02.0: supports D1 D2
     pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
     PCI: bus0: Fast back to back transfers disabled
    -pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
(parent [mem 0xee080000-0xee08ffff])
    -pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
(parent [mem 0xee080000-0xee08ffff])
    -pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
    +pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
(parent [mem 0xee080000-0xee09ffff])
    +pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
(parent [mem 0xee080000-0xee09ffff])
    +pci_bus 0000:00: resource 4 [mem 0xee080000-0xee09ffff]
     pci_bus 0000:00: resource 5 [mem 0xee090000-0xee090bff]


Impact on /proc/iomem:

     ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
     ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
     ec740000-ec7401ff : ec500000.sound audmapp
    -ee080000-ee08ffff : pci@ee090000
    +ee080000-ee09ffff : pci@ee090000
       ee080000-ee080fff : 0000:00:01.0
         ee080000-ee080fff : ohci_hcd
       ee081000-ee0810ff : 0000:00:02.0
         ee081000-ee0810ff : ehci_hcd
    -ee090000-ee090bff : ee090000.pci pci@ee090000
    +  ee090000-ee090bff : ee090000.pci pci@ee090000
     ee0c0000-ee0cffff : pci@ee0d0000
       ee0c0000-ee0c0fff : 0001:01:01.0
         ee0c0000-ee0c0fff : ohci_hcd


> which would also avoid the coalescing issue.

Also correct: I can remove the coalescing workaround again without
having any impact on /proc/iomem.

> Again, I'm not entirely sure if that would be an acceptable solution.

I am afraid not, as it should keep on working with existing DTBs,
as per the stable DT ABI rule.
Thanks!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Kai-Heng Feng 4 months ago

On 2025/10/8 1:30 AM, Ilpo Järvinen wrote:
> External email: Use caution opening links or attachments
> 
> 
> + Kai-Heng
> 
> On Mon, 6 Oct 2025, Geert Uytterhoeven wrote:
>> On Mon, 6 Oct 2025 at 14:37, Ilpo Järvinen
>> <ilpo.jarvinen@linux.intel.com> wrote:
>>> On Mon, 6 Oct 2025, Geert Uytterhoeven wrote:
>>>> On Fri, 3 Oct 2025 at 16:58, Ilpo Järvinen
>>>> <ilpo.jarvinen@linux.intel.com> wrote:
>>>>> On Fri, 3 Oct 2025, Geert Uytterhoeven wrote:
>>>>>> On Thu, 2 Oct 2025 at 18:59, Ilpo Järvinen
>>>>>> <ilpo.jarvinen@linux.intel.com> wrote:
>>>>>>> On Thu, 2 Oct 2025, Geert Uytterhoeven wrote:
>>>>>>>> On Thu, 2 Oct 2025 at 16:54, Ilpo Järvinen
>>>>>>>> <ilpo.jarvinen@linux.intel.com> wrote:
>>>>>>>>> On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
>>>>>>>>>> On Wed, 1 Oct 2025 at 15:06, Ilpo Järvinen
>>>>>>>>>> <ilpo.jarvinen@linux.intel.com> wrote:
>>>>>>>>>>> On Wed, 1 Oct 2025, Geert Uytterhoeven wrote:
>>>>>>>>>>>> On Tue, 30 Sept 2025 at 18:32, Ilpo Järvinen
>>>>>>>>>>>> <ilpo.jarvinen@linux.intel.com> wrote:
>>>>>>>>>>>>> On Tue, 30 Sep 2025, Geert Uytterhoeven wrote:
>>>>>>>>>>>>>> On Fri, 26 Sept 2025 at 04:40, Ilpo Järvinen
>>>>>>>>>>>>>> <ilpo.jarvinen@linux.intel.com> wrote:
>>>>>>>>>>>>>>> PNP resources are checked for conflicts with the other resource in the
>>>>>>>>>>>>>>> system by quirk_system_pci_resources() that walks through all PCI
>>>>>>>>>>>>>>> resources. quirk_system_pci_resources() correctly filters out resource
>>>>>>>>>>>>>>> with IORESOURCE_UNSET.
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Resources that do not reside within their bridge window, however, are
>>>>>>>>>>>>>>> not properly initialized with IORESOURCE_UNSET resulting in bogus
>>>>>>>>>>>>>>> conflicts detected in quirk_system_pci_resources():
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
>>>>>>>>>>>>>>> pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
>>>>>>>>>>>>>>> ...
>>>>>>>>>>>>>>> pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
>>>>>>>>>>>>>>> pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
>>>>>>>>>>>>>>> ...
>>>>>>>>>>>>>>> pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
>>>>>>>>>>>>>>> pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
>>>>>>>>>>>>>>> pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
>>>>>>>>>>>>>>> pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
>>>>>>>>>>>>>>> pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
>>>>>>>>>>>>>>> pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
>>>>>>>>>>>>>>> pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
>>>>>>>>>>>>>>> pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
>>>>>>>>>>>>>>> pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
>>>>>>>>>>>>>>> pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Mark resources that are not contained within their bridge window with
>>>>>>>>>>>>>>> IORESOURCE_UNSET in __pci_read_base() which resolves the false
>>>>>>>>>>>>>>> positives for the overlap check in quirk_system_pci_resources().
>>>>>>>>>>>>>>>
>>>>>>>>>>>>>>> Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
>>>>>>>>>>>>>>> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Thanks for your patch, which is now commit 06b77d5647a4d6a7 ("PCI:
>>>>>>>>>>>>>> Mark resources IORESOURCE_UNSET when outside bridge windows") in
>>>>>>>>>>>>>> linux-next/master next-20250929 pci/next
>>>>>>>>>>>>
>>>>>>>>>>>>>> This replaces the actual resources by their sizes in the boot log on
>>>>>>>>>>>>>> e.g. on R-Car M2-W:
>>>>>>>>>>>>>>
>>>>>>>>>>>>>>       pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
>>>>>>>>>>>>>>       pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff -> 0x00ee080000
>>>>>>>>>>>>>>       pci-rcar-gen2 ee090000.pci: PCI: revision 11
>>>>>>>>>>>>>>       pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
>>>>>>>>>>>>>>       pci_bus 0000:00: root bus resource [bus 00]
>>>>>>>>>>>>>>       pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
>>>>>>>>>>>>>>       pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
>>>>>>>>>>>>>>      -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
>>>>>>>>>>>>>>      -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]
>>>>>>>>>>>>>
>>>>>>>>>>>>> What is going to be the parent of these resources? They don't seem to fall
>>>>>>>>>>>>> under the root bus resource above in which case the output change is
>>>>>>>>>>>>> intentional so they don't appear as if address range would be "okay".
>>>>>>>>>>>>
>>>>>>>>>>>> >From /proc/iomem:
>>>>>>>>>>>>
>>>>>>>>>>>>      ee080000-ee08ffff : pci@ee090000
>>>>>>>>>>>>        ee080000-ee080fff : 0000:00:01.0
>>>>>>>>>>>>          ee080000-ee080fff : ohci_hcd
>>>>>>>>>>>>        ee081000-ee0810ff : 0000:00:02.0
>>>>>>>>>>>>          ee081000-ee0810ff : ehci_hcd
>>>>>>>>>>>>      ee090000-ee090bff : ee090000.pci pci@ee090000
>>>>>>>>>>>
>>>>>>>>>>> Okay, so this seem to appear in the resource tree but not among the root
>>>>>>>>>>> bus resources.
>>>>>>>>>>>
>>>>>>>>>>>>      ee0c0000-ee0cffff : pci@ee0d0000
>>>>>>>>>>>>        ee0c0000-ee0c0fff : 0001:01:01.0
>>>>>>>>>>>>          ee0c0000-ee0c0fff : ohci_hcd
>>>>>>>>>>>>        ee0c1000-ee0c10ff : 0001:01:02.0
>>>>>>>>>>>>          ee0c1000-ee0c10ff : ehci_hcd
>>>>>>>>>>>>
>>>>>>>>>>>>> When IORESOURCE_UNSET is set in a resource, %pR does not print the start
>>>>>>>>>>>>> and end addresses.
>>>>>>>>>>>>
>>>>>>>>>>>> Yeah, that's how I found this commit, without bisecting ;-)
>>>>>>>>>>>>
>>>>>>>>>>>>>>      +pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
>>>>>>>>>>>>>>      +pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
>>>>>>>>>>>>>>       pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
>>>>>>>>>>>>>>      -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]
>>>>>>>>>>>>>>      +pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
>>>>>>>>>>>>>
>>>>>>>>>>>>> For this resource, it's very much intentional. It's a zero-based BAR which
>>>>>>>>>>>>> was left without IORESOURCE_UNSET prior to my patch leading to others part
>>>>>>>>>>>>> of the kernel to think that resource range valid and in use (in your
>>>>>>>>>>>>> case it's so small it wouldn't collide with anything but it wasn't
>>>>>>>>>>>>> properly set up resource, nonetheless).
>>>>>>>>>>>>>
>>>>>>>>>>>>>>       pci 0000:00:01.0: supports D1 D2
>>>>>>>>>>>>>>       pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
>>>>>>>>>>>>>>       pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
>>>>>>>>>>>>>>      -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]
>>>>>>>>>>>>>>      +pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
>>>>>>>>>>>>>
>>>>>>>>>>>>> And this as well is very much intentional.
>>>>>>>>>>>>>
>>>>>>>>>>>>>>       pci 0000:00:02.0: supports D1 D2
>>>>>>>>>>>>>>       pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
>>>>>>>>>>>>>>       PCI: bus0: Fast back to back transfers disabled
>>>>>>>>>>>>>>       pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
>>>>>>>>>>>>>>       pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
>>>>>>>>>>>>>>       pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
>>>>>>>>>>>>>>
>>>>>>>>>>>>>> Is that intentional?
>>>>>>>>>>>>>
>>>>>>>>>>>>> There's also that pci_dbg() in the patch which would show the original
>>>>>>>>>>>>> addresses (print the resource before setting IORESOURCE_UNSET) but to see
>>>>>>>>>>>>> it one would need to enable it with dyndbg=... Bjorn was thinking of
>>>>>>>>>>>>> making that pci_info() though so it would appear always.
>>>>>>>>>>>>>
>>>>>>>>>>>>> Was this the entire PCI related diff? I don't see those 0000:00:00.0 BARs
>>>>>>>>>>>>> getting assigned anywhere.
>>>>>>>>>>>>
>>>>>>>>>>>> The above log is almost complete (lacked enabling the device afterwards).
>>>>>>>>>>>>
>>>>>>>>>>>> AFAIU, the BARs come from the reg and ranges properties in the
>>>>>>>>>>>> PCI controller nodes;
>>>>>>>>>>>> https://elixir.bootlin.com/linux/v6.17/source/arch/arm/boot/dts/renesas/r8a7791.dtsi#L1562
>>>>>>>>>>>
>>>>>>>>>>> Thanks, although I had already found this line by grep. I was just
>>>>>>>>>>> expecting the address appear among root bus resources too.
>>>>>>>>>>>
>>>>>>>>>>> Curiously enough, pci_register_host_bridge() seems to try to add some
>>>>>>>>>>> resource from that list into bus and it's what prints those "root bus
>>>>>>>>>>> resource" lines and ee090000 is not among the printed lines despite
>>>>>>>>>>> appearing in /proc/iomem. As is, the resource tree and PCI bus view on the
>>>>>>>>>>> resources seems to be in disagreement and I'm not sure what to make of it.
>>>>>>>>>>>
>>>>>>>>>>> But before considering going into that direction or figuring out why this
>>>>>>>>>>> ee090000 resource does not appear among root bus resources, could you
>>>>>>>>>>> check if the attached patch changes behavior for the resource which are
>>>>>>>>>>> non-zero based?
>>>>>>>>>>
>>>>>>>>>> This patch has no impact on dmesg, lspci output, or /proc/iomem
>>>>>>>>>> for pci-rcar-gen2.
>>>>>>>>>
>>>>>>>>> It would have been too easy... :-(
>>>>>>>>>
>>>>>>>>> I'm sorry I don't really know these platform well and I'm currently trying
>>>>>>>>> to understand what adds that ee090000 resource into the resource tree
>>>>>>>>> and so far I've not been very successful.
>>>>>>>>>
>>>>>>>>> Perhaps it would be easiest to print a stacktrace when the resource is
>>>>>>>>> added but there are many possible functions. I think all of them
>>>>>>>>> converge in __request_resource() so I suggest adding:
>>>>>>>>>
>>>>>>>>> WARN_ON(new->start == 0xee090000);
>>>>>>>>>
>>>>>>>>> before __request_resource() does anything.
>>>>>>>>
>>>>>>>>      Call trace:
>>>>>>>>       unwind_backtrace from show_stack+0x10/0x14
>>>>>>>>       show_stack from dump_stack_lvl+0x7c/0xb0
>>>>>>>>       dump_stack_lvl from __warn+0x80/0x198
>>>>>>>>       __warn from warn_slowpath_fmt+0xc0/0x124
>>>>>>>>       warn_slowpath_fmt from __request_resource+0x38/0xc8
>>>>>>>>       __request_resource from __request_region+0xc4/0x1e8
>>>>>>>>       __request_region from __devm_request_region+0x80/0xac
>>>>>>>>       __devm_request_region from __devm_ioremap_resource+0xcc/0x160
>>>>>>>>       __devm_ioremap_resource from rcar_pci_probe+0x58/0x350
>>>>>>>>       rcar_pci_probe from platform_probe+0x58/0x90
>>>>>>>>
>>>>>>>> I.e. the call to devm_platform_get_and_ioremap_resource() in
>>>>>>>> drivers/pci/controller/pci-rcar-gen2.c:rcar_pci_probe().
>>>>>>>
>>>>>>> Thanks, the patch below might help BAR0 (but I'm not sure if it's the
>>>>>>> correct solution due to being so unfamiliar with these kind of platforms
>>>>>>> and how they're initialized).
>>>>>>
>>>>>> Thanks, that has the following impact on dmesg:
>>>>>>
>>>>>>       pci-rcar-gen2 ee090000.pci: PCI: revision 11
>>>>>>       pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
>>>>>>       pci_bus 0000:00: root bus resource [bus 00]
>>>>>>      -pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
>>>>>>      +pci_bus 0000:00: root bus resource [mem 0xee080000-0xee090bff]
>>>>>>       pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
>>>>>> PCI endpoint
>>>>>>      -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
>>>>>> claim (no window)
>>>>>>      -pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
>>>>>>      -pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
>>>>>> initial claim (no window)
>>>>>>      +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
>>>>>>       pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
>>>>>>       pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
>>>>>> PCI endpoint
>>>>>>      -pci 0000:00:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial
>>>>>> claim (no window)
>>>>>>       pci 0000:00:01.0: BAR 0 [mem size 0x00001000]
>>>>>>       pci 0000:00:01.0: supports D1 D2
>>>>>>       pci 0000:00:01.0: PME# supported from D0 D1 D2 D3hot
>>>>>>       pci 0000:00:02.0: [1033:00e0] type 00 class 0x0c0320 conventional
>>>>>> PCI endpoint
>>>>>>      -pci 0000:00:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial
>>>>>> claim (no window)
>>>>>
>>>>> Did you e.g. forget to change pci_dbg() to pci_info() as these all went
>>>>> away, I cannot see why it should disappear because of my patch?
>>>>>
>>>>> (No need to apologize if that was the case, just confirming if that
>>>>> explains it is enough. :-))
>>>>
>>>> I indeed dropped that change. Adding it back...
>>>>
>>>>>>       pci 0000:00:02.0: BAR 0 [mem size 0x00000100]
>>>>>>       pci 0000:00:02.0: supports D1 D2
>>>>>>       pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
>>>>>>       PCI: bus0: Fast back to back transfers disabled
>>>>>>       pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
>>>>>>       pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
>>>>>
>>>>> Perhaps print here what's the parent resource of these resource.
>>>>
>>>> pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned (parent
>>>> [mem 0xee080000-0xee08ffff])
>>>> pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned (parent
>>>> [mem 0xee080000-0xee08ffff])
>>>
>>> Were these from a kernel without the problematic commit at all or with the
>>> problematic commit and my fix? They look like the former case. The full
>>> /proc/iomem also shows all the parent resources I think.
>>
>> With commit 06b77d5647a4d6a7 ("PCI: Mark resources IORESOURCE_UNSET when
>> outside bridge windows"), but without adding
>> "pci_add_resource(&bridge->windows, cfg_res);" in .probe().
>>
>>>>>>      -pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
>>>>>>      +pci_bus 0000:00: resource 4 [mem 0xee080000-0xee090bff]
>>>>>>       pci-rcar-gen2 ee0d0000.pci: adding to PM domain always-on
>>>>>>       PM: genpd_add_device: Add ee0d0000.pci to always-on
>>>>>>       pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
>>>>>>      @@ -414,26 +416,22 @@ PM: ==== always-on/ee0d0000.pci: start
>>>>>>       pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
>>>>>>       pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
>>>>>>       pci_bus 0001:01: root bus resource [bus 01]
>>>>>>      -pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
>>>>>>      +pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0d0bff]
>>>>>>       pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional PCI endpoint
>>>>>>      -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial claim (no window)
>>>>>>      -pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
>>>>>>      -pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no initial claim (no window)
>>>>>>      +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
>>>>>>       pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
>>>>>>       pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional PCI endpoint
>>>>>>      -pci 0001:01:01.0: BAR 0 [mem 0x00000000-0x00000fff]: no initial claim (no window)
>>>>>>       pci 0001:01:01.0: BAR 0 [mem size 0x00001000]
>>>>>>       pci 0001:01:01.0: supports D1 D2
>>>>>>       pci 0001:01:01.0: PME# supported from D0 D1 D2 D3hot
>>>>>>       pci 0001:01:02.0: [1033:00e0] type 00 class 0x0c0320 conventional PCI endpoint
>>>>>>      -pci 0001:01:02.0: BAR 0 [mem 0x00000000-0x000000ff]: no initial claim (no window)
>>>>>>       pci 0001:01:02.0: BAR 0 [mem size 0x00000100]
>>>>>>       pci 0001:01:02.0: supports D1 D2
>>>>>>       pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
>>>>>>       PCI: bus1: Fast back to back transfers disabled
>>>>>>       pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
>>>>>>       pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
>>>>>>      -pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
>>>>>>      +pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0d0bff]
>>>>>>       rcar-pcie fe000000.pcie: adding to PM domain always-on
>>>>>>       PM: genpd_add_device: Add fe000000.pcie to always-on
>>>>>>       rcar-pcie fe000000.pcie: host bridge /soc/pcie@fe000000 ranges:
>>>>>>
>>>>>> and on /proc/iomem (I used "diff -w" to reduce clutter):
>>>>>>
>>>>>>       ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
>>>>>>       ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
>>>>>>       ec740000-ec7401ff : ec500000.sound audmapp
>>>>>>      -ee080000-ee08ffff : pci@ee090000
>>>>>
>>>>> So what did add this previous? (Maybe use the same WARN_ON() trick as
>>>>> previously to find out.)
>>>>
>>>> First call:
>>>>
>>>>      + __request_resource from request_resource_conflict+0x24/0x3c
>>>>      + request_resource_conflict from devm_request_resource+0x48/0x9c
>>>>      + devm_request_resource from devm_request_pci_bus_resources+0x5c/0x70
>>>>      + devm_request_pci_bus_resources from devm_of_pci_bridge_init+0x7c/0x1c0
>>>>      + devm_of_pci_bridge_init from devm_pci_alloc_host_bridge+0x44/0x6c
>>>>      + devm_pci_alloc_host_bridge from rcar_pci_probe+0x34/0x384
>>>>      + rcar_pci_probe from platform_probe+0x58/0x90
>>>
>>> Thanks. So this is the call of interest, the rest are just the childs of
>>> it with the same address.
>>>
>>> I'm looking devm_of_pci_get_host_bridge_resources(), it seems to read
>>> "ranges" property but not "reg" at all.
>>>
>>> I wonder if devm_of_pci_get_host_bridge_resources() should also loop
>>> through "reg" addresses and add those to host resources which are outside
>>> of the "ranges"? Or if there should be a "range" that covers all what's
>>> in "reg" to get them added into host bridge resources? That would seem the
>>> generic solution instead of trying to do this in rcar_pci_probe().
>>>
>>> (Perhaps these are stupid questions, please excuse my lack of knowledge
>>> about OF things.)
>>>
>>> While looking at another issue report, I also notice of_pci_prop_ranges()
>>> assumes there are only bridge windows or BARs, but not both (not sure if
>>> this relates to anything, just an observation while reading these code
>>> paths).
>>
>> We still have Rob in CC...
> 
> While we wait, can you simply try to make the "ranges" large enough to fit
> the BAR0 too?
> 
> I think it will results in making the larger "ranges" entry the parent of
> ee090000-ee090bff : ee090000.pci pci@ee090000 entry in the resource tree
> which would also avoid the coalescing issue.
> 
> Again, I'm not entirely sure if that would be an acceptable solution.
> 
>>>> Second call:
>>>>
>>>>      + __request_resource from allocate_resource+0x1b8/0x1d4
>>>>      + allocate_resource from pci_bus_alloc_from_region+0x1e0/0x220
>>>>      + pci_bus_alloc_from_region from pci_bus_alloc_resource+0x84/0xb8
>>>>      + pci_bus_alloc_resource from _pci_assign_resource+0x78/0x150
>>>>      + _pci_assign_resource from pci_assign_resource+0x10c/0x310
>>>>      + pci_assign_resource from assign_requested_resources_sorted+0x78/0xac
>>>>      + assign_requested_resources_sorted from
>>>> __assign_resources_sorted+0x74/0x5c4
>>>>      + __assign_resources_sorted from __pci_bus_assign_resources+0x50/0x1f0
>>>>      + __pci_bus_assign_resources from
>>>> pci_assign_unassigned_root_bus_resources+0xa8/0x190
>>>>      + pci_assign_unassigned_root_bus_resources from pci_host_probe+0x5c/0xb0
>>>>      + pci_host_probe from rcar_pci_probe+0x2e0/0x384
>>>>      + rcar_pci_probe from platform_probe+0x58/0x90
>>>>
>>>> Third call:
>>>>
>>>>      + __request_resource from __request_region+0xc4/0x1e8
>>>>      + __request_region from __devm_request_region+0x80/0xac
>>>>      + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
>>>>      + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
>>>>      + pci_device_probe from really_probe+0x128/0x28c
>>>>
>>>> Fourth call:
>>>>
>>>>      + __request_region from __devm_request_region+0x80/0xac
>>>>      + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
>>>>      + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
>>>>      + pci_device_probe from really_probe+0x128/0x28c
>>>>
>>>> Fifth call:
>>>>
>>>>      + __request_region from __devm_request_region+0x80/0xac
>>>>      + __devm_request_region from usb_hcd_pci_probe+0x15c/0x35c
>>>>      + usb_hcd_pci_probe from pci_device_probe+0x94/0x104
>>>>      + pci_device_probe from really_probe+0x128/0x28c
>>>>
>>>>> It might have gotten broken because the coalesed resource
>>>>> ee080000-ee090bff overlaps with that other resource in the resource tree.
>>>>> But I don't see anything to that effect in the log so it's either silent
>>>>> failure or there's much filtered from the log.
>>>>>
>>>>>>      -  ee080000-ee080fff : 0000:00:01.0
>>>>>>           ee080000-ee080fff : ohci_hcd
>>>>>>      -  ee081000-ee0810ff : 0000:00:02.0
>>>>>>           ee081000-ee0810ff : ehci_hcd
>>>>>>       ee090000-ee090bff : ee090000.pci pci@ee090000
>>>>>>      -ee0c0000-ee0cffff : pci@ee0d0000
>>>>>>      -  ee0c0000-ee0c0fff : 0001:01:01.0
>>>>>>           ee0c0000-ee0c0fff : ohci_hcd
>>>>>>      -  ee0c1000-ee0c10ff : 0001:01:02.0
>>>>>>           ee0c1000-ee0c10ff : ehci_hcd
>>>>>>       ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
>>>>>>       ee100000-ee100327 : ee100000.mmc mmc@ee100000
>>>>>>
>>>>>> Removing the pci@ee0x0000 and 000x:0x:0x.0 entries doesn't look
>>>>>> right to me? Or am I missing something?
>>>>>
>>>>> I cannot understand this output, these resources seem to have been now
>>>>> left without a parent and due to -w I don't know what's their real
>>>>> indentation level.
>>>>
>>>> The *_hcd resources are now at the top level.
>>>>
>>>>       ec700000-ec70ffff : ec700000.dma-controller dma-controller@ec700000
>>>>       ec720000-ec72ffff : ec720000.dma-controller dma-controller@ec720000
>>>>       ec740000-ec7401ff : ec500000.sound audmapp
>>>>      -ee080000-ee08ffff : pci@ee090000
>>>>      -  ee080000-ee080fff : 0000:00:01.0
>>>>      -    ee080000-ee080fff : ohci_hcd
>>>>      -  ee081000-ee0810ff : 0000:00:02.0
>>>>      -    ee081000-ee0810ff : ehci_hcd
>>>>      +ee080000-ee080fff : ohci_hcd
>>>>      +ee081000-ee0810ff : ehci_hcd
>>>>       ee090000-ee090bff : ee090000.pci pci@ee090000
>>>>      -ee0c0000-ee0cffff : pci@ee0d0000
>>>>      -  ee0c0000-ee0c0fff : 0001:01:01.0
>>>>      -    ee0c0000-ee0c0fff : ohci_hcd
>>>>      -  ee0c1000-ee0c10ff : 0001:01:02.0
>>>>      -    ee0c1000-ee0c10ff : ehci_hcd
>>>>      +ee0c0000-ee0c0fff : ohci_hcd
>>>>      +ee0c1000-ee0c10ff : ehci_hcd
>>>>       ee0d0000-ee0d0bff : ee0d0000.pci pci@ee0d0000
>>>>       ee100000-ee100327 : ee100000.mmc mmc@ee100000
>>>>       ee140000-ee1400ff : ee140000.mmc mmc@ee140000
>>>>
>>>> I assume the others are gone because they now conflict with the *_hcd
>>>> resources at the top level.
>>>
>>> Like you initially assumed, it is wrong (while it works as the resources
>>> themselves don't care that much about their parent they're under as long
>>> as the resource is assigned, it's still not intended to be that way).
>>>
>>> It might be worth to see if the coalescing in pci_register_host_bridge()
>>> somehow messes these resources up either by not doing the coalesing loop
>>> at all or by adding:
>>>
>>>                  if (res->parent || next_res->parent) {
>>>                          if (res->parent)
>>>                                  pr_info("Has parent %pR\n", res);
>>>                          if (next_res->parent)
>>>                                  pr_info("Has parent %pR\n", next_res);
>>>                          continue;
>>>                  }
>>>
>>> ...into the coalescing loop in case one of them happens to have a parent
>>> (this is to be tested with the rcar_probe() fix).
>>
>> The above restores the missing entries in /proc/iomem.
>> Changes to dmesg:
>>
>>       pci-rcar-gen2 ee090000.pci: host bridge /soc/pci@ee090000 ranges:
>>       pci-rcar-gen2 ee090000.pci:      MEM 0x00ee080000..0x00ee08ffff
>> -> 0x00ee080000
>>       pci-rcar-gen2 ee090000.pci: PCI: revision 11
>>       pci-rcar-gen2 ee090000.pci: PCI host bridge to bus 0000:00
>>      +Has parent [mem 0xee080000-0xee08ffff]
>>       pci_bus 0000:00: root bus resource [bus 00]
>>       pci_bus 0000:00: root bus resource [mem 0xee080000-0xee08ffff]
>>      +pci_bus 0000:00: root bus resource [mem 0xee090000-0xee090bff]
>>       pci 0000:00:00.0: [1033:0000] type 00 class 0x060000 conventional
>> PCI endpoint
>>      -pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]: no initial
>> claim (no window)
>>      -pci 0000:00:00.0: BAR 0 [mem size 0x00000400]
>>      +pci 0000:00:00.0: BAR 0 [mem 0xee090800-0xee090bff]
>>       pci 0000:00:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
>> initial claim (no window)
>>       pci 0000:00:00.0: BAR 1 [mem size 0x40000000 pref]
>>       pci 0000:00:01.0: [1033:0035] type 00 class 0x0c0310 conventional
>> PCI endpoint
>>      @@ -403,21 +397,24 @@ pci 0000:00:02.0: BAR 0 [mem size 0x0000
>>       pci 0000:00:02.0: supports D1 D2
>>       pci 0000:00:02.0: PME# supported from D0 D1 D2 D3hot
>>       PCI: bus0: Fast back to back transfers disabled
>>       pci 0000:00:01.0: BAR 0 [mem 0xee080000-0xee080fff]: assigned
>>       pci 0000:00:02.0: BAR 0 [mem 0xee081000-0xee0810ff]: assigned
>>       pci_bus 0000:00: resource 4 [mem 0xee080000-0xee08ffff]
>>      +pci_bus 0000:00: resource 5 [mem 0xee090000-0xee090bff]
>>       pci-rcar-gen2 ee0d0000.pci: adding to PM domain always-on
>>       pci-rcar-gen2 ee0d0000.pci: host bridge /soc/pci@ee0d0000 ranges:
>>       pci-rcar-gen2 ee0d0000.pci:      MEM 0x00ee0c0000..0x00ee0cffff
>> -> 0x00ee0c0000
>>       pci-rcar-gen2 ee0d0000.pci: PCI: revision 11
>>       pci-rcar-gen2 ee0d0000.pci: PCI host bridge to bus 0001:01
>>      +Has parent [mem 0xee0c0000-0xee0cffff]
> 
> So this ended up locating another bug in the coalescing loop.
> 
> It's very dangerous to mess with resources like that as the backing
> struct resource is shared with whatever added that resource, which is
> different sites in this case.
> 
> I'm preparing a better approach to do the resource merge, however, I'm
> left unsure if the clean up of everything will happen "correctly" as this
> coalescing is removing resources from the resource tree which were added
> there by something else so it's then becomes very muddy who is responsible
> for releasing it in the end.

So what about a helper function pci_try_contiguous_apertures() to allocate 
across resources when single resource isn't large enough?

Anyway, I am happy to try your new approach.

Kai-Heng

> 
>>       pci_bus 0001:01: root bus resource [bus 01]
>>       pci_bus 0001:01: root bus resource [mem 0xee0c0000-0xee0cffff]
>>      +pci_bus 0001:01: root bus resource [mem 0xee0d0000-0xee0d0bff]
>>       pci 0001:01:00.0: [1033:0000] type 00 class 0x060000 conventional
>> PCI endpoint
>>      -pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]: no initial
>> claim (no window)
>>      -pci 0001:01:00.0: BAR 0 [mem size 0x00000400]
>>      +pci 0001:01:00.0: BAR 0 [mem 0xee0d0800-0xee0d0bff]
>>       pci 0001:01:00.0: BAR 1 [mem 0x40000000-0x7fffffff pref]: no
>> initial claim (no window)
>>       pci 0001:01:00.0: BAR 1 [mem size 0x40000000 pref]
>>       pci 0001:01:01.0: [1033:0035] type 00 class 0x0c0310 conventional
>> PCI endpoint
>>      @@ -431,9 +428,10 @@ pci 0001:01:02.0: BAR 0 [mem size 0x0000
>>       pci 0001:01:02.0: supports D1 D2
>>       pci 0001:01:02.0: PME# supported from D0 D1 D2 D3hot
>>       PCI: bus1: Fast back to back transfers disabled
>>       pci 0001:01:01.0: BAR 0 [mem 0xee0c0000-0xee0c0fff]: assigned
>>       pci 0001:01:02.0: BAR 0 [mem 0xee0c1000-0xee0c10ff]: assigned
>>       pci_bus 0001:01: resource 4 [mem 0xee0c0000-0xee0cffff]
>>      +pci_bus 0001:01: resource 5 [mem 0xee0d0000-0xee0d0bff]
>>
>>>>>>> If this works, we'll also have to decide what to do with the BAR1 (it
>>>>>>> didn't appear in your (partial?) /proc/iomem quote so I'm left unsure how
>>>>>>> to approach it).
>>>>>>
>>>>>> That is indeed not visible in /proc/iomem.
>>>>>
>>>>> I meant before the commit 06b77d5647a4d6a7 ("PCI Mark resources
>>>>> IORESOURCE_UNSET when outside bridge windows"), was it present?
>>>>
>>>> No, it was not present.
>>>>
>>>>>> I tried the following (whitespace-damaged):
>>>>>>
>>>>>> --- a/drivers/pci/controller/pci-rcar-gen2.c
>>>>>> +++ b/drivers/pci/controller/pci-rcar-gen2.c
>>>>>> @@ -179,6 +179,7 @@ static void rcar_pci_setup(struct rcar_pci *priv)
>>>>>>          unsigned long window_size;
>>>>>>          unsigned long window_addr;
>>>>>>          unsigned long window_pci;
>>>>>> +       struct resource res;
>>>>>>          u32 val;
>>>>>>
>>>>>>          entry = resource_list_first_type(&bridge->dma_ranges, IORESOURCE_MEM);
>>>>>> @@ -191,6 +192,8 @@ static void rcar_pci_setup(struct rcar_pci *priv)
>>>>>>                  window_pci = entry->res->start - entry->offset;
>>>>>>                  window_size = resource_size(entry->res);
>>>>>>          }
>>>>>> +       resource_set_range(&res, window_addr, window_size);
>>>>>
>>>>> You need to set flags properly too as this now tried to insert BUS, not
>>>>> MEM resource (DEFINE_RES() might be the more appropriate in that case
>>>>> anyway).
>>>>>
>>>>> However, if there's not &bridge->dma_ranges ranges entry, rcar_pci_setup()
>>>>> seems to initialize the resource to 0x40000000-0x7fffffff and I'm not sure
>>>>
>>>> I guess the not &bridge->dma_ranges case dates back to the time the
>>>> DTS didn't have dma-ranges yet.  However, upon closer look, the DTS
>>>> still doesn't have dma_ranges, thus always using the default.
>>>>
>>>>> how it's supposed to work if there's more than one of these devices as per
>>>>> the log above.
>>>>
>>>> Upon closer look, this is not a resource of the device, but an inbound
>>>> memory region.  Hence there is no issue if multiple devices use the
>>>> same region.
>>>>
>>>>>
>>>>>> +       pci_add_resource(&bridge->windows, &res);
>>>>>
>>>>> What would be the backing resource in the resource tree for this? I'm not
>>>>> sure if pci_add_resource() is going to result in adding one into the
>>>>> resource tree.
>>>>
>>>> Likewise, it should not appear in /proc/ioem.
>>>
>>> Thanks for checking it out.
>>>
>>> I wonder how it would be supposed to work if PCI resource fitting logic
>>> finds place for it and changes its address. I don't think it would ever
>>> happen because it should never fit...
>>>
>>> ...But the logic still is a bit fishy if rcar2 code expects that address
>>> to be fixed but doesn't flag the resource to have a fixed address.
>>
>> How can the PCI resource fitting logic change it? It is an inbound
>> memory region, not a normal BAR?
> 
> I thought it can happen because it appears as BAR1, all resources from
> BARs are eligible for the normal assignment but now that I think it more,
> the underlying struct resource is going different for that BAR1 and the
> actual dma_ranges entry.
> 
> --
>   i.

Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Bjorn Helgaas 4 months, 2 weeks ago
On Wed, Sep 24, 2025 at 04:42:28PM +0300, Ilpo Järvinen wrote:
> PNP resources are checked for conflicts with the other resource in the
> system by quirk_system_pci_resources() that walks through all PCI
> resources. quirk_system_pci_resources() correctly filters out resource
> with IORESOURCE_UNSET.
> 
> Resources that do not reside within their bridge window, however, are
> not properly initialized with IORESOURCE_UNSET resulting in bogus
> conflicts detected in quirk_system_pci_resources():
> 
> pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> ...
> pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> ...
> pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> 
> Mark resources that are not contained within their bridge window with
> IORESOURCE_UNSET in __pci_read_base() which resolves the false
> positives for the overlap check in quirk_system_pci_resources().
> 
> Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> ---
> 
> This change uses resource_contains() which will reject partial overlaps.
> I don't know for sure if partial overlaps should be allowed or not (but
> they feel as something FW didn't set things up properly so I chose to
> mark them UNSET as well).
> 
>  drivers/pci/probe.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> index 7f9da8c41620..097389f25853 100644
> --- a/drivers/pci/probe.c
> +++ b/drivers/pci/probe.c
> @@ -205,6 +205,26 @@ static void __pci_size_rom(struct pci_dev *dev, unsigned int pos, u32 *sizes)
>  	__pci_size_bars(dev, 1, pos, sizes, true);
>  }
>  
> +static struct resource *pbus_select_window_for_res_addr(
> +					const struct pci_bus *bus,
> +					const struct resource *res)
> +{
> +	unsigned long type = res->flags & IORESOURCE_TYPE_BITS;
> +	struct resource *r;
> +
> +	pci_bus_for_each_resource(bus, r) {
> +		if (!r || r == &ioport_resource || r == &iomem_resource)
> +			continue;
> +
> +		if ((r->flags & IORESOURCE_TYPE_BITS) != type)
> +			continue;
> +
> +		if (resource_contains(r, res))
> +			return r;
> +	}
> +	return NULL;
> +}
> +
>  /**
>   * __pci_read_base - Read a PCI BAR
>   * @dev: the PCI device
> @@ -329,6 +349,18 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
>  			 res_name, (unsigned long long)region.start);
>  	}
>  
> +	if (!(res->flags & IORESOURCE_UNSET)) {
> +		struct resource *b_res;
> +
> +		b_res = pbus_select_window_for_res_addr(dev->bus, res);
> +		if (!b_res ||
> +		    b_res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) {
> +			pci_dbg(dev, "%s %pR: no initial claim (no window)\n",
> +				res_name, res);

Should this be pci_info()?  Or is there somewhere else that we
complain about a child resource that's not contained in a bridge
window?

I recently got an internal report of child BARs being reassigned, I
think because they weren't inside a bridge window, and the dmesg log
(from an older kernel) showed the BAR reassignments, but didn't say
anything about the *reason* for the reassignment.

> +			res->flags |= IORESOURCE_UNSET;
> +		}
> +	}
> +
>  	goto out;
>  
>  
> -- 
> 2.39.5
> 
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Ilpo Järvinen 4 months, 2 weeks ago
On Thu, 25 Sep 2025, Bjorn Helgaas wrote:
> On Wed, Sep 24, 2025 at 04:42:28PM +0300, Ilpo Järvinen wrote:
> > PNP resources are checked for conflicts with the other resource in the
> > system by quirk_system_pci_resources() that walks through all PCI
> > resources. quirk_system_pci_resources() correctly filters out resource
> > with IORESOURCE_UNSET.
> > 
> > Resources that do not reside within their bridge window, however, are
> > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > conflicts detected in quirk_system_pci_resources():
> > 
> > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0x1fffffff 64bit pref]
> > pci 0000:00:02.0: VF BAR 2 [mem 0x00000000-0xdfffffff 64bit pref]: contains BAR 2 for 7 VFs
> > ...
> > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x1ffffffff 64bit pref]
> > pci 0000:03:00.0: VF BAR 2 [mem 0x00000000-0x3dffffffff 64bit pref]: contains BAR 2 for 31 VFs
> > ...
> > pnp 00:04: disabling [mem 0xfc000000-0xfc00ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff] because it overlaps 0000:00:02.0 BAR 9 [mem 0x00000000-0xdfffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfedc0000-0xfedc7fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfeda0000-0xfeda0fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfeda1000-0xfeda1fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xc0000000-0xcfffffff disabled] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfed20000-0xfed7ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfed90000-0xfed93fff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfed45000-0xfed8ffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > pnp 00:05: disabling [mem 0xfee00000-0xfeefffff] because it overlaps 0000:03:00.0 BAR 9 [mem 0x00000000-0x3dffffffff 64bit pref]
> > 
> > Mark resources that are not contained within their bridge window with
> > IORESOURCE_UNSET in __pci_read_base() which resolves the false
> > positives for the overlap check in quirk_system_pci_resources().
> > 
> > Fixes: f7834c092c42 ("PNP: Don't check for overlaps with unassigned PCI BARs")
> > Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
> > ---
> > 
> > This change uses resource_contains() which will reject partial overlaps.
> > I don't know for sure if partial overlaps should be allowed or not (but
> > they feel as something FW didn't set things up properly so I chose to
> > mark them UNSET as well).
> > 
> >  drivers/pci/probe.c | 32 ++++++++++++++++++++++++++++++++
> >  1 file changed, 32 insertions(+)
> > 
> > diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
> > index 7f9da8c41620..097389f25853 100644
> > --- a/drivers/pci/probe.c
> > +++ b/drivers/pci/probe.c
> > @@ -205,6 +205,26 @@ static void __pci_size_rom(struct pci_dev *dev, unsigned int pos, u32 *sizes)
> >  	__pci_size_bars(dev, 1, pos, sizes, true);
> >  }
> >  
> > +static struct resource *pbus_select_window_for_res_addr(
> > +					const struct pci_bus *bus,
> > +					const struct resource *res)
> > +{
> > +	unsigned long type = res->flags & IORESOURCE_TYPE_BITS;
> > +	struct resource *r;
> > +
> > +	pci_bus_for_each_resource(bus, r) {
> > +		if (!r || r == &ioport_resource || r == &iomem_resource)

I started to wonder if those two parent "anchor" resource can ever appear 
in resources returned by pci_bus_for_each_resource()?

I've just copied those check from find_bus_resource_of_type() but it could 
be snake oil there as well.

At least I don't see them ever in my quick tests, they only appeared as 
parents of the resources this loop iterates over. But again I'm limited to 
x86 systems so not sure if my testing yields universally true answers.

> > +			continue;
> > +
> > +		if ((r->flags & IORESOURCE_TYPE_BITS) != type)
> > +			continue;
> > +
> > +		if (resource_contains(r, res))
> > +			return r;
> > +	}
> > +	return NULL;
> > +}
> > +
> >  /**
> >   * __pci_read_base - Read a PCI BAR
> >   * @dev: the PCI device
> > @@ -329,6 +349,18 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
> >  			 res_name, (unsigned long long)region.start);
> >  	}
> >  
> > +	if (!(res->flags & IORESOURCE_UNSET)) {
> > +		struct resource *b_res;
> > +
> > +		b_res = pbus_select_window_for_res_addr(dev->bus, res);
> > +		if (!b_res ||
> > +		    b_res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) {
> > +			pci_dbg(dev, "%s %pR: no initial claim (no window)\n",
> > +				res_name, res);
> 
> Should this be pci_info()?  Or is there somewhere else that we
> complain about a child resource that's not contained in a bridge
> window?

AFAIK, there's no other print. The kernel didn't even recognize this case 
until now so how could there have been one?!

They'd generally show up as failures later in resource assignment if the 
resource doesn't fit to the bridge window [1], which should also set 
IORESOURCE_UNSET, but good luck for inferring things from that. It's 
tedious, I know. :-) If the bridge window is large enough, the base 
address would just change where the resource fits (I think).

It can be pci_info() if you think that's better. I just picked the level 
which is the least noisy. We can go with pci_info() now and if the logging 
turns out excessive when we start to see dmesgs with it, we can of course 
adjust it later so it's not permanent either way.

In any case, there's not much user can do for these as it's the setup FW 
gave us.

> I recently got an internal report of child BARs being reassigned, I
> think because they weren't inside a bridge window, and the dmesg log
> (from an older kernel) showed the BAR reassignments, but didn't say
> anything about the *reason* for the reassignment.

Resource reassignment is only done after the resource was initially 
assigned so I'm not sure if that inferring chain is sound.

Admittedly, you didn't exactly specify how you picked up that it was 
"reassigned" so it could be just terminology that doesn't match what 
setup-bus/res.c considers as resource reassignment. That is, if BAR's 
address was simply changed from the initial, that's not "reassignment" in 
the sense used by the kernel.


I see these for ROM resource and uninitialized (0-based) resources but 
that isn't to say there couldn't be a case where the non-ROM resource was 
an invalid non-zero base address.


[footnote 1]

Some code uses IORESOURCE_UNSET where as others use ->parent to 
determine of the resource is not yet assigned. pdev_sort_resources() picks 
them based on ->parent so the resource fitting algorith tries to assign 
also resource that do not have IORESOURCE_UNSET. This entire ->parent and 
IORESOURCE_UNSET handling has lots of overlap and likely some remaining 
inconsistencies as well.

I initially thought I could entirely drop IORESOURCE_UNSET and base 
everything on ->parent but I've now changed my mind because of this 
series. We need this flag between initial reading of BARs/windows and 
running the resource fitting/assignment algorithm.

I could see some benefit from altering the meaning to something along the 
lines of IORESOURCE_INITIALLY_UNSET which is permanent flag. That 
information could then be used to determine we don't produce worse 
resource fits than what FW did. But it might be too hard to make such
change to IORESOURCE_UNSET and there are not extra bits available in 
->flags for realizing it parallel to existing flags.

It may be useful to add some warnings if UNSET and ->parent are in 
disagreement to ensure consistent state for any resource. But those 
checks would need to cope the initial transient when windows are not yet 
claimed from the resource tree which makes it harder to find good spots 
for such checks.

I generally dislike IORESOURCE_UNSET because it's semantics are not very 
clear and not properly enforced.


-- 
 i.
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Bjorn Helgaas 4 months, 1 week ago
On Fri, Sep 26, 2025 at 03:21:17PM +0300, Ilpo Järvinen wrote:
> On Thu, 25 Sep 2025, Bjorn Helgaas wrote:
> > On Wed, Sep 24, 2025 at 04:42:28PM +0300, Ilpo Järvinen wrote:
> > > PNP resources are checked for conflicts with the other resource in the
> > > system by quirk_system_pci_resources() that walks through all PCI
> > > resources. quirk_system_pci_resources() correctly filters out resource
> > > with IORESOURCE_UNSET.
> > > 
> > > Resources that do not reside within their bridge window, however, are
> > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > conflicts detected in quirk_system_pci_resources():

> > > @@ -329,6 +349,18 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
> > >  			 res_name, (unsigned long long)region.start);
> > >  	}
> > >  
> > > +	if (!(res->flags & IORESOURCE_UNSET)) {
> > > +		struct resource *b_res;
> > > +
> > > +		b_res = pbus_select_window_for_res_addr(dev->bus, res);
> > > +		if (!b_res ||
> > > +		    b_res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) {
> > > +			pci_dbg(dev, "%s %pR: no initial claim (no window)\n",
> > > +				res_name, res);
> > 
> > Should this be pci_info()?  Or is there somewhere else that we
> > complain about a child resource that's not contained in a bridge
> > window?
> 
> AFAIK, there's no other print. The kernel didn't even recognize this case 
> until now so how could there have been one?!

> They'd generally show up as failures later in resource assignment if the 
> resource doesn't fit to the bridge window [1], which should also set 
> IORESOURCE_UNSET, but good luck for inferring things from that. It's 
> tedious, I know. :-) If the bridge window is large enough, the base 
> address would just change where the resource fits (I think).
> 
> It can be pci_info() if you think that's better. I just picked the level 
> which is the least noisy. We can go with pci_info() now and if the logging 
> turns out excessive when we start to see dmesgs with it, we can of course 
> adjust it later so it's not permanent either way.
> 
> In any case, there's not much user can do for these as it's the setup FW 
> gave us.
> 
> > I recently got an internal report of child BARs being reassigned, I
> > think because they weren't inside a bridge window, and the dmesg log
> > (from an older kernel) showed the BAR reassignments, but didn't say
> > anything about the *reason* for the reassignment.
> 
> Resource reassignment is only done after the resource was initially 
> assigned so I'm not sure if that inferring chain is sound.
> 
> Admittedly, you didn't exactly specify how you picked up that it was 
> "reassigned" so it could be just terminology that doesn't match what 
> setup-bus/res.c considers as resource reassignment. That is, if BAR's 
> address was simply changed from the initial, that's not "reassignment" in 
> the sense used by the kernel.

Here's the case I saw (a v6.1 kernel, so old log messages):

  pci 0000:00:00.0: bridge window [mem 0x80000000-0x97fffffff 64bit pref] to [bus 01-05] add_size 80000000 add_align 80000000
  pci 0000:00:00.0: BAR 15: assigned [mem 0x380000000-0xcffffffff 64bit pref]
  pci 0000:01:01.0: BAR 0: [mem 0xb00000000-0xbffffffff 64bit pref]
  ...
  pci 0000:01:01.7: BAR 0: [mem 0x400000000-0x4ffffffff 64bit pref]
  pci 0000:01:01.0: BAR 0: assigned [mem 0x400000000-0x4ffffffff 64bit pref]

Obviously these initial BAR 0 values don't fit in the
[0x80000000-0x97fffffff] bridge window, so I think we moved and
expanded it and then assigned the BARs to be inside.

I was thinking might get the "can't claim; no compatible bridge
window" message in pci_claim_resource() as a clue, but we didn't.

This *seems* like a firmware defect: why would firmware bother to
program these BARs at all unless it also made a bridge window that
could reach them.

Bjorn
Re: [PATCH 2/2] PCI: Resources outside their window must set IORESOURCE_UNSET
Posted by Ilpo Järvinen 4 months, 1 week ago
On Fri, 26 Sep 2025, Bjorn Helgaas wrote:
> On Fri, Sep 26, 2025 at 03:21:17PM +0300, Ilpo Järvinen wrote:
> > On Thu, 25 Sep 2025, Bjorn Helgaas wrote:
> > > On Wed, Sep 24, 2025 at 04:42:28PM +0300, Ilpo Järvinen wrote:
> > > > PNP resources are checked for conflicts with the other resource in the
> > > > system by quirk_system_pci_resources() that walks through all PCI
> > > > resources. quirk_system_pci_resources() correctly filters out resource
> > > > with IORESOURCE_UNSET.
> > > > 
> > > > Resources that do not reside within their bridge window, however, are
> > > > not properly initialized with IORESOURCE_UNSET resulting in bogus
> > > > conflicts detected in quirk_system_pci_resources():
> 
> > > > @@ -329,6 +349,18 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
> > > >  			 res_name, (unsigned long long)region.start);
> > > >  	}
> > > >  
> > > > +	if (!(res->flags & IORESOURCE_UNSET)) {
> > > > +		struct resource *b_res;
> > > > +
> > > > +		b_res = pbus_select_window_for_res_addr(dev->bus, res);
> > > > +		if (!b_res ||
> > > > +		    b_res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) {
> > > > +			pci_dbg(dev, "%s %pR: no initial claim (no window)\n",
> > > > +				res_name, res);
> > > 
> > > Should this be pci_info()?  Or is there somewhere else that we
> > > complain about a child resource that's not contained in a bridge
> > > window?
> > 
> > AFAIK, there's no other print. The kernel didn't even recognize this case 
> > until now so how could there have been one?!
> 
> > They'd generally show up as failures later in resource assignment if the 
> > resource doesn't fit to the bridge window [1], which should also set 
> > IORESOURCE_UNSET, but good luck for inferring things from that. It's 
> > tedious, I know. :-) If the bridge window is large enough, the base 
> > address would just change where the resource fits (I think).
> > 
> > It can be pci_info() if you think that's better. I just picked the level 
> > which is the least noisy. We can go with pci_info() now and if the logging 
> > turns out excessive when we start to see dmesgs with it, we can of course 
> > adjust it later so it's not permanent either way.
> > 
> > In any case, there's not much user can do for these as it's the setup FW 
> > gave us.
> > 
> > > I recently got an internal report of child BARs being reassigned, I
> > > think because they weren't inside a bridge window, and the dmesg log
> > > (from an older kernel) showed the BAR reassignments, but didn't say
> > > anything about the *reason* for the reassignment.
> > 
> > Resource reassignment is only done after the resource was initially 
> > assigned so I'm not sure if that inferring chain is sound.
> > 
> > Admittedly, you didn't exactly specify how you picked up that it was 
> > "reassigned" so it could be just terminology that doesn't match what 
> > setup-bus/res.c considers as resource reassignment. That is, if BAR's 
> > address was simply changed from the initial, that's not "reassignment" in 
> > the sense used by the kernel.
> 
> Here's the case I saw (a v6.1 kernel, so old log messages):
> 
>   pci 0000:00:00.0: bridge window [mem 0x80000000-0x97fffffff 64bit pref] to [bus 01-05] add_size 80000000 add_align 80000000
>   pci 0000:00:00.0: BAR 15: assigned [mem 0x380000000-0xcffffffff 64bit pref]
>   pci 0000:01:01.0: BAR 0: [mem 0xb00000000-0xbffffffff 64bit pref]
>   ...
>   pci 0000:01:01.7: BAR 0: [mem 0x400000000-0x4ffffffff 64bit pref]
>   pci 0000:01:01.0: BAR 0: assigned [mem 0x400000000-0x4ffffffff 64bit pref]
> 
> Obviously these initial BAR 0 values don't fit in the
> [0x80000000-0x97fffffff] bridge window, so I think we moved and
> expanded it and then assigned the BARs to be inside.
> 
> I was thinking might get the "can't claim; no compatible bridge
> window" message in pci_claim_resource() as a clue, but we didn't.

Is pci_bus_claim_resources() called in this case? That requires 
preserve_config. In my tests pci_bus_allocate_dev_resources() is never 
called, only bridge window resources are claimed.

> This *seems* like a firmware defect: why would firmware bother to
> program these BARs at all unless it also made a bridge window that
> could reach them.

-- 
 i.