summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/vfio
diff options
context:
space:
mode:
authorJosh Hilke <jrhilke@google.com>2026-08-05 00:21:00 +0000
committerAlex Williamson <alex@shazbot.org>2026-08-10 13:24:40 -0600
commit28ca5f67e1a79f62ed7988674fb07a8fc9eab8d2 (patch)
tree9e829ab9b2e97d2adea7b546632a3b13094a1cce /tools/testing/selftests/vfio
parent1583ef1175ba533e326dfeff6d8b9f3aaf761225 (diff)
downloadlinux-next-28ca5f67e1a79f62ed7988674fb07a8fc9eab8d2.tar.gz
linux-next-28ca5f67e1a79f62ed7988674fb07a8fc9eab8d2.zip
vfio: selftests: Retry on EAGAIN during device reset
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: David Matlack <dmatlack@google.com> Signed-off-by: Josh Hilke <jrhilke@google.com> Acked-by: David Matlack <dmatlack@google.com> Link: https://lore.kernel.org/r/20260805-igb_v3_b4-v10-3-9c86dc849c0d@google.com Signed-off-by: Alex Williamson <alex@shazbot.org>
Diffstat (limited to 'tools/testing/selftests/vfio')
-rw-r--r--tools/testing/selftests/vfio/lib/include/libvfio/vfio_pci_device.h1
-rw-r--r--tools/testing/selftests/vfio/lib/vfio_pci_device.c20
2 files changed, 20 insertions, 1 deletions
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 89a039ab3075..e19bd94b8dd2 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
@@ -43,6 +43,7 @@ void vfio_pci_device_free(struct vfio_pci_device *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 65a4fffb480c..4063a0e2b3df 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>
@@ -259,9 +260,26 @@ 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 retries = 20;
+ int r;
+
+ do {
+ r = __vfio_pci_device_reset(device);
+ if (r == -EAGAIN)
+ usleep(10000);
+ } while (r == -EAGAIN && retries-- > 0);
+
+ VFIO_ASSERT_EQ(r, 0, "ioctl(device->fd, VFIO_DEVICE_RESET) failed\n");
}
void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf)