mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v9] vfio: selftests: Find devices that have VFIO selftest drivers
@ 2026-11-20  1:25 Josh Hilke
  2026-11-20 18:14 ` Sean Christopherson
  2026-11-25 19:12 ` David Matlack
  0 siblings, 2 replies; 3+ messages in thread
From: Josh Hilke @ 2026-11-20  1:25 UTC (permalink / raw)
  To: Alex Williamson
  Cc: David Matlack, Josh Hilke, kvm, linux-kernel,
	Sean Christopherson, Vipin Sharma

Add list_supported_devices.sh to print the PCI addresses, names, and
selftest driver paths of devices on the host that have a VFIO selftest
driver. Group the output into sections based on whether vfio-pci is
loaded, whether the vfio-pci denylist blocks the device, and whether a
GPU requires an architecture check at probe time.

Match NVIDIA GPUs by vendor ID and PCI display class, since nv_falcon
identifies compatible GPUs by reading BAR0 rather than by PCI device
ID. Group them under "Possibly supported", list the valid GPU
architectures, and warn that nv_falcon skips MSI tests.

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, NVIDIA GPU, 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] - lib/drivers/ioat/ioat.c
  ...

Possibly supported (depends on GPU architecture):
  0000:3b:00.0 - NVIDIA GPU [10de:1eb8] - lib/drivers/nv_falcon/nv_falcon.c

  nv_falcon supports Kepler, Maxwell, Pascal, Volta, Turing, Ampere,
  Ada, and Hopper GPUs. It does not support send_msi() and will skip
  tests that try to send MSIs.

Unusable (available, but denylisted by the kernel):
  0000:6a:01.0 - Intel DSA SPR [8086:0b25] - lib/drivers/dsa/dsa.c
  ...

  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
...
0000:3b:00.0

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

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

v8 -> v9, all changes suggested by David Matlack:
- Match NVIDIA GPUs by vendor 0x10de and PCI display class 0x03, group
  them under "Possibly supported (depends on GPU architecture):" with a
  note listing valid GPU architectures and warning that MSI tests skip,
  and include them in -q output.
- Print the selftest driver path lib/drivers/<driver>/<driver>.c at the
  end of each device line.
- Use is_*() naming consistently for condition-checking functions.
- Add a blank line between output sections.

v8: https://lore.kernel.org/kvm/20261118064309.219592-1-jrhilke@google.com/
v7: https://lore.kernel.org/kvm/20261106051726.3964374-1-jrhilke@google.com/
v6: https://lore.kernel.org/kvm/20260602222941.3133236-1-jrhilke@google.com/
v5: https://lore.kernel.org/kvm/20260602185615.3025904-1-jrhilke@google.com/

 tools/testing/selftests/vfio/Makefile         |   1 +
 .../vfio/scripts/list_supported_devices.sh    | 251 ++++++++++++++++++
 2 files changed, 252 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 2c32c48db509..160aa989828f 100644
