Skip to contentSkip to conversation

cxl: Add tests for extended linear cache support

PATCH Applied Dave Jiang 2 participants 12 messages Oct 31, 2025 – Nov 16, 2025

Subsystems (2)

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore

Dave Jiang

author maintainer
#0 lore raw

cover cxl: Add tests for extended linear cache support

The series adds unit tests to verify the kernel support for extended linear cache (ELC). Added a test to check if the ELC region is setup correctly, and another test to go through the poison handling flow via the poison injection testing.

Dave Jiang (5):
cxl/test: Add test for extended linear cache support cxl/test: Fix cxl-poison.sh to detect the correct elc sysfs attrib cxl/test: Move cxl-poison.sh to use cxl_test auto region cxl/test: Move common part of poison unit test to common file cxl/test: Add support for poison test for ELC

 test/common-poison     | 202 ++++++++++++++++++++++++++++++++++++++++
 test/cxl-elc.sh        |  89 ++++++++++++++++++
 test/cxl-poison-elc.sh |  41 +++++++++
 test/cxl-poison.sh     | 203 +----------------------------------------
 test/meson.build       |   4 +
 5 files changed, 338 insertions(+), 201 deletions(-)
 create mode 100644 test/common-poison
 create mode 100755 test/cxl-elc.sh
 create mode 100755 test/cxl-poison-elc.sh

base-commit: 01c90830d65b6b331986f5996dcf6ad73c1579f4

Signature · 1 line
2.51.0
author maintainer
#1 lore raw

PATCH 1/5 cxl/test: Add test for extended linear cache support

Add a unit test that verifies the extended linear cache setup paths in the kernel driver. cxl_test provides a mock'd version. The test verifies the sysfs attribute that indicates extended linear cache support is correctly reported. It also verifies the sizing and offset of the regions and decoders.

The expecation is that CFMWS covers the entire extended linear cache region. The first part is DRAM and second part is CXL memory in a 1:1 setup. The start base for hardware decoders should be offsetted by the DRAM size.

---
 test/cxl-elc.sh  | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
 test/meson.build |  2 ++
 2 files changed, 91 insertions(+)
 create mode 100755 test/cxl-elc.sh
