mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] cxl/region: Fail region creation for a root decoder without a CXL window
@ 2026-11-21 10:57 Unsung Lee
  0 siblings, 0 replies; only message 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] only message in thread

only message in thread, other threads:[~2026-11-21 10:57 UTC | newest]

Thread overview: (only message) (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

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®