* [PATCH 0/2] vfio: selftests: Automate finding/setting up devices for testing
@ 2026-04-09 1:51 Josh Hilke
2026-04-09 1:51 ` [PATCH 1/2] vfio: selftests: Find devices that are compatible with VFIO selftests Josh Hilke
2026-04-09 1:51 ` [PATCH 2/2] vfio: selftests: Automate setting up devices for testing Josh Hilke
0 siblings, 2 replies; 6+ messages in thread
From: Josh Hilke @ 2026-04-09 1:51 UTC (permalink / raw)
To: Alex Williamson
Cc: David Matlack, Vipin Sharma, Raghavendra Rao Ananta, kvm,
linux-kernel, Josh Hilke
This series introduces two improvements to make setting up devices for VFIO
selftests more user-friendly.
1. Add functionality to the VFIO selftest setup script to find devices on a
user's system that are compatible with the VFIO selftest framework (i.e. devices
that have a VFIO selftest driver).
Example:
$ ./tools/testing/selftests/vfio/scripts/setup.sh -l
Supported devices:
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
2. Modify the VFIO selftest setup script to try to find and set up a compatible
device automatically. "Set up the device for testing" means unbind the device
from its driver, then bind it to VFIO. The user is no longer required to find a
segment:bus:device.function number to pass to the script (though this
functionality is still available through a -d option).
Example of automated device setup:
$ ./tools/testing/selftests/vfio/scripts/setup.sh
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/idxd/unbind
+ echo "vfio-pci" > /sys/bus/pci/devices/0000:6a:01.0/driver_override
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/vfio-pci/bind
Successfully set up 0000:6a:01.0
Example of manual device setup:
$ ./tools/testing/selftests/vfio/scripts/setup.sh -d 0000:6a:01.0
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/idxd/unbind
+ echo "vfio-pci" > /sys/bus/pci/devices/0000:6a:01.0/driver_override
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/vfio-pci/bind
Successfully set up 0000:6a:01.0
Josh Hilke (2):
vfio: selftests: Find devices that are compatible with VFIO selftests
vfio: selftests: Automate finding/setting up devices for testing
tools/testing/selftests/vfio/scripts/setup.sh | 63 +++++++++++++++++--
1 file changed, 59 insertions(+), 4 deletions(-)
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply [flat|nested] 6+ messages in thread* [PATCH 1/2] vfio: selftests: Find devices that are compatible with VFIO selftests
2026-04-09 1:51 [PATCH 0/2] vfio: selftests: Automate finding/setting up devices for testing Josh Hilke
@ 2026-04-09 1:51 ` Josh Hilke
2026-04-10 22:40 ` David Matlack
2026-04-09 1:51 ` [PATCH 2/2] vfio: selftests: Automate setting up devices for testing Josh Hilke
1 sibling, 1 reply; 6+ messages in thread
From: Josh Hilke @ 2026-04-09 1:51 UTC (permalink / raw)
To: Alex Williamson
Cc: David Matlack, Vipin Sharma, Raghavendra Rao Ananta, kvm,
linux-kernel, Josh Hilke
Update the VFIO selftest setup script to print the segment:bus:device.function
numbers of devices on the user's system that have VFIO selftest drivers (i.e.
are compatible with the VFIO selftest infrastructure). This makes it easy for
users to quickly find devices that are compatible with VFIO selftests.
Example of how to list compatible devices on the system:
$ ./tools/testing/selftests/vfio/scripts/setup.sh -l
Supported devices:
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
Example of setting up a device:
$ ./tools/testing/selftests/vfio/scripts/setup.sh -d 0000:6a:01.0
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/idxd/unbind
+ echo "vfio-pci" > /sys/bus/pci/devices/0000:6a:01.0/driver_override
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/vfio-pci/bind
Successfully set up 0000:6a:01.0
This makes the script much more user friendly so that no one has to dig
around in the VFIO selftest libraries to figure out which devices can
run the selftests.
Signed-off-by: Josh Hilke <jrhilke@google.com>
---
tools/testing/selftests/vfio/scripts/setup.sh | 43 +++++++++++++++++--
1 file changed, 40 insertions(+), 3 deletions(-)
diff --git a/tools/testing/selftests/vfio/scripts/setup.sh b/tools/testing/selftests/vfio/scripts/setup.sh
index 49a499e51cbe..2cde07eb9c8b 100755
--- a/tools/testing/selftests/vfio/scripts/setup.sh
+++ b/tools/testing/selftests/vfio/scripts/setup.sh
@@ -3,18 +3,54 @@ set -e
source $(dirname -- "${BASH_SOURCE[0]}")/lib.sh
+# List of devices which have a VFIO selftest driver
+DEVICES=(
+ "8086:0b25" # Intel Data Streaming Accelerator
+ "8086:0cf8" # Intel CBDMA
+)
+
+function print_supported_devices() {
+ local vendor_device_id
+ local id
+
+ for vendor_device_id in "${DEVICES[@]}"; do
+ read -r id <<< "${vendor_device_id}"
+ lspci -D -d "${id}" | awk '{ print $1 }'
+ done
+}
+
+function usage() {
+ echo "usage: $0 [-l] [-d <segment:bus:device.function>]" >&2
+ echo "" >&2
+ echo " -l List segment:bus:device.function numbers of supported devices." >&2
+ echo " -d segment:bus:device.function to set up." >&2
+}
+
function main() {
local device_bdf
local device_dir
local numvfs
local driver
+ local bdf_list=()
+
+ while getopts "ld:" opt; do
+ case ${opt} in
+ l)
+ echo "Supported devices: "
+ print_supported_devices
+ exit 0
+ ;;
+ d) bdf_list+=("${OPTARG}") ;;
+ *) usage; exit 1 ;;
+ esac
+ done
- if [ $# = 0 ]; then
- echo "usage: $0 segment:bus:device.function ..." >&2
+ if [ ${#bdf_list[@]} -eq 0 ]; then
+ usage
exit 1
fi
- for device_bdf in "$@"; do
+ for device_bdf in "${bdf_list[@]}"; do
test -d /sys/bus/pci/devices/${device_bdf}
device_dir=${DEVICES_DIR}/${device_bdf}
@@ -42,6 +78,7 @@ function main() {
bind ${device_bdf} vfio-pci
touch ${device_dir}/vfio-pci
+ echo "Successfully set up ${device_bdf}"
done
}
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 1/2] vfio: selftests: Find devices that are compatible with VFIO selftests
2026-04-09 1:51 ` [PATCH 1/2] vfio: selftests: Find devices that are compatible with VFIO selftests Josh Hilke
@ 2026-04-10 22:40 ` David Matlack
0 siblings, 0 replies; 6+ messages in thread
From: David Matlack @ 2026-04-10 22:40 UTC (permalink / raw)
To: Josh Hilke
Cc: Alex Williamson, Vipin Sharma, Raghavendra Rao Ananta, kvm,
linux-kernel
On 2026-04-09 01:51 AM, Josh Hilke wrote:
> Update the VFIO selftest setup script to print the segment:bus:device.function
> numbers of devices on the user's system that have VFIO selftest drivers (i.e.
> are compatible with the VFIO selftest infrastructure). This makes it easy for
> users to quickly find devices that are compatible with VFIO selftests.
>
> Example of how to list compatible devices on the system:
>
> $ ./tools/testing/selftests/vfio/scripts/setup.sh -l
> Supported devices:
> 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
>
> Example of setting up a device:
>
> $ ./tools/testing/selftests/vfio/scripts/setup.sh -d 0000:6a:01.0
> + echo "0000:6a:01.0" > /sys/bus/pci/drivers/idxd/unbind
> + echo "vfio-pci" > /sys/bus/pci/devices/0000:6a:01.0/driver_override
> + echo "0000:6a:01.0" > /sys/bus/pci/drivers/vfio-pci/bind
> Successfully set up 0000:6a:01.0
>
> This makes the script much more user friendly so that no one has to dig
> around in the VFIO selftest libraries to figure out which devices can
> run the selftests.
>
> Signed-off-by: Josh Hilke <jrhilke@google.com>
> ---
> tools/testing/selftests/vfio/scripts/setup.sh | 43 +++++++++++++++++--
> 1 file changed, 40 insertions(+), 3 deletions(-)
>
> diff --git a/tools/testing/selftests/vfio/scripts/setup.sh b/tools/testing/selftests/vfio/scripts/setup.sh
> index 49a499e51cbe..2cde07eb9c8b 100755
> --- a/tools/testing/selftests/vfio/scripts/setup.sh
> +++ b/tools/testing/selftests/vfio/scripts/setup.sh
> @@ -3,18 +3,54 @@ set -e
>
> source $(dirname -- "${BASH_SOURCE[0]}")/lib.sh
>
> +# List of devices which have a VFIO selftest driver
> +DEVICES=(
> + "8086:0b25" # Intel Data Streaming Accelerator
Please also add the new DMR and GNR-D DSA devices that were added
recently:
https://github.com/awilliam/linux-vfio/commit/c82cfe15916d33e89c2d2efeeb624e8c9c2c4ca8
> + "8086:0cf8" # Intel CBDMA
> +)
> +
> +function print_supported_devices() {
> + local vendor_device_id
> + local id
> +
> + for vendor_device_id in "${DEVICES[@]}"; do
> + read -r id <<< "${vendor_device_id}"
Sashiko seems to think the read here is unecessary.
https://sashiko.dev/#/patchset/20260409015139.2800185-1-jrhilke%40google.com?part=1
> + lspci -D -d "${id}" | awk '{ print $1 }'
Let's print the whole line and let the user parse out the BDF with awk.
That will let the user see which type of device it its rather than just
raw BDFs.
> + done
> +}
> +
> +function usage() {
> + echo "usage: $0 [-l] [-d <segment:bus:device.function>]" >&2
> + echo "" >&2
> + echo " -l List segment:bus:device.function numbers of supported devices." >&2
> + echo " -d segment:bus:device.function to set up." >&2
> +}
> +
> function main() {
> local device_bdf
> local device_dir
> local numvfs
> local driver
> + local bdf_list=()
> +
> + while getopts "ld:" opt; do
> + case ${opt} in
> + l)
> + echo "Supported devices: "
> + print_supported_devices
> + exit 0
> + ;;
nit: Put the echo in print_supported_devices and this can be a one-liner
like the rest of the options.
while getopts "ld:" opt; do
case ${opt} in
l) print_supported_devices; exit 0 ;;
d) bdf_list+=("${OPTARG}") ;;
*) usage; exit 1 ;;
esac
done
> + d) bdf_list+=("${OPTARG}") ;;
Let's keep the current semantics where the list of BDFs is passed as
positional arguments. The next commit would just pick a device if there
are no positional arguments.
This will keep the script backwards compatible with current usage and
also keep it simple (no need to pass extra -d flag for every BDF):
./setup.sh BDF1 BDF2 BDF3
vs.
./setup.sh -d BDF1 -d BDF2 -d BDF3
> + *) usage; exit 1 ;;
> + esac
> + done
>
> - if [ $# = 0 ]; then
> - echo "usage: $0 segment:bus:device.function ..." >&2
> + if [ ${#bdf_list[@]} -eq 0 ]; then
> + usage
> exit 1
> fi
>
> - for device_bdf in "$@"; do
> + for device_bdf in "${bdf_list[@]}"; do
> test -d /sys/bus/pci/devices/${device_bdf}
>
> device_dir=${DEVICES_DIR}/${device_bdf}
> @@ -42,6 +78,7 @@ function main() {
>
> bind ${device_bdf} vfio-pci
> touch ${device_dir}/vfio-pci
> + echo "Successfully set up ${device_bdf}"
> done
> }
>
> --
> 2.53.0.1213.gd9a14994de-goog
>
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 2/2] vfio: selftests: Automate setting up devices for testing
2026-04-09 1:51 [PATCH 0/2] vfio: selftests: Automate finding/setting up devices for testing Josh Hilke
2026-04-09 1:51 ` [PATCH 1/2] vfio: selftests: Find devices that are compatible with VFIO selftests Josh Hilke
@ 2026-04-09 1:51 ` Josh Hilke
2026-04-10 22:49 ` David Matlack
2026-04-10 22:54 ` David Matlack
1 sibling, 2 replies; 6+ messages in thread
From: Josh Hilke @ 2026-04-09 1:51 UTC (permalink / raw)
To: Alex Williamson
Cc: David Matlack, Vipin Sharma, Raghavendra Rao Ananta, kvm,
linux-kernel, Josh Hilke
Update the VFIO selftest setup script to find a device that has a VFIO selftest
driver on the system, and set it up (i.e unbind that device from its driver, and
then bind that device to VFIO).
This makes the process of setting up a device to VFIO selftests much easier, as
users don't have to manually figure out which device to use. Though, users can
still manually setup a device by passing the -d argument with a
segment:bus:device.function number.
Example of automated device setup:
$ ./tools/testing/selftests/vfio/scripts/setup.sh./setup.sh
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/idxd/unbind
+ echo "vfio-pci" > /sys/bus/pci/devices/0000:6a:01.0/driver_override
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/vfio-pci/bind
Successfully set up 0000:6a:01.0
Example of automated device setup where no compatible devices exist:
$ . ./tools/testing/selftests/vfio/scripts/setup.sh/setup.sh
No available supported devices found on the system.
Example of manual device setup:
$ ./tools/testing/selftests/vfio/scripts/setup.sh -d 0000:6a:01.0
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/idxd/unbind
+ echo "vfio-pci" > /sys/bus/pci/devices/0000:6a:01.0/driver_override
+ echo "0000:6a:01.0" > /sys/bus/pci/drivers/vfio-pci/bind
Successfully set up 0000:6a:01.0
Signed-off-by: Josh Hilke <jrhilke@google.com>
---
tools/testing/selftests/vfio/scripts/setup.sh | 22 +++++++++++++++++--
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/vfio/scripts/setup.sh b/tools/testing/selftests/vfio/scripts/setup.sh
index 2cde07eb9c8b..6d4492b211ea 100755
--- a/tools/testing/selftests/vfio/scripts/setup.sh
+++ b/tools/testing/selftests/vfio/scripts/setup.sh
@@ -19,11 +19,30 @@ function print_supported_devices() {
done
}
+function pick_device() {
+ local bdf
+
+ while read -r bdf; do
+ if [ -n "${bdf}" ]; then
+ if [ -d "${DEVICES_DIR}/${bdf}" ]; then
+ echo "${bdf} has already been set up, exiting." >&2
+ exit 0
+ fi
+ echo "${bdf}"
+ return 0
+ fi
+ done <<< "$(print_supported_devices)"
+
+ echo "No available supported devices found on the system." >&2
+ exit 1
+}
+
function usage() {
echo "usage: $0 [-l] [-d <segment:bus:device.function>]" >&2
echo "" >&2
echo " -l List segment:bus:device.function numbers of supported devices." >&2
echo " -d segment:bus:device.function to set up." >&2
+ echo " If -d is not specified, a device will be automatically picked." >&2
}
function main() {
@@ -46,8 +65,7 @@ function main() {
done
if [ ${#bdf_list[@]} -eq 0 ]; then
- usage
- exit 1
+ bdf_list=($(pick_device))
fi
for device_bdf in "${bdf_list[@]}"; do
--
2.53.0.1213.gd9a14994de-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH 2/2] vfio: selftests: Automate setting up devices for testing
2026-04-09 1:51 ` [PATCH 2/2] vfio: selftests: Automate setting up devices for testing Josh Hilke
@ 2026-04-10 22:49 ` David Matlack
2026-04-10 22:54 ` David Matlack
1 sibling, 0 replies; 6+ messages in thread
From: David Matlack @ 2026-04-10 22:49 UTC (permalink / raw)
To: Josh Hilke
Cc: Alex Williamson, Vipin Sharma, Raghavendra Rao Ananta, kvm,
linux-kernel, seanjc
On 2026-04-09 01:51 AM, Josh Hilke wrote:
> Update the VFIO selftest setup script to find a device that has a VFIO selftest
> driver on the system, and set it up (i.e unbind that device from its driver, and
> then bind that device to VFIO).
>
> This makes the process of setting up a device to VFIO selftests much easier, as
> users don't have to manually figure out which device to use. Though, users can
> still manually setup a device by passing the -d argument with a
> segment:bus:device.function number.
>
> Example of automated device setup:
>
> $ ./tools/testing/selftests/vfio/scripts/setup.sh./setup.sh
Script path here got garbled
> + echo "0000:6a:01.0" > /sys/bus/pci/drivers/idxd/unbind
> + echo "vfio-pci" > /sys/bus/pci/devices/0000:6a:01.0/driver_override
> + echo "0000:6a:01.0" > /sys/bus/pci/drivers/vfio-pci/bind
> Successfully set up 0000:6a:01.0
>
> Example of automated device setup where no compatible devices exist:
>
> $ . ./tools/testing/selftests/vfio/scripts/setup.sh/setup.sh
Here too, also the extra '.' before the path looks like a mistake.
> No available supported devices found on the system.
>
> Example of manual device setup:
>
> $ ./tools/testing/selftests/vfio/scripts/setup.sh -d 0000:6a:01.0
> + echo "0000:6a:01.0" > /sys/bus/pci/drivers/idxd/unbind
> + echo "vfio-pci" > /sys/bus/pci/devices/0000:6a:01.0/driver_override
> + echo "0000:6a:01.0" > /sys/bus/pci/drivers/vfio-pci/bind
> Successfully set up 0000:6a:01.0
>
> Signed-off-by: Josh Hilke <jrhilke@google.com>
Please add Suggested-by tag for Sean and also Cc Sean on next version
of the series :)
> ---
> tools/testing/selftests/vfio/scripts/setup.sh | 22 +++++++++++++++++--
> 1 file changed, 20 insertions(+), 2 deletions(-)
>
> diff --git a/tools/testing/selftests/vfio/scripts/setup.sh b/tools/testing/selftests/vfio/scripts/setup.sh
> index 2cde07eb9c8b..6d4492b211ea 100755
> --- a/tools/testing/selftests/vfio/scripts/setup.sh
> +++ b/tools/testing/selftests/vfio/scripts/setup.sh
> @@ -19,11 +19,30 @@ function print_supported_devices() {
> done
> }
>
> +function pick_device() {
> + local bdf
> +
> + while read -r bdf; do
> + if [ -n "${bdf}" ]; then
> + if [ -d "${DEVICES_DIR}/${bdf}" ]; then
> + echo "${bdf} has already been set up, exiting." >&2
> + exit 0
> + fi
> + echo "${bdf}"
> + return 0
> + fi
> + done <<< "$(print_supported_devices)"
> +
> + echo "No available supported devices found on the system." >&2
I think we should make it clear what "supported" means in this log. This
is about finding a device that has a VFIO selftests driver, which is
only required by some tests.
Same goes for the -l option in the previous commit actually and the
usage message below.
> + exit 1
> +}
> +
> function usage() {
> echo "usage: $0 [-l] [-d <segment:bus:device.function>]" >&2
> echo "" >&2
> echo " -l List segment:bus:device.function numbers of supported devices." >&2
> echo " -d segment:bus:device.function to set up." >&2
> + echo " If -d is not specified, a device will be automatically picked." >&2
> }
>
> function main() {
> @@ -46,8 +65,7 @@ function main() {
> done
>
> if [ ${#bdf_list[@]} -eq 0 ]; then
> - usage
> - exit 1
> + bdf_list=($(pick_device))
Sashiko thinks this will ignore any errors from pick_device():
https://sashiko.dev/#/patchset/20260409015139.2800185-1-jrhilke%40google.com?part=2
> fi
>
> for device_bdf in "${bdf_list[@]}"; do
> --
> 2.53.0.1213.gd9a14994de-goog
>
^ permalink raw reply [flat|nested] 6+ messages in thread* Re: [PATCH 2/2] vfio: selftests: Automate setting up devices for testing
2026-04-09 1:51 ` [PATCH 2/2] vfio: selftests: Automate setting up devices for testing Josh Hilke
2026-04-10 22:49 ` David Matlack
@ 2026-04-10 22:54 ` David Matlack
1 sibling, 0 replies; 6+ messages in thread
From: David Matlack @ 2026-04-10 22:54 UTC (permalink / raw)
To: Josh Hilke
Cc: Alex Williamson, Vipin Sharma, Raghavendra Rao Ananta, kvm,
linux-kernel
On 2026-04-09 01:51 AM, Josh Hilke wrote:
> Update the VFIO selftest setup script to find a device that has a VFIO selftest
> driver on the system, and set it up (i.e unbind that device from its driver, and
> then bind that device to VFIO).
I am leaning toward putting this behind an explicit flag (maybe -p for
pick_device or -a for automatic device setup?) that way we are sure the
user is ok with letting the script start messing with devices on their
system.
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2026-04-10 22:54 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-09 1:51 [PATCH 0/2] vfio: selftests: Automate finding/setting up devices for testing Josh Hilke
2026-04-09 1:51 ` [PATCH 1/2] vfio: selftests: Find devices that are compatible with VFIO selftests Josh Hilke
2026-04-10 22:40 ` David Matlack
2026-04-09 1:51 ` [PATCH 2/2] vfio: selftests: Automate setting up devices for testing Josh Hilke
2026-04-10 22:49 ` David Matlack
2026-04-10 22:54 ` David Matlack
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox