* [PATCH v2 0/2] vhost: VDUSE startup workaround and fix
@ 2025-09-16 9:35 Maxime Coquelin
2025-09-16 9:35 ` [PATCH v2 1/2] vhost: add VDUSE virtqueue ready state polling workaround Maxime Coquelin
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Maxime Coquelin @ 2025-09-16 9:35 UTC (permalink / raw)
To: dev, david.marchand, chenbox; +Cc: Maxime Coquelin
This series is a follow-up of the workaround to ensure queues are
in a ready state before starting the device.
It also adds a patch to ensure data passed to the kernel are properly
initialized.
Changes in v2:
==============
- Improve comments (David)
- Initialize vq_info properly (David)
- Add David's R-by
Maxime Coquelin (2):
vhost: add VDUSE virtqueue ready state polling workaround
vhost: fix uninitialized VQ info in VDUSE vring setup
lib/vhost/vduse.c | 63 ++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 60 insertions(+), 3 deletions(-)
--
2.51.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 1/2] vhost: add VDUSE virtqueue ready state polling workaround
2025-09-16 9:35 [PATCH v2 0/2] vhost: VDUSE startup workaround and fix Maxime Coquelin
@ 2025-09-16 9:35 ` Maxime Coquelin
2025-09-16 9:35 ` [PATCH v2 2/2] vhost: fix uninitialized VQ info in VDUSE vring setup Maxime Coquelin
2025-09-16 13:09 ` [PATCH v2 0/2] vhost: VDUSE startup workaround and fix Patrick Robb
2 siblings, 0 replies; 4+ messages in thread
From: Maxime Coquelin @ 2025-09-16 9:35 UTC (permalink / raw)
To: dev, david.marchand, chenbox; +Cc: Maxime Coquelin, stable
Add workaround to poll virtqueue ready states before starting device
when VIRTIO_DEVICE_STATUS_DRIVER_OK is set in vduse_events_handler().
For each virtqueue, poll using VDUSE_VQ_GET_INFO ioctl to check
vq_info->ready state with configurable retry limit. This addresses
timing issues where device start was attempted before all virtqueues
were properly initialized and ready.
A notification mechanism will be introduced in the next version of
the VDUSE uAPI. When it lands, we would only apply this workaround
when the kernel does not support it.
Fixes: a9120db8b98b ("vhost: add VDUSE device startup")
Cc: stable@dpdk.org
Reviewed-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
lib/vhost/vduse.c | 61 +++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 59 insertions(+), 2 deletions(-)
diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c
index 9de7f04a4f..422c4ab8f3 100644
--- a/lib/vhost/vduse.c
+++ b/lib/vhost/vduse.c
@@ -272,6 +272,55 @@ vduse_vring_cleanup(struct virtio_net *dev, unsigned int index)
vq->last_avail_idx = 0;
}
+/*
+ * Tests show that virtqueues get ready at the first retry at worst,
+ * but let's be on the safe side and allow more retries.
+ */
+#define VDUSE_VQ_READY_POLL_MAX_RETRIES 100
+
+static int
+vduse_wait_for_virtqueues_ready(struct virtio_net *dev)
+{
+ unsigned int i;
+ int ret;
+
+ for (i = 0; i < dev->nr_vring; i++) {
+ int retry_count = 0;
+
+ while (retry_count < VDUSE_VQ_READY_POLL_MAX_RETRIES) {
+ struct vduse_vq_info vq_info = { 0 };
+
+ vq_info.index = i;
+ ret = ioctl(dev->vduse_dev_fd, VDUSE_VQ_GET_INFO, &vq_info);
+ if (ret) {
+ VHOST_CONFIG_LOG(dev->ifname, ERR,
+ "Failed to get VQ %u info while polling ready state: %s",
+ i, strerror(errno));
+ return -1;
+ }
+
+ if (vq_info.ready) {
+ VHOST_CONFIG_LOG(dev->ifname, DEBUG,
+ "VQ %u is ready after %u retries", i, retry_count);
+ break;
+ }
+
+ retry_count++;
+ usleep(1000);
+ }
+
+ if (retry_count >= VDUSE_VQ_READY_POLL_MAX_RETRIES) {
+ VHOST_CONFIG_LOG(dev->ifname, ERR,
+ "VQ %u ready state polling timeout after %u retries",
+ i, VDUSE_VQ_READY_POLL_MAX_RETRIES);
+ return -1;
+ }
+ }
+
+ VHOST_CONFIG_LOG(dev->ifname, INFO, "All virtqueues are ready after polling");
+ return 0;
+}
+
static void
vduse_device_start(struct virtio_net *dev, bool reconnect)
{
@@ -414,10 +463,18 @@ vduse_events_handler(int fd, void *arg, int *close __rte_unused)
}
if ((old_status ^ dev->status) & VIRTIO_DEVICE_STATUS_DRIVER_OK) {
- if (dev->status & VIRTIO_DEVICE_STATUS_DRIVER_OK)
+ if (dev->status & VIRTIO_DEVICE_STATUS_DRIVER_OK) {
+ /* Poll virtqueues ready states before starting device */
+ ret = vduse_wait_for_virtqueues_ready(dev);
+ if (ret < 0) {
+ VHOST_CONFIG_LOG(dev->ifname, ERR,
+ "Failed to wait for virtqueues ready, aborting device start");
+ return;
+ }
vduse_device_start(dev, false);
- else
+ } else {
vduse_device_stop(dev);
+ }
}
VHOST_CONFIG_LOG(dev->ifname, INFO, "Request %s (%u) handled successfully",
--
2.51.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2 2/2] vhost: fix uninitialized VQ info in VDUSE vring setup
2025-09-16 9:35 [PATCH v2 0/2] vhost: VDUSE startup workaround and fix Maxime Coquelin
2025-09-16 9:35 ` [PATCH v2 1/2] vhost: add VDUSE virtqueue ready state polling workaround Maxime Coquelin
@ 2025-09-16 9:35 ` Maxime Coquelin
2025-09-16 13:09 ` [PATCH v2 0/2] vhost: VDUSE startup workaround and fix Patrick Robb
2 siblings, 0 replies; 4+ messages in thread
From: Maxime Coquelin @ 2025-09-16 9:35 UTC (permalink / raw)
To: dev, david.marchand, chenbox; +Cc: Maxime Coquelin, stable
Initialize vduse_vq_info structure to zero to avoid using
uninitialized memory when setting up VDUSE virtual rings.
This ensures all fields start with known values.
Fixes: a9120db8b98b ("vhost: add VDUSE device startup")
Cc: stable@dpdk.org
Reported-by: David Marchand <david.marchand@redhat.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
lib/vhost/vduse.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/vhost/vduse.c b/lib/vhost/vduse.c
index 422c4ab8f3..6f286c2963 100644
--- a/lib/vhost/vduse.c
+++ b/lib/vhost/vduse.c
@@ -141,7 +141,7 @@ vduse_vring_setup(struct virtio_net *dev, unsigned int index, bool reconnect)
{
struct vhost_virtqueue *vq = dev->virtqueue[index];
struct vhost_vring_addr *ra = &vq->ring_addrs;
- struct vduse_vq_info vq_info;
+ struct vduse_vq_info vq_info = { 0 };
struct vduse_vq_eventfd vq_efd;
int ret;
--
2.51.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2 0/2] vhost: VDUSE startup workaround and fix
2025-09-16 9:35 [PATCH v2 0/2] vhost: VDUSE startup workaround and fix Maxime Coquelin
2025-09-16 9:35 ` [PATCH v2 1/2] vhost: add VDUSE virtqueue ready state polling workaround Maxime Coquelin
2025-09-16 9:35 ` [PATCH v2 2/2] vhost: fix uninitialized VQ info in VDUSE vring setup Maxime Coquelin
@ 2025-09-16 13:09 ` Patrick Robb
2 siblings, 0 replies; 4+ messages in thread
From: Patrick Robb @ 2025-09-16 13:09 UTC (permalink / raw)
To: Maxime Coquelin; +Cc: dev
[-- Attachment #1: Type: text/plain, Size: 781 bytes --]
Putting in a retest at the Community Lab.
On Tue, Sep 16, 2025 at 5:36 AM Maxime Coquelin <maxime.coquelin@redhat.com>
wrote:
> This series is a follow-up of the workaround to ensure queues are
> in a ready state before starting the device.
>
> It also adds a patch to ensure data passed to the kernel are properly
> initialized.
>
> Changes in v2:
> ==============
> - Improve comments (David)
> - Initialize vq_info properly (David)
> - Add David's R-by
>
> Maxime Coquelin (2):
> vhost: add VDUSE virtqueue ready state polling workaround
> vhost: fix uninitialized VQ info in VDUSE vring setup
>
> lib/vhost/vduse.c | 63 ++++++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 60 insertions(+), 3 deletions(-)
>
> --
> 2.51.0
>
>
[-- Attachment #2: Type: text/html, Size: 1140 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-09-16 13:16 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-09-16 9:35 [PATCH v2 0/2] vhost: VDUSE startup workaround and fix Maxime Coquelin
2025-09-16 9:35 ` [PATCH v2 1/2] vhost: add VDUSE virtqueue ready state polling workaround Maxime Coquelin
2025-09-16 9:35 ` [PATCH v2 2/2] vhost: fix uninitialized VQ info in VDUSE vring setup Maxime Coquelin
2025-09-16 13:09 ` [PATCH v2 0/2] vhost: VDUSE startup workaround and fix Patrick Robb
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).