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

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