From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by dpdk.org (Postfix) with ESMTP id 9FFDC8D99 for ; Sun, 20 May 2018 15:09:04 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 4ED3C216BD; Sun, 20 May 2018 09:09:04 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Sun, 20 May 2018 09:09:04 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fridaylinux.org; h=cc:date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=sZVYMnwWhki03l5QM 2xrefoLhK+yp2xub8HYgH5BOY8=; b=f7JiUTIgBBVenlmbZNk9O8TV91s2IyfJV WAQkbrFrF1sMY+PVhUOPuBA0JfnkJJUgdQjnR1imVVe6zi4+BGdwQU3MuV/vS/3H 5KTUF6iZezNR88bwaBvO7JwrBlpHE8AVsostt07NpK4gfk7NwASlP3KZnwOklHur T36YrBvZnMOmDjFynasZTGE9lSfILVUb/LZ2G2bhkObSHe2tgV3wd2Dp9/8ha0m1 3yHNp+FRTkMXIBk+exBSPwx/76vEmp1ZNnsDnYp3Z7cyd/DDXzBDDRgoar5TP8d8 d+stYSk7e4BbbcY/gCJJUfAU9i/uQT+XUQv5WH+l5vmuWFQLl2CjQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; bh=sZVYMnwWhki03l5QM2xrefoLhK+yp2xub8HYgH5BOY8=; b=Hvd6a1VK aukMSil7nOMFFRF5m6HiTSMCXo8iMYEEsQJV0MlW2AkZ/7q9dV7gWfaUqP47z78Y PkMKnwwntZZb+P4tYxYf0jTh+/SGpO3kMfeR9naSVrL2N7WwtiIFpG3oEfDwigBS 5or4nFoQiWWcqhh91wL/u3OA1Aa7X/7039bRjl0c5c7NWCAUlAeWIywOOtBREaqb Ha4BP3tsPR5Bq+f54Ri/57rI7a9oQ7h7164HUJWohliZZS2t18qWTc1qpyAx0FwP LsWryNiudsC8HV1iTQ+dET339CWaKz49XPqnHvS2rslHFeRVyTVyvh25yntPrINm gy+YAIdQkcT4tQ== X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from yuanhanliu-NB0.tencent.com (unknown [223.74.148.80]) by mail.messagingengine.com (Postfix) with ESMTPA id 7D1671025C; Sun, 20 May 2018 09:09:02 -0400 (EDT) From: Yuanhan Liu To: Tonghao Zhang Cc: Maxime Coquelin , dpdk stable Date: Sun, 20 May 2018 21:02:33 +0800 Message-Id: <20180520130246.16287-17-yliu@fridaylinux.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20180520130246.16287-1-yliu@fridaylinux.org> References: <20180520130246.16287-1-yliu@fridaylinux.org> Subject: [dpdk-stable] patch 'vhost: fix dead lock on closing in server mode' has been queued to LTS release 17.11.3 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches for DPDK stable branches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 20 May 2018 13:09:04 -0000 Hi, FYI, your patch has been queued to LTS release 17.11.3 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 05/27/18. So please shout if anyone has objections. Thanks. --yliu --- >>From 01670e717dccf35c5678cd779a525cdc1561514b Mon Sep 17 00:00:00 2001 From: Tonghao Zhang Date: Fri, 27 Apr 2018 08:19:43 -0700 Subject: [PATCH] vhost: fix dead lock on closing in server mode [ upstream commit 8b4b949144b80cc7312bbc189d38a3feaf2c74e5 ] When qemu close the unix socket fd of the vhostuser as a server, and then immediately delete the vhostuser port on openvswitch. There will be a deadlock. A thread (fdset event thread): B thread: 1. fdset_event_dispatch rte_vhost_driver_unregister 2. set the fd busy to 1. lock vsocket->conn_mutex 3. vhost_user_read_cb fdset_del waits busy changed to 0. 4. vhost peer closed, remove the conn from vsocket->conn_list: lock vsocket->conn_mutex 5. set the fd busy to 0 Fixes: 65388b43f592 ("vhost: fix fd leaks for vhost-user server mode") Signed-off-by: Tonghao Zhang Acked-by: Maxime Coquelin --- lib/librte_vhost/fd_man.c | 32 ++++++++++++++++++++++++++++++++ lib/librte_vhost/fd_man.h | 1 + lib/librte_vhost/socket.c | 14 +++++++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/fd_man.c b/lib/librte_vhost/fd_man.c index 4c6fed418..173ec75c8 100644 --- a/lib/librte_vhost/fd_man.c +++ b/lib/librte_vhost/fd_man.c @@ -200,6 +200,38 @@ fdset_del(struct fdset *pfdset, int fd) return dat; } +/** + * Unregister the fd from the fdset. + * + * If parameters are invalid, return directly -2. + * And check whether fd is busy, if yes, return -1. + * Otherwise, try to delete the fd from fdset and + * return true. + */ +int +fdset_try_del(struct fdset *pfdset, int fd) +{ + int i; + + if (pfdset == NULL || fd == -1) + return -2; + + pthread_mutex_lock(&pfdset->fd_mutex); + i = fdset_find_fd(pfdset, fd); + if (i != -1 && pfdset->fd[i].busy) { + pthread_mutex_unlock(&pfdset->fd_mutex); + return -1; + } + + if (i != -1) { + pfdset->fd[i].fd = -1; + pfdset->fd[i].rcb = pfdset->fd[i].wcb = NULL; + pfdset->fd[i].dat = NULL; + } + + pthread_mutex_unlock(&pfdset->fd_mutex); + return 0; +} /** * This functions runs in infinite blocking loop until there is no fd in diff --git a/lib/librte_vhost/fd_man.h b/lib/librte_vhost/fd_man.h index 90d34db19..c00883882 100644 --- a/lib/librte_vhost/fd_man.h +++ b/lib/librte_vhost/fd_man.h @@ -63,6 +63,7 @@ int fdset_add(struct fdset *pfdset, int fd, fd_cb rcb, fd_cb wcb, void *dat); void *fdset_del(struct fdset *pfdset, int fd); +int fdset_try_del(struct fdset *pfdset, int fd); void *fdset_event_dispatch(void *arg); diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 72831b347..f816601bb 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -761,13 +761,25 @@ rte_vhost_driver_unregister(const char *path) vhost_user_remove_reconnect(vsocket); } +again: pthread_mutex_lock(&vsocket->conn_mutex); for (conn = TAILQ_FIRST(&vsocket->conn_list); conn != NULL; conn = next) { next = TAILQ_NEXT(conn, next); - fdset_del(&vhost_user.fdset, conn->connfd); + /* + * If r/wcb is executing, release the + * conn_mutex lock, and try again since + * the r/wcb may use the conn_mutex lock. + */ + if (fdset_try_del(&vhost_user.fdset, + conn->connfd) == -1) { + pthread_mutex_unlock( + &vsocket->conn_mutex); + goto again; + } + RTE_LOG(INFO, VHOST_CONFIG, "free connfd = %d for device '%s'\n", conn->connfd, path); -- 2.11.0