All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v11 0/2] vfio: selftests: Find supported devices for testing
@ 2026-12-03 23:01 Josh Hilke
  2026-12-03 23:01 ` [PATCH v11 1/2] vfio: selftests: Require -f in setup.sh to unbind a bound device Josh Hilke
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Josh Hilke @ 2026-12-03 23:01 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Josh Hilke, David Matlack, kvm, linux-kernel, Sean Christopherson,
	Vipin Sharma

One last patchset to address a nit from David about verbiage. See
changelog for details. Thanks Sean and David for the reviews!

Changelog

v10 -> v11:
- Print "No usable devices found (run without -q for details)" when -q
  is passed without -a and no usable devices exist, instead of
  "No devices with a VFIO selftest driver found.".

v9 -> v10:
- Add patch 1 to require -f in setup.sh before unbinding a device bound
  to a driver other than vfio-pci, and add -h.
- Print the current kernel driver binding via lib.sh get_driver() on
  each device line in list_supported_devices.sh.
- Print "No devices with a VFIO selftest driver found." to stderr and
  exit non-zero when no devices are printed, including under -q.
- Add -h to list_supported_devices.sh to print usage and exit 0.
- Use disable_denylist=Y in print_denylist_note() to match
  is_denylist_enforced() and vfio-selftests.rst.
- Add "Keep in sync with" comments on DEVICES and DENYLIST.
- Refactor list_supported_devices.sh main() into format_device_line(),
  scan_devices(), and print_devices().
- Document setup.sh -f and list_supported_devices.sh in
  Documentation/driver-api/vfio-selftests.rst.

v10: https://lore.kernel.org/kvm/20261201170849.296378-1-jrhilke@google.com/
v9: https://lore.kernel.org/kvm/20261120012553.3745742-1-jrhilke@google.com/
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/

Josh Hilke (2):
  vfio: selftests: Require -f in setup.sh to unbind a bound device
  vfio: selftests: Find devices that have VFIO selftest drivers

 Documentation/driver-api/vfio-selftests.rst   |  25 +-
 tools/testing/selftests/vfio/Makefile         |   1 +
 .../vfio/scripts/list_supported_devices.sh    | 310 ++++++++++++++++++
 tools/testing/selftests/vfio/scripts/setup.sh |  41 ++-
 4 files changed, 367 insertions(+), 10 deletions(-)
 create mode 100755 tools/testing/selftests/vfio/scripts/list_supported_devices.sh


base-commit: 076d7e989cb69f6ded7d60f2a080eb909930061b
-- 
2.56.1.915.g69d5ec7298-goog


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

* [PATCH v11 1/2] vfio: selftests: Require -f in setup.sh to unbind a bound device
  2026-12-03 23:01 [PATCH v11 0/2] vfio: selftests: Find supported devices for testing Josh Hilke
@ 2026-12-03 23:01 ` Josh Hilke
  2026-12-03 23:01 ` [PATCH v11 2/2] vfio: selftests: Find devices that have VFIO selftest drivers Josh Hilke
  2026-12-04 23:24 ` [PATCH v11 0/2] vfio: selftests: Find supported devices for testing David Matlack
  2 siblings, 0 replies; 5+ messages in thread
From: Josh Hilke @ 2026-12-03 23:01 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Josh Hilke, David Matlack, kvm, linux-kernel, Sean Christopherson,
	Vipin Sharma

Make setup.sh refuse to set up a device that is currently bound to a
driver other than vfio-pci unless -f is passed. Devices that are unbound
or already bound to vfio-pci do not require -f.

Validate all device arguments before modifying any device so a refused
device does not leave partial state behind.

Also add -h to print usage and exit 0, and document -f in
Documentation/driver-api/vfio-selftests.rst.

Suggested-by: David Matlack <dmatlack@google.com>
Signed-off-by: Josh Hilke <jrhilke@google.com>
---
 Documentation/driver-api/vfio-selftests.rst   |  9 ++--
 tools/testing/selftests/vfio/scripts/setup.sh | 41 +++++++++++++++++--
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/Documentation/driver-api/vfio-selftests.rst b/Documentation/driver-api/vfio-selftests.rst
index 9d39a22519d6..cfe7a3a06602 100644
--- a/Documentation/driver-api/vfio-selftests.rst
+++ b/Documentation/driver-api/vfio-selftests.rst
@@ -48,12 +48,13 @@ Setting up Devices
 
 .. code-block:: sh
 
