libvhost-user: look for available vq buffers upon SET_VRING_KICK
When a vring is started the back-end must look for available vq buffers and process them. This scenario can happen if the back-end is stopped with unprocessed available buffers and then started again. The inflight I/O tracking code already did this, but it should also be done when inflight I/O tracking is not enabled. Move the code and make it robust in case of EINTR or EAGAIN. Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com> Reviewed-by: Stefano Garzarella <sgarzare@redhat.com> Reviewed-by: Michael S. Tsirkin <mst@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com> Message-ID: <20260604201029.250450-3-stefanha@redhat.com>
Stefan Hajnoczi committed
Jun 4, 2026 at 16:10 UTC
1ace07171a4f772afd85a419bcd55fe56631966f
1 file changed
+14
-5
subprojects/libvhost-user/libvhost-user.c
+14
-5
@@ -1390,11 +1390,6 @@ vu_check_queue_inflights(VuDev *dev, VuVirtq *vq)
1390
vq->counter = vq->resubmit_list[0].counter + 1;
1391
}
1392
1393
- /* in case of I/O hang after reconnecting */
1394
- if (eventfd_write(vq->kick_fd, 1)) {
1395
- return -1;
1396
- }
1397
-
1393
return 0;
1394
}
1395
@@ -1436,6 +1431,20 @@ vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg)
1431
vu_panic(dev, "Failed to check inflights for vq: %d\n", index);
1432
}
1433
1434
+ /* Inject a kick to look for available vq buffers */
1435
+ if (dev->vq[index].kick_fd != -1) {
1436
+ int ret;
1437
+
1438
+ do {
1439
+ ret = eventfd_write(dev->vq[index].kick_fd, 1);
1440
+ } while (ret != 0 && errno == EINTR);
1441
+
1442
+ if (ret != 0 && errno != EAGAIN /* already readable */) {
1443
+ vu_panic(dev, "Failed to inject kick during SET_VRING_KICK "
1444
+ "on vq: %d with error: %m\n", index);
1445
+ }
1446
+ }
1447
+
1448
return false;
1449
}
1450