Skip to contentSkip to conversation

vfio: selftests: Find devices that have VFIO selftest drivers

PATCH Superseded Josh Hilke 2 participants 2 messages May 29 – Jun 1

Subsystems (4)

v4 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Josh Hilke

author
#0 lore raw

PATCH v4 1/1 vfio: selftests: Find devices that have VFIO selftest drivers

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

---
Changelog

v3 -> v4:
- Move argument parsing into main() (David)
- Use empty string for false in quiet flag (David)
- Simplify logic to print device names and IDs (David)

 tools/testing/selftests/vfio/Makefile         |  1 +
 .../selftests/vfio/scripts/list_devices.sh    | 43 +++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100755 tools/testing/selftests/vfio/scripts/list_devices.sh
tools/testing/selftests/vfio/Makefile +1 -0
index 0684932d91bf..777f91f09057 100644
@@ -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_devices.sh
 TEST_FILES += scripts/run.sh
 TEST_FILES += scripts/setup.sh
 
tools/testing/selftests/vfio/scripts/list_devices.sh new file +43 -0

43 lines not on this page · raw message

Signature · 1 line
2.54.0.929.g9b7fa37559-goog
#1 lore raw
Quoted 51 lines · Josh Hilke

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

---
Changelog

v3 -> v4:
- Move argument parsing into main() (David)
- Use empty string for false in quiet flag (David)
- Simplify logic to print device names and IDs (David)

 tools/testing/selftests/vfio/Makefile         |  1 +
 .../selftests/vfio/scripts/list_devices.sh    | 43 +++++++++++++++++++
 2 files changed, 44 insertions(+)
 create mode 100755 tools/testing/selftests/vfio/scripts/list_devices.sh
tools/testing/selftests/vfio/Makefile +0 -0
index 0684932d91bf..777f91f09057 100644

tools/testing/selftests/vfio/Makefile TEST_GEN_PROGS += vfio_pci_driver_test · line 18

Quoted 4 lines
tools/testing/selftests/vfio/Makefile +1 -0
@@ -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_devices.sh

Nit: Should this file be renamed to supported_devices.sh?

list_devices.sh sounds to me it will list all of the devices. Just a suggestion.

Quoted 9 lines
tools/testing/selftests/vfio/Makefile +0 -0
 TEST_FILES += scripts/run.sh
 TEST_FILES += scripts/setup.sh
 
tools/testing/selftests/vfio/scripts/list_devices.sh new file +0 -0
new file mode 100755
index 000000000000..249532f15570

tools/testing/selftests/vfio/scripts/list_devices.sh line 8

Quoted 8 lines
tools/testing/selftests/vfio/scripts/list_devices.sh new file +8 -0
@@ -0,0 +1,43 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# List of devices which have a VFIO selftest driver
+readonly DEVICES=(
+	"8086:0b25,Intel SPR DSA"
+	"8086:11fb,Intel GNR-D DSA"
+	"8086:1212,Intel DR DSA"

Nit: I think this should be DMR instead of DR.

tools/testing/selftests/vfio/scripts/list_devices.sh line 9

Quoted 1 line
tools/testing/selftests/vfio/scripts/list_devices.sh new file +1 -0
+	"8086:0cf8,Intel CBDMA"

Where is this device in selftests/vfio/lib/drivers/*? I am not able to find it.

Also, selftests/vfio/lib/drivers/ioat/ioat.c has PCI_DEVICE_ID_INTEL_IOAT_SKX (0x2021) device. Should that be added here?

I think we should write the comment above that DEVICES list is populated from the IDs in lib/drivers/* files.

Quoted 19 lines
tools/testing/selftests/vfio/scripts/list_devices.sh new file +19 -0
+)
+
+# 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
+

tools/testing/selftests/vfio/scripts/list_devices.sh line 38

Quoted 10 lines
tools/testing/selftests/vfio/scripts/list_devices.sh new file +10 -0
+	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})|"

Nit: lspci prints vendor and device id in [], and use () for revision. Should this script also use []?

Quoted 8 lines
tools/testing/selftests/vfio/scripts/list_devices.sh new file +5 -0
+		fi
+	done
+}
+
+main "$@"
Signature · 1 line
2.54.0.929.g9b7fa37559-goog