-    tools/testing/selftests/vfio/scripts/setup.sh 0000:01:00.0
+    tools/testing/selftests/vfio/scripts/setup.sh [-f] 0000:01:00.0
 
 The script handles unbinding the device from its current driver and binding it
-to ``vfio-pci``. Metadata about this device is stored in
-``/tmp/vfio-selftests-devices`` so that the device can be cleaned up later
-(bound back to its original driver).
+to ``vfio-pci``. If a device is currently bound to a driver other than
+``vfio-pci``, ``setup.sh`` refuses to unbind it unless ``-f`` is passed.
+Metadata about this device is stored in ``/tmp/vfio-selftests-devices`` so that
+the device can be cleaned up later (bound back to its original driver).
 
 Execution
 ---------
diff --git a/tools/testing/selftests/vfio/scripts/setup.sh b/tools/testing/selftests/vfio/scripts/setup.sh
index 49a499e51cbe..7eacd301f0c7 100755
--- a/tools/testing/selftests/vfio/scripts/setup.sh
+++ b/tools/testing/selftests/vfio/scripts/setup.sh
@@ -3,20 +3,55 @@ set -e
 
 source $(dirname -- "${BASH_SOURCE[0]}")/lib.sh
 
+function usage() {
+	cat >&2 <<EOF
+Usage: $0 [-f] [-h] segment:bus:device.function ...
+
+Options:
+  -f  Unbind devices that are currently bound to a driver other than vfio-pci.
+  -h  Print this help message.
+EOF
+}
+
 function main() {
+	local device_bdfs=()
 	local device_bdf
 	local device_dir
+	local force=""
 	local numvfs
 	local driver
+	local opt
 
-	if [ $# = 0 ]; then
-		echo "usage: $0 segment:bus:device.function ..." >&2
+	while getopts "fh" opt; do
+		case "${opt}" in
+		f) force="true" ;;
+		h) usage; exit 0 ;;
+		*) usage; exit 1 ;;
+		esac
+	done
+	shift $((OPTIND - 1))
+
+	device_bdfs=("$@")
+	if [ ${#device_bdfs[@]} -eq 0 ]; then
+		usage
 		exit 1
 	fi
 
-	for device_bdf in "$@"; do
+	for device_bdf in "${device_bdfs[@]}"; do
 		test -d /sys/bus/pci/devices/${device_bdf}
 
+		if [ "${force}" ]; then
+			continue
+		fi
+
+		driver=$(get_driver ${device_bdf})
+		if [ "${driver}" ] && [ "${driver}" != "vfio-pci" ]; then
+			echo "${device_bdf} is bound to ${driver}, pass -f to unbind it." >&2
+			exit 1
+		fi
+	done
+
+	for device_bdf in "${device_bdfs[@]}"; do
 		device_dir=${DEVICES_DIR}/${device_bdf}
 		if [ -d "${device_dir}" ]; then
 			echo "${device_bdf} has already been set up, exiting."
-- 
2.56.1.915.g69d5ec7298-goog


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

* [PATCH v11 2/2] vfio: selftests: Find devices that have VFIO selftest drivers
  2026-12-03 23:01 [PATCH v11 0/2] vfio: selftests: Find supported devices for testing Josh Hilke
  2026-12-03 23:01 ` [PATCH v11 1/2] vfio: selftests: Require -f in setup.sh to unbind a bound device Josh Hilke
@ 2026-12-03 23:01 ` Josh Hilke
  2026-12-03 23:14   ` sashiko-bot
  2026-12-04 23:24 ` [PATCH v11 0/2] vfio: selftests: Find supported devices for testing David Matlack
  2 siblings, 1 reply; 5+ messages in thread
From: Josh Hilke @ 2026-12-03 23:01 UTC (permalink / raw)
  To: Alex Williamson
  Cc: Josh Hilke, David Matlack, kvm, linux-kernel, Sean Christopherson,
	Vipin Sharma

Add list_supported_devices.sh to print the PCI addresses, names,
selftest driver paths, and current kernel driver bindings 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 scripts can
consume them or pass them to setup.sh, -a for use with -q to include
unusable devices as well, and -h to print usage and exit 0. Print a
message to stderr and exit non-zero when no devices are printed.

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.

Document list_supported_devices.sh in
Documentation/driver-api/vfio-selftests.rst.

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 (bound to ioatdma)
  ...

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

  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 (bound to idxd)
  ...

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

$ ./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>
---
 Documentation/driver-api/vfio-selftests.rst   |  16 +-
 tools/testing/selftests/vfio/Makefile         |   1 +
 .../vfio/scripts/list_supported_devices.sh    | 310 ++++++++++++++++++
 3 files changed, 324 insertions(+), 3 deletions(-)
 create mode 100755 tools/testing/selftests/vfio/scripts/list_supported_devices.sh

diff --git a/Documentation/driver-api/vfio-selftests.rst b/Documentation/driver-api/vfio-selftests.rst
index cfe7a3a06602..06e1e70f4416 100644
--- a/Documentation/driver-api/vfio-selftests.rst
+++ b/Documentation/driver-api/vfio-selftests.rst
@@ -31,9 +31,19 @@ Some VFIO selftests require a device with a supported driver implementation in
 the selftests library (see `Driver Framework`_), while other tests (such as
 basic PCI configuration space or reset tests) can use any arbitrary PCI device.
 
-This section will be expanded in the future to guide developers on how to find
-a device with a supported driver. In the meantime, the selftests library
-includes driver support for the following devices:
+Run ``list_supported_devices.sh`` to find devices on the host that have a
+supported selftest driver:
+
+.. code-block:: sh
+
+    tools/testing/selftests/vfio/scripts/list_supported_devices.sh
+
+The script prints each matching device's PCI address, name, selftest driver
+path, and current kernel driver binding, grouped by whether the device can be
+used with ``vfio-pci``. Pass ``-q`` to print only the PCI addresses of usable
+devices, or ``-q -a`` to include unusable devices.
+
+The selftests library includes driver support for the following devices:
 
 - Intel IGB Gigabit Ethernet controllers
 - Intel IOAT (I/O Acceleration Technology) DMA engines
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..3a3ae152dfce
--- /dev/null
+++ b/tools/testing/selftests/vfio/scripts/list_supported_devices.sh
@@ -0,0 +1,310 @@
+#!/bin/bash
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+source $(dirname -- "${BASH_SOURCE[0]}")/lib.sh
+
+# Devices that have a driver in tools/testing/selftests/vfio/lib/drivers/.
+# Keep in sync with the probe() routines in that directory. 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. Keep in sync with
+# 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 print_device_name_and_driver() {
+	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
+}
+
+denylisted_devices=()
+allowed_devices=()
+quiet_devices=()
+nv_gpus=()
+section_printed=""
+
+# Print a section header and indented device lines.
+# ${1}: Section header text.
+# ${2}...: Formatted device lines to print under the header.
+# Return 0 if at least one device line was printed. Return 1 otherwise.
+function print_section() {
+	local header="${1}"
+	local device
+
+	shift
+	if [ $# -eq 0 ]; then
+		return 1
+	fi
+
+	[ "${section_printed}" ] && echo
+	section_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=Y"
+	echo "  (or boot the kernel with vfio_pci.disable_denylist=Y)."
+}
+
+function usage() {
+	cat >&2 <<EOF
+Usage: $0 [-q] [-a] [-h]
+
+Options:
+  -q  Print only the PCI addresses of usable devices.
+  -a  Include unusable devices when used with -q.
+  -h  Print this help message.
+EOF
+}
+
+function format_device_line() {
+	local current_driver
+	local driver="${4}"
+	local name="${3}"
+	local bdf="${1}"
+	local id="${2}"
+	local binding
+
+	current_driver=$(get_driver "${bdf}")
+	if [ "${current_driver}" ]; then
+		binding="bound to ${current_driver}"
+	else
+		binding="unbound"
+	fi
+
+	echo "${bdf} - ${name} [${id}] - lib/drivers/${driver}/${driver}.c (${binding})"
+}
+
+# Scan /sys/bus/pci/devices for supported devices. Populate quiet_devices in
+# quiet mode, or allowed_devices, nv_gpus, and denylisted_devices otherwise.
+# ${1}: Non-empty to enable quiet mode.
+# ${2}: Non-empty to include unusable devices in quiet mode.
+function scan_devices() {
+	local quiet="${1}"
+	local all="${2}"
+	local vendor
+	local driver
+	local device
+	local entry
+	local line
+	local name
+	local bdf
+	local id
+
+	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=$(print_device_name_and_driver "${bdf}" "${id}") || continue
+
+		if [ "${quiet}" ]; then
+			if [ "${all}" ] || ! is_blocked "${id}"; then
+				quiet_devices+=("${bdf}")
+			fi
+			continue
+		fi
+
+		IFS=',' read -r name driver <<< "${entry}"
+		line=$(format_device_line "${bdf}" "${id}" "${name}" "${driver}")
+		if is_denylisted "${id}"; then
+			denylisted_devices+=("${line}")
+		elif [ "${driver}" = "nv_falcon" ]; then
+			nv_gpus+=("${line}")
+		else
+			allowed_devices+=("${line}")
+		fi
+	done
+}
+
+function print_devices() {
+	if ! is_vfio_pci_loaded; then
+		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
+		return
+	fi
+
+	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
+}
+
+function main() {
+	local printed=""
+	local quiet=""
+	local all=""
+	local bdf
+	local opt
+
+	while getopts "qah" opt; do
+		case "${opt}" in
+			q) quiet="true" ;;
+			a) all="true" ;;
+			h) usage; exit 0 ;;
+			\?) usage; exit 1 ;;
+		esac
+	done
+
+	if [ "${all}" ] && [ -z "${quiet}" ]; then
+		usage
+		exit 1
+	fi
+
+	scan_devices "${quiet}" "${all}"
+
+	if [ "${quiet}" ]; then
+		for bdf in "${quiet_devices[@]}"; do
+			echo "${bdf}"
+			printed="true"
+		done
+	elif [ ${#allowed_devices[@]} -gt 0 ] || \
+	     [ ${#nv_gpus[@]} -gt 0 ] || \
+	     [ ${#denylisted_devices[@]} -gt 0 ]; then
+		print_devices
+		printed="true"
+	fi
+
+	if [ -z "${printed}" ]; then
+		if [ "${quiet}" ] && [ -z "${all}" ]; then
+			echo "No usable devices found (run without -q for details)" >&2
+		else
+			echo "No devices with a VFIO selftest driver found." >&2
+		fi
+		return 1
+	fi
+}
+
+main "$@"
-- 
2.56.1.915.g69d5ec7298-goog


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

* Re: [PATCH v11 2/2] vfio: selftests: Find devices that have VFIO selftest drivers
  2026-12-03 23:01 ` [PATCH v11 2/2] vfio: selftests: Find devices that have VFIO selftest drivers Josh Hilke
@ 2026-12-03 23:14   ` sashiko-bot
  0 siblings, 0 replies; 5+ messages in thread
From: sashiko-bot @ 2026-12-03 23:14 UTC (permalink / raw)
  To: Josh Hilke; +Cc: kvm

Thank you for your contribution! Sashiko AI review found 3 potential
issues to consider:
- [Low] vfio: selftests: main() does not reject unexpected positional
  arguments
- [Low] vfio: selftests: unchecked sysfs reads reuse stale IDs in
  scan_devices()
- [Low] vfio: selftests: unquoted command substitution when sourcing
  lib.sh
--

commit 5433f70e41c5fa212afb1ca8022908cf6396102c
Author: Josh Hilke <jrhilke@google.com>

vfio: selftests: Find devices that have VFIO selftest drivers

This commit adds list_supported_devices.sh to scan /sys/bus/pci/devices for
devices supported by VFIO selftest drivers, installs it via the VFIO
selftests Makefile, and documents it in vfio-selftests.rst.

> 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 0000000000000..3a3ae152dfcec
> --- /dev/null
> +++ b/tools/testing/selftests/vfio/scripts/list_supported_devices.sh
> @@ -0,0 +1,310 @@
> +#!/bin/bash
> +# SPDX-License-Identifier: GPL-2.0-or-later
> +
> +source $(dirname -- "${BASH_SOURCE[0]}")/lib.sh

[Severity: Low]
Should this command substitution be quoted as
source "$(dirname -- "${BASH_SOURCE[0]}")/lib.sh"?

When the script lives in a path containing whitespace or glob characters,
word splitting or pathname expansion causes source to fail or load the wrong
file.  Because set -e is not enabled, execution continues and
format_device_line() calls the undefined get_driver helper, misreporting
bound devices as unbound.

[ ... ]

> +	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}"

[Severity: Low]
Can scan_devices() report a removed PCI device using the previous device's
vendor and device IDs?

If a device such as an SR-IOV VF disappears mid-scan, the unchecked input
redirection fails before read runs.  vendor and device then keep the prior
iteration's values, causing the vanished BDF to be falsely reported even in
-q output.

Checking the redirections with 2>/dev/null || continue avoids reusing stale
IDs.  Similarly, is_nv_gpu() performs an unchecked read on
/sys/bus/pci/devices/${bdf}/class that emits a raw shell error if the device
vanishes mid-scan.

[ ... ]

> +	while getopts "qah" opt; do
> +		case "${opt}" in
> +			q) quiet="true" ;;
> +			a) all="true" ;;
> +			h) usage; exit 0 ;;
> +			\?) usage; exit 1 ;;
> +		esac
> +	done
> +
> +	if [ "${all}" ] && [ -z "${quiet}" ]; then

