* [PATCH] cxl/region: Fix target accounting when detaching direct EP
@ 2026-11-04 9:28 Richard Cheng
0 siblings, 0 replies; only message in thread
From: Richard Cheng @ 2026-11-04 9:28 UTC (permalink / raw)
To: dave, jic23, dave.jiang, alison.schofield, vishal.l.verma
Cc: iweiny, ming.li, icheng, gourry, rrichter, alucerop, linux-cxl,
linux-kernel
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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-04 9:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 9:28 [PATCH] cxl/region: Fix target accounting when detaching direct EP Richard Cheng
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®