Commit d7d215da authored by Changpeng Liu's avatar Changpeng Liu
Browse files

nvmf/vfio-user: avoid recursive lock when disconnecting qpair

When destroying controller, we will disconnect each connected qpair,
and in the spdk_nvmf_qpair_disconnect() call, qpair_fini() will also
try to hold the same lock, so existing vfio-user implementation assume
that qpair_fini() will not be called in the same context.  Patch
https://review.spdk.io/gerrit/c/spdk/spdk/+/8963

 remind me that
vfio-user has this issue.  While here, we add one more thread poll
to avoid such issue.

Change-Id: I83b82ddcce3eb54c724291223e794dcb53a08059
Signed-off-by: default avatarChangpeng Liu <changpeng.liu@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/9998


Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Reviewed-by: default avatarAleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
parent d64ed942
Loading
Loading
Loading
Loading
+15 −3
Original line number Diff line number Diff line
@@ -2303,12 +2303,23 @@ vfio_user_qpair_disconnect_cb(void *ctx)
	if (TAILQ_EMPTY(&ctrlr->connected_qps)) {
		endpoint->ctrlr = NULL;
		free_ctrlr(ctrlr, false);
		pthread_mutex_unlock(&endpoint->lock);
		return;
	}
	pthread_mutex_unlock(&endpoint->lock);
}

static void
_vfio_user_qpair_disconnect(void *ctx)
{
	struct nvmf_vfio_user_qpair *vu_qpair = ctx;
	struct nvmf_vfio_user_ctrlr *vu_ctrlr;
	struct nvmf_vfio_user_endpoint *endpoint;

	vu_ctrlr = vu_qpair->ctrlr;
	endpoint = vu_ctrlr->endpoint;

	spdk_nvmf_qpair_disconnect(&vu_qpair->qpair, vfio_user_qpair_disconnect_cb, endpoint);
}

static int
vfio_user_destroy_ctrlr(struct nvmf_vfio_user_ctrlr *ctrlr)
{
@@ -2329,7 +2340,8 @@ vfio_user_destroy_ctrlr(struct nvmf_vfio_user_ctrlr *ctrlr)
	}

	TAILQ_FOREACH(qpair, &ctrlr->connected_qps, tailq) {
		spdk_nvmf_qpair_disconnect(&qpair->qpair, vfio_user_qpair_disconnect_cb, endpoint);
		/* add another round thread poll to avoid recursive endpoint lock */
		spdk_thread_send_msg(ctrlr->thread, _vfio_user_qpair_disconnect, qpair);
	}
	pthread_mutex_unlock(&endpoint->lock);