From 912b2116dae9f647f8b8d4db6bf0365e183da644 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Thu, 25 Mar 2021 17:50:41 +0800 Subject: [PATCH] nvmf/vfio-user: fix the race condition when creating new connection We used the controller ready field to indicate ADMIN queue connection, but the accept poller and ADMIN poll group may run in different threads, this may lead vfu_attach_ctx() be called several times, so change the 'ready' to true when a new socket connection is created. Fix issue #1854. Change-Id: Iab6ffd6dffb3fff5cf893e79774bc28fe0b2830c Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/7073 Community-CI: Broadcom CI Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Ben Walker --- lib/nvmf/vfio_user.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/nvmf/vfio_user.c b/lib/nvmf/vfio_user.c index e80c93a8a..9bddc73c2 100644 --- a/lib/nvmf/vfio_user.c +++ b/lib/nvmf/vfio_user.c @@ -151,7 +151,7 @@ struct nvmf_vfio_user_ctrlr { struct nvmf_vfio_user_endpoint *endpoint; struct nvmf_vfio_user_transport *transport; - /* True when the admin queue is connected */ + /* True when the socket connection is active */ bool ready; /* Number of connected queue pairs */ uint32_t num_connected_qps; @@ -1547,6 +1547,7 @@ nvmf_vfio_user_create_ctrlr(struct nvmf_vfio_user_transport *transport, goto out; } endpoint->ctrlr = ctrlr; + ctrlr->ready = true; /* Notify the generic layer about the new admin queue pair */ TAILQ_INSERT_TAIL(&ctrlr->transport->new_qps, ctrlr->qp[0], link); @@ -1838,7 +1839,6 @@ handle_queue_connect_rsp(struct nvmf_vfio_user_req *req, void *cb_arg) pthread_mutex_lock(&endpoint->lock); if (nvmf_qpair_is_admin_queue(&qpair->qpair)) { ctrlr->cntlid = qpair->qpair.ctrlr->cntlid; - ctrlr->ready = true; } ctrlr->num_connected_qps++; pthread_mutex_unlock(&endpoint->lock);