From patchwork Tue Jan 14 18:53:57 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Coquelin X-Patchwork-Id: 64680 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 8A2B8A0512; 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 6083F1C11E; Tue, 14 Jan 2020 19:54:15 +0100 (CET) Received: from us-smtp-delivery-1.mimecast.com (us-smtp-1.mimecast.com [207.211.31.81]) by dpdk.org (Postfix) with ESMTP id 5EAD91C10E 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 Subject: [dpdk-dev] [PATCH] vhost: fix deadlock on port deletion 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" 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 Reviewed-by: Tiwei Bie Acked-by: Eelco Chaudron --- 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) next = TAILQ_NEXT(conn, next); /* - * If r/wcb is executing, release the - * conn_mutex lock, and try again since - * the r/wcb may use the conn_mutex lock. + * If r/wcb is executing, release vsocket's + * conn_mutex and vhost_user's mutex locks, and + * try again since the r/wcb may use the + * conn_mutex and mutex locks. */ if (fdset_try_del(&vhost_user.fdset, conn->connfd) == -1) { @@ -1075,8 +1076,17 @@ rte_vhost_driver_unregister(const char *path) pthread_mutex_unlock(&vsocket->conn_mutex); if (vsocket->is_server) { - fdset_del(&vhost_user.fdset, - vsocket->socket_fd); + /* + * If r/wcb is executing, release vhost_user's + * mutex lock, and try again since the r/wcb + * may use the mutex lock. + */ + if (fdset_try_del(&vhost_user.fdset, + vsocket->socket_fd) == -1) { + pthread_mutex_unlock(&vhost_user.mutex); + goto again; + } + close(vsocket->socket_fd); unlink(path); } else if (vsocket->reconnect) {