test/cxl-elc.sh new file +89 -0
new file mode 100755
index 000000000000..632e859c21f3
@@ -0,0 +1,89 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2025 Intel Corporation. All rights reserved.
+
+. "$(dirname "$0")"/common
+
+rc=77
+
+set -ex
+[ -d "/sys/kernel/tracing" ] || do_skip "test requires CONFIG_TRACING"
+
+trap 'err $LINENO' ERR
+
+check_prereq "jq"
+
+modprobe -r cxl_test
+modprobe cxl_test extended_linear_cache=1
+
+rc=1
+
+find_region()
+{
+	json="$($CXL list -b cxl_test -R)"
+	region=$(echo "$json" | jq -r '.[] | select(has("extended_linear_cache_size") and .extended_linear_cache_size != null) | .region')
+	[[ -n "$region" && "$region" != "null" ]] || do_skip "no test extended linear cache region found"
+}
+
+retrieve_info()
+{
+	# Root decoder name
+	cxlrd="$($CXL list -r$region -D | jq -r '.[] | select(has("root decoders")) | ."root decoders"[0].decoder')"
+	# Root decoder (CFMWS) window size
+	cxlrd_size="$($CXL list -b cxl_test -d $cxlrd | jq '.[0]."decoders:root0"[0].size')"
+	# Root decoder (CFMWS) window address base
+	cxlrd_hpa="$($CXL list -b cxl_test -r $region | jq '.[0]."regions:root0"[0].resource')"
+
+	# Region size
+	region_size="$($CXL list -b cxl_test -r $region | jq '.[0]."regions:root0"[0].size')"
+
+	# switch port 0 size
+	swp0_size="$($CXL list -r $region -D | jq '.[] | select(has("port decoders")) | ."port decoders"[0] | .size')"
+	# switch port 0 base address
+	swp0_hpa="$($CXL list -r $region -D | jq '.[] | select(has("port decoders")) | ."port decoders"[0] | .resource')"
+
+	# switch port 1 size
+	swp1_size="$($CXL list -r $region -D | jq '.[] | select(has("port decoders")) | ."port decoders"[1] | .size')"
+	# switch port 1 base address
+	swp1_hpa="$($CXL list -r $region -D | jq '.[] | select(has("port decoders")) | ."port decoders"[1] | .resource')"
+
+	# endpoint port 0 size
+	ep0_size="$($CXL list -r $region -D | jq '.[] | select(has("endpoint decoders")) | ."endpoint decoders"[0] | .size')"
+	# endpoint port 0 base address
+	ep0_hpa="$($CXL list -r $region -D | jq '.[] | select(has("endpoint decoders")) | ."endpoint decoders"[0] | .resource')"
+
+	# endpoint port 1 size
+	ep1_size="$($CXL list -r $region -D | jq '.[] | select(has("endpoint decoders")) | ."endpoint decoders"[1] | .size')"
+	# endpoint port 1 base address
+	ep1_hpa="$($CXL list -r $region -D | jq '.[] | select(has("endpoint decoders")) | ."endpoint decoders"[1] | .resource')"
+}
+
+compare_sizes()
+{
+	# The CXL region size should equal to the CFMWS size.
+	# It should be DRAM+CXL size combined
+	((cxlrd_size == region_size)) || err "$LINENO"
+
+	# The switch decoder size should be half of CFMWS size.
+	((cxlrd_size == swp0_size * 2)) || err "$LINENO"
+	((cxlrd_size == swp1_size * 2)) || err "$LINENO"
+
+	# The endpoint decoder size should be half of CFMWS size
+	((cxlrd_size == ep0_size * 2)) || err "$LINENO"
+	((cxlrd_size == ep1_size * 2)) || err "$LINENO"
+}
+
+# The extended linear cache is expected to be DRAM:CXL of 1:1 size
+# The CXL region occupies the second half of the CFMWS
+compare_bases()
+{
+	((cxlrd_hpa == swp0_hpa - swp0_size)) || err "$LINENO"
+	((cxlrd_hpa == swp1_hpa - swp1_size)) || err "$LINENO"
+
+	((cxlrd_hpa == ep0_hpa - ep0_size)) || err "$LINENO"
+	((cxlrd_hpa == ep1_hpa - ep1_size)) || err "$LINENO"
+}
+
+retrieve_info
+compare_sizes
+compare_bases
test/meson.build +2 -0
index 615376ea635a..710a15850e2b 100644
@@ -167,6 +167,7 @@ cxl_events = find_program('cxl-events.sh')
 cxl_sanitize = find_program('cxl-sanitize.sh')
 cxl_destroy_region = find_program('cxl-destroy-region.sh')
 cxl_qos_class = find_program('cxl-qos-class.sh')
