From patchwork Tue May 16 14:34:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Stojaczyk, DariuszX" X-Patchwork-Id: 24321 X-Patchwork-Delegate: yuanhan.liu@linux.intel.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 23FC92A5D; Tue, 16 May 2017 13:03:54 +0200 (CEST) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by dpdk.org (Postfix) with ESMTP id CD1FE29D9 for ; Tue, 16 May 2017 13:03:51 +0200 (CEST) Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 May 2017 04:03:50 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos; i="5.38,349,1491289200"; d="scan'208"; a="1148366185" Received: from gklab-246-153.igk.intel.com (HELO Sent) ([10.217.246.153]) by fmsmga001.fm.intel.com with SMTP; 16 May 2017 04:03:48 -0700 Received: by Sent (sSMTP sendmail emulation); Tue, 16 May 2017 16:37:05 +0200 From: Dariusz Stojaczyk To: dev@dpdk.org Cc: Pawel Wodkowski , Dariusz Stojaczyk Date: Tue, 16 May 2017 16:34:32 +0200 Message-Id: <1494945272-126732-1-git-send-email-dariuszx.stojaczyk@intel.com> X-Mailer: git-send-email 2.7.4 Subject: [dpdk-dev] [PATCH] vhost: fix deadlock on rte_vhost_driver_unregister() X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Consider the following scenario, threads A and B: (A) * fdset_event_dispatch() start * pfdentry->busy = 1; * vhost_user_read_cb() start * vhost_destroy_device() start (B) * rte_vhost_driver_unregister() start * pthread_mutex_lock(&vsocket->conn_mutex); * fdset_del() * endless loop, waiting for pfdentry->busy == 0 (A) * vhost_destroy_device() end * pthread_mutex_lock(&vsocket->conn_mutex); (mutex already locked - deadlock at this point) Thread B has locked vsocket->conn_mutex and is in while(1) loop waiting for given fd to change it's busy flag to 0. Thread A would have to finish vhost_user_read_cb() in order to set busy flag back to 0, but that can't happen due to the vsocket->conn_mutex lock. This patch synchronizes rte_vhost_driver_unregister() with vhost_user_read_cb() through vhost_user.mutex. Signed-off-by: Dariusz Stojaczyk --- lib/librte_vhost/socket.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index c7f99b0..77e58fe 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -273,6 +273,8 @@ vhost_user_read_cb(int connfd, void *dat, int *remove) ret = vhost_user_msg_handler(conn->vid, connfd); if (ret < 0) { + pthread_mutex_lock(&vhost_user.mutex); + close(connfd); *remove = 1; vhost_destroy_device(conn->vid); @@ -287,6 +289,8 @@ vhost_user_read_cb(int connfd, void *dat, int *remove) create_unix_socket(vsocket); vhost_user_start_client(vsocket); } + + pthread_mutex_unlock(&vhost_user.mutex); } }