From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 26B312901 for ; Tue, 16 May 2017 15:57:58 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 May 2017 06:57:58 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.38,349,1491289200"; d="scan'208";a="968999608" Received: from fmsmsx106.amr.corp.intel.com ([10.18.124.204]) by orsmga003.jf.intel.com with ESMTP; 16 May 2017 06:57:57 -0700 Received: from HASMSX110.ger.corp.intel.com (10.184.198.28) by FMSMSX106.amr.corp.intel.com (10.18.124.204) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 16 May 2017 06:57:57 -0700 Received: from hasmsx105.ger.corp.intel.com ([169.254.1.51]) by HASMSX110.ger.corp.intel.com ([169.254.11.79]) with mapi id 14.03.0319.002; Tue, 16 May 2017 16:57:55 +0300 From: "Stojaczyk, DariuszX" To: "dev@dpdk.org" CC: "Wodkowski, PawelX" Thread-Topic: [PATCH] vhost: fix deadlock on rte_vhost_driver_unregister() Thread-Index: AQHSzjQsP9dNVLO0okO0jNtMg9l2d6H28dOQ Date: Tue, 16 May 2017 13:57:54 +0000 Message-ID: References: <1494945272-126732-1-git-send-email-dariuszx.stojaczyk@intel.com> In-Reply-To: <1494945272-126732-1-git-send-email-dariuszx.stojaczyk@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-product: dlpe-windows dlp-version: 10.0.102.7 dlp-reaction: no-action x-originating-ip: [10.184.70.10] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [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: , X-List-Received-Date: Tue, 16 May 2017 13:57:59 -0000 > -----Original Message----- > From: Stojaczyk, DariuszX > Sent: Tuesday, May 16, 2017 4:35 PM > To: dev@dpdk.org > Cc: Wodkowski, PawelX ; Stojaczyk, DariuszX > > Subject: [PATCH] vhost: fix deadlock on rte_vhost_driver_unregister() >=20 > Consider the following scenario, threads A and B: > (A) > * fdset_event_dispatch() start > * pfdentry->busy =3D 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 =3D=3D 0 > (A) > * vhost_destroy_device() end > * pthread_mutex_lock(&vsocket->conn_mutex); > (mutex already locked - deadlock at this point) >=20 > Thread B has locked vsocket->conn_mutex and is in while(1) loop waiting f= or > 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 f= lag > back to 0, but that can't happen due to the vsocket->conn_mutex lock. >=20 > This patch synchronizes rte_vhost_driver_unregister() with > vhost_user_read_cb() through vhost_user.mutex. >=20 > Signed-off-by: Dariusz Stojaczyk > --- > lib/librte_vhost/socket.c | 4 ++++ > 1 file changed, 4 insertions(+) >=20 > 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) >=20 > ret =3D vhost_user_msg_handler(conn->vid, connfd); > if (ret < 0) { > + pthread_mutex_lock(&vhost_user.mutex); > + > close(connfd); > *remove =3D 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); > } > } >=20 > -- > 2.7.4 I've found other cases where rte_vhost_driver_unregister() can still deadlo= ck.=20 Please do not merge this patch now, I will try to come up with a different = solution for this issue.