--- a/tools/testing/selftests/vfio/Makefile
+++ b/tools/testing/selftests/vfio/Makefile
@@ -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
 
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..15d93dbb232f
--- /dev/null
+++ b/tools/testing/selftests/vfio/scripts/list_supported_devices.sh
@@ -0,0 +1,251 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+# Devices that have a driver in selftests/vfio/lib/drivers. NVIDIA GPUs are
+# matched separately in is_nv_gpu() because nv_falcon_probe() matches on
+# vendor, PCI class, and PMC_BOOT_0 rather than PCI device ID.
+readonly DEVICES=(
+	"8086:0b25,Intel DSA SPR,dsa"
+	"8086:11fb,Intel DSA GNR-D,dsa"
+	"8086:1212,Intel DSA DMR,dsa"
+	"8086:2021,Intel IOAT SKX,ioat"
+	"8086:10c9,Intel 82576 Gigabit Ethernet Controller,igb"
+	"15b3:1011,Mellanox Connect-IB,mlx5"
+	"15b3:1012,Mellanox Connect-IB VF,mlx5"
+	"15b3:1013,Mellanox ConnectX-4,mlx5"
+	"15b3:1014,Mellanox ConnectX-4 VF,mlx5"
+	"15b3:1015,Mellanox ConnectX-4LX,mlx5"
+	"15b3:1016,Mellanox ConnectX-4LX VF,mlx5"
+	"15b3:1017,Mellanox ConnectX-5,mlx5"
+	"15b3:1018,Mellanox ConnectX-5 VF,mlx5"
+	"15b3:1019,Mellanox ConnectX-5 Ex,mlx5"
+	"15b3:101a,Mellanox ConnectX-5 Ex VF,mlx5"
+	"15b3:101b,Mellanox ConnectX-6,mlx5"
+	"15b3:101c,Mellanox ConnectX-6 VF,mlx5"
+	"15b3:101d,Mellanox ConnectX-6 Dx,mlx5"
+	"15b3:101e,Mellanox ConnectX-6 Dx VF,mlx5"
+	"15b3:101f,Mellanox ConnectX-6 LX,mlx5"
+	"15b3:1021,Mellanox ConnectX-7,mlx5"
+	"15b3:1023,Mellanox ConnectX-8,mlx5"
+	"15b3:1025,Mellanox ConnectX-9,mlx5"
+	"15b3:1027,Mellanox ConnectX-10,mlx5"
+	"15b3:2101,Mellanox ConnectX-10 NVLink-C2C,mlx5"
+	"15b3:a2d2,Mellanox BlueField integrated ConnectX-5,mlx5"
+	"15b3:a2d3,Mellanox BlueField integrated ConnectX-5 VF,mlx5"
+	"15b3:a2d6,Mellanox BlueField-2 integrated ConnectX-6 Dx,mlx5"
+	"15b3:a2dc,Mellanox BlueField-3 integrated ConnectX-7,mlx5"
+	"15b3:a2df,Mellanox BlueField-4 integrated ConnectX-8,mlx5"
+)
+
+# Devices in DEVICES that are also on the vfio-pci denylist. The denylist is
+# in vfio_pci_dev_in_denylist() in drivers/vfio/pci/vfio_pci.c.
+readonly DENYLIST=(
+	"8086:0b25"
+)
+
+readonly DISABLE_DENYLIST=/sys/module/vfio_pci/parameters/disable_denylist
+readonly VFIO_PCI_DRIVER=/sys/bus/pci/drivers/vfio-pci
+readonly PCI_VENDOR_ID_NVIDIA=10de
+readonly PCI_BASE_CLASS_DISPLAY=3
+
+function is_vfio_pci_loaded() {
+	[ -d "${VFIO_PCI_DRIVER}" ]
+}
+
+function is_denylisted() {
+	local id
+
+	for id in "${DENYLIST[@]}"; do
+		[ "${id}" = "${1}" ] && return 0
+	done
+
+	return 1
+}
+
+function is_denylist_enforced() {
+	local value
+
+	read -r value 2>/dev/null < "${DISABLE_DENYLIST}"
+	[ "${value}" != "Y" ]
+}
+
+function is_blocked() {
+	if ! is_vfio_pci_loaded; then
+		return 0
+	fi
+
+	is_denylisted "${1}" && is_denylist_enforced
+}
+
+function is_nv_gpu() {
+	local bdf="${1}"
+	local id="${2}"
+	local class
+
+	if [[ "${id}" != "${PCI_VENDOR_ID_NVIDIA}:"* ]]; then
+		return 1
+	fi
+
+	read -r class < "/sys/bus/pci/devices/${bdf}/class"
+	[ $((class >> 16)) -eq ${PCI_BASE_CLASS_DISPLAY} ]
+}
+
+function device_entry() {
+	local bdf="${1}"
+	local id="${2}"
+	local entry
+
+	for entry in "${DEVICES[@]}"; do
+		if [ "${entry%%,*}" = "${id}" ]; then
+			echo "${entry#*,}"
+			return 0
+		fi
+	done
+
+	if is_nv_gpu "${bdf}" "${id}"; then
+		echo "NVIDIA GPU,nv_falcon"
+		return 0
+	fi
+
+	return 1
+}
+
+printed=""
+
+function print_section() {
+	local header="${1}"
+	local device
+
+	shift
+	if [ $# -eq 0 ]; then
+		return 1
+	fi
+
+	[ "${printed}" ] && echo
+	printed="true"
+
+	echo "${header}"
+	for device in "$@"; do
+		echo "  ${device}"
+	done
+}
+
+# Keep in sync with nv_gpu_arch_lookup() in
+# tools/testing/selftests/vfio/lib/drivers/nv_falcon/nv_falcon.c.
+function print_nv_falcon_note() {
+	echo
+	echo "  nv_falcon supports Kepler, Maxwell, Pascal, Volta, Turing, Ampere,"
+	echo "  Ada, and Hopper GPUs. It does not support send_msi() and will skip"
+	echo "  tests that try to send MSIs."
+}
+
+function print_denylist_note() {
+	echo
+	echo "  To use denylisted devices, load vfio-pci with disable_denylist=1"
+	echo "  (or boot the kernel with vfio_pci.disable_denylist=1)."
+}
+
+function usage() {
+	echo "Usage: $0 [-q] [-a]" >&2
+	echo >&2
+	echo "Options:" >&2
+	echo "  -q  Print only the PCI addresses of usable devices." >&2
+	echo "  -a  Include unusable devices when used with -q." >&2
+	exit 1
+}
+
+function main() {
+	local denylisted_devices=()
+	local allowed_devices=()
+	local nv_gpus=()
+	local quiet=""
+	local all=""
+	local vendor
+	local driver
+	local device
+	local entry
+	local line
+	local name
+	local bdf
+	local opt
+	local id
+
+	while getopts "qa" opt; do
+		case "${opt}" in
+			q) quiet="true" ;;
+			a) all="true" ;;
+			\?) usage ;;
+		esac
+	done
+
+	if [ "${all}" ] && [ -z "${quiet}" ]; then
+		usage
+	fi
+
+	for bdf in $(ls /sys/bus/pci/devices); do
+		read -r vendor < "/sys/bus/pci/devices/${bdf}/vendor"
+		read -r device < "/sys/bus/pci/devices/${bdf}/device"
+		printf -v id "%04x:%04x" "${vendor}" "${device}"
+
+		entry=$(device_entry "${bdf}" "${id}") || continue
+
+		if [ "${quiet}" ]; then
+			if [ "${all}" ] || ! is_blocked "${id}"; then
+				echo "${bdf}"
+			fi
+			continue
+		fi
+
+		IFS=',' read -r name driver <<< "${entry}"
+		line="${bdf} - ${name} [${id}] - lib/drivers/${driver}/${driver}.c"
+		if is_denylisted "${id}"; then
+			denylisted_devices+=("${line}")
+		elif [ "${driver}" = "nv_falcon" ]; then
+			nv_gpus+=("${line}")
+		else
+			allowed_devices+=("${line}")
+		fi
+	done
+
+	if [ "${quiet}" ]; then
+		return 0
+	fi
+
+	if is_vfio_pci_loaded; then
+		print_section "Supported:" "${allowed_devices[@]}"
+
+		if ! is_denylist_enforced; then
+			print_section "Supported (on denylist, but denylist disabled):" \
+				"${denylisted_devices[@]}"
+		fi
+
+		if print_section "Possibly supported (depends on GPU architecture):" \
+				"${nv_gpus[@]}"; then
+			print_nv_falcon_note
+		fi
+
+		if is_denylist_enforced && \
+		   print_section "Unusable (available, but denylisted by the kernel):" \
+				 "${denylisted_devices[@]}"; then
+			print_denylist_note
+		fi
+	else
+		if print_section "Unusable (available, but vfio-pci not loaded):" \
+				"${allowed_devices[@]}" "${nv_gpus[@]}" && \
+		   [ ${#nv_gpus[@]} -gt 0 ]; then
+			print_nv_falcon_note
+		fi
+
+		if print_section \
+			"Unusable (available, but vfio-pci not loaded, and denylisted by the kernel):" \
+			"${denylisted_devices[@]}"; then
+			print_denylist_note
+		fi
+	fi
+
+	if [ -z "${printed}" ]; then
+		echo "No devices with a VFIO selftest driver found." >&2
+	fi
+}
+
+main "$@"
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v9] vfio: selftests: Find devices that have VFIO selftest drivers
  2026-11-20  1:25 [PATCH v9] vfio: selftests: Find devices that have VFIO selftest drivers Josh Hilke