+cxl_elc = find_program('cxl-elc.sh')
 
 tests = [
   [ 'libndctl',               libndctl,		  'ndctl' ],
@@ -199,6 +200,7 @@ tests = [
   [ 'cxl-sanitize.sh',        cxl_sanitize,       'cxl'   ],
   [ 'cxl-destroy-region.sh',  cxl_destroy_region, 'cxl'   ],
   [ 'cxl-qos-class.sh',       cxl_qos_class,      'cxl'   ],
+  [ 'cxl-elc.sh',             cxl_elc,            'cxl'   ],
 ]
 
 if get_option('destructive').enabled()
Signature · 1 line
2.51.0
maintainer
#2 lore raw

Re: [NDCTL PATCH 1/5] cxl/test: Add test for extended linear cache support

Quoted 31 lines · Dave Jiang

Add a unit test that verifies the extended linear cache setup paths in the kernel driver. cxl_test provides a mock'd version. The test verifies the sysfs attribute that indicates extended linear cache support is correctly reported. It also verifies the sizing and offset of the regions and decoders.

The expecation is that CFMWS covers the entire extended linear cache region. The first part is DRAM and second part is CXL memory in a 1:1 setup. The start base for hardware decoders should be offsetted by the DRAM size.

---
 test/cxl-elc.sh  | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
 test/meson.build |  2 ++
 2 files changed, 91 insertions(+)
 create mode 100755 test/cxl-elc.sh
test/cxl-elc.sh new file +7 -0
new file mode 100755
index 000000000000..632e859c21f3
@@ -0,0 +1,89 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2025 Intel Corporation. All rights reserved.
+
+. "$(dirname "$0")"/common
+
+rc=77

test/cxl-elc.sh line 17

Quoted 10 lines
test/cxl-elc.sh new file +10 -0
+
+set -ex
+[ -d "/sys/kernel/tracing" ] || do_skip "test requires CONFIG_TRACING"
+
+trap 'err $LINENO' ERR
+
+check_prereq "jq"
+
+modprobe -r cxl_test
+modprobe cxl_test extended_linear_cache=1

With 6.18, this reports a false pass when it should skip. Make sure that param exist w something like this:

modprobe cxl_test extended_linear_cache=1
[ -f /sys/module/cxl_test/parameters/extended_linear_cache ] || \
do_skip "extended_linear_cache cxl_test param not available"

snip

test/cxl-elc.sh line 89

Quoted 3 lines
test/cxl-elc.sh new file +3 -0
+retrieve_info
+compare_sizes
+compare_bases

check_dmesg and remove module before exit.

Please fixup the shellcheck complaints about needing double quotes.

snip to end

maintainer
#3 lore raw

Re: [NDCTL PATCH 1/5] cxl/test: Add test for extended linear cache support

In reply to Dave Jiang
Quoted 17 lines · Dave Jiang

Add a unit test that verifies the extended linear cache setup paths in the kernel driver. cxl_test provides a mock'd version. The test verifies the sysfs attribute that indicates extended linear cache support is correctly reported. It also verifies the sizing and offset of the regions and decoders.

The expecation is that CFMWS covers the entire extended linear cache region. The first part is DRAM and second part is CXL memory in a 1:1 setup. The start base for hardware decoders should be offsetted by the DRAM size.

---
 test/cxl-elc.sh  | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
 test/meson.build |  2 ++
 2 files changed, 91 insertions(+)
 create mode 100755 test/cxl-elc.sh

snip

Quoted 1 line

The call to this:

test/cxl-elc.sh line 27

Quoted 7 lines
test/cxl-elc.sh new file +7 -0
+find_region()
+{
+	json="$($CXL list -b cxl_test -R)"
+	region=$(echo "$json" | jq -r '.[] | select(has("extended_linear_cache_size") and .extended_linear_cache_size != null) | .region')
+	[[ -n "$region" && "$region" != "null" ]] || do_skip "no test extended linear cache region found"
+}
+

is missing from here. Just found while testing w patches supporting the parameter. So you can fix this and ignore my review comment about looking up the parameter.

Quoted 3 lines
test/cxl-elc.sh new file +3 -0
+retrieve_info
+compare_sizes
+compare_bases
maintainer
#4 lore raw

Re: [NDCTL PATCH 1/5] cxl/test: Add test for extended linear cache support

Quoted 24 lines · Alison Schofield
Quoted 17 lines · Dave Jiang

Add a unit test that verifies the extended linear cache setup paths in the kernel driver. cxl_test provides a mock'd version. The test verifies the sysfs attribute that indicates extended linear cache support is correctly reported. It also verifies the sizing and offset of the regions and decoders.

The expecation is that CFMWS covers the entire extended linear cache region. The first part is DRAM and second part is CXL memory in a 1:1 setup. The start base for hardware decoders should be offsetted by the DRAM size.

---
 test/cxl-elc.sh  | 89 ++++++++++++++++++++++++++++++++++++++++++++++++
 test/meson.build |  2 ++
 2 files changed, 91 insertions(+)
 create mode 100755 test/cxl-elc.sh

snip

Quoted 1 line

The call to this:

Quoted 11 lines

test/cxl-elc.sh line 27

Quoted 7 lines
test/cxl-elc.sh new file +7 -0
+find_region()
+{
+	json="$($CXL list -b cxl_test -R)"
+	region=$(echo "$json" | jq -r '.[] | select(has("extended_linear_cache_size") and .extended_linear_cache_size != null) | .region')
+	[[ -n "$region" && "$region" != "null" ]] || do_skip "no test extended linear cache region found"
+}
+

is missing from here. Just found while testing w patches supporting the parameter. So you can fix this and ignore my review comment about looking up the parameter.

I got that wrong, we do need both checks:
Skip if the param is missing
Fail if the ELC region is not found since that signals cxl-test breakage

Quoted 7 lines
Quoted 4 lines
test/cxl-elc.sh new file +3 -0
+retrieve_info
+compare_sizes
+compare_bases
author maintainer
#5 lore raw

PATCH 2/5 cxl/test: Fix cxl-poison.sh to detect the correct elc sysfs attrib

In reply to Dave Jiang

The cxl-poison.sh script attempts to read the extended linear cache size sysfs attribute but is using the incorrect attribute name.

---
 test/cxl-poison.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
test/cxl-poison.sh +2 -2
index 231a0733f096..8e81baceeb24 100644
@@ -197,8 +197,8 @@ test_poison_by_region_offset_negative()
 
 	# This case is a no-op until cxl-test ELC mocking arrives
 	# Try to get cache_size if the attribute exists
-	if [ -f "/sys/bus/cxl/devices/$region/cache_size" ]; then
-		cache_size=$(cat /sys/bus/cxl/devices/"$region"/cache_size)
+	if [ -f "/sys/bus/cxl/devices/$region/extended_linear_cache_size" ]; then
+		cache_size=$(cat /sys/bus/cxl/devices/"$region"/extended_linear_cache_size)
 	fi
 
 	# Offset within extended linear cache (if cache_size > 0)
Signature · 1 line
2.51.0
maintainer Applied
#6 lore raw

Re: [NDCTL PATCH 2/5] cxl/test: Fix cxl-poison.sh to detect the correct elc sysfs attrib

Quoted 4 lines · Dave Jiang

The cxl-poison.sh script attempts to read the extended linear cache size sysfs attribute but is using the incorrect attribute name.

Reviewed, tested and updated to the no-op comment
[ alisons: update the no-op attribute comment ]

Applied: https://github.com/pmem/ndctl/commits/pending

Thanks!

Quoted 22 lines
---
 test/cxl-poison.sh | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
test/cxl-poison.sh +2 -2
index 231a0733f096..8e81baceeb24 100644
@@ -197,8 +197,8 @@ test_poison_by_region_offset_negative()
 
 	# This case is a no-op until cxl-test ELC mocking arrives
 	# Try to get cache_size if the attribute exists
-	if [ -f "/sys/bus/cxl/devices/$region/cache_size" ]; then
-		cache_size=$(cat /sys/bus/cxl/devices/"$region"/cache_size)
+	if [ -f "/sys/bus/cxl/devices/$region/extended_linear_cache_size" ]; then
+		cache_size=$(cat /sys/bus/cxl/devices/"$region"/extended_linear_cache_size)
 	fi
 
 	# Offset within extended linear cache (if cache_size > 0)
Signature · 1 line
2.51.0
author maintainer
#7 lore raw

PATCH 3/5 cxl/test: Move cxl-poison.sh to use cxl_test auto region

In reply to Dave Jiang

Move cxl-poison.sh to use the cxl_test auto region instead of manually create an additional region. This is in preparation to allow utilize the existing poison unit tests to also test the extended linear cache region.

The offset has been changed due to the auto region starts at 0 and pmem region starts at 0x40000000. The original test was creating a pmem region. It makes no difference what type of region is being used for testing.

---
 test/cxl-poison.sh | 38 ++++++++++++--------------------------
 1 file changed, 12 insertions(+), 26 deletions(-)
test/cxl-poison.sh +12 -26
index 8e81baceeb24..430780cf7128 100644
@@ -35,28 +35,14 @@ find_memdev()
 	memdev=${capable_mems[0]}
 }
 
