Skip to contentSkip to conversation

vfio: selftests: Find devices that have VFIO selftest drivers

PATCH In review Josh Hilke 2 participants 2 messages Nov 18 – Nov 19

Subsystems (4)
lore
Share & tools
lore

Josh Hilke

author
#0 lore raw

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

Add list_supported_devices.sh to print the PCI addresses and names of devices on the host that have a VFIO selftest driver. Group the output into supported and unusable sections based on whether vfio-pci is loaded and whether the vfio-pci denylist blocks the device.

Add -q to print only the PCI addresses of usable devices so the output can go straight to setup.sh. Add -a for use with -q to include unusable devices as well.

When vfio-pci is loaded with disable_denylist=Y, the script lists the denylisted devices under "Supported (on denylist, but denylist disabled):" and includes them in the -q output. When vfio-pci is not loaded, the script lists all devices as unusable and omits them from -q unless -a is also passed.

Example on a host with Intel IOAT and Intel DSA devices when vfio-pci is loaded with disable_denylist=N:

$ ./list_supported_devices.sh
Supported:
  0000:00:04.0 - Intel IOAT SKX [8086:2021]
  ...
Unusable (available, but denylisted by the kernel):
  0000:6a:01.0 - Intel DSA SPR [8086:0b25]
  ...

To use denylisted devices, load vfio-pci with disable_denylist=1 (or boot the kernel with vfio_pci.disable_denylist=1).

$ ./list_supported_devices.sh -q
0000:00:04.0
...
$ ./list_supported_devices.sh -q -a
0000:00:04.0
...
0000:6a:01.0
...

---
Changelog

v7 -> v8
- Group devices under Supported and Unusable headers instead of repeating denylist state on every line, and shorten the denylist hint at the end of the denylisted section. Suggested by Sean.
- Check /sys/bus/pci/drivers/vfio-pci to verify that vfio-pci is loaded, mark devices as unusable when it is not loaded, and omit them from -q unless -a is passed. Suggested by Sean.
- Add -a for use with -q to include unusable devices in the SBDF output. Suggested by Sean.

v7: https://lore.kernel.org/kvm/[email protected]/
v6: https://lore.kernel.org/kvm/[email protected]/
v5: https://lore.kernel.org/kvm/[email protected]/

 tools/testing/selftests/vfio/Makefile         |   1 +
 .../vfio/scripts/list_supported_devices.sh    | 199 ++++++++++++++++++
 2 files changed, 200 insertions(+)
 create mode 100755 tools/testing/selftests/vfio/scripts/list_supported_devices.sh
tools/testing/selftests/vfio/Makefile +1 -0
index 2c32c48db509..160aa989828f 100644
@@ -16,6 +16,7 @@ TEST_GEN_PROGS += vfio_pci_sriov_uapi_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
 
tools/testing/selftests/vfio/scripts/list_supported_devices.sh new file +199 -0

199 lines not on this page · raw message

Signature · 1 line
2.56.0.679.gc527c65306-goog
maintainer
#1 lore raw

tools/testing/selftests/vfio/scripts/list_supported_devices.sh line 36

Quoted 6 lines · Josh Hilke
tools/testing/selftests/vfio/scripts/list_supported_devices.sh new file +5 -0
+# Devices that have a driver in selftests/vfio/lib/drivers.
+readonly DEVICES=(
+	"8086:0b25,Intel DSA SPR"
[...]
+	"15b3:a2df,Mellanox BlueField-4 integrated ConnectX-8"
+)

This is missing GPUs that are supported by the nv_falcon driver.

I saw in the v7 changelog that you left them out because nv_falcon_probe() matches on PMC_BOOT_0 rather than PCI ID. But the first thing nv_falcon_probe() does is check vendor == 0x10de and base class == PCI_BASE_CLASS_DISPLAY, and the script can get both of those from sysfs. And past that, nv_falcon_probe() only rejects GPUs with an unknown architecture; unverified GPUs are accepted with a "possibly not supported" message. So matching on vendor and class gets the script about as close as the driver itself gets.

e.g. something like:

	read -r class < /sys/bus/pci/devices/${bdf}/class
	if [ "${vendor}" = "0x10de" ] && [ $((class >> 16)) -eq 3 ]; then
		...
	fi

Also, nv_falcon does not implement send_msi(), so on NVIDIA GPUs the send_msi tests in vfio_pci_driver_test are skipped and kvm/irq_test does not run at all. The script should make this clear when it reports an NVIDIA GPU so users know they're getting reduced coverage.

Since the script can't check the GPU architecture itself, it would also help to tell the user which architectures nv_falcon supports, so they can check their GPU themselves. e.g. something like:

Supported:

    0000:00:04.0 - Intel IOAT SKX [8086:2021]

Possibly supported (depends on GPU architecture):
0000:3b:00.0 - NVIDIA GPU [10de:1eb8]

nv_falcon supports Kepler, Maxwell, Pascal, Volta, Turing, Ampere, Ada, and Hopper GPUs. It does not support send_msi().

Please add a comment next to the list of architectures pointing at nv_gpu_arch_lookup() so the two stay in sync.

I think it's fine to include these GPUs in the -q output. If the GPU turns out to be unsupported, vfio_pci_driver_test will just skip.

Printing the selftest driver name for each device might also help here, and would make it easier to tie the list back to lib/drivers/.

tools/testing/selftests/vfio/scripts/list_supported_devices.sh line 68

Quoted 9 lines
tools/testing/selftests/vfio/scripts/list_supported_devices.sh new file +7 -0
+function vfio_pci_loaded() {
+	[ -d ${VFIO_PCI_DRIVER} ]
+}
+
+function denylisted() {
[...]
+function denylist_enforced() {
[...]
+function is_blocked() {

Please consistently use is_*() for functions that check a condition, e.g. is_vfio_pci_loaded(), is_denylisted(), is_denylist_enforced(), and is_blocked(). That makes call sites like this one read more clearly:

	if [ "${all}" ] || ! is_blocked ${id}; then

tools/testing/selftests/vfio/scripts/list_supported_devices.sh line 196

Quoted 7 lines
tools/testing/selftests/vfio/scripts/list_supported_devices.sh new file +7 -0
+	if [ ${#allowed_devices[@]} -gt 0 ]; then
+		print_allowed_devices "${allowed_devices[@]}"
+	fi
+
+	if [ ${#denylisted_devices[@]} -gt 0 ]; then
+		print_denylisted_devices "${denylisted_devices[@]}"
+	fi

nit: When both groups have devices, there's no blank line between the last "Supported:" entry and the "Unusable ...:" header, which makes the output harder to scan.