[PATCH v6 5/6] vfio: selftests: Retry on EAGAIN during device reset

From: Josh Hilke

Date: Tue Jul 21 2026 - 22:37:18 EST


Add retry logic to vfio_pci_device_reset() to handle the case where PCI
resets fail due to lock contention, in which case
pci_try_reset_function() returns -EAGAIN.

Suggested-by: Sashiko
Suggested-by: David Matlack <dmatlack@xxxxxxxxxx>
Signed-off-by: Josh Hilke <jrhilke@xxxxxxxxxx>
---
.../vfio/lib/include/libvfio/vfio_pci_device.h | 1 +
tools/testing/selftests/vfio/lib/vfio_pci_device.c | 17 ++++++++++++++++-
2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
index 2e67afc0d580..27bdf561925f 100644
--- a/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
+++ b/tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h
@@ -41,6 +41,7 @@ struct vfio_pci_device {
struct vfio_pci_device *vfio_pci_device_init(const char *bdf, struct iommu *iommu);
void vfio_pci_device_cleanup(struct vfio_pci_device *device);

+int __vfio_pci_device_reset(struct vfio_pci_device *device);
void vfio_pci_device_reset(struct vfio_pci_device *device);

void vfio_pci_config_access(struct vfio_pci_device *device, bool write,
diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
index 7b8394d0ac50..1b29cef96b04 100644
--- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
+++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: GPL-2.0-only
#include <dirent.h>
+#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <stdint.h>
@@ -221,9 +222,23 @@ void vfio_pci_config_access(struct vfio_pci_device *device, bool write,
write ? "write to" : "read from", config);
}

+int __vfio_pci_device_reset(struct vfio_pci_device *device)
+{
+ if (ioctl(device->fd, VFIO_DEVICE_RESET, NULL))
+ return -errno;
+
+ return 0;
+}
+
void vfio_pci_device_reset(struct vfio_pci_device *device)
{
- ioctl_assert(device->fd, VFIO_DEVICE_RESET, NULL);
+ int r;
+
+ do {
+ r = __vfio_pci_device_reset(device);
+ } while (r == -EAGAIN);
+
+ VFIO_ASSERT_EQ(r, 0, "ioctl(device->fd, VFIO_DEVICE_RESET) failed\n");
}

static unsigned int vfio_pci_get_group_from_dev(const char *bdf)

--
2.55.0.229.g6434b31f56-goog