mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: Unsung Lee <unsung0317@gmail.com>
Cc: <linux-cxl@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	"Davidlohr Bueso" <dave@stgolabs.net>,
	Jonathan Cameron <jic23@kernel.org>,
	Dave Jiang <dave.jiang@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: Re: [PATCH] cxl/region: Fail region creation for a root decoder without a CXL window
Date: Thu, 3 Dec 2026 11:21:08 -0800	[thread overview]
Message-ID: <axHBJLgBH3su4zs8@aschofie-mobl2.lan> (raw)
In-Reply-To: <20261121105714.1542859-1-unsung0317@gmail.com>

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
> 

      reply	other threads:[~2026-12-03 19:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-21 10:57 Unsung Lee
2026-12-03 19:21 ` Alison Schofield [this message]

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=axHBJLgBH3su4zs8@aschofie-mobl2.lan \
    --to=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=unsung0317@gmail.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®