From 1ace07171a4f772afd85a419bcd55fe56631966f Mon Sep 17 00:00:00 2001 From: Stefan Hajnoczi Date: Thu, 4 Jun 2026 16:10:28 -0400 Subject: [PATCH] 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 Reviewed-by: Stefano Garzarella Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin Message-ID: <20260604201029.250450-3-stefanha@redhat.com> --- subprojects/libvhost-user/libvhost-user.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/subprojects/libvhost-user/libvhost-user.c b/subprojects/libvhost-user/libvhost-user.c index d2df50e3d0..2c35bddd6f 100644 --- a/subprojects/libvhost-user/libvhost-user.c +++ b/subprojects/libvhost-user/libvhost-user.c @@ -1390,11 +1390,6 @@ vu_check_queue_inflights(VuDev *dev, VuVirtq *vq) vq->counter = vq->resubmit_list[0].counter + 1; } - /* in case of I/O hang after reconnecting */ - if (eventfd_write(vq->kick_fd, 1)) { - return -1; - } - return 0; } @@ -1436,6 +1431,20 @@ vu_set_vring_kick_exec(VuDev *dev, VhostUserMsg *vmsg) vu_panic(dev, "Failed to check inflights for vq: %d\n", index); } + /* Inject a kick to look for available vq buffers */ + if (dev->vq[index].kick_fd != -1) { + int ret; + + do { + ret = eventfd_write(dev->vq[index].kick_fd, 1); + } while (ret != 0 && errno == EINTR); + + if (ret != 0 && errno != EAGAIN /* already readable */) { + vu_panic(dev, "Failed to inject kick during SET_VRING_KICK " + "on vq: %d with error: %m\n", index); + } + } + return false; }