public inbox for linux-cxl@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Jiang <dave.jiang@intel.com>
To: Alison Schofield <alison.schofield@intel.com>,
	nvdimm@lists.linux.dev, linux-cxl@vger.kernel.org
Subject: Re: [ndctl PATCH 2/2] test/cxl-region-replay.sh: add test of region replay workflow
Date: Thu, 16 Apr 2026 14:09:51 -0700	[thread overview]
Message-ID: <7da11db2-94aa-4b21-847e-5a9684ae9b06@intel.com> (raw)
In-Reply-To: <7ec630ea29675b57c052e9606b1d33177e989a2a.1773466514.git.alison.schofield@intel.com>



On 3/13/26 11:21 PM, Alison Schofield wrote:
> Add a CXL unit test that exercises the replay_regions() helpers
> introduced in test/common.
> 
> The test creates regions through the user interface, captures the
> resulting region configuration, performs a cxl_acpi driver unbind/bind
> cycle, and verifies that the regions reconstructed during enumeration
> match the original configuration.
> 
> This validates the decoder replay mechanism implemented in the kernel
> cxl_test module by replaying user-created regions as auto-discovered
> regions during driver initialization.
> 
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>

Reviewed-by: Dave Jiang <dave.jiang@intel.com>

> ---
>  test/cxl-region-replay.sh | 148 ++++++++++++++++++++++++++++++++++++++
>  test/meson.build          |   2 +
>  2 files changed, 150 insertions(+)
>  create mode 100644 test/cxl-region-replay.sh
> 
> diff --git a/test/cxl-region-replay.sh b/test/cxl-region-replay.sh
> new file mode 100644
> index 000000000000..3049ca9f34b5
> --- /dev/null
> +++ b/test/cxl-region-replay.sh
> @@ -0,0 +1,148 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0
> +# Copyright (C) 2022 Intel Corporation. All rights reserved.
> +
> +. $(dirname $0)/common
> +
> +rc=77
> +
> +set -ex
> +
> +trap 'err $LINENO' ERR
> +
> +check_prereq "jq"
> +
> +modprobe -r cxl_test
> +modprobe cxl_test
> +
> +# Replay support is exposed by cxl_acpi after cxl_test loads
> +if [ ! -e /sys/bus/platform/devices/cxl_acpi.0/decoder_reset_preserve_registry ]; then
> +	do_skip "test requires decoder registry replay support"
> +fi
> +
> +rc=1
> +
> +# Demonstrate and validate CXL region replay support in cxl_test.
> +#
> +# Replay helpers in test/common snapshot the current region topology,
> +# replay the configuration, and verify that the reconstructed regions
> +# match the original configuration.
> +#
> +# Tests should use the common helper:
> +#   replay_regions
> +#
> +# This test serves as both a sanity check for replay support and an
> +# example of how other cxl_test unit tests can use replay_regions().
> +
> +destroy_regions() {
> +	$CXL destroy-region -f -b cxl_test all
> +}
> +
> +create_region() {
> +	region=$($CXL create-region -d "$decoder" -m "$memdevs" |
> +		jq -r ".region")
> +
> +	if [[ ! $region ]]; then
> +		echo "create-region failed for $decoder"
> +		err "$LINENO"
> +	fi
> +}
> +
> +create_x2_pmem_region() {
> +	# Find a pmem-capable x2 decoder
> +	decoder=$($CXL list -b cxl_test -D -d root | jq -r ".[] |
> +		select(.pmem_capable == true) |
> +		select(.nr_targets == 2) |
> +		.decoder")
> +
> +	# Select one 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")
> +	memdevs="$mem0 $mem1"
> +	create_region
> +}
> +
> +create_x4_ram_region() {
> +	# Find a volatile-capable x2 decoder
> +	decoder=$($CXL list -b cxl_test -D -d root | jq -r ".[] |
> +		select(.volatile_capable == true) |
> +		select(.nr_targets == 2) |
> +		.decoder")
> +
> +	# Select two memdevs 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")
> +	mem2=$($CXL list -M -p "$port_dev0" | jq -r ".[1].memdev")
> +	mem3=$($CXL list -M -p "$port_dev1" | jq -r ".[1].memdev")
> +	memdevs="$mem0 $mem1 $mem2 $mem3"
> +	create_region
> +}
> +
> +AUTO_MEMDEVS=""
> +AUTO_ROOT_DECODER=""
> +
> +capture_auto_region() {
> +	local region_json dec_json
> +
> +	region_json=$($CXL list -R --targets)
> +
> +	# Expect exactly one auto region
> +	[ "$(jq 'length' <<<"$region_json")" -eq 1 ] || err "$LINENO"
> +
> +	AUTO_MEMDEVS=$(jq -r '.[0].mappings | sort_by(.position) | .[].memdev' \
> +		<<<"$region_json" | xargs)
> +	[[ $AUTO_MEMDEVS ]] || err "$LINENO"
> +
> +	dec_json=$($CXL list -R --decoders)
> +	AUTO_ROOT_DECODER=$(jq -r '.[0]["root decoders"][0].decoder' <<<"$dec_json")
> +	[[ $AUTO_ROOT_DECODER ]] || err "$LINENO"
> +}
> +
> +create_user_region_in_auto_region_space() {
> +	decoder="$AUTO_ROOT_DECODER"
> +	memdevs="$AUTO_MEMDEVS"
> +	create_region
> +}
> +
> +# To remove the auto region, destroy and recreate in user space.
> +# With that action, there will be no 'auto' decoders and it will not be
> +# preserved across acpi rebind.
> +#
> +# This is done here as example if test wants the resources freed
> +remove_auto_region() {
> +	capture_auto_region
> +	destroy_regions
> +	create_user_region_in_auto_region_space
> +	destroy_regions
> +	replay_regions || err "$LINENO"
> +}
> +
> +# Replay the built-in auto region
> +[ "$($CXL list -R | jq 'length')" -ne 0 ] || err "$LINENO"
> +replay_regions || err "$LINENO"
> +
> +# Remove the built-in auto region to free up resources
> +remove_auto_region
> +[ "$($CXL list -R | jq 'length')" -eq 0 ] || err "$LINENO"
> +
> +# Create and replay a volatile region
> +create_x4_ram_region
> +replay_regions || err "$LINENO"
> +
> +# Add-on a pmem region
> +create_x2_pmem_region
> +
> +# Replay both the x4_ram and x2_pmem
> +replay_regions || err "$LINENO"
> +
> +check_dmesg "$LINENO"
> +
> +modprobe -r cxl_test
> diff --git a/test/meson.build b/test/meson.build
> index 8a3718d2b558..fb195e07d0ba 100644
> --- a/test/meson.build
> +++ b/test/meson.build
> @@ -169,6 +169,7 @@ cxl_destroy_region = find_program('cxl-destroy-region.sh')
>  cxl_qos_class = find_program('cxl-qos-class.sh')
>  cxl_translate = find_program('cxl-translate.sh')
>  cxl_elc = find_program('cxl-elc.sh')
> +cxl_region_replay = find_program('cxl-region-replay.sh')
>  
>  tests = [
>    [ 'libndctl',               libndctl,		  'ndctl' ],
> @@ -203,6 +204,7 @@ tests = [
>    [ 'cxl-qos-class.sh',       cxl_qos_class,      'cxl'   ],
>    [ 'cxl-translate.sh',       cxl_translate,      'cxl'   ],
>    [ 'cxl-elc.sh',             cxl_elc,            'cxl'   ],
> +  [ 'cxl-region-replay.sh',   cxl_region_replay,  'cxl'   ],
>  ]
>  
>  if get_option('destructive').enabled()


  reply	other threads:[~2026-04-16 21:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-14  6:21 [ndctl PATCH 1/2] test/common: add helpers for CXL region replay testing Alison Schofield
2026-03-14  6:21 ` [ndctl PATCH 2/2] test/cxl-region-replay.sh: add test of region replay workflow Alison Schofield
2026-04-16 21:09   ` Dave Jiang [this message]
2026-04-16 21:08 ` [ndctl PATCH 1/2] test/common: add helpers for CXL region replay testing 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=7da11db2-94aa-4b21-847e-5a9684ae9b06@intel.com \
    --to=dave.jiang@intel.com \
    --cc=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