From 25440c3bdb6b5159e75f12c206441e543dea38ba Mon Sep 17 00:00:00 2001 From: Thanos Makatos Date: Wed, 12 Oct 2022 09:08:19 +0000 Subject: [PATCH] nvmf/vfio-user: don't blindly drain poll group eventfd This eventfd may be passed by libvfio-user to the remote process which might remove the EFD_NONBLOCK flag, in which case we would block indefinitely. Signed-off-by: Thanos Makatos Change-Id: If9826cd700b4a7b3458a0a8278a96322d99ac08e Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/15385 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: John Levon Reviewed-by: Jim Harris Reviewed-by: Changpeng Liu --- lib/nvmf/vfio_user.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index 7c3fd44c5..61b1846dc 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -4810,20 +4810,13 @@ _post_completion_msg(void *ctx) static int nvmf_vfio_user_poll_group_poll(struct spdk_nvmf_transport_poll_group *group); static int -vfio_user_poll_group_intr(void *ctx) +vfio_user_poll_group_process(void *ctx) { struct nvmf_vfio_user_poll_group *vu_group = ctx; - eventfd_t val; int ret = 0; SPDK_DEBUGLOG(vfio_user_db, "pg:%p got intr\n", vu_group); - /* - * NB: this might fail if called from vfio_user_ctrlr_intr(), but it's - * non-blocking, so not an issue. - */ - eventfd_read(vu_group->intr_fd, &val); - ret |= nvmf_vfio_user_poll_group_poll(&vu_group->group); /* @@ -4835,6 +4828,16 @@ vfio_user_poll_group_intr(void *ctx) return ret != 0 ? SPDK_POLLER_BUSY : SPDK_POLLER_IDLE; } +static int +vfio_user_poll_group_intr(void *ctx) +{ + struct nvmf_vfio_user_poll_group *vu_group = ctx; + eventfd_t val; + + eventfd_read(vu_group->intr_fd, &val); + return vfio_user_poll_group_process(ctx); +} + /* * Handle an interrupt for the given controller: we must poll the vfu_ctx, and * the SQs assigned to our own poll group. Other poll groups are handled via @@ -4880,7 +4883,7 @@ vfio_user_ctrlr_intr(void *ctx) } } - ret |= vfio_user_poll_group_intr(vu_ctrlr_group); + ret |= vfio_user_poll_group_process(vu_ctrlr_group); return ret; }