@ 2026-11-20 18:14 ` Sean Christopherson
  2026-11-25 19:12 ` David Matlack
  1 sibling, 0 replies; 3+ messages in thread
From: Sean Christopherson @ 2026-11-20 18:14 UTC (permalink / raw)
  To: Josh Hilke
  Cc: Alex Williamson, David Matlack, kvm, linux-kernel, Vipin Sharma

On Fri, Nov 20, 2026, Josh Hilke wrote:
> Add list_supported_devices.sh to print the PCI addresses, names, and
> selftest driver paths of devices on the host that have a VFIO selftest
> driver. Group the output into sections based on whether vfio-pci is
> loaded, whether the vfio-pci denylist blocks the device, and whether a
> GPU requires an architecture check at probe time.

...

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

Output LGTM, but I'm most definitely not going to try and understand the bash
magic :-)

Thanks for enduring, much appreciated!

Tested-by: Sean Christopherson <seanjc@google.com>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v9] vfio: selftests: Find devices that have VFIO selftest drivers
  2026-11-20  1:25 [PATCH v9] vfio: selftests: Find devices that have VFIO selftest drivers Josh Hilke
  2026-11-20 18:14 ` Sean Christopherson
@ 2026-11-25 19:12 ` David Matlack
  1 sibling, 0 replies; 3+ messages in thread
From: David Matlack @ 2026-11-25 19:12 UTC (permalink / raw)
  To: Josh Hilke, Alex Williamson
  Cc: David Matlack, kvm, linux-kernel, Sean Christopherson, Vipin Sharma

