Blame SOURCES/0186-cxl-test-Checkout-region-setup-teardown.patch

2eb93d
From eef9685245d172a80e9a5dfd830942824e7d40b4 Mon Sep 17 00:00:00 2001
2eb93d
From: Dan Williams <dan.j.williams@intel.com>
2eb93d
Date: Thu, 14 Jul 2022 10:02:55 -0700
2eb93d
Subject: [PATCH 186/217] cxl/test: Checkout region setup/teardown
2eb93d
2eb93d
Exercise the fundamental region provisioning sysfs mechanisms of discovering
2eb93d
available DPA capacity, allocating DPA to a region, and programming HDM
2eb93d
decoders.
2eb93d
2eb93d
Link: https://lore.kernel.org/r/165781817516.1555691.3557156570639615515.stgit@dwillia2-xfh.jf.intel.com
2eb93d
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2eb93d
Signed-off-by: Vishal Verma <vishal.l.verma@intel.com>
2eb93d
---
2eb93d
 test/cxl-region-sysfs.sh | 122 +++++++++++++++++++++++++++++++++++++++
2eb93d
 test/meson.build         |   2 +
2eb93d
 2 files changed, 124 insertions(+)
2eb93d
 create mode 100644 test/cxl-region-sysfs.sh
2eb93d
2eb93d
diff --git a/test/cxl-region-sysfs.sh b/test/cxl-region-sysfs.sh
2eb93d
new file mode 100644
2eb93d
index 0000000..2582edb
2eb93d
--- /dev/null
2eb93d
+++ b/test/cxl-region-sysfs.sh
2eb93d
@@ -0,0 +1,122 @@
2eb93d
+#!/bin/bash
2eb93d
+# SPDX-License-Identifier: GPL-2.0
2eb93d
+# Copyright (C) 2022 Intel Corporation. All rights reserved.
2eb93d
+
2eb93d
+. $(dirname $0)/common
2eb93d
+
2eb93d
+rc=1
2eb93d
+
2eb93d
+set -ex
2eb93d
+
2eb93d
+trap 'err $LINENO' ERR
2eb93d
+
2eb93d
+check_prereq "jq"
2eb93d
+
2eb93d
+modprobe -r cxl_test
2eb93d
+modprobe cxl_test
2eb93d
+udevadm settle
2eb93d
+
2eb93d
+# THEORY OF OPERATION: Create a x8 interleave across the pmem capacity
2eb93d
+# of the 8 endpoints defined by cxl_test, commit the decoders (which
2eb93d
+# just stubs out the actual hardware programming aspect, but updates the
2eb93d
+# driver state), and then tear it all down again. As with other cxl_test
2eb93d
+# tests if the CXL topology in tools/testing/cxl/test/cxl.c ever changes
2eb93d
+# then the paired update must be made to this test.
2eb93d
+
2eb93d
+# find the root decoder that spans both test host-bridges and support pmem
2eb93d
+decoder=$($CXL list -b cxl_test -D -d root | jq -r ".[] |
2eb93d
+	  select(.pmem_capable == true) |
2eb93d
+	  select(.nr_targets == 2) |
2eb93d
+	  .decoder")
2eb93d
+
2eb93d
+# find the memdevs mapped by that decoder
2eb93d
+readarray -t mem < <($CXL list -M -d $decoder | jq -r ".[].memdev")
2eb93d
+
2eb93d
+# ask cxl reserve-dpa to allocate pmem capacity from each of those memdevs
2eb93d
+readarray -t endpoint < <($CXL reserve-dpa -t pmem ${mem[*]} -s $((256<<20)) |
2eb93d
+			  jq -r ".[] | .decoder.decoder")
2eb93d
+
2eb93d
+# instantiate an empty region
2eb93d
+region=$(cat /sys/bus/cxl/devices/$decoder/create_pmem_region)
2eb93d
+echo $region > /sys/bus/cxl/devices/$decoder/create_pmem_region
2eb93d
+uuidgen > /sys/bus/cxl/devices/$region/uuid
2eb93d
+
2eb93d
+# setup interleave geometry
2eb93d
+nr_targets=${#endpoint[@]}
2eb93d
+echo $nr_targets > /sys/bus/cxl/devices/$region/interleave_ways
2eb93d
+g=$(cat /sys/bus/cxl/devices/$decoder/interleave_granularity)
2eb93d
+echo $g > /sys/bus/cxl/devices/$region/interleave_granularity
2eb93d
+echo $((nr_targets * (256<<20))) > /sys/bus/cxl/devices/$region/size
2eb93d
+
2eb93d
+# grab the list of memdevs grouped by host-bridge interleave position
2eb93d
+port_dev0=$($CXL list -T -d $decoder | jq -r ".[] |
2eb93d
+	    .targets | .[] | select(.position == 0) | .target")
2eb93d
+port_dev1=$($CXL list -T -d $decoder | jq -r ".[] |
2eb93d
+	    .targets | .[] | select(.position == 1) | .target")
2eb93d
+readarray -t mem_sort0 < <($CXL list -M -p $port_dev0 | jq -r ".[] | .memdev")
2eb93d
+readarray -t mem_sort1 < <($CXL list -M -p $port_dev1 | jq -r ".[] | .memdev")
2eb93d
+
2eb93d
+# TODO: add a cxl list option to list memdevs in valid region provisioning
2eb93d
+# order, hardcode for now.
2eb93d
+mem_sort=()
2eb93d
+mem_sort[0]=${mem_sort0[0]}
2eb93d
+mem_sort[1]=${mem_sort1[0]}
2eb93d
+mem_sort[2]=${mem_sort0[2]}
2eb93d
+mem_sort[3]=${mem_sort1[2]}
2eb93d
+mem_sort[4]=${mem_sort0[1]}
2eb93d
+mem_sort[5]=${mem_sort1[1]}
2eb93d
+mem_sort[6]=${mem_sort0[3]}
2eb93d
+mem_sort[7]=${mem_sort1[3]}
2eb93d
+
2eb93d
+# TODO: use this alternative memdev ordering to validate a negative test for
2eb93d
+# specifying invalid positions of memdevs
2eb93d
+#mem_sort[2]=${mem_sort0[0]}
2eb93d
+#mem_sort[1]=${mem_sort1[0]}
2eb93d
+#mem_sort[0]=${mem_sort0[2]}
2eb93d
+#mem_sort[3]=${mem_sort1[2]}
2eb93d
+#mem_sort[4]=${mem_sort0[1]}
2eb93d
+#mem_sort[5]=${mem_sort1[1]}
2eb93d
+#mem_sort[6]=${mem_sort0[3]}
2eb93d
+#mem_sort[7]=${mem_sort1[3]}
2eb93d
+
2eb93d
+# re-generate the list of endpoint decoders in region position programming order
2eb93d
+endpoint=()
2eb93d
+for i in ${mem_sort[@]}
2eb93d
+do
2eb93d
+	readarray -O ${#endpoint[@]} -t endpoint < <($CXL list -Di -d endpoint -m $i | jq -r ".[] |
2eb93d
+						     select(.mode == \"pmem\") | .decoder")
2eb93d
+done
2eb93d
+
2eb93d
+# attach all endpoint decoders to the region
2eb93d
+pos=0
2eb93d
+for i in ${endpoint[@]}
2eb93d
+do
2eb93d
+	echo $i > /sys/bus/cxl/devices/$region/target$pos
2eb93d
+	pos=$((pos+1))
2eb93d
+done
2eb93d
+echo "$region added ${#endpoint[@]} targets: ${endpoint[@]}"
2eb93d
+
2eb93d
+# walk up the topology and commit all decoders
2eb93d
+echo 1 > /sys/bus/cxl/devices/$region/commit
2eb93d
+
2eb93d
+# walk down the topology and de-commit all decoders
2eb93d
+echo 0 > /sys/bus/cxl/devices/$region/commit
2eb93d
+
2eb93d
+# remove endpoints from the region
2eb93d
+pos=0
2eb93d
+for i in ${endpoint[@]}
2eb93d
+do
2eb93d
+	echo "" > /sys/bus/cxl/devices/$region/target$pos
2eb93d
+	pos=$((pos+1))
2eb93d
+done
2eb93d
+
2eb93d
+# release DPA capacity
2eb93d
+readarray -t endpoint < <($CXL free-dpa -t pmem ${mem[*]} |
2eb93d
+			  jq -r ".[] | .decoder.decoder")
2eb93d
+echo "$region released ${#endpoint[@]} targets: ${endpoint[@]}"
2eb93d
+
2eb93d
+# validate no WARN or lockdep report during the run
2eb93d
+log=$(journalctl -r -k --since "-$((SECONDS+1))s")
2eb93d
+grep -q "Call Trace" <<< $log && err "$LINENO"
2eb93d
+
2eb93d
+modprobe -r cxl_test
2eb93d
diff --git a/test/meson.build b/test/meson.build
2eb93d
index 210dcb0..3203d9c 100644
2eb93d
--- a/test/meson.build
2eb93d
+++ b/test/meson.build
2eb93d
@@ -151,6 +151,7 @@ max_extent = find_program('max_available_extent_ns.sh')
2eb93d
 pfn_meta_errors = find_program('pfn-meta-errors.sh')
2eb93d
 track_uuid = find_program('track-uuid.sh')
2eb93d
 cxl_topo = find_program('cxl-topology.sh')
2eb93d
+cxl_sysfs = find_program('cxl-region-sysfs.sh')
2eb93d
 
2eb93d
 tests = [
2eb93d
   [ 'libndctl',               libndctl,		  'ndctl' ],
2eb93d
@@ -176,6 +177,7 @@ tests = [
2eb93d
   [ 'pfn-meta-errors.sh',     pfn_meta_errors,	  'ndctl' ],
2eb93d
   [ 'track-uuid.sh',          track_uuid,	  'ndctl' ],
2eb93d
   [ 'cxl-topology.sh',	      cxl_topo,		  'cxl'   ],
2eb93d
+  [ 'cxl-region-sysfs.sh',    cxl_sysfs,	  'cxl'   ],
2eb93d
 ]
2eb93d
 
2eb93d
 if get_option('destructive').enabled()
2eb93d
-- 
2eb93d
2.27.0
2eb93d