-create_x2_region()
+find_auto_region()
 {
-	# Find an x2 decoder
-	decoder="$($CXL list -b "$CXL_TEST_BUS" -D -d root | jq -r ".[] |
-		select(.pmem_capable == true) |
-		select(.nr_targets == 2) |
-		.decoder")"
-
-	# Find a memdev for each host-bridge interleave position
-	port_dev0="$($CXL list -T -d "$decoder" | jq -r ".[] |
-		.targets | .[] | select(.position == 0) | .target")"
-	port_dev1="$($CXL list -T -d "$decoder" | jq -r ".[] |
-		.targets | .[] | select(.position == 1) | .target")"
-	mem0="$($CXL list -M -p "$port_dev0" | jq -r ".[0].memdev")"
-	mem1="$($CXL list -M -p "$port_dev1" | jq -r ".[0].memdev")"
-
-	region="$($CXL create-region -d "$decoder" -m "$mem0" "$mem1" |
-		jq -r ".region")"
-	if [[ ! $region ]]; then
-		echo "create-region failed for $decoder"
-		err "$LINENO"
-	fi
+	region="$($CXL list -b "$CXL_TEST_BUS" -R | jq -r ".[0].region")"
+	[[ -n "$region" && "$region" != "null" ]] || do_skip "no test region found"
+	mem0="$($CXL list -r "$region" --targets | jq -r ".[0].mappings[0].memdev")"
+	[[ -n "$mem0" && "$mem0" != "null" ]] || do_skip "no region target0 found"
+	mem1="$($CXL list -r "$region" --targets | jq -r ".[0].mappings[1].memdev")"
+	[[ -n "$mem1" && "$mem1" != "null" ]] || do_skip "no region target1 found"
 	echo "$region"
 }
 