[Severity: Low]
Does main() silently ignore unexpected positional arguments and any flags
that follow them?

getopts stops parsing at the first non-option argument, so invoking the
script with a BDF like "0000:00:04.0 -q" discards both arguments and prints
verbose output with exit status 0 instead of failing with usage().  Running
shift $((OPTIND - 1)) and rejecting $# -ne 0 would catch stray arguments.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261203230106.32033-1-jrhilke@google.com?part=2

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

* Re: [PATCH v11 0/2] vfio: selftests: Find supported devices for testing
  2026-12-03 23:01 [PATCH v11 0/2] vfio: selftests: Find supported devices for testing Josh Hilke
  2026-12-03 23:01 ` [PATCH v11 1/2] vfio: selftests: Require -f in setup.sh to unbind a bound device Josh Hilke
  2026-12-03 23:01 ` [PATCH v11 2/2] vfio: selftests: Find devices that have VFIO selftest drivers Josh Hilke
@ 2026-12-04 23:24 ` David Matlack
  2 siblings, 0 replies; 5+ messages in thread
From: David Matlack @ 2026-12-04 23:24 UTC (permalink / raw)
  To: Josh Hilke, Alex Williamson
  Cc: David Matlack, kvm, linux-kernel, Sean Christopherson,
	Vipin Sharma

On Thu Dec 3, 2026 at 3:01 PM PST, Josh Hilke wrote:
> One last patchset to address a nit from David about verbiage. See
> changelog for details. Thanks Sean and David for the reviews!
>
> Changelog
>
> v10 -> v11:
> - Print "No usable devices found (run without -q for details)" when -q
>   is passed without -a and no usable devices exist, instead of
>   "No devices with a VFIO selftest driver found.".
>
> Josh Hilke (2):
>   vfio: selftests: Require -f in setup.sh to unbind a bound device
>   vfio: selftests: Find devices that have VFIO selftest drivers

Reviewed-by: David Matlack <dmatlack@google.com>

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

end of thread, other threads:[~2026-12-04 23:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-03 23:01 [PATCH v11 0/2] vfio: selftests: Find supported devices for testing Josh Hilke
2026-12-03 23:01 ` [PATCH v11 1/2] vfio: selftests: Require -f in setup.sh to unbind a bound device Josh Hilke
2026-12-03 23:01 ` [PATCH v11 2/2] vfio: selftests: Find devices that have VFIO selftest drivers Josh Hilke
2026-12-03 23:14   ` sashiko-bot
2026-12-04 23:24 ` [PATCH v11 0/2] vfio: selftests: Find supported devices for testing David Matlack

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.