diff mbox series

[ndctl,2/2] cxl/test: Validate sanitize notifications

Message ID 169657750601.1491881.9906006449269786700.stgit@dwillia2-xfh.jf.intel.com
State Accepted
Commit 0a56a23359e4068a7615ca4a19e16c87b44fd373
Headers show
Series cxl: Add sanitization notifier tests | expand

Commit Message

Dan Williams Oct. 6, 2023, 7:31 a.m. UTC
Exercise the memX/security/sanitize and memX/security/state ABIs by setting
up cxl_test to emulate a 2 second sanitize operation, and use 'cxl
wait-sanitize' to validate the notification fires.

Also implement a negative test for the kernel protecting against submitting
sanitize while a device has mapped decoders.

Cc: Davidlohr Bueso <dave@stgolabs.net>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 test/cxl-sanitize.sh |   76 ++++++++++++++++++++++++++++++++++++++++++++++++++
 test/meson.build     |    2 +
 2 files changed, 78 insertions(+)
 create mode 100644 test/cxl-sanitize.sh
diff mbox series

Patch

diff --git a/test/cxl-sanitize.sh b/test/cxl-sanitize.sh
new file mode 100644
index 000000000000..9c161014ccb7
--- /dev/null
+++ b/test/cxl-sanitize.sh
@@ -0,0 +1,76 @@ 
+#!/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
+rc=1
+
+# THEORY OF OPERATION: Find a memdev with programmed decoders, validate
+# that sanitize requests fail. Find a memdev without programmed
+# decoders, validate that submission succeeds, and validate that the
+# notifier fires.
+
+mem_to_host()
+{
+	host=$("$CXL" list -m $1 | jq -r '.[].host')
+	echo $host
+}
+
+set_timeout()
+{
+	host=$(mem_to_host $1)
+	echo $2 > /sys/bus/platform/devices/$host/sanitize_timeout
+}
+
+# find all memdevs
+readarray -t all_mem < <("$CXL" list -b cxl_test -M | jq -r '.[].memdev')
+
+# try to sanitize an active memdev
+readarray -t active_mem < <("$CXL" list -b cxl_test -RT | jq -r '.[].mappings[].memdev')
+count=${#active_mem[@]}
+((count > 0)) || err $LINENO
+
+# set timeout to 2 seconds
+set_timeout ${active_mem[0]} 2000
+
+# sanitize with an active memdev should fail
+echo 1 > /sys/bus/cxl/devices/${active_mem[0]}/security/sanitize && err $LINENO
+
+# find an inactive mem
+inactive=""
+for mem in ${all_mem[@]}; do
+	inactive=$mem
+	for active in ${active_mem[@]}; do
+		if [ $mem = $active ]; then
+			inactive=""
+		fi
+	done
+	if [ -z $inactive ]; then
+		continue;
+	fi
+	break
+done
+[ -z $inactive ] && err $LINENO
+
+# kickoff a background sanitize and make sure the wait takes a couple
+# secounds
+set_timeout $inactive 3000
+start=$SECONDS
+echo 1 > /sys/bus/cxl/devices/${inactive}/security/sanitize &
+"$CXL" wait-sanitize $inactive || err $LINENO
+((SECONDS > start + 2)) || err $LINENO
+
+check_dmesg "$LINENO"
+
+modprobe -r cxl_test
diff --git a/test/meson.build b/test/meson.build
index 224adaf41fcc..b7c44f319dad 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -157,6 +157,7 @@  cxl_create_region = find_program('cxl-create-region.sh')
 cxl_xor_region = find_program('cxl-xor-region.sh')
 cxl_update_firmware = find_program('cxl-update-firmware.sh')
 cxl_events = find_program('cxl-events.sh')
+cxl_sanitize = find_program('cxl-sanitize.sh')
 
 tests = [
   [ 'libndctl',               libndctl,		  'ndctl' ],
@@ -186,6 +187,7 @@  tests = [
   [ 'cxl-create-region.sh',   cxl_create_region,  'cxl'   ],
   [ 'cxl-xor-region.sh',      cxl_xor_region,     'cxl'   ],
   [ 'cxl-events.sh',          cxl_events,         'cxl'   ],
+  [ 'cxl-sanitize.sh',        cxl_sanitize,       'cxl'   ],
 ]
 
 if get_option('destructive').enabled()