From: Unsung Lee <unsung0317@gmail.com>
To: linux-cxl@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, Davidlohr Bueso <dave@stgolabs.net>,
Jonathan Cameron <jic23@kernel.org>,
Dave Jiang <dave.jiang@intel.com>,
Alison Schofield <alison.schofield@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Dan Williams <djbw@kernel.org>, Ira Weiny <iweiny@kernel.org>,
Li Ming <ming.li@zohomail.com>
Subject: [PATCH] cxl/region: Fail region creation for a root decoder without a CXL window
Date: Sat, 21 Nov 2026 19:57:14 +0900 [thread overview]
Message-ID: <20261121105714.1542859-1-unsung0317@gmail.com> (raw)
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
reply other threads:[~2026-11-21 10:57 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261121105714.1542859-1-unsung0317@gmail.com \
--to=unsung0317@gmail.com \
--cc=alison.schofield@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=djbw@kernel.org \
--cc=iweiny@kernel.org \
--cc=jic23@kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=ming.li@zohomail.com \
--cc=vishal.l.verma@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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®