[PATCH v2 4/8] vfio: selftests: Skip vfio_pci_sriov_uapi_test if SR-IOV can't be enabled

From: David Matlack

Date: Wed Nov 18 2026 - 19:02:59 EST


Skip vfio_pci_sriov_uapi_test if writing to the PF's sriov_numvfs file
fails with -ENOENT, which means SR-IOV cannot be configured on the PF.

vfio-pci returns -ENOENT unless its enable_sriov module parameter is
set, which it is not by default, so the test currently fails during
setup instead of skipping.

Fixes: a6e4e726600d ("vfio: selftests: Add tests to validate SR-IOV UAPI")
Signed-off-by: David Matlack <dmatlack@xxxxxxxxxx>
---
tools/testing/selftests/vfio/vfio_pci_sriov_uapi_test.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/vfio/vfio_pci_sriov_uapi_test.c b/tools/testing/selftests/vfio/vfio_pci_sriov_uapi_test.c
index f3a018b8699d..f27418fa5960 100644
--- a/tools/testing/selftests/vfio/vfio_pci_sriov_uapi_test.c
+++ b/tools/testing/selftests/vfio/vfio_pci_sriov_uapi_test.c
@@ -210,6 +210,7 @@ static void vf_setup(void)
{
char *vf_driver;
int nr_vfs;
+ int ret;

nr_vfs = sysfs_sriov_totalvfs_get(pf_bdf);
if (nr_vfs <= 0)
@@ -220,7 +221,12 @@ static void vf_setup(void)
ksft_exit_skip("SR-IOV already configured for the PF: %s\n", pf_bdf);

/* Create only one VF for testing */
- sysfs_sriov_numvfs_set(pf_bdf, 1);
+ ret = __sysfs_sriov_numvfs_set(pf_bdf, 1);
+ if (ret == -ENOENT)
+ ksft_exit_skip("Cannot enable SR-IOV on %s (vfio-pci requires enable_sriov=1)\n",
+ pf_bdf);
+
+ VFIO_ASSERT_EQ(ret, 0);

/*
* Setup an exit handler to destroy the VF in case of failures
--
2.56.1.708.g77570a6a1d-goog