mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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>, Richard Cheng <icheng@nvidia.com>,
	Ben Cheatham <benjamin.cheatham@amd.com>,
	Unsung Lee <unsung0317@gmail.com>
Subject: [PATCH v2 1/2] cxl/region: Fail region creation for a root decoder without a CXL window
Date: Fri,  4 Dec 2026 22:57:53 +0900	[thread overview]
Message-ID: <20261204135754.639574-2-unsung0317@gmail.com> (raw)
In-Reply-To: <20261204135754.639574-1-unsung0317@gmail.com>

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


  reply	other threads:[~2026-12-04 13:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-04 13:57 [PATCH v2 0/2] cxl: " Unsung Lee
2026-12-04 13:57 ` Unsung Lee [this message]
2026-12-04 13:57 ` [PATCH v2 2/2] cxl/acpi: Correct the add_cxl_resources() kernel-doc on a trimmed window Unsung Lee

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=20261204135754.639574-2-unsung0317@gmail.com \
    --to=unsung0317@gmail.com \
    --cc=alison.schofield@intel.com \
    --cc=benjamin.cheatham@amd.com \
    --cc=dave.jiang@intel.com \
    --cc=dave@stgolabs.net \
    --cc=djbw@kernel.org \
    --cc=icheng@nvidia.com \
    --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®