On Thu Nov 19, 2026 at 5:25 PM PST, Josh Hilke wrote:
> 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.

Feeding the output straight into setup.sh worries me a bit. -q prints
every matching device, including ones the host is actively using, e.g.
the ConnectX NIC carrying the host's network connection or the GPU
driving the display. And once the NVMe driver lands, that could include
the boot disk. setup.sh will happily unbind all of them.

I don't think list_supported_devices.sh should try to filter these out,
but it should at least show the user what each device is currently bound
to (see below). The real protection belongs in setup.sh, since that's
the script that actually unbinds devices, regardless of how the user
picked the BDF. Please add a patch before this one that makes setup.sh
refuse to set up a device that is bound to a driver (other than
vfio-pci) unless -f is passed, e.g.

  $ ./setup.sh 0000:00:04.0
  0000:00:04.0 is bound to ioatdma, pass -f to unbind it.

Devices that are unbound or already bound to vfio-pci should not
require -f.

[...]

> +# Devices that have a driver in selftests/vfio/lib/drivers. NVIDIA GPUs are
> +# matched separately in is_nv_gpu() because nv_falcon_probe() matches on
> +# vendor, PCI class, and PMC_BOOT_0 rather than PCI device ID.
> +readonly DEVICES=(

Please add a comment that this list must be kept in sync with the probe()
routines in lib/drivers/, similar to what you did for
print_nv_falcon_note(). Otherwise the next device ID added to e.g.
mlx5.c is going to get missed here.

> +# Devices in DEVICES that are also on the vfio-pci denylist. The denylist is
> +# in vfio_pci_dev_in_denylist() in drivers/vfio/pci/vfio_pci.c.

Same here, s/The denylist is in/Keep in sync with/.

[...]

> +function print_denylist_note() {
> +	echo
> +	echo "  To use denylisted devices, load vfio-pci with disable_denylist=1"
> +	echo "  (or boot the kernel with vfio_pci.disable_denylist=1)."
> +}

The script checks for "Y" when reading disable_denylist, so please use
disable_denylist=Y here too, to keep things consistent.

[...]

> +	while getopts "qa" opt; do
> +		case "${opt}" in
> +			q) quiet="true" ;;
> +			a) all="true" ;;
> +			\?) usage ;;
> +		esac
> +	done

Please add a -h option to print the usage. Right now -h works by
accident, but getopts prints a confusing "illegal option -- h" first.
-h should also exit 0, since asking for help isn't an error.

[...]

> +		IFS=',' read -r name driver <<< "${entry}"
> +		line="${bdf} - ${name} [${id}] - lib/drivers/${driver}/${driver}.c"

Please also print the kernel driver the device is currently bound to (if
any), so users can see at a glance which devices are in use by the host
before handing them to setup.sh. e.g.

  Supported:
    0000:00:04.0 - Intel IOAT SKX [8086:2021] - lib/drivers/ioat/ioat.c (bound to ioatdma)
    0000:00:04.1 - Intel IOAT SKX [8086:2021] - lib/drivers/ioat/ioat.c (bound to vfio-pci)
    0000:00:04.2 - Intel IOAT SKX [8086:2021] - lib/drivers/ioat/ioat.c (unbound)

Please source lib.sh and use get_driver() for this rather than
open-coding it, like the other scripts do.

Note that "driver" is already used in this script to refer to the
selftest driver, so you'll want a different name for the kernel driver
variable.

[...]

> +	if [ -z "${printed}" ]; then
> +		echo "No devices with a VFIO selftest driver found." >&2
> +	fi
> +}

Please print this with -q as well, since the message goes to stderr
anyway and won't get mixed in with the BDFs. Right now -q silently
prints nothing, e.g. when vfio-pci isn't loaded, which leaves the user
guessing.

And in both cases the script should exit with a non-zero status when it
doesn't find any devices, so callers can tell the difference. This
should include the case where devices are found but none of them are
usable (e.g. -q without -a when vfio-pci isn't loaded or the devices
are all denylisted), since -q prints nothing in that case either.

Lastly, please update Documentation/driver-api/vfio-selftests.rst. The
"Picking a Device" section says it "will be expanded in the future to
guide developers on how to find a device with a supported driver", which
is exactly what this script does. Please describe the script there, and
update the "Setting up Devices" section to cover the new -f option for
setup.sh.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-11-25 19:12 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-20  1:25 [PATCH v9] vfio: selftests: Find devices that have VFIO selftest drivers Josh Hilke
2026-11-20 18:14 ` Sean Christopherson
2026-11-25 19:12 ` David Matlack

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®