Skip to contentSkip to conversation

vfio: selftests: Find devices that have VFIO selftest drivers

PATCH Superseded Josh Hilke 3 participants 8 messages Apr 14 – May 11

Subsystems (4)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Josh Hilke

author
#0 lore raw

v2 cover vfio: selftests: Find devices that have VFIO selftest drivers

v2 of this series is only a single patch which adds a new script to print the segment:bus:device.function numbers of PCI devices on the user's system which have a VFIO selftest driver.

Example:

$ ./tools/testing/selftests/vfio/scripts/list_devices.sh
0000:6a:01.0
0000:6f:01.0
0000:74:01.0

The devices are compatible with all VFIO selftests. Other devices may be compatible with VFIO selftests that don't use the driver functionality, but no gaurantees.

User's can automate binding devices to VFIO (which is required in order to run the selftests) by directing the output of list_devices.sh into tools/testing/selftests/vfio/scripts/setup.sh.

Example:

$ ./tools/testing/selftests/vfio/scripts/setup.sh $(./tools/testing/selftests/vfio/scripts/list_devices.sh)
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/vfio-pci/unbind
+ echo "" > /sys/bus/pci/devices/0000:6a:01.0/driver_override
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/idxd/bind
+ echo "0000:6f:01.0" > /sys/bus/pci/drivers/vfio-pci/unbind
+ echo "" > /sys/bus/pci/devices/0000:6f:01.0/driver_override
+ echo "0000:6f:01.0" > /sys/bus/pci/drivers/idxd/bind
+ echo "0000:74:01.0" > /sys/bus/pci/drivers/vfio-pci/unbind
+ echo "" > /sys/bus/pci/devices/0000:74:01.0/driver_override
+ echo "0000:74:01.0" > /sys/bus/pci/drivers/idxd/bind

This series is based on top of the kvm/queue branch.

Changes from v1:
---
- Move the functionality to discover devices from setup.sh into its own script (Sean)
- Omit the patch which automates binding devices to VFIO (Sean, David)
- Change title of cover letter (Me)

v1: https://lore.kernel.org/kvm/[email protected]/

Josh Hilke (1):
vfio: selftests: Find devices that have VFIO selftest drivers

 tools/testing/selftests/vfio/Makefile         |  1 +
 .../selftests/vfio/scripts/list_devices.sh    | 22 +++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100755 tools/testing/selftests/vfio/scripts/list_devices.sh
Signature · 1 line
2.54.0.rc0.605.g598a273b03-goog
author
#1 lore raw

PATCH v2 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 numbers 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, because devices that have a VFIO selftest driver are compatible with all VFIO selftests.

Example:

$ ./tools/testing/selftests/vfio/scripts/list_devices.sh
0000:6a:01.0
0000:6f:01.0
0000:74:01.0
---
 tools/testing/selftests/vfio/Makefile         |  1 +
 .../selftests/vfio/scripts/list_devices.sh    | 22 +++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100755 tools/testing/selftests/vfio/scripts/list_devices.sh
tools/testing/selftests/vfio/Makefile +1 -0
index 8e90e409e91d..d48ac967f1dc 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 +22 -0
new file mode 100755
index 000000000000..b56fa23d5657
@@ -0,0 +1,22 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# List of devices which have a VFIO selftest driver
+DEVICES=(
+	"8086:0b25" # Intel SPR DSA
+	"8086:11fb" # Intel GNR-D DSA
+	"8086:1212" # Intel DR DSA
+	"8086:0cf8" # Intel CBDMA
+)
+
+# Print the segment:bus:device.function numbers of PCI devices that can be used
+# to run VFIO selftests.
+function main() {
+	local vendor_device_id
+
+	for vendor_device_id in "${DEVICES[@]}"; do
+		lspci -D -d "${vendor_device_id}" | awk '{print $1}'
+	done
+}
+
+main "$@"
Signature · 1 line
2.54.0.rc0.605.g598a273b03-goog
maintainer Reviewed-by on v2 1/1
#2 lore raw
Quoted 6 lines · Josh Hilke

Add a new script, list_devices.sh, which prints out the segment:bus:device.function numbers 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, because devices that have a VFIO selftest driver are compatible with all VFIO selftests.

Quoted 8 lines

Example:

$ ./tools/testing/selftests/vfio/scripts/list_devices.sh
0000:6a:01.0
0000:6f:01.0
0000:74:01.0

Aside the nit below, looks good to me. But would like to get Sean's feedback too since he requested it.

Quoted 24 lines
---
 tools/testing/selftests/vfio/Makefile         |  1 +
 .../selftests/vfio/scripts/list_devices.sh    | 22 +++++++++++++++++++
 2 files changed, 23 insertions(+)
 create mode 100755 tools/testing/selftests/vfio/scripts/list_devices.sh
tools/testing/selftests/vfio/Makefile +1 -0
index 8e90e409e91d..d48ac967f1dc 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 +0 -0
new file mode 100755
index 000000000000..b56fa23d5657

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