@@ -153,12 +139,12 @@ test_poison_by_memdev_by_dpa()
 
 test_poison_by_region_by_dpa()
 {
-	inject_poison_sysfs "$mem0" "0x40000000"
-	inject_poison_sysfs "$mem1" "0x40000000"
+	inject_poison_sysfs "$mem0" "0"
+	inject_poison_sysfs "$mem1" "0"
 	validate_poison_found "-r $region" 2
 
-	clear_poison_sysfs "$mem0" "0x40000000"
-	clear_poison_sysfs "$mem1" "0x40000000"
+	clear_poison_sysfs "$mem0" "0"
+	clear_poison_sysfs "$mem1" "0"
 	validate_poison_found "-r $region" 0
 }
 
@@ -228,7 +214,7 @@ echo 1 > /sys/kernel/tracing/events/cxl/cxl_poison/enable
 echo 1 > /sys/kernel/tracing/tracing_on
 
 test_poison_by_memdev_by_dpa
-create_x2_region
+find_auto_region
 test_poison_by_region_by_dpa
 [ -f "/sys/kernel/debug/cxl/$region/inject_poison" ] ||
        do_skip "test cases requires inject by region kernel support"
Signature · 1 line
2.51.0
maintainer
#8 lore raw

Re: [NDCTL PATCH 3/5] cxl/test: Move cxl-poison.sh to use cxl_test auto region

Quoted 9 lines · Dave Jiang

Move cxl-poison.sh to use the cxl_test auto region instead of manually create an additional region. This is in preparation to allow utilize the existing poison unit tests to also test the extended linear cache region.

The offset has been changed due to the auto region starts at 0 and pmem region starts at 0x40000000. The original test was creating a pmem region. It makes no difference what type of region is being used for testing.

Reviewed, tested, and applied: https://github.com/pmem/ndctl/commits/pending

Thanks!

author maintainer
#9 lore raw

PATCH 4/5 cxl/test: Move common part of poison unit test to common file

In reply to Dave Jiang

To allow extended linear cache to also utilize the poison test, move the common helper functions to a common file for sourcing.

---
 test/common-poison | 190 +++++++++++++++++++++++++++++++++++++++++++++
 test/cxl-poison.sh | 187 +-------------------------------------------
 2 files changed, 191 insertions(+), 186 deletions(-)
 create mode 100644 test/common-poison
