From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2C6BDA0512 for ; Tue, 14 Jan 2020 19:54:15 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 210FD1C10D; Tue, 14 Jan 2020 19:54:15 +0100 (CET) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by dpdk.org (Postfix) with ESMTP id 42D851C10D for ; Tue, 14 Jan 2020 19:54:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1579028052; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=B+1t00Cd2XHRTvROkJHc4sKyCPvGHQWMaxSgKJmuGxc=; b=cl8WtE5F3gqvInOqWbXI5GKM/fi2wbC0DQA5P5mlnzNHvuQbsixzHqAUpTcsU/1o3kBji+ /rGhPiXq6O2LPATNocJwf+rWfsS+yrbBHUy95RMW0MKN4ADOTZsBUC7YkEM9/DhrhK7MXg XQj5oYf7oJSFKYzFKW8qM/5iaNhuUTk= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-165-1qqMWHXGO_OMXJfUm0sjeQ-1; Tue, 14 Jan 2020 13:54:11 -0500 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 50F39DB2F; Tue, 14 Jan 2020 18:54:08 +0000 (UTC) Received: from localhost.localdomain (unknown [10.36.112.13]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8C0585DDA5; Tue, 14 Jan 2020 18:54:03 +0000 (UTC) From: Maxime Coquelin To: dev@dpdk.org, tiwei.bie@intel.com, amorenoz@redhat.com, zhihong.wang@intel.com, echaudro@redhat.com Cc: Maxime Coquelin , stable@dpdk.org Date: Tue, 14 Jan 2020 19:53:57 +0100 Message-Id: <20200114185357.25819-1-maxime.coquelin@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-MC-Unique: 1qqMWHXGO_OMXJfUm0sjeQ-1 X-Mimecast-Spam-Score: 0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Subject: [dpdk-stable] [PATCH] vhost: fix deadlock on port deletion 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: , Errors-To: stable-bounces@dpdk.org Sender: "stable" If the vhost-user application (e.g. OVS) deletes the vhost-user port while Qemu sends a vhost-user request, a deadlock can happen if the request handler tries to acquire vhost-user's global mutex, which is also locked by the vhost-user port deletion API (rte_vhost_driver_unregister). This patch prevents the deadlock by making rte_vhost_driver_unregister() to release the mutex and try again if a request is being handled to give a chance to the request handler to complete. Fixes: 8b4b949144b8 ("vhost: fix dead lock on closing in server mode") Fixes: 5fbb3941da9f ("vhost: introduce driver features related APIs") Cc: stable@dpdk.org Signed-off-by: Maxime Coquelin --- lib/librte_vhost/socket.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 633c2cbc27..c57a0c7cdd 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -1052,9 +1052,10 @@ rte_vhost_driver_unregister(const char *path) =09=09=09=09next =3D TAILQ_NEXT(conn, next); =20 =09=09=09=09/* -=09=09=09=09 * If r/wcb is executing, release the -=09=09=09=09 * conn_mutex lock, and try again since -=09=09=09=09 * the r/wcb may use the conn_mutex lock. +=09=09=09=09 * If r/wcb is executing, release vsocket's +=09=09=09=09 * conn_mutex and vhost_user's mutex locks, and +=09=09=09=09 * try again since the r/wcb may use the +=09=09=09=09 * conn_mutex and mutex locks. =09=09=09=09 */ =09=09=09=09if (fdset_try_del(&vhost_user.fdset, =09=09=09=09=09=09 conn->connfd) =3D=3D -1) { @@ -1075,8 +1076,17 @@ rte_vhost_driver_unregister(const char *path) =09=09=09pthread_mutex_unlock(&vsocket->conn_mutex); =20 =09=09=09if (vsocket->is_server) { -=09=09=09=09fdset_del(&vhost_user.fdset, -=09=09=09=09=09=09vsocket->socket_fd); +=09=09=09=09/* +=09=09=09=09 * If r/wcb is executing, release vhost_user's +=09=09=09=09 * mutex lock, and try again since the r/wcb +=09=09=09=09 * may use the mutex lock. +=09=09=09=09 */ +=09=09=09=09if (fdset_try_del(&vhost_user.fdset, +=09=09=09=09=09=09vsocket->socket_fd) =3D=3D -1) { +=09=09=09=09=09pthread_mutex_unlock(&vhost_user.mutex); +=09=09=09=09=09goto again; +=09=09=09=09} + =09=09=09=09close(vsocket->socket_fd); =09=09=09=09unlink(path); =09=09=09} else if (vsocket->reconnect) { --=20 2.21.0