Quoted 5 lines
tools/testing/selftests/vfio/scripts/list_devices.sh new file +5 -0
@@ -0,0 +1,22 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# List of devices which have a VFIO selftest driver
+DEVICES=(

nit: Use readonly here.

Quoted 20 lines
tools/testing/selftests/vfio/scripts/list_devices.sh new file +17 -0
+	"8086:0b25" # Intel SPR DSA
+	"8086:11fb" # Intel GNR-D DSA
+	"8086:1212" # Intel DR DSA
+	"8086:0cf8" # Intel CBDMA
+)
+
+# Print the segment:bus:device.function numbers of PCI devices that can be used
+# to run VFIO selftests.
+function main() {
+	local vendor_device_id
+
+	for vendor_device_id in "${DEVICES[@]}"; do
+		lspci -D -d "${vendor_device_id}" | awk '{print $1}'
+	done
+}
+
+main "$@"
Signature · 1 line
2.54.0.rc0.605.g598a273b03-goog
#3 lore raw
In reply to Josh Hilke

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

Quoted 7 lines · Josh Hilke
tools/testing/selftests/vfio/scripts/list_devices.sh new file +7 -0
+# Print the segment:bus:device.function numbers of PCI devices that can be used
+# to run VFIO selftests.
+function main() {
+	local vendor_device_id
+
+	for vendor_device_id in "${DEVICES[@]}"; do
+		lspci -D -d "${vendor_device_id}" | awk '{print $1}'

For ignorant people like me, it would be helpful to capture what device was actually found. I mean, I don't necessarily know exactly what these devices do, but as the list grows, at least having a general sense of what device I'm going to be feeding into VFIO would be helpful.

E.g. something like this (ignore my terrible script skills)?

#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later

# List of devices which have a VFIO selftest driver DEVICES=(

	"8086:0b25","Intel SPR DSA"
	"8086:11fb","Intel GNR-D DSA"
	"8086:1212","Intel DR DSA"
	"8086:0cf8","Intel CBDMA"

)

# Print the segment:bus:device.function numbers of PCI devices that can be used

# to run VFIO selftests.
function main() {
	local found
	local i 
	OLDIFS=$IFS
	IFS=','

	for i in "${DEVICES[@]}"; do
		set -- $i
		found=$(lspci -D -d "$1" | cut -f 1 -d ' ')
		if [[ -n $found ]]; then
			echo "$2 ($1) Device IDs:"
			echo $found
		fi
	done

	IFS=$OLDIFS
}

main

# ./devices.sh 
Intel SPR DSA (8086:0b25) Device IDs:
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

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

Quoted 4 lines
tools/testing/selftests/vfio/scripts/list_devices.sh new file +4 -0
+	done
+}
+
+main "$@"

Why pass along args? The script doesn't actually recognize any arguments.

Quoted 3 lines
Signature · 1 line
2.54.0.rc0.605.g598a273b03-goog
author
#4 lore raw
Quoted 15 lines · Sean Christopherson

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