test/common-poison new file +190 -0
new file mode 100644
index 000000000000..15a091e41dc3
@@ -0,0 +1,190 @@
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (C) 2025 Intel Corporation. All rights reserved.
+
+find_memdev()
+{
+	readarray -t capable_mems < <("$CXL" list -b "$CXL_TEST_BUS" -M |
+		jq -r ".[] | select(.pmem_size != null) |
+		select(.ram_size != null) | .memdev")
+
+	if [ ${#capable_mems[@]} == 0 ]; then
+		echo "no memdevs found for test"
+		err "$LINENO"
+	fi
+
+	memdev=${capable_mems[0]}
+}
+
+find_auto_region()
+{
+	region="$($CXL list -b "$CXL_TEST_BUS" -R | jq -r ".[0].region")"
+	[[ -n "$region" && "$region" != "null" ]] || do_skip "no test region found"
+	mem0="$($CXL list -r "$region" --targets | jq -r ".[0].mappings[0].memdev")"
+	[[ -n "$mem0" && "$mem0" != "null" ]] || do_skip "no region target0 found"
+	mem1="$($CXL list -r "$region" --targets | jq -r ".[0].mappings[1].memdev")"
+	[[ -n "$mem1" && "$mem1" != "null" ]] || do_skip "no region target1 found"
+	echo "$region"
+}
+
+# When cxl-cli support for inject and clear arrives, replace
+# the writes to /sys/kernel/debug with the new cxl commands.
+
+_do_poison_sysfs()
+{
+	local action="$1" dev="$2" addr="$3"
+	local expect_fail=${4:-false}
+
+	if "$expect_fail"; then
+		if echo "$addr" > "/sys/kernel/debug/cxl/$dev/${action}_poison"; then
+			echo "Expected ${action}_poison to fail for $addr"
+			err "$LINENO"
+		fi
+	else
+		echo "$addr" > "/sys/kernel/debug/cxl/$dev/${action}_poison"
+	fi
+}
+
+inject_poison_sysfs()
+{
+	_do_poison_sysfs 'inject' "$@"
+}
+
+clear_poison_sysfs()
+{
+	_do_poison_sysfs 'clear' "$@"
+}
+
+check_trace_entry()
+{
+	local expected_region="$1"
+	local expected_hpa="$2"
+
+	local trace_line
+	trace_line=$(grep "cxl_poison" /sys/kernel/tracing/trace | tail -n 1)
+	if [[ -z "$trace_line" ]]; then
+		echo "No cxl_poison trace event found"
+		err "$LINENO"
+	fi
+
+	local trace_region trace_hpa
+	trace_region=$(echo "$trace_line" | grep -o 'region=[^ ]*' | cut -d= -f2)
+	trace_hpa=$(echo "$trace_line" | grep -o 'hpa=0x[0-9a-fA-F]\+' | cut -d= -f2)
+
+	if [[ "$trace_region" != "$expected_region" ]]; then
+		echo "Expected region $expected_region not found in trace"
+		echo "$trace_line"
+		err "$LINENO"
+	fi
+
+	if [[ "$trace_hpa" != "$expected_hpa" ]]; then
+		echo "Expected HPA $expected_hpa not found in trace"
+		echo "$trace_line"
+		err "$LINENO"
+	fi
+}
+
+validate_poison_found()
+{
+	list_by="$1"
+	nr_expect="$2"
+
+	poison_list="$($CXL list "$list_by" --media-errors |
+		jq -r '.[].media_errors')"
+	if [[ ! $poison_list ]]; then
+		nr_found=0
+	else
+		nr_found=$(jq "length" <<< "$poison_list")
+	fi
+	if [ "$nr_found" -ne "$nr_expect" ]; then
+		echo "$nr_expect poison records expected, $nr_found found"
+		err "$LINENO"
+	fi
+}
+
+test_poison_by_memdev_by_dpa()
+{
+	find_memdev
+	inject_poison_sysfs "$memdev" "0x40000000"
+	inject_poison_sysfs "$memdev" "0x40001000"
+	inject_poison_sysfs "$memdev" "0x600"
+	inject_poison_sysfs "$memdev" "0x0"
+	validate_poison_found "-m $memdev" 4
+
+	clear_poison_sysfs "$memdev" "0x40000000"
+	clear_poison_sysfs "$memdev" "0x40001000"
+	clear_poison_sysfs "$memdev" "0x600"
+	clear_poison_sysfs "$memdev" "0x0"
+	validate_poison_found "-m $memdev" 0
+}
+
+test_poison_by_region_by_dpa()
+{
+	inject_poison_sysfs "$mem0" "0"
+	inject_poison_sysfs "$mem1" "0"
+	validate_poison_found "-r $region" 2
+
+	clear_poison_sysfs "$mem0" "0"
+	clear_poison_sysfs "$mem1" "0"
+	validate_poison_found "-r $region" 0
+}
+
+test_poison_by_region_offset()
+{
+	local base gran hpa1 hpa2
+	base=$(cat /sys/bus/cxl/devices/"$region"/resource)
+	gran=$(cat /sys/bus/cxl/devices/"$region"/interleave_granularity)
+
+	# Test two HPA addresses: base and base + granularity
+	# This hits the two memdevs in the region interleave.
+	hpa1=$(printf "0x%x" $((base)))
+	hpa2=$(printf "0x%x" $((base + gran)))
+
+	# Inject at the offset and check result using the hpa
+	# ABI takes an offset, but recall the hpa to check trace event
+
+	inject_poison_sysfs "$region" 0
+	check_trace_entry "$region" "$hpa1"
+	inject_poison_sysfs "$region" "$gran"
+	check_trace_entry "$region" "$hpa2"
+	validate_poison_found "-r $region" 2
+
+	clear_poison_sysfs "$region" 0
+	check_trace_entry "$region" "$hpa1"
+	clear_poison_sysfs "$region" "$gran"
+	check_trace_entry "$region" "$hpa2"
+	validate_poison_found "-r $region" 0
+}
+
+test_poison_by_region_offset_negative()
+{
+	local region_size cache_size cache_offset exceed_offset large_offset
+	region_size=$(cat /sys/bus/cxl/devices/"$region"/size)
+	cache_size=0
+
+	# This case is a no-op until cxl-test ELC mocking arrives
+	# Try to get cache_size if the attribute exists
+	if [ -f "/sys/bus/cxl/devices/$region/extended_linear_cache_size" ]; then
+		cache_size=$(cat /sys/bus/cxl/devices/"$region"/extended_linear_cache_size)
+	fi
+
+	# Offset within extended linear cache (if cache_size > 0)
+	if [[ $cache_size -gt 0 ]]; then
+		cache_offset=$((cache_size - 1))
+		echo "Testing offset within cache: $cache_offset (cache_size: $cache_size)"
+		inject_poison_sysfs "$region" "$cache_offset" true
+		clear_poison_sysfs "$region" "$cache_offset" true
+	else
+		echo "Skipping cache test - cache_size is 0"
+	fi
+
+	# Offset exceeds region size
+	exceed_offset=$((region_size))
+	inject_poison_sysfs "$region" "$exceed_offset" true
+	clear_poison_sysfs "$region" "$exceed_offset" true
+
+	# Offset exceeds region size by a lot
+	large_offset=$((region_size * 2))
+	inject_poison_sysfs "$region" "$large_offset" true
+	clear_poison_sysfs "$region" "$large_offset" true
+}
+
test/cxl-poison.sh +1 -186

193 lines not on this page · raw message

Signature · 1 line
2.51.0
author maintainer
#10 lore raw

PATCH 5/5 cxl/test: Add support for poison test for ELC

In reply to Dave Jiang

Add a unit test for extended linear cache (ELC) poison handling testing. The common code needs to be adjusted in order to handle the offset created by ELC. The caculations are not impacted for normal region testing since ELC size would be 0.

---
 test/common-poison     | 22 +++++++++++++++++-----
 test/cxl-poison-elc.sh | 41 +++++++++++++++++++++++++++++++++++++++++
 test/meson.build       |  2 ++
 3 files changed, 60 insertions(+), 5 deletions(-)
 create mode 100755 test/cxl-poison-elc.sh
test/common-poison +17 -5
index 15a091e41dc3..3926e2fef4c4 100644
@@ -130,9 +130,21 @@ test_poison_by_region_by_dpa()
 
 test_poison_by_region_offset()
 {
-	local base gran hpa1 hpa2
+	local base gran hpa1 hpa2 cache_size cache_offset
 	base=$(cat /sys/bus/cxl/devices/"$region"/resource)
 	gran=$(cat /sys/bus/cxl/devices/"$region"/interleave_granularity)
+	cache_size=0
+
+	# This case is a no-op until cxl-test ELC mocking arrives
+	# Try to get cache_size if the attribute exists
+	if [ -f "/sys/bus/cxl/devices/$region/extended_linear_cache_size" ]; then
+		cache_size=$(cat /sys/bus/cxl/devices/"$region"/extended_linear_cache_size)
+	fi
+
+	# Offset within extended linear cache (if cache_size > 0)
+	if [[ $cache_size -gt 0 ]]; then
+		base=$((base + cache_size))
+	fi
 
 	# Test two HPA addresses: base and base + granularity
 	# This hits the two memdevs in the region interleave.
@@ -142,15 +154,15 @@ test_poison_by_region_offset()
 	# Inject at the offset and check result using the hpa
 	# ABI takes an offset, but recall the hpa to check trace event
 
-	inject_poison_sysfs "$region" 0
+	inject_poison_sysfs "$region" $cache_size
 	check_trace_entry "$region" "$hpa1"
-	inject_poison_sysfs "$region" "$gran"
+	inject_poison_sysfs "$region" "$((gran + cache_size))"
 	check_trace_entry "$region" "$hpa2"
 	validate_poison_found "-r $region" 2
 
-	clear_poison_sysfs "$region" 0
+	clear_poison_sysfs "$region" $cache_size
 	check_trace_entry "$region" "$hpa1"
-	clear_poison_sysfs "$region" "$gran"
+	clear_poison_sysfs "$region" "$((gran + cache_size))"
 	check_trace_entry "$region" "$hpa2"
 	validate_poison_found "-r $region" 0
 }
test/cxl-poison-elc.sh new file +41 -0

41 lines not on this page · raw message

test/meson.build +2 -0
index 710a15850e2b..248917fd1edd 100644
@@ -255,8 +255,10 @@ endif
 
 if get_option('libtracefs').enabled()
   cxl_poison = find_program('cxl-poison.sh')
+  cxl_poison_elc = find_program('cxl-poison-elc.sh')
   tests += [
     [ 'cxl-poison.sh', cxl_poison, 'cxl' ],
+    [ 'cxl-poison-elc.sh', cxl_poison_elc, 'cxl' ],
   ]
 endif
 
Signature · 1 line
2.51.0
maintainer
#11 lore raw
In reply to Dave Jiang
Quoted 10 lines · Dave Jiang

The series adds unit tests to verify the kernel support for extended linear cache (ELC). Added a test to check if the ELC region is setup correctly, and another test to go through the poison handling flow via the poison injection testing.

Dave Jiang (5):
cxl/test: Add test for extended linear cache support cxl/test: Fix cxl-poison.sh to detect the correct elc sysfs attrib cxl/test: Move cxl-poison.sh to use cxl_test auto region

The next 2 patches may add more complexity than is needed by splitting the work among a common file and 2 test scripts. Consider keeping the work in one file and wrapping the test execution in a 'run_poison_tests' function. Then call it that after each load of the module, like -

run_poison_tests
.
.
.
modprobe -r cxl_test
modprobe cxl_test
run_poison_tests
modprobe -r cxl_test

modprobe cxl_test extended_linear_cache=1
run_poison_tests
modprobe -r cxl_test

Quoted 18 lines

cxl/test: Move common part of poison unit test to common file cxl/test: Add support for poison test for ELC

 test/common-poison     | 202 ++++++++++++++++++++++++++++++++++++++++
 test/cxl-elc.sh        |  89 ++++++++++++++++++
 test/cxl-poison-elc.sh |  41 +++++++++
 test/cxl-poison.sh     | 203 +----------------------------------------
 test/meson.build       |   4 +
 5 files changed, 338 insertions(+), 201 deletions(-)
 create mode 100644 test/common-poison
 create mode 100755 test/cxl-elc.sh
 create mode 100755 test/cxl-poison-elc.sh

base-commit: 01c90830d65b6b331986f5996dcf6ad73c1579f4

Signature · 1 line
2.51.0