Skip to contentSkip to conversation

test/cxl-region-sysfs.sh: test a repeat write of a region target

PATCH Applied Alison Schofield 2 participants 3 messages Oct 26 – Nov 19 libnvdimm: non-volatile memory device

lore
Share & tools
lore

Alison Schofield

author maintainer
#0 lore raw

PATCH v2 1/1 test/cxl-region-sysfs.sh: test a repeat write of a region target

A CXL driver fix making its way upstream[1], makes a repeat write of an endpoint decoder to the region targetN attribute that already holds it succeed without changing the region. Without the fix, that write fails, leaves the region half detached from the endpoint's ports, and a later write can crash the kernel.

Add a test case to backstop that fix. Write target0 twice on a partially populated region and check that the second write succeeds and leaves the region's decoders attached.

[1] https://lore.kernel.org/linux-cxl/920d80735a449f93a1f17a8bca4c25e4b302cb42.1792989098.git.alison.schofield@intel.com/

---

Changes since v1:
- Expect a repeat write to succeed, as the v2 kernel fix makes it a no-op

 test/cxl-region-sysfs.sh | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
test/cxl-region-sysfs.sh +13 -3
index db1a163efb30..cb5e6ba53e71 100644
@@ -87,9 +87,19 @@ do
 						     select(.mode == \"pmem\") | .decoder")
 done
 
-# attach all endpoint decoders to the region
-pos=0
-for i in ${endpoint[@]}
+# a repeat write of an attached endpoint decoder must succeed and leave
+# every decoder between it and the root attached
+echo "${endpoint[0]}" > "/sys/bus/cxl/devices/$region/target0"
+nr_attached=$(cat /sys/bus/cxl/devices/decoder*/region | grep -cx "$region")
+if ! echo "${endpoint[0]}" > "/sys/bus/cxl/devices/$region/target0"; then
+	err "$LINENO: repeat write of ${endpoint[0]} to target0 failed"
+fi
+nr=$(cat /sys/bus/cxl/devices/decoder*/region | grep -cx "$region")
+[ "$nr" -ne "$nr_attached" ] && err "$LINENO: $nr of $nr_attached decoders still attached"
+
+# attach the remaining endpoint decoders to the region
+pos=1
+for i in ${endpoint[@]:1}
 do
 	echo $i > /sys/bus/cxl/devices/$region/target$pos
 	pos=$((pos+1))
Signature · 1 line
2.37.3
maintainer Reviewed-by on v2 1/1
#1 lore raw
Quoted 6 lines · Alison Schofield

A CXL driver fix making its way upstream[1], makes a repeat write of an endpoint decoder to the region targetN attribute that already holds it succeed without changing the region. Without the fix, that write fails, leaves the region half detached from the endpoint's ports, and a later write can crash the kernel.

Quoted 7 lines

Add a test case to backstop that fix. Write target0 twice on a partially populated region and check that the second write succeeds and leaves the region's decoders attached.

[1] https://lore.kernel.org/linux-cxl/920d80735a449f93a1f17a8bca4c25e4b302cb42.1792989098.git.alison.schofield@intel.com/

Quoted 36 lines

---

Changes since v1:
- Expect a repeat write to succeed, as the v2 kernel fix makes it a no-op

 test/cxl-region-sysfs.sh | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)
test/cxl-region-sysfs.sh +13 -3
index db1a163efb30..cb5e6ba53e71 100644
@@ -87,9 +87,19 @@ do
 						     select(.mode == \"pmem\") | .decoder")
 done
 
-# attach all endpoint decoders to the region
-pos=0
-for i in ${endpoint[@]}
+# a repeat write of an attached endpoint decoder must succeed and leave
+# every decoder between it and the root attached
+echo "${endpoint[0]}" > "/sys/bus/cxl/devices/$region/target0"
+nr_attached=$(cat /sys/bus/cxl/devices/decoder*/region | grep -cx "$region")
+if ! echo "${endpoint[0]}" > "/sys/bus/cxl/devices/$region/target0"; then
+	err "$LINENO: repeat write of ${endpoint[0]} to target0 failed"
+fi
+nr=$(cat /sys/bus/cxl/devices/decoder*/region | grep -cx "$region")
+[ "$nr" -ne "$nr_attached" ] && err "$LINENO: $nr of $nr_attached decoders still attached"
+
+# attach the remaining endpoint decoders to the region
+pos=1
+for i in ${endpoint[@]:1}
 do
 	echo $i > /sys/bus/cxl/devices/$region/target$pos
 	pos=$((pos+1))
author maintainer Applied
#2 lore raw
In reply to Alison Schofield
Quoted 6 lines · Alison Schofield

A CXL driver fix making its way upstream[1], makes a repeat write of an endpoint decoder to the region targetN attribute that already holds it succeed without changing the region. Without the fix, that write fails, leaves the region half detached from the endpoint's ports, and a later write can crash the kernel.

Quoted 8 lines

Add a test case to backstop that fix. Write target0 twice on a partially populated region and check that the second write succeeds and leaves the region's decoders attached.

[1] https://lore.kernel.org/linux-cxl/920d80735a449f93a1f17a8bca4c25e4b302cb42.1792989098.git.alison.schofield@intel.com/

---

Applied to pending for NDCTL v86
https://github.com/pmem/ndctl/commits/pending/