From: Alex Williamson <alex.williamson@nvidia.com>
To: Alex Williamson <alex@shazbot.org>, kvm <kvm@vger.kernel.org>
Cc: Alex Williamson <alex.williamson@nvidia.com>,
linux-kernel <linux-kernel@vger.kernel.org>,
Jason Gunthorpe <jgg@ziepe.ca>, Kevin Tian <kevin.tian@intel.com>,
Yi Liu <yi.l.liu@intel.com>, David Matlack <dmatlack@google.com>
Subject: [PATCH 2/4] selftests/vfio: Wait out transient -EBUSY on open/bind
Date: Tue, 1 Sep 2026 15:53:55 -0600 [thread overview]
Message-ID: <20260901215358.2421359-3-alex.williamson@nvidia.com> (raw)
In-Reply-To: <20260901215358.2421359-1-alex.williamson@nvidia.com>
If a test is killed, for example due to timeout, fput can be delayed,
allowing the subsequent test to be started while the failing test still
holds the device open count elevated. This results in a cascade of
failures as each subsequent test fails on open, blocked by the single
user requirement at the group or device cdev file.
We can make the test framework more robust, and allow better
identification of specific failing scenarios, by waiting-out transient
-EBUSY failures on group open and cdev bind.
The 20s retry window is heuristically determined in testing on a system
where scheduling can be significantly delayed due to SMI handling of
platform errors generated from the mix-and-match test.
The SR-IOV uAPI and IOMMUFD setup tests retain their non-retry bind
paths as these are not expected to encounter process kills due to
underlying platform error handling variability.
Assisted-by: Qwen3.8-27B
Signed-off-by: Alex Williamson <alex.williamson@nvidia.com>
---
.../selftests/vfio/lib/vfio_pci_device.c | 29 +++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/vfio/lib/vfio_pci_device.c b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
index 4063a0e2b3df..8a3139b7c6dd 100644
--- a/tools/testing/selftests/vfio/lib/vfio_pci_device.c
+++ b/tools/testing/selftests/vfio/lib/vfio_pci_device.c
@@ -282,18 +282,34 @@ void vfio_pci_device_reset(struct vfio_pci_device *device)
VFIO_ASSERT_EQ(r, 0, "ioctl(device->fd, VFIO_DEVICE_RESET) failed\n");
}
+/*
+ * A prior test's delayed fput can briefly leave the open count elevated, so
+ * group open and cdev bind can see a transient -EBUSY. Retry to wait out the
+ * fput scheduling latency.
+ */
+#define VFIO_DEVICE_BUSY_RETRIES 200
+#define VFIO_DEVICE_BUSY_INTERVAL_US 100000
+
void vfio_pci_group_setup(struct vfio_pci_device *device, const char *bdf)
{
struct vfio_group_status group_status = {
.argsz = sizeof(group_status),
};
char group_path[32];
+ int retries = VFIO_DEVICE_BUSY_RETRIES;
int group;
group = sysfs_iommu_group_get(bdf);
snprintf_assert(group_path, sizeof(group_path), "/dev/vfio/%d", group);
- device->group_fd = open(group_path, O_RDWR);
+ for (;;) {
+ device->group_fd = open(group_path, O_RDWR);
+ if (device->group_fd >= 0 || errno != EBUSY || retries-- <= 0)
+ break;
+
+ usleep(VFIO_DEVICE_BUSY_INTERVAL_US);
+ }
+
VFIO_ASSERT_GE(device->group_fd, 0, "open(%s) failed\n", group_path);
ioctl_assert(device->group_fd, VFIO_GROUP_GET_STATUS, &group_status);
@@ -432,7 +448,16 @@ int __vfio_device_bind_iommufd(int device_fd, int iommufd, const char *vf_token)
static void vfio_device_bind_iommufd(int device_fd, int iommufd,
const char *vf_token)
{
- int ret = __vfio_device_bind_iommufd(device_fd, iommufd, vf_token);
+ int retries = VFIO_DEVICE_BUSY_RETRIES;
+ int ret;
+
+ for (;;) {
+ ret = __vfio_device_bind_iommufd(device_fd, iommufd, vf_token);
+ if (ret != -EBUSY || retries-- <= 0)
+ break;
+
+ usleep(VFIO_DEVICE_BUSY_INTERVAL_US);
+ }
VFIO_ASSERT_EQ(ret, 0, "Failed VFIO_DEVICE_BIND_IOMMUFD ioctl\n");
}
--
2.53.0
next prev parent reply other threads:[~2026-09-01 21:54 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 21:53 [PATCH 0/4] vfio: Fix cdev second-open and harden selftests Alex Williamson
2026-09-01 21:53 ` [PATCH 1/4] vfio: Reject a second cdev open before mutating shared device state Alex Williamson
2026-09-09 22:27 ` David Matlack
2026-09-10 13:51 ` Jason Gunthorpe
2026-09-01 21:53 ` Alex Williamson [this message]
2026-09-09 21:40 ` [PATCH 2/4] selftests/vfio: Wait out transient -EBUSY on open/bind David Matlack
2026-09-10 22:50 ` Alex Williamson
2026-09-01 21:53 ` [PATCH 3/4] selftests/vfio: Extend mix_and_match timeout to 90s Alex Williamson
2026-09-09 21:42 ` David Matlack
2026-09-01 21:53 ` [PATCH 4/4] selftests/vfio: Extend timeout for runner executions Alex Williamson
2026-09-09 21:51 ` David Matlack
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=20260901215358.2421359-3-alex.williamson@nvidia.com \
--to=alex.williamson@nvidia.com \
--cc=alex@shazbot.org \
--cc=dmatlack@google.com \
--cc=jgg@ziepe.ca \
--cc=kevin.tian@intel.com \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=yi.l.liu@intel.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®