Quoted 7 lines · Josh Hilke
tools/testing/selftests/vfio/scripts/list_devices.sh new file +7 -0
+# Print the segment:bus:device.function numbers of PCI devices that can be used
+# to run VFIO selftests.
+function main() {
+     local vendor_device_id
+
+     for vendor_device_id in "${DEVICES[@]}"; do
+             lspci -D -d "${vendor_device_id}" | awk '{print $1}'

For ignorant people like me, it would be helpful to capture what device was actually found. I mean, I don't necessarily know exactly what these devices do, but as the list grows, at least having a general sense of what device I'm going to be feeding into VFIO would be helpful.

Sure I can do that.

Quoted 10 lines
# ./devices.sh
Intel SPR DSA (8086:0b25) Device IDs:
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

How about a "-v" (verbose) option which prints the device name alongside the BDF?

$ ./list_devices.sh -v
0000:6a:01.0 Intel SPR DSA (8086:0b25)
0000:6f:01.0 Intel SPR DSA (8086:0b25)

This approach preserves the ability to pipe the script output into /tools/testing/selftests/vfio/scripts/setup.sh to automate binding the devices to VFIO by excluding the -v arg since the setup script expects a list of BDFs.

Quoted 3 lines
Quoted 1 line

+main "$@"

Why pass along args? The script doesn't actually recognize any arguments.

It's a remnant from copying another script when creating this one. I'll remove it if we don't add the -v argument.

#5 lore raw
Quoted 30 lines · Josh Hilke
Quoted 15 lines · Sean Christopherson

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

Quoted 7 lines · Josh Hilke
tools/testing/selftests/vfio/scripts/list_devices.sh new file +7 -0
+# Print the segment:bus:device.function numbers of PCI devices that can be used
+# to run VFIO selftests.
+function main() {
+     local vendor_device_id
+
+     for vendor_device_id in "${DEVICES[@]}"; do
+             lspci -D -d "${vendor_device_id}" | awk '{print $1}'

For ignorant people like me, it would be helpful to capture what device was actually found. I mean, I don't necessarily know exactly what these devices do, but as the list grows, at least having a general sense of what device I'm going to be feeding into VFIO would be helpful.

Sure I can do that.

Quoted 10 lines
# ./devices.sh
Intel SPR DSA (8086:0b25) Device IDs:
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
Quoted 7 lines

How about a "-v" (verbose) option which prints the device name alongside the BDF?
Works for me.

$ ./list_devices.sh -v
0000:6a:01.0 Intel SPR DSA (8086:0b25)
0000:6f:01.0 Intel SPR DSA (8086:0b25)

Maybe add a dash to visually separate things? E.g.

0000:6a:01.0 - Intel SPR DSA (8086:0b25)

Quoted 4 lines

This approach preserves the ability to pipe the script output into /tools/testing/selftests/vfio/scripts/setup.sh to automate binding the devices to VFIO by excluding the -v arg since the setup script expects a list of BDFs.

Alternatively, -q for quiet? Or:

./devices.sh | cut -f 1 -d ' ' | setup.sh

Or have setup.h do the cutting? I'm a-ok with a -v, but if the script is mostly going to be run by humans (no idea if this is true), it seems like it should use the more verbose version by default.

maintainer
#6 lore raw
Quoted 49 lines · Sean Christopherson
Quoted 30 lines · Josh Hilke
Quoted 15 lines · Sean Christopherson

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

Quoted 7 lines · Josh Hilke
tools/testing/selftests/vfio/scripts/list_devices.sh new file +7 -0
+# Print the segment:bus:device.function numbers of PCI devices that can be used
+# to run VFIO selftests.
+function main() {
+     local vendor_device_id
+
+     for vendor_device_id in "${DEVICES[@]}"; do
+             lspci -D -d "${vendor_device_id}" | awk '{print $1}'

For ignorant people like me, it would be helpful to capture what device was actually found. I mean, I don't necessarily know exactly what these devices do, but as the list grows, at least having a general sense of what device I'm going to be feeding into VFIO would be helpful.

Sure I can do that.

Quoted 10 lines
# ./devices.sh
Intel SPR DSA (8086:0b25) Device IDs:
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
Quoted 7 lines

How about a "-v" (verbose) option which prints the device name alongside the BDF?
Works for me.

$ ./list_devices.sh -v
0000:6a:01.0 Intel SPR DSA (8086:0b25)
0000:6f:01.0 Intel SPR DSA (8086:0b25)

Maybe add a dash to visually separate things? E.g.

0000:6a:01.0 - Intel SPR DSA (8086:0b25)

Quoted 4 lines

This approach preserves the ability to pipe the script output into /tools/testing/selftests/vfio/scripts/setup.sh to automate binding the devices to VFIO by excluding the -v arg since the setup script expects a list of BDFs.

Quoted 7 lines

Alternatively, -q for quiet? Or:

./devices.sh | cut -f 1 -d ' ' | setup.sh

Or have setup.h do the cutting? I'm a-ok with a -v, but if the script is mostly going to be run by humans (no idea if this is true), it seems like it should use the more verbose version by default.

Let's do -q. That makes the default (no arguments) usable by humans. For scripting, it's easy enough to pass in -q.

author
#7 lore raw
Quoted 53 lines · David Matlack
Quoted 51 lines · Sean Christopherson
Quoted 30 lines · Josh Hilke
Quoted 15 lines · Sean Christopherson

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

Quoted 7 lines · Josh Hilke
tools/testing/selftests/vfio/scripts/list_devices.sh new file +7 -0
+# Print the segment:bus:device.function numbers of PCI devices that can be used
+# to run VFIO selftests.
+function main() {
+     local vendor_device_id
+
+     for vendor_device_id in "${DEVICES[@]}"; do
+             lspci -D -d "${vendor_device_id}" | awk '{print $1}'

For ignorant people like me, it would be helpful to capture what device was actually found. I mean, I don't necessarily know exactly what these devices do, but as the list grows, at least having a general sense of what device I'm going to be feeding into VFIO would be helpful.

Sure I can do that.

Quoted 10 lines
# ./devices.sh
Intel SPR DSA (8086:0b25) Device IDs:
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
Quoted 7 lines

How about a "-v" (verbose) option which prints the device name alongside the BDF?
Works for me.

$ ./list_devices.sh -v
0000:6a:01.0 Intel SPR DSA (8086:0b25)
0000:6f:01.0 Intel SPR DSA (8086:0b25)

Maybe add a dash to visually separate things? E.g.

0000:6a:01.0 - Intel SPR DSA (8086:0b25)

Quoted 4 lines

This approach preserves the ability to pipe the script output into /tools/testing/selftests/vfio/scripts/setup.sh to automate binding the devices to VFIO by excluding the -v arg since the setup script expects a list of BDFs.

Alternatively, -q for quiet? Or:

Quoted 8 lines
Quoted 5 lines

./devices.sh | cut -f 1 -d ' ' | setup.sh

Or have setup.h do the cutting? I'm a-ok with a -v, but if the script is mostly going to be run by humans (no idea if this is true), it seems like it should use the more verbose version by default.

Let's do -q. That makes the default (no arguments) usable by humans. For scripting, it's easy enough to pass in -q.

-q sounds good to me. Will do in v3.