public inbox for nvdimm@lists.linux.dev
 help / color / mirror / Atom feed
From: Alison Schofield <alison.schofield@intel.com>
To: nvdimm@lists.linux.dev
Cc: Alison Schofield <alison.schofield@intel.com>, linux-cxl@vger.kernel.org
Subject: [ndctl PATCH] test/cxl-topology.sh: test switch port target
Date: Wed,  7 Jan 2026 21:25:48 -0800	[thread overview]
Message-ID: <20260108052552.395896-1-alison.schofield@intel.com> (raw)

Add a test case to validate that all switch port decoders sharing
downstream ports, dports, have target lists properly enumerated.

This test catches the regression fixed by a recent kernel patch[1]
where only one decoder per switch port has targets populated while
others have nr_targets=0, even when dports are available.

This test is based on the current cxl_test topology which provides
multiple switch ports with 8 decoders each. Like other testcases in
cxl-topology.sh, if the cxl_test topology changes (number of switches,
decoders per port, or hierarchy), this test will need corresponding
updates.

This new case is quietly skipped with kernel version 6.18 where it
is known broken.

[1] https://lore.kernel.org/linux-cxl/20260107100356.389490-1-rrichter@amd.com/

Signed-off-by: Alison Schofield <alison.schofield@intel.com>
---

 test/common          | 12 +++++++++++
 test/cxl-topology.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)

diff --git a/test/common b/test/common
index 2d076402ef7c..2eb11b7396d0 100644
--- a/test/common
+++ b/test/common
@@ -101,6 +101,18 @@ check_min_kver()
 	[[ "$ver" == "$(echo -e "$ver\n$KVER" | sort -V | head -1)" ]]
 }
 
+# check_eq_kver
+# $1: Kernel version to match. format: X.Y
+#
+check_eq_kver()
+{
+        local ver="$1"
+        : "${KVER:=$(uname -r)}"
+
+        [ -n "$ver" ] || return 1
+        [[ "$KVER" == "$ver"* ]]
+}
+
 # do_skip
 # $1: Skip message
 #
diff --git a/test/cxl-topology.sh b/test/cxl-topology.sh
index b68cb8b262b6..d9475b1bae9c 100644
--- a/test/cxl-topology.sh
+++ b/test/cxl-topology.sh
@@ -151,6 +151,57 @@ count=$(jq "map(select(.pmem_size == $pmem_size)) | length" <<< $json)
 ((bridges == 2 && count == 8 || bridges == 3 && count == 10 ||
   bridges == 4 && count == 11)) || err "$LINENO"
 
+# Test that switch port decoders have complete target list enumeration
+# Validates a fix for multiple decoders sharing the same dport.
+# Based on the cxl_test topology expectation of switch ports at depth 2
+# with 8 decoders each. Adjust if that expectation changes.
+test_switch_decoder_target_enumeration() {
+
+	# Get verbose output to see targets arrays
+	json=$($CXL list -b cxl_test -vvv)
+
+	switch_port_issues=$(jq '
+	# Find all switch ports (depth 2)
+	[.. | objects | select(.depth == 2 and has("decoders:" + .port))] |
+
+	# For each switch port, analyze its decoder target pattern
+	map({
+		port: .port,
+		nr_dports: .nr_dports,
+
+		# Count non-endpoint decoders (no "mode" field)
+		total: ([to_entries[] | select(.key | startswith("decoders:"))
+			| .value[] | select(has("mode") == false)] |
+			length),
+
+		# Count how many have targets
+		with_targets: ([to_entries[] | select(.key |
+			startswith("decoders:")) | .value[] |
+			select(has("mode") == false and .nr_targets > 0)] |
+			length),
+
+		# Count how many explicitly have no targets
+		without_targets: ([to_entries[] | select(.key |
+			startswith("decoders:")) | .value[] |
+			select(has("mode") == false and .nr_targets == 0)] |
+			length)
+		}) |
+
+		# Filter for the expected pattern and count them
+		map(select(.nr_dports > 0 and
+			   .with_targets == 1 and
+			   .without_targets >= 7)) |
+			   length
+	' <<<"$json")
+
+	((switch_port_issues == 0)) || {
+		echo "Found $switch_port_issues switch ports with incomplete target enumeration"
+		echo "Only 1 decoder has targets while 7+ have nr_targets=0"
+		err "$LINENO"
+	}
+}
+# Skip the target enumeration test where known broken
+check_eq_kver 6.18 || test_switch_decoder_target_enumeration
 
 # check that switch ports disappear after all of their memdevs have been
 # disabled, and return when the memdevs are enabled.
-- 
2.37.3


             reply	other threads:[~2026-01-08  5:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-08  5:25 Alison Schofield [this message]
2026-01-08 17:02 ` [ndctl PATCH] test/cxl-topology.sh: test switch port target Dave Jiang
2026-01-08 17:46   ` Alison Schofield
2026-01-08 17:56     ` Dave Jiang

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=20260108052552.395896-1-alison.schofield@intel.com \
    --to=alison.schofield@intel.com \
    --cc=linux-cxl@vger.kernel.org \
    --cc=nvdimm@lists.linux.dev \
    /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