From: Richard Cheng <icheng@nvidia.com>
To: dave@stgolabs.net, jic23@kernel.org, dave.jiang@intel.com,
alison.schofield@intel.com, vishal.l.verma@intel.com
Cc: iweiny@kernel.org, ming.li@zohomail.com, icheng@nvidia.com,
gourry@gourry.net, rrichter@amd.com, alucerop@amd.com,
linux-cxl@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH] cxl/region: Fix target accounting when detaching direct EP
Date: Wed, 4 Nov 2026 17:28:40 +0800 [thread overview]
Message-ID: <20261104092840.56715-1-icheng@nvidia.com> (raw)
cxl_port_detach_region() avoids decrementing nr_targets if another
endpoint in the region has the same ep->next. However, for directly
attached endpoints, ep->next is NULL. Comparing these NULL pointers
incorrectly treats EPs on different downstream ports as sharing a
target. Removing one endpoint while another remains therefore leaves
nr_targets stale.
E.g. 2 direct EP using a 2-target switch decoder, clearing one region
targetN entry leaves nr_targets at 2 instead of 1. Refilling that entry
then attempts to add a 3rd target and fails with -ENXIO, even though the
requested config fits.
Decrement nr_targets when the removed endpoint has no next port,
regardless of whether another endpoint also has a NULL next pointer.
Signed-off-by: Richard Cheng <icheng@nvidia.com>
---
Tested using tools/testing/cxl in an isolated arm64 QEMU/KVM guest.
Configure an 8-way PMEM region across the 8 memdevs under the mock
two-target root decoder, reserving 256 MB per EP.
Run the following as root:
```
set -eu
sys=/sys/bus/cxl/devices
region=region3
r="$sys/$region"
decoder=$(cat "$r/target0")
test -n "$decoder"
test ! -L "$r/driver"
test "$(cat "$r/commit")" = 1
# Clear only target0, leaving the other targets populated.
printf '\n' > "$r/target0"
test -z "$(cat "$r/target0")"
test -z "$(cat "$sys/$decoder/region")"
test "$(cat "$r/commit")" = 0
# Restore the endpoint decoder to its original position.
printf '%s\n' "$decoder" > "$r/target0"
test "$(cat "$r/target0")" = "$decoder"
test "$(cat "$sys/$decoder/region")" = "$region"
# The restored region should be committable again.
printf '1\n' > "$r/commit"
test "$(cat "$r/commit")" = 1
```
Before the fix, clearing target0 succeeds but restoring its decoder
fails with ENXIO. With dynamic debug enabled, the kernel reports:
... overflows targets: 2
With the fix, the clear, refill and recommit sequence succeeds.
Best regards,
Richard Cheng.
---
drivers/cxl/core/region.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/drivers/cxl/core/region.c b/drivers/cxl/core/region.c
index a048bd5c06cb..30686059ec7b 100644
--- a/drivers/cxl/core/region.c
+++ b/drivers/cxl/core/region.c
@@ -1344,7 +1344,8 @@ static void cxl_port_detach_region(struct cxl_port *port,
break;
}
}
- if (!found)
+ /* Endpoints with no next port do not share a target. */
+ if (!found || !ep->next)
cxl_rr->nr_targets--;
}
base-commit: 05441d697f7f9a927264f4058cbbc6a03dfcac9d
--
2.43.0
reply other threads:[~2026-11-04 9:28 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=20261104092840.56715-1-icheng@nvidia.com \
--to=icheng@nvidia.com \
--cc=alison.schofield@intel.com \
--cc=alucerop@amd.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=gourry@gourry.net \
--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=rrichter@amd.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®