From 91eb10b4becfc658ad60c0aca19c39b2cd4a8fb5 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Mon, 18 Jul 2022 12:04:07 +0800 Subject: [PATCH] nvmf/vfio-user: only kick controller when in interrupt mode There is a race condition if we call this function in the polling mode when running with multi-cores, same as other places where the function is called, we only kick controller in interrupt mode, also in `vfio_user_ctrlr_intr`, `ctrlr->sqs[0]` may be set to NULL after the controller poll call, so return earlier for this case. Change-Id: I03a7b74a39c966a2b8be610bca0e492d902f6b08 Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/13696 Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker Reviewed-by: Dong Yi --- lib/nvmf/vfio_user.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index 4bc967c48..290e69b59 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -2918,6 +2918,13 @@ struct ctrlr_quiesce_ctx { static void ctrlr_quiesce(struct nvmf_vfio_user_ctrlr *vu_ctrlr); +static inline bool +in_interrupt_mode(struct nvmf_vfio_user_transport *vu_transport) +{ + return spdk_interrupt_mode_is_enabled() && + vu_transport->intr_mode_supported; +} + static void _vfio_user_endpoint_resume_done_msg(void *ctx) { @@ -2938,7 +2945,9 @@ _vfio_user_endpoint_resume_done_msg(void *ctx) * kick ourselves so we'll definitely check again while in * VFIO_USER_CTRLR_RUNNING state. */ - ctrlr_kick(vu_ctrlr); + if (in_interrupt_mode(endpoint->transport)) { + ctrlr_kick(vu_ctrlr); + } return; } @@ -4549,13 +4558,6 @@ nvmf_vfio_user_poll_group_create(struct spdk_nvmf_transport *transport, return &vu_group->group; } -static bool -in_interrupt_mode(struct nvmf_vfio_user_transport *vu_transport) -{ - return spdk_interrupt_mode_is_enabled() && - vu_transport->intr_mode_supported; -} - static struct spdk_nvmf_transport_poll_group * nvmf_vfio_user_get_optimal_poll_group(struct spdk_nvmf_qpair *qpair) { @@ -4765,6 +4767,12 @@ vfio_user_ctrlr_intr(void *ctx) * Poll vfio-user for this controller. */ ret = vfio_user_poll_vfu_ctx(ctrlr); + /* `sqs[0]` could be set to NULL in vfio_user_poll_vfu_ctx() context, just return + * for this case. + */ + if (ctrlr->sqs[0] == NULL) { + return ret; + } vu_group = ctrlr_to_poll_group(ctrlr);