* [PATCH v2 0/2] cxl: Fail region creation for a root decoder without a CXL window
@ 2026-12-04 13:57 Unsung Lee
2026-12-04 13:57 ` [PATCH v2 1/2] cxl/region: " Unsung Lee
2026-12-04 13:57 ` [PATCH v2 2/2] cxl/acpi: Correct the add_cxl_resources() kernel-doc on a trimmed window Unsung Lee
0 siblings, 2 replies; 4+ messages in thread
From: Unsung Lee @ 2026-12-04 13:57 UTC (permalink / raw)
To: linux-cxl
Cc: linux-kernel, Davidlohr Bueso, Jonathan Cameron, Dave Jiang,
Alison Schofield, Vishal Verma, Dan Williams, Ira Weiny, Li Ming,
Richard Cheng, Ben Cheatham, Unsung Lee
When add_cxl_resources() trims or removes a CXL window, the window's
root decoder stays registered without a resource, and creating a region
under it oopses. Patch 1 rejects region creation for such a decoder and
logs the decoder when it is left unpaired. Patch 2 corrects the
add_cxl_resources() kernel-doc.
On the kernel-doc question: the trimmed tail is not usable, and has not
been since pair_cxl_resource() was added in 0f157c7fa1a0, because a
root decoder is only paired with a window that covers its whole HPA
range. Making the tail usable would need a different pairing and HPA
allocation, which is beyond this fix, so patch 2 changes the comment to
match the code.
Changes since v1:
- Shortened the commit message; setup details moved below --- (Alison)
- dev_dbg() for a root decoder left without a window (Alison)
- New patch 2 for the kernel-doc (Alison)
- Rebased on cxl/next 5ee57f66c2
Test details are below the --- line in patch 1.
An AI coding assistant was used to analyze the bug, draft changelogs,
and automate the QEMU testing. I reviewed the text and the results.
v1: https://lore.kernel.org/linux-cxl/20261121105714.1542859-1-unsung0317@gmail.com/
Unsung Lee (2):
cxl/region: Fail region creation for a root decoder without a CXL
window
cxl/acpi: Correct the add_cxl_resources() kernel-doc on a trimmed
window
drivers/cxl/acpi.c | 18 ++++++++++++++----
drivers/cxl/core/region.c | 2 +-
2 files changed, 15 insertions(+), 5 deletions(-)
base-commit: 5ee57f66c2cc4565b35967ef64a02de2df1fe0ab
--
2.34.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] cxl/region: Fail region creation for a root decoder without a CXL window
2026-12-04 13:57 [PATCH v2 0/2] cxl: Fail region creation for a root decoder without a CXL window Unsung Lee
@ 2026-12-04 13:57 ` Unsung Lee
2026-12-04 14:15 ` sashiko-bot
2026-12-04 13:57 ` [PATCH v2 2/2] cxl/acpi: Correct the add_cxl_resources() kernel-doc on a trimmed window Unsung Lee
1 sibling, 1 reply; 4+ messages in thread
From: Unsung Lee @ 2026-12-04 13:57 UTC (permalink / raw)
To: linux-cxl
Cc: linux-kernel, Davidlohr Bueso, Jonathan Cameron, Dave Jiang,
Alison Schofield, Vishal Verma, Dan Williams, Ira Weiny, Li Ming,
Richard Cheng, Ben Cheatham, Unsung Lee
A resource overlap can leave a root decoder registered without a usable
CXL window. Setting a region's size under that decoder then dereferences
NULL with resource_lock held, which can stall other resource tree users.
Both the sysfs and the auto-assembly paths create regions through
__create_region(). Reject region creation there with -ENXIO, before
either path can use the missing resource, and log the unpaired root
decoder with its HPA range in pair_cxl_resource().
The oops was reproduced with cxl_test in a QEMU guest whose 64-bit PCI
MMIO window overlaps the cxl_test mock windows. The same state can
arise when a firmware System RAM range starts inside one CXL window and
extends into the next; that case and the auto-assembly path are from
code inspection.
Fixes: 23a22cd1c98b ("cxl/region: Allocate HPA capacity to regions")
Signed-off-by: Unsung Lee <unsung0317@gmail.com>
---
Notes:
Test details
cxl/next 5ee57f66c2, QEMU 11.2.0-rc2 (q35, KVM, SeaBIOS 1.17.0, 4 vCPU,
4G), Ubuntu 24.04 guest, one pxb-cxl host bridge with a cxl-type3
volatile device and an 8G fixed memory window, plus
"modprobe cxl_test interleave_arithmetic=1". The 64-bit PCI window
and the cxl_test mock windows overlap, so Window 0 is expanded over
PCI Bus 0000:00 and contains Windows 1-4:
7000000000-700000ffff : PCI Bus 0000:0c
7000010000-787fffffff : CXL Window 0
7000010000-703fffffff : PCI Bus 0000:00
7040000000-704fffffff : PCI Bus 0000:0c
7050000000-787fffffff : PCI Bus 0000:00
Before: decoder2.1-2.4 are left without a window. Writing the size of a
pmem region under decoder2.1 oopses and the guest stops responding:
BUG: kernel NULL pointer dereference, address: 0000000000000000
RIP: 0010:get_free_mem_region+0xfa/0x360
alloc_free_mem_region+0x1e/0x30
size_store+0x1d5/0x300 [cxl_core]
After: create_pmem_region (decoder2.1-2.3) and create_ram_region
(decoder2.4) fail with ENXIO, no splat, and with cxl_acpi.dyndbg=+p:
cxl decoder2.1: no CXL window covers HPA range 0x7090000000-0x710fffffff
cxl decoder2.2: no CXL window covers HPA range 0x7110000000-0x71cfffffff
cxl decoder2.3: no CXL window covers HPA range 0x71d0000000-0x724fffffff
cxl decoder2.4: no CXL window covers HPA range 0x7250000000-0x728fffffff
decoder2.0 still has its window and behaves as before.
ndctl v85 cxl suite in the same VM, with cxl-poison.sh run last:
without the patch: cxl-poison.sh oopses the same way
with the patch: cxl-poison.sh fails at line 262, no oops
The other 16 tests give the same results with and without the patch:
12 pass, cxl-security.sh is skipped, and cxl-xor-region.sh (line 30),
cxl-destroy-region.sh (exit 5) and cxl-region-replay.sh (line 47)
fail. No BUG/WARNING with the patch.
drivers/cxl/acpi.c | 7 +++++++
drivers/cxl/core/region.c | 2 +-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c
index 666452c04c..13609e2e98 100644
--- a/drivers/cxl/acpi.c
+++ b/drivers/cxl/acpi.c
@@ -898,6 +898,13 @@ static int pair_cxl_resource(struct device *dev, void *data)
}
}
+ if (!p) {
+ struct cxl_decoder *cxld = &to_cxl_root_decoder(dev)->cxlsd.cxld;
+
+ dev_dbg(dev, "no CXL window covers HPA range %#llx-%#llx\n",
+ cxld->hpa_range.start, cxld->hpa_range.end);
+ }
+
return 0;
}
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 7573cd115e..4a1386ffa4 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -3106,7 +3106,7 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,
{
int rc;
- if (cxlrd->dead)
+ if (cxlrd->dead || !cxlrd->res)
return ERR_PTR(-ENXIO);
switch (mode) {
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] cxl/acpi: Correct the add_cxl_resources() kernel-doc on a trimmed window
2026-12-04 13:57 [PATCH v2 0/2] cxl: Fail region creation for a root decoder without a CXL window Unsung Lee
2026-12-04 13:57 ` [PATCH v2 1/2] cxl/region: " Unsung Lee
@ 2026-12-04 13:57 ` Unsung Lee
1 sibling, 0 replies; 4+ messages in thread
From: Unsung Lee @ 2026-12-04 13:57 UTC (permalink / raw)
To: linux-cxl
Cc: linux-kernel, Davidlohr Bueso, Jonathan Cameron, Dave Jiang,
Alison Schofield, Vishal Verma, Dan Williams, Ira Weiny, Li Ming,
Richard Cheng, Ben Cheatham, Unsung Lee
The kernel-doc says that when a System RAM range spans two CXL windows,
the tail of the second window is left for dynamic region provisioning.
pair_cxl_resource() only pairs a root decoder with a window that covers
its whole HPA range, so the root decoder of a trimmed window has never
had a resource, and no region can be created in that tail.
Describe what happens instead; region creation under such a decoder
now fails with -ENXIO. No functional change.
Signed-off-by: Unsung Lee <unsung0317@gmail.com>
---
drivers/cxl/acpi.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/drivers/cxl/acpi.c b/drivers/cxl/acpi.c
index 13609e2e98..bd04780a15 100644
--- a/drivers/cxl/acpi.c
+++ b/drivers/cxl/acpi.c
@@ -832,11 +832,14 @@ static void remove_cxl_resources(void *data)
* |-- "CXL Window 0" --||----- "CXL Window 1" -----|
* |--------------- "System RAM" -------------|
*
- * ...where platform firmware has established as System RAM resource across 2
- * windows, but has left some portion of window 1 for dynamic CXL region
- * provisioning. In this case "Window 0" will span the entirety of the "System
+ * ...where platform firmware has established a System RAM resource across 2
+ * windows. In this case "CXL Window 0" will span the entirety of the "System
* RAM" span, and "CXL Window 1" is truncated to the remaining tail past the end
- * of that "System RAM" resource.
+ * of that "System RAM" resource. The truncated window no longer covers the HPA
+ * range of its root decoder, so pair_cxl_resource() leaves that decoder
+ * without a resource and no region can be created under it. The same happens
+ * to the root decoder of a window that is removed because an expanded window
+ * contains it.
*/
static int add_cxl_resources(struct resource *cxl_res)
{
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2 1/2] cxl/region: Fail region creation for a root decoder without a CXL window
2026-12-04 13:57 ` [PATCH v2 1/2] cxl/region: " Unsung Lee
@ 2026-12-04 14:15 ` sashiko-bot
0 siblings, 0 replies; 4+ messages in thread
From: sashiko-bot @ 2026-12-04 14:15 UTC (permalink / raw)
To: Unsung Lee, linux-cxl
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] cxl: data race on cxlrd->res between pair_cxl_resource() and
__create_region()
--
commit f8ca0af34d0d599d4141c4a1d8c9733e462badf1
Author: Unsung Lee <unsung0317@gmail.com>
cxl/region: Fail region creation for a root decoder without a CXL window
This commit rejects region creation in __create_region() with -ENXIO when
cxlrd->res is NULL and logs unpaired root decoders in pair_cxl_resource().
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 7573cd115e57d..4a1386ffa43ed 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -3106,7 +3106,7 @@ static struct cxl_region *__create_region(struct cxl_root_decoder *cxlrd,
> {
> int rc;
>
> - if (cxlrd->dead)
> + if (cxlrd->dead || !cxlrd->res)
> return ERR_PTR(-ENXIO);
>
> switch (mode) {
[Severity: Medium]
Can this read of cxlrd->res race with pair_cxl_resource() during
cxl_acpi_probe()?
CPU0 CPU1
cxl_acpi_probe()
acpi_table_parse_cedt()
__cxl_parse_cfmws()
cxl_decoder_add(cxld)
create_region_store()
lock(&cxlrd->regions_lock)
... __create_region()
pair_cxl_resource() if (cxlrd->dead || !cxlrd->res)
cxlrd->res = ... <-- data race / spurious -ENXIO
__cxl_parse_cfmws() exposes the root decoder in sysfs via cxl_decoder_add()
before pair_cxl_resource() populates cxlrd->res. create_region_store()
holds only cxlrd->regions_lock, while pair_cxl_resource() writes cxlrd->res
with a plain store without taking cxlrd->regions_lock.
This introduces a data race on cxlrd->res and can cause valid root decoders
to transiently fail region creation with -ENXIO during probe.
Taking cxlrd->regions_lock around the cxlrd->res store in
pair_cxl_resource() would fix the data race, and deferring cxl_decoder_add()
until after resource pairing would close the probe window.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261204135754.639574-1-unsung0317@gmail.com?part=1
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-12-04 14:15 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-04 13:57 [PATCH v2 0/2] cxl: Fail region creation for a root decoder without a CXL window Unsung Lee
2026-12-04 13:57 ` [PATCH v2 1/2] cxl/region: " Unsung Lee
2026-12-04 14:15 ` sashiko-bot
2026-12-04 13:57 ` [PATCH v2 2/2] cxl/acpi: Correct the add_cxl_resources() kernel-doc on a trimmed window Unsung Lee
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox