From patchwork Fri Jan 11 13:49:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?5a2Z5paH5p2w?= X-Patchwork-Id: 49763 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 86F0E1B587; Sat, 12 Jan 2019 23:18:37 +0100 (CET) Received: from mail-pf1-f194.google.com (mail-pf1-f194.google.com [209.85.210.194]) by dpdk.org (Postfix) with ESMTP id 190FE1BC0A for ; Fri, 11 Jan 2019 14:49:42 +0100 (CET) Received: by mail-pf1-f194.google.com with SMTP id i12so6984636pfo.7 for ; Fri, 11 Jan 2019 05:49:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bwXUfZk83KbVZ7POj0xrfMRw4Mgq46wmwwONuJM8cyo=; b=fXm9rmIVjI8bUEGfoTr1C6NJSHWCfc/8dx2l8xovh5QzGdPNwGLO2SupXpXS1NSBh3 OgdOus7BAnow3VYGZXqQbpbWI41Tk4CteoUW6tYwW9q78hOPdFZy8xIIoIwOyIb3+vBz gBb1JGL5sJVLCHsydXnugf/cbN0eGZP16EGpA+2FYEH72/lVNYlULM8JGFMnctUayFBE anBihMky2NWlEcmASDUNqglxzdFQAF/foO8IXnLdSOQPRB42hGWFhlkFfefUf9M9oqjr mHFgtQKrsxIePIYyZPSdTZF3GEoDmBrsaWzOlJdmzg3e/5ys7rXVIdXsoT06QZaj/1yK HjEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bwXUfZk83KbVZ7POj0xrfMRw4Mgq46wmwwONuJM8cyo=; b=agL/2QUqwkQOxYXh30wc3lCxegxWlEAY951CPPOfyPdUgJo9GFTDqOW9FWVC83IalR dQ9jx93OY4u2CT/Ss+219Nj1gc8J3NNqDArrN/tV65eRixIFCHMh9lbjN5tqglZMLP3x lt6fjwYsKsziGUFY4WY/PwLE7vdmBcRIYlLu3QcNeHY9b+lZmjCxd95w0+LbPJjBka8L YwQkKbqDoJxXlpSWEvgBVoShzbqCu6Uppgl1F04/kFk7c5vmI6pbudDNmNN6xfynOoHs jUTl+Y8TruIOO3RXiRpGRfXzsTRr6bZHuRBml2cWn3X9mrtgz2eyPfMVLgia5sFOwN3i qPxA== X-Gm-Message-State: AJcUukfy7Ds48M0PvZPWphvIzqMjaeSKXHPnQwb+fSHyJNvByVKa0NLE JtQ3lDdzyt322EU8iJ6UNzkWRlvy X-Google-Smtp-Source: ALg8bN6EV1swWGVVLfeGMVqvPdtTUYXYJBahr20X6/+XF74UjAr6FWPl7yuY7d58hWp5CQEN32+lDQ== X-Received: by 2002:a63:c303:: with SMTP id c3mr3335587pgd.268.1547214580861; Fri, 11 Jan 2019 05:49:40 -0800 (PST) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id o1sm117244845pgn.63.2019.01.11.05.49.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Jan 2019 05:49:39 -0800 (PST) From: sunwenjie To: dev@dpdk.org Cc: sunwenjie Date: Fri, 11 Jan 2019 21:49:31 +0800 Message-Id: <20190111134931.28402-1-findtheonlyway@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Mailman-Approved-At: Sat, 12 Jan 2019 23:18:31 +0100 Subject: [dpdk-dev] [PATCH] vhost: fix deadlock when vhost 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" When rte_vhost_driver_unregister delete the connection fd, fdset_try_del will always try and donot release the vhostuser.mutex if the fd is busy, but the fdset_event_dispatch will set the fd to busy and call vhost_user_msg_handler to get vhostuser.mutex, which will cause deadlock. Unlock the vhost_user.mutexif fdset_try_del fail and relock it when retry. Signed-off-by: findtheonlway Signed-off-by: sunwenjie --- lib/librte_vhost/socket.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 9cf34ad17..7959c5ece 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -961,13 +961,13 @@ rte_vhost_driver_unregister(const char *path) int count; struct vhost_user_connection *conn, *next; +again: pthread_mutex_lock(&vhost_user.mutex); for (i = 0; i < vhost_user.vsocket_cnt; i++) { struct vhost_user_socket *vsocket = vhost_user.vsockets[i]; if (!strcmp(vsocket->path, path)) { -again: pthread_mutex_lock(&vsocket->conn_mutex); for (conn = TAILQ_FIRST(&vsocket->conn_list); conn != NULL; @@ -981,6 +981,7 @@ rte_vhost_driver_unregister(const char *path) */ if (fdset_try_del(&vhost_user.fdset, conn->connfd) == -1) { + pthread_mutex_unlock(&vhost_user.mutex); pthread_mutex_unlock( &vsocket->conn_mutex); goto again;