[PATCH v5] vfio: selftests: Find devices that have VFIO selftest drivers

Josh Hilke posted 1 patch 5 days, 9 hours ago
There is a newer version of this series
tools/testing/selftests/vfio/Makefile         |  1 +
.../vfio/scripts/list_supported_devices.sh    | 44 +++++++++++++++++++
2 files changed, 45 insertions(+)
create mode 100755 tools/testing/selftests/vfio/scripts/list_supported_devices.sh
[PATCH v5] vfio: selftests: Find devices that have VFIO selftest drivers
Posted by Josh Hilke 5 days, 9 hours ago
Add a new script, list_devices.sh, which prints out the
segment:bus:device.function (SBDF) numbers and names of devices on a
machine that have a VFIO selftest driver. This makes it easier to
determine if the system is capable of running VFIO selftests.

Includes a -q (quiet) argument which prints just the SBDFs so that the
output can be piped into tools/testing/selftests/vfio/script/setup.sh to
bind the devices to VFIO to use in VFIO selftests.

Examples:

$ ./list_devices.sh
0000:6a:01.0 - Intel SPR DSA (8086:0b25)
0000:6f:01.0 - Intel SPR DSA (8086:0b25)
0000:74:01.0 - Intel SPR DSA (8086:0b25)
0000:79:01.0 - Intel SPR DSA (8086:0b25)
0000:e7:01.0 - Intel SPR DSA (8086:0b25)
0000:ec:01.0 - Intel SPR DSA (8086:0b25)
0000:f1:01.0 - Intel SPR DSA (8086:0b25)
0000:f6:01.0 - Intel SPR DSA (8086:0b25)

$ ./list_devices.sh -q
0000:6a:01.0
0000:6f:01.0
0000:74:01.0
0000:79:01.0
0000:e7:01.0
0000:ec:01.0
0000:f1:01.0
0000:f6:01.0

Suggested-by: Sean Christopherson <seanjc@google.com>
Signed-off-by: Josh Hilke <jrhilke@google.com>
---
Changelog

v4 -> v5
- Rename list_devices.sh to list_supported_devices.sh (Vipin)
- Document the source of supported device names/IDs (Vipin)
- Align the output format with `lspci` (Vipin) 
- Fix errors in device names and IDs (Vipin)

v4: https://lore.kernel.org/kvm/20260529180425.4162392-1-jrhilke@google.com/

 tools/testing/selftests/vfio/Makefile         |  1 +
 .../vfio/scripts/list_supported_devices.sh    | 44 +++++++++++++++++++
 2 files changed, 45 insertions(+)
 create mode 100755 tools/testing/selftests/vfio/scripts/list_supported_devices.sh

diff --git a/tools/testing/selftests/vfio/Makefile b/tools/testing/selftests/vfio/Makefile
index 0684932d91bf..127e70b996a9 100644
--- a/tools/testing/selftests/vfio/Makefile
+++ b/tools/testing/selftests/vfio/Makefile
@@ -15,6 +15,7 @@ TEST_GEN_PROGS += vfio_pci_driver_test
 
 TEST_FILES += scripts/cleanup.sh
 TEST_FILES += scripts/lib.sh
+TEST_FILES += scripts/list_supported_devices.sh
 TEST_FILES += scripts/run.sh
 TEST_FILES += scripts/setup.sh
 
diff --git a/tools/testing/selftests/vfio/scripts/list_supported_devices.sh b/tools/testing/selftests/vfio/scripts/list_supported_devices.sh
new file mode 100755
index 000000000000..a123a965d358
--- /dev/null
+++ b/tools/testing/selftests/vfio/scripts/list_supported_devices.sh
@@ -0,0 +1,44 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# List of devices which have a VFIO selftest driver. Device IDs are found in the
+# drivers in selftests/vfio/lib/drivers.
+readonly DEVICES=(
+	"8086:0b25,Intel DSA SPR"
+	"8086:11fb,Intel DSA GNR-D"
+	"8086:1212,Intel DSA DMR"
+	"8086:2021,Intel IOAT SKX"
+)
+
+# Print the segment:bus:device.function numbers of PCI devices that can be used
+# to run VFIO selftests.
+function main() {
+	local id_name
+	local quiet=""
+	local name
+	local bdfs
+	local bdf
+	local id
+
+	while getopts "q" opt; do
+		case $opt in
+			q) quiet="true" ;;
+			\?) echo "Usage: $0 [-q]" >&2; exit 1 ;;
+		esac
+	done
+
+	for id_name in "${DEVICES[@]}"; do
+		IFS=',' read -r id name <<< "$id_name"
+		bdfs=$(lspci -D -d "${id}" | awk '{print $1}')
+
+		[[ -z $bdfs ]] && continue
+
+		if [ "$quiet" ]; then
+			echo "${bdfs}"
+		else
+			echo "${bdfs}" | sed "s|$| - ${name} [${id}]|"
+		fi
+	done
+}
+
+main "$@"
-- 
2.54.0.1013.g208068f2d8-goog