* [RFC PATCH 0/2] Allow reusing PCI domain numbers in DT
@ 2026-11-02 9:51 Cui Chao
2026-11-02 9:51 ` [PATCH 1/2] dt-bindings: PCI: Add linux,pci-domain-reuse property Cui Chao
2026-11-02 9:51 ` [PATCH 2/2] PCI: Allow reusing PCI domain numbers in DT Cui Chao
0 siblings, 2 replies; 6+ messages in thread
From: Cui Chao @ 2026-11-02 9:51 UTC (permalink / raw)
To: Will Deacon, Krzysztof Kozlowski, Conor Dooley, Bjorn Helgaas
Cc: Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Wang Yinfeng, linux-pci,
devicetree, linux-arm-kernel, linux-kernel
This series allows multiple PCIe host bridges to reuse the same software
domain number in Device Tree (DT), provided their resources are disjoint.
In mainstream GPU P2P functionality, whether the GPUs participating in
P2P belong to the same PCIe domain is one of the decision criteria. In
the existing DT path, a uniqueness constraint is imposed on the PCI
domains of multiple PCIe nodes, which prevents devices under different
PCIe RCs from reusing the same software domain number.
It should be noted that equality of PCI domains at the software level
is not equivalent to the final P2P decision. The ACPI path directly
returns '_SEG' and does not perform a similar uniqueness check, as
'_SEG' is a purely software concept and allows multiple RCs to use the
same value.
Cui Chao (2):
dt-bindings: PCI: Add linux,pci-domain-reuse property
PCI: Allow reusing PCI domain numbers in DT
.../devicetree/bindings/pci/host-generic-pci.yaml | 10 ++++++++++
drivers/pci/pci.c | 14 ++++++++++++--
2 files changed, 22 insertions(+), 2 deletions(-)
--
2.33.0
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/2] dt-bindings: PCI: Add linux,pci-domain-reuse property
2026-11-02 9:51 [RFC PATCH 0/2] Allow reusing PCI domain numbers in DT Cui Chao
@ 2026-11-02 9:51 ` Cui Chao
2026-11-02 9:58 ` sashiko-bot
2026-11-02 10:00 ` Krzysztof Kozlowski
2026-11-02 9:51 ` [PATCH 2/2] PCI: Allow reusing PCI domain numbers in DT Cui Chao
1 sibling, 2 replies; 6+ messages in thread
From: Cui Chao @ 2026-11-02 9:51 UTC (permalink / raw)
To: Will Deacon, Krzysztof Kozlowski, Conor Dooley, Bjorn Helgaas
Cc: Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Wang Yinfeng, linux-pci,
devicetree, linux-arm-kernel, linux-kernel
Add a new optional boolean property 'linux,pci-domain-reuse' for PCI
host bridges.
By default, the 'linux,pci-domain' property must be unique across all
host bridges. This property allows a host bridge to explicitly opt-out
of this uniqueness check, permitting multiple host bridges to reuse the
same software domain number.
Host bridges reusing the same domain number must have disjoint ECAM,
bus-range, memory, and IO windows so that (domain, bus) tuples remain
globally unique.
Co-developed-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Cui Chao <cuichao1753@phytium.com.cn>
---
.../devicetree/bindings/pci/host-generic-pci.yaml | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/Documentation/devicetree/bindings/pci/host-generic-pci.yaml b/Documentation/devicetree/bindings/pci/host-generic-pci.yaml
index 420d551e9af9..1b439e2f38af 100644
--- a/Documentation/devicetree/bindings/pci/host-generic-pci.yaml
+++ b/Documentation/devicetree/bindings/pci/host-generic-pci.yaml
@@ -114,6 +114,16 @@ properties:
Requests with Address Type (AT).
type: boolean
+ linux,pci-domain-reuse:
+ description:
+ Boolean indicating that this host bridge is allowed to reuse the same
+ "linux,pci-domain" value as another host bridge on the platform. Host
+ bridges reusing the same domain must have disjoint ECAM, bus-range,
+ memory, and IO windows so that (domain, bus) tuples remain globally
+ unique. A duplicate domain on a host bridge without this property
+ remains an error.
+ type: boolean
+
required:
- compatible
- reg
--
2.33.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/2] PCI: Allow reusing PCI domain numbers in DT
2026-11-02 9:51 [RFC PATCH 0/2] Allow reusing PCI domain numbers in DT Cui Chao
2026-11-02 9:51 ` [PATCH 1/2] dt-bindings: PCI: Add linux,pci-domain-reuse property Cui Chao
@ 2026-11-02 9:51 ` Cui Chao
2026-11-02 10:02 ` sashiko-bot
1 sibling, 1 reply; 6+ messages in thread
From: Cui Chao @ 2026-11-02 9:51 UTC (permalink / raw)
To: Will Deacon, Krzysztof Kozlowski, Conor Dooley, Bjorn Helgaas
Cc: Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Wang Yinfeng, linux-pci,
devicetree, linux-arm-kernel, linux-kernel
In the existing DT path, a uniqueness constraint is imposed on the PCI
domains of multiple PCIe nodes, which prevents devices under different
PCIe RCs from reusing the same software domain number.
Add support for the 'linux,pci-domain-reuse' DT property. For a PCI
node that declares this property, it is allowed to reuse the same
'linux,pci-domain' number with other nodes. For a PCI node that does
not declare this property, the original uniqueness check remains in
place.
Reasonable resource partitioning does not affect the global uniqueness
of devices. When domains are the same, as long as the physical
resources of two PCIe nodes (RCs), such as ECAM, bus ranges, mem32,
mem64, and IO, do not overlap, (domain, bus) remains globally unique,
and the BDFs of all devices are also globally unique.
Device tree example:
Each RC node participating in reuse declares 'linux,pci-domain-reuse';
whether the same number is actually reused is determined by the
'linux,pci-domain' value. In the example, the ECAM, bus-range, and
ranges of the two RCs do not overlap.
pcie0: pcie@10000000 {
...
linux,pci-domain = <0>;
linux,pci-domain-reuse;
bus-range = <0x00 0x7f>;
ranges = <0x01000000 0x00000000 0x00100000 0x00000000
0x10000000 0x00000000 0x00100000
0x02000000 0x00000000 0x20000000 0x00000000
0x20000000 0x00000000 0x10000000
0x43000000 0x00000200 0x00000000 0x00000200
0x00000000 0x00000100 0x00000000>;
...
};
pcie1: pcie@20000000 {
...
linux,pci-domain = <0>;
linux,pci-domain-reuse;
bus-range = <0x80 0xff>;
ranges = <0x01000000 0x00000000 0x00200000 0x00000000
0x10100000 0x00000000 0x00100000
0x02000000 0x00000000 0x30000000 0x00000000
0x30000000 0x00000000 0x10000000
0x43000000 0x00000300 0x00000000 0x00000300
0x00000000 0x00000100 0x00000000>;
...
};
Co-developed-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Wang Yinfeng <wangyinfeng@phytium.com.cn>
Signed-off-by: Cui Chao <cuichao1753@phytium.com.cn>
---
drivers/pci/pci.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 7c6f2aba8144..245ffb9d2f74 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -6801,13 +6801,19 @@ static int of_pci_bus_find_domain_nr(struct device *parent)
/*
* If domain is in DT, allocate it in static IDA. This
* prevents duplicate static allocations in case of errors
- * in DT.
+ * in DT. Platform that legitimately reuse a domain number
+ * across host bridges (disjoint ECAM/bus/memory/IO) opt out
+ * of this check with "linux,pci-domain-reuse".
*/
domain_nr = of_get_pci_domain_nr(parent->of_node);
- if (domain_nr >= 0)
+ if (domain_nr >= 0) {
+ if (of_property_read_bool(parent->of_node,
+ "linux,pci-domain-reuse"))
+ return domain_nr;
return ida_alloc_range(&pci_domain_nr_static_ida,
domain_nr, domain_nr,
GFP_KERNEL);
+ }
}
/*
@@ -6824,6 +6830,10 @@ static void of_pci_bus_release_domain_nr(struct device *parent, int domain_nr)
if (domain_nr < 0)
return;
+ /* Reusers never acquire the static slot, so never release it */
+ if (of_property_read_bool(parent->of_node, "linux,pci-domain-reuse"))
+ return;
+
/* Release domain from IDA where it was allocated. */
if (parent && of_get_pci_domain_nr(parent->of_node) == domain_nr)
ida_free(&pci_domain_nr_static_ida, domain_nr);
--
2.33.0
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] dt-bindings: PCI: Add linux,pci-domain-reuse property
2026-11-02 9:51 ` [PATCH 1/2] dt-bindings: PCI: Add linux,pci-domain-reuse property Cui Chao
@ 2026-11-02 9:58 ` sashiko-bot
2026-11-02 10:00 ` Krzysztof Kozlowski
1 sibling, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-02 9:58 UTC (permalink / raw)
To: Cui Chao; +Cc: linux-pci, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] dt-bindings: PCI: redundant linux,pci-domain-reuse OS-policy property
--
commit 4d7d1f09f7c3c39f32142c31f5a0c2f23d8b30fc
Author: Cui Chao <cuichao1753@phytium.com.cn>
dt-bindings: PCI: Add linux,pci-domain-reuse property
This commit adds an optional boolean property linux,pci-domain-reuse to the
generic PCI host bridge Device Tree binding so that multiple host bridges with
disjoint resources can share the same software PCI domain number.
> diff --git a/Documentation/devicetree/bindings/pci/host-generic-pci.yaml b/Documentation/devicetree/bindings/pci/host-generic-pci.yaml
> index 420d551e9af97..1b439e2f38af7 100644
> --- a/Documentation/devicetree/bindings/pci/host-generic-pci.yaml
> +++ b/Documentation/devicetree/bindings/pci/host-generic-pci.yaml
> @@ -114,6 +114,16 @@ properties:
> Requests with Address Type (AT).
> type: boolean
>
> + linux,pci-domain-reuse:
> + description:
> + Boolean indicating that this host bridge is allowed to reuse the same
> + "linux,pci-domain" value as another host bridge on the platform. Host
> + bridges reusing the same domain must have disjoint ECAM, bus-range,
> + memory, and IO windows so that (domain, bus) tuples remain globally
> + unique. A duplicate domain on a host bridge without this property
> + remains an error.
> + type: boolean
[Severity: Medium]
Is a new Device Tree property needed here when the hardware topology of
multiple host bridges sharing a domain with disjoint bus ranges is already
fully described by setting the same linux,pci-domain alongside disjoint
bus-range, reg, and ranges properties?
In the PCI core, pci_register_host_bridge() in drivers/pci/probe.c already
tracks per-domain bus number resources via get_pci_domain_busn_res() and
pci_bus_insert_busn_res(), and rejects conflicting (domain, busnr) tuples:
drivers/pci/probe.c:pci_register_host_bridge() {
...
b = pci_find_bus(pci_domain_nr(bus), bridge->busnr);
if (b) {
/* Ignore it if we already got here via a different bridge */
dev_dbg(&b->dev, "bus already known\n");
err = -EEXIST;
goto free;
}
...
}
The only reason duplicate linux,pci-domain values currently fail in Device
Tree is that of_pci_bus_find_domain_nr() in drivers/pci/pci.c unconditionally
allocates static DT domain numbers from pci_domain_nr_static_ida:
drivers/pci/pci.c:of_pci_bus_find_domain_nr() {
...
domain_nr = of_get_pci_domain_nr(parent->of_node);
if (domain_nr >= 0)
return ida_alloc_range(&pci_domain_nr_static_ida,
domain_nr, domain_nr,
GFP_KERNEL);
...
}
Could the kernel distinguish valid multi-bridge domain sharing (disjoint
bus-range) from accidental DT duplication (overlapping bus-range) directly
using existing DT properties, rather than introducing a Linux-specific policy
property in the binding ABI?
Also, if a binding property were used, shouldn't it live in
Documentation/devicetree/bindings/pci/pci-host-bridge.yaml where
linux,pci-domain is defined (and parsed by generic OF PCI code in
drivers/pci/pci.c), rather than only in host-generic-pci.yaml?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261102095150.2370959-1-cuichao1753@phytium.com.cn?part=1
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 1/2] dt-bindings: PCI: Add linux,pci-domain-reuse property
2026-11-02 9:51 ` [PATCH 1/2] dt-bindings: PCI: Add linux,pci-domain-reuse property Cui Chao
2026-11-02 9:58 ` sashiko-bot
@ 2026-11-02 10:00 ` Krzysztof Kozlowski
1 sibling, 0 replies; 6+ messages in thread
From: Krzysztof Kozlowski @ 2026-11-02 10:00 UTC (permalink / raw)
To: Cui Chao, Will Deacon, Krzysztof Kozlowski, Conor Dooley,
Bjorn Helgaas
Cc: Lorenzo Pieralisi, Krzysztof Wilczyński,
Manivannan Sadhasivam, Rob Herring, Wang Yinfeng, linux-pci,
devicetree, linux-arm-kernel, linux-kernel
On 02/11/2026 10:51, Cui Chao wrote:
> Add a new optional boolean property 'linux,pci-domain-reuse' for PCI
> host bridges.
>
> By default, the 'linux,pci-domain' property must be unique across all
> host bridges. This property allows a host bridge to explicitly opt-out
> of this uniqueness check, permitting multiple host bridges to reuse the
> same software domain number.
Why isn't this deducible from the compatibles?
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 2/2] PCI: Allow reusing PCI domain numbers in DT
2026-11-02 9:51 ` [PATCH 2/2] PCI: Allow reusing PCI domain numbers in DT Cui Chao
@ 2026-11-02 10:02 ` sashiko-bot
0 siblings, 0 replies; 6+ messages in thread
From: sashiko-bot @ 2026-11-02 10:02 UTC (permalink / raw)
To: Cui Chao; +Cc: linux-pci, devicetree, robh, conor+dt
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
- [High] PCI: NULL pointer dereference in of_pci_bus_release_domain_nr()
- [Medium] PCI: dynamic domain ID leak in of_pci_bus_release_domain_nr()
- [Medium] PCI: uniqueness check bypassed in of_pci_bus_find_domain_nr()
--
commit 6f168ee04fb909d8010153d5588cf34c9e1e6db6
Author: Cui Chao <cuichao1753@phytium.com.cn>
PCI: Allow reusing PCI domain numbers in DT
This commit adds support for the linux,pci-domain-reuse Device Tree property
to allow multiple PCIe host bridges with disjoint physical resources to share
the same static linux,pci-domain number.
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index b2879a6be5f80..9cb3132673f86 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -6738,13 +6738,19 @@ static int of_pci_bus_find_domain_nr(struct device *parent)
> /*
> * If domain is in DT, allocate it in static IDA. This
> * prevents duplicate static allocations in case of errors
> - * in DT.
> + * in DT. Platform that legitimately reuse a domain number
> + * across host bridges (disjoint ECAM/bus/memory/IO) opt out
> + * of this check with "linux,pci-domain-reuse".
> */
> domain_nr = of_get_pci_domain_nr(parent->of_node);
> - if (domain_nr >= 0)
> + if (domain_nr >= 0) {
> + if (of_property_read_bool(parent->of_node,
> + "linux,pci-domain-reuse"))
> + return domain_nr;
> return ida_alloc_range(&pci_domain_nr_static_ida,
> domain_nr, domain_nr,
> GFP_KERNEL);
> + }
> }
[Severity: Medium]
The commit message states that for a PCI node that does not declare
linux,pci-domain-reuse, the original uniqueness check remains in place, and
that each RC node participating in reuse declares linux,pci-domain-reuse.
In drivers/pci/pci.c:of_pci_bus_find_domain_nr(), returning domain_nr
directly without recording or checking anything in pci_domain_nr_static_ida
means that if one host bridge declares linux,pci-domain = <0> with
linux,pci-domain-reuse and a second host bridge declares
linux,pci-domain = <0> without linux,pci-domain-reuse, both host bridges
succeed regardless of probe order.
If the reusing bridge probes first, domain 0 is never allocated in
pci_domain_nr_static_ida, so the non-reusing bridge's call to
ida_alloc_range(&pci_domain_nr_static_ida, 0, 0, GFP_KERNEL) succeeds. If the
non-reusing bridge probes first, it allocates domain 0 in
pci_domain_nr_static_ida, and the reusing bridge then bypasses
pci_domain_nr_static_ida completely.
Doesn't this allow a host bridge without linux,pci-domain-reuse to silently
share its domain number with another bridge?
>
> /*
> @@ -6761,6 +6767,10 @@ static void of_pci_bus_release_domain_nr(struct device *parent, int domain_nr)
> if (domain_nr < 0)
> return;
>
> + /* Reusers never acquire the static slot, so never release it */
> + if (of_property_read_bool(parent->of_node, "linux,pci-domain-reuse"))
> + return;
> +
> /* Release domain from IDA where it was allocated. */
> if (parent && of_get_pci_domain_nr(parent->of_node) == domain_nr)
> ida_free(&pci_domain_nr_static_ida, domain_nr);
[Severity: High]
Can this dereference a NULL parent pointer in
drivers/pci/pci.c:of_pci_bus_release_domain_nr()?
When a root bus is created without a parent device (for example via
pci_create_root_bus(NULL, ...) or pci_scan_bus()), of_pci_bus_find_domain_nr()
checks if (parent) and allocates a dynamic domain number from
pci_domain_nr_dynamic_ida.
If pci_register_host_bridge() fails and unwinds, or when
pci_remove_root_bus() tears down the bus:
pci_register_host_bridge() / pci_remove_root_bus()
pci_bus_release_domain_nr(NULL, bus->domain_nr)
of_pci_bus_release_domain_nr(NULL, domain_nr)
Evaluating parent->of_node in of_property_read_bool(parent->of_node, ...)
happens before the existing if (parent && ...) check below (which was added in
commit f7245901de89 ("PCI: Avoid NULL dereference in
of_pci_bus_release_domain_nr()")), causing a NULL pointer dereference.
[Severity: Medium]
Also in drivers/pci/pci.c:of_pci_bus_release_domain_nr(), does returning early
on linux,pci-domain-reuse before checking of_get_pci_domain_nr(parent->of_node)
== domain_nr leak a dynamic domain ID from pci_domain_nr_dynamic_ida?
In drivers/pci/pci.c:of_pci_bus_find_domain_nr():
if (parent) {
domain_nr = of_get_pci_domain_nr(parent->of_node);
if (domain_nr >= 0) {
if (of_property_read_bool(parent->of_node,
"linux,pci-domain-reuse"))
return domain_nr;
...
}
}
return ida_alloc(&pci_domain_nr_dynamic_ida, GFP_KERNEL);
If a DT node specifies linux,pci-domain-reuse without a valid
linux,pci-domain property (so domain_nr < 0), of_pci_bus_find_domain_nr()
falls through and allocates domain_nr from pci_domain_nr_dynamic_ida.
When of_pci_bus_release_domain_nr() is later called on error or removal,
checking of_property_read_bool(parent->of_node, "linux,pci-domain-reuse")
before verifying that domain_nr came from of_get_pci_domain_nr(parent->of_node)
returns early instead of freeing domain_nr from pci_domain_nr_dynamic_ida in
the else branch:
if (parent && of_get_pci_domain_nr(parent->of_node) == domain_nr) {
if (!of_property_read_bool(parent->of_node,
"linux,pci-domain-reuse"))
ida_free(&pci_domain_nr_static_ida, domain_nr);
} else {
ida_free(&pci_domain_nr_dynamic_ida, domain_nr);
}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261102095150.2370959-1-cuichao1753@phytium.com.cn?part=2
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-11-02 10:02 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-02 9:51 [RFC PATCH 0/2] Allow reusing PCI domain numbers in DT Cui Chao
2026-11-02 9:51 ` [PATCH 1/2] dt-bindings: PCI: Add linux,pci-domain-reuse property Cui Chao
2026-11-02 9:58 ` sashiko-bot
2026-11-02 10:00 ` Krzysztof Kozlowski
2026-11-02 9:51 ` [PATCH 2/2] PCI: Allow reusing PCI domain numbers in DT Cui Chao
2026-11-02 10:02 ` sashiko-bot
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.