mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Josh Hilke <jrhilke@google.com>
To: David Matlack <dmatlack@google.com>, Alex Williamson <alex@shazbot.org>
Cc: Shuah Khan <shuah@kernel.org>,
	linux-kernel@vger.kernel.org, kvm@vger.kernel.org,
	 linux-kselftest@vger.kernel.org,
	Vipin Sharma <vipinsh@google.com>,
	 Josh Hilke <jrhilke@google.com>
Subject: [PATCH v6 5/6] vfio: selftests: Retry on EAGAIN during device reset
Date: Wed, 22 Jul 2026 00:15:40 +0000	[thread overview]
Message-ID: <20260722-igb_v3_b4-v6-5-0be1d29918d4@google.com> (raw)
In-Reply-To: <20260722-igb_v3_b4-v6-0-0be1d29918d4@google.com>

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@google.com>
Signed-off-by: Josh Hilke <jrhilke@google.com>
---
 .../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


  parent reply	other threads:[~2026-07-22  0:15 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-22  0:15 [PATCH v6 0/6] vfio: selftests: Add driver for Intel Ethernet Gigabit Controller (IGB) Josh Hilke
2026-07-22  0:15 ` [PATCH v6 1/6] vfio: selftests: igb: Add driver for Intel 82576 device Josh Hilke
2026-07-28 18:14   ` Alex Williamson
2026-07-22  0:15 ` [PATCH v6 2/6] vfio: selftests: igb: Use PHY internal loopback on 82576 Josh Hilke
2026-07-22  0:15 ` [PATCH v6 3/6] vfio: selftests: Add helpers to re-enable interrupts Josh Hilke
2026-07-22  0:15 ` [PATCH v6 4/6] vfio: selftests: igb: Factor hardware programming into igb_hw_init() Josh Hilke
2026-07-22  0:15 ` Josh Hilke [this message]
2026-07-22  0:15 ` [PATCH v6 6/6] vfio: selftests: igb: Recover after DMA-read faults Josh Hilke
2026-07-24 21:42 ` [PATCH v6 0/6] vfio: selftests: Add driver for Intel Ethernet Gigabit Controller (IGB) David Matlack
2026-07-27 20:57   ` Josh Hilke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260722-igb_v3_b4-v6-5-0be1d29918d4@google.com \
    --to=jrhilke@google.com \
    --cc=alex@shazbot.org \
    --cc=dmatlack@google.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=shuah@kernel.org \
    --cc=vipinsh@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®