* [PATCH] cxl/region: Fail region creation for a root decoder without a CXL window
@ 2026-11-21 10:57 Unsung Lee
2026-12-03 19:21 ` Alison Schofield
0 siblings, 1 reply; 2+ messages in thread
From: Unsung Lee @ 2026-11-21 10: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
add_cxl_resources() expands a CXL window over a conflicting resource
and then removes any following window that the expanded one contains,
or trims the start of one that it partly overlaps. pair_cxl_resource()
only sets cxlrd->res when a window still contains the whole HPA range
of the root decoder, so the root decoder of a removed or trimmed window
stays registered with cxlrd->res == NULL.
Region code uses cxlrd->res without a check. Writing a region size
under such a decoder passes NULL to alloc_free_mem_region() and oopses
with resource_lock held for write, which then stalls every other
resource tree user:
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]
kernfs_fop_write_iter+0x13f/0x1e0
Auto-assembly of a committed region under such a decoder would do the
same in __construct_region() and cxl_extended_linear_cache_resize().
Both the sysfs and the auto-assembly paths create the region with
__create_region(), so reject a root decoder without a window there,
next to the existing check for a dead root decoder.
This was hit with cxl_test in a QEMU guest whose 64-bit PCI window
overlaps the cxl_test mock windows: CXL Window 0 is expanded over
PCI Bus 0000:00 and swallows Window 1 and 2.
The problem was found, reproduced and the fix tested with an LLM coding
assistant driving the QEMU and cxl_test runs.
Fixes: 23a22cd1c98b ("cxl/region: Allocate HPA capacity to regions")
Signed-off-by: Unsung Lee <unsung0317@gmail.com>
---
Notes:
- How this patch was made: an LLM coding assistant found the problem
while running cxl_test in QEMU, analysed it, drafted the fix and this
changelog, and drove the reproduction and test runs below. I reviewed
the analysis and the fix against the code.
- Reproduced on v7.3.1, v7.4-rc3 and cxl/next (32af781935). With the
fix on cxl/next, all four root decoders without a window fail
create_pmem_region/create_ram_region with -ENXIO and the guest
stays up; the ndctl v85 cxl suite gives the same results as
without the fix, except cxl-poison.sh, which now fails instead of
oopsing the kernel.
- Only the alloc_hpa() path was reproduced. The auto-assembly path and
the case in the add_cxl_resources() comment (System RAM spanning two
windows, the second window trimmed) are from reading the code.
- With the trimmed window, its decoder now gets -ENXIO instead of
using the remaining tail of the window for dynamic regions, as that
comment suggests. That matches what pair_cxl_resource() already does
(no window, no cxlrd->res); making the tail usable would need the
decoder range to follow the trimmed window and is left alone here.
- An alternative is to warn in pair_cxl_resource() or not to register
such a root decoder at all. Rejecting in __create_region() is the
smallest change that covers every user of cxlrd->res.
drivers/cxl/core/region.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index 27e63e6da..a2cd18571 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -2792,7 +2792,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.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] cxl/region: Fail region creation for a root decoder without a CXL window
2026-11-21 10:57 [PATCH] cxl/region: Fail region creation for a root decoder without a CXL window Unsung Lee
@ 2026-12-03 19:21 ` Alison Schofield
0 siblings, 0 replies; 2+ messages in thread
From: Alison Schofield @ 2026-12-03 19:21 UTC (permalink / raw)
To: Unsung Lee
Cc: linux-cxl, linux-kernel, Davidlohr Bueso, Jonathan Cameron,
Dave Jiang, Vishal Verma, Dan Williams, Ira Weiny, Li Ming
On Sat, Nov 21, 2026 at 07:57:14PM +0900, Unsung Lee wrote:
Hi Unsung,
Thanks for the patch!
This is a good fix. __create_region() is the right place for the check
because it covers both sysfs region creation and auto-assembly.
> add_cxl_resources() expands a CXL window over a conflicting resource
> and then removes any following window that the expanded one contains,
> or trims the start of one that it partly overlaps.
Please replace this walkthrough with a short summary of the bug and the fix.
Two short paragraphs should do it.
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. Reject
region creation with -ENXIO before either creation path can use the missing
resource.
Then give the configuration context in a sentence or two. You reproduced the
oops with QEMU PCI MMIO overlapping the cxl_test windows. The same unpaired-
decoder state can arise when a firmware System RAM range starts inside one
CXL window and extends into the next. The firmware case and the auto-assembly
failure are from code inspection. Put the relevant /proc/iomem entries, QEMU
version and guest configuration, and ndctl results below the --- line.
more inline below ...
> .... pair_cxl_resource()
> only sets cxlrd->res when a window still contains the whole HPA range
> of the root decoder, so the root decoder of a removed or trimmed window
> stays registered with cxlrd->res == NULL.
>
> Region code uses cxlrd->res without a check. Writing a region size
> under such a decoder passes NULL to alloc_free_mem_region() and oopses
> with resource_lock held for write, which then stalls every other
> resource tree user:
>
> 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]
> kernfs_fop_write_iter+0x13f/0x1e0
>
> Auto-assembly of a committed region under such a decoder would do the
> same in __construct_region() and cxl_extended_linear_cache_resize().
>
> Both the sysfs and the auto-assembly paths create the region with
> __create_region(), so reject a root decoder without a window there,
> next to the existing check for a dead root decoder.
>
> This was hit with cxl_test in a QEMU guest whose 64-bit PCI window
> overlaps the cxl_test mock windows: CXL Window 0 is expanded over
> PCI Bus 0000:00 and swallows Window 1 and 2.
>
> The problem was found, reproduced and the fix tested with an LLM coding
> assistant driving the QEMU and cxl_test runs.
>
> Fixes: 23a22cd1c98b ("cxl/region: Allocate HPA capacity to regions")
> Signed-off-by: Unsung Lee <unsung0317@gmail.com>
> ---
> Notes:
>
> - How this patch was made: an LLM coding assistant found the problem
> while running cxl_test in QEMU, analysed it, drafted the fix and this
> changelog, and drove the reproduction and test runs below. I reviewed
> the analysis and the fix against the code.
> - Reproduced on v7.3.1, v7.4-rc3 and cxl/next (32af781935). With the
> fix on cxl/next, all four root decoders without a window fail
> create_pmem_region/create_ram_region with -ENXIO and the guest
> stays up; the ndctl v85 cxl suite gives the same results as
> without the fix, except cxl-poison.sh, which now fails instead of
> oopsing the kernel.
> - Only the alloc_hpa() path was reproduced. The auto-assembly path and
> the case in the add_cxl_resources() comment (System RAM spanning two
> windows, the second window trimmed) are from reading the code.
> - With the trimmed window, its decoder now gets -ENXIO instead of
> using the remaining tail of the window for dynamic regions, as that
> comment suggests. That matches what pair_cxl_resource() already does
> (no window, no cxlrd->res); making the tail usable would need the
> decoder range to follow the trimmed window and is left alone here.
> - An alternative is to warn in pair_cxl_resource() or not to register
> such a root decoder at all. Rejecting in __create_region() is the
> smallest change that covers every user of cxlrd->res.
>
> drivers/cxl/core/region.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
> index 27e63e6da..a2cd18571 100644
> --- a/drivers/cxl/core/region.c
> +++ b/drivers/cxl/core/region.c
> @@ -2792,7 +2792,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);
The kernel-doc says the trimmed tail is available for dynamic provisioning.
Is that still the intent? If the tail is intentionally unusable, please update
the kernel-doc to match.
Please add a dev_dbg() in pair_cxl_resource() when a root decoder is left unpaired.
Include the decoder name and HPA range.
Thanks,
Alison
>
> switch (mode) {
> --
> 2.43.0
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 19:21 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-21 10:57 [PATCH] cxl/region: Fail region creation for a root decoder without a CXL window Unsung Lee
2026-12-03 19:21 ` Alison Schofield
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®