From patchwork Tue Jan 8 11:45:09 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: 49552 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 614311B57A; Wed, 9 Jan 2019 17:50:32 +0100 (CET) Received: from mail-pf1-f193.google.com (mail-pf1-f193.google.com [209.85.210.193]) by dpdk.org (Postfix) with ESMTP id 2245CDE0 for ; Tue, 8 Jan 2019 12:45:20 +0100 (CET) Received: by mail-pf1-f193.google.com with SMTP id z9so1829372pfi.2 for ; Tue, 08 Jan 2019 03:45:20 -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=+bPlxsTsDkJl5Yw+rLL6S5m/2V0OsFFkhjmdgoroABg=; b=E9IcbCxp2xB6zmI55IuxmjsaEq1OHB0qoUcQNB4duJ5yt2ysyvvzL7Th5rZgfRnKZf zKOQ7gDZ4pRPnNvO7aNLZxu0rBis0D8zEafWN3+loyitTCg/mjs7nex+eBvCxf0+vJ9s dSB2Ef0gYuxT/sReYAfe/ATj4nlGA+gJur0/Z8TgRSmai9yWuUrPKoucmrgbQvqsYvn1 4JPJtsT/IJiyape8oNAglQ6NfCvU7xTKXt65GvSYdAlbGTMt+6o9rk7EkXlwDSpjMvY1 RvGrlnHK4VBIKLCMiiNcaC/TKl2PFUo9HADD/WIpMj16yN4Er0Xr0HE5iTO8aFKPRMeh kSVA== 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=+bPlxsTsDkJl5Yw+rLL6S5m/2V0OsFFkhjmdgoroABg=; b=cOkQb8ykORi4oDJI2gqQEt14+a6XS6F6LoRUIn82GVe1y6N7PKECUE7X9MFngdPu3T xZLDA86pI3PqNKbDDIGPbh7m0mCbBtZDZdXjQS2jZ8JVvRV56DtmmZLRh1baSatRGFU3 CJXHPOTIIInG14vH+WvN/q0DzyX1lS4IMlJh0i2ITRXhhZ7MfIDUtalCuS69A71KvCGQ yVdSvwShpiCAxZv9F4UykvKhBpBJFrJEDXNhheSzhCWcSB+KnBQWU0NAB/0wk5+zZ39d iOgJOZW9SMLFMaORcYtkLveV7rWtN3S6SzPxX6UzvB96rw1Pvqjpf+Aw2bYtYhoDdXEg oonw== X-Gm-Message-State: AJcUukdOKvZXgKgXVsIEhF6lECc1tt8pZfmDCNdKw8nQBzeEcsavHxFU hGNKhKXOSSOlPl/1z/6zuFkvpt28 X-Google-Smtp-Source: ALg8bN6Z+ax9rJWAD+wyibo4WV+f5E5sMzR0P5d7yjif1FWx9M5p7bOFYmIsB14cSctmOPPzS621Bw== X-Received: by 2002:a65:590b:: with SMTP id f11mr1263978pgu.60.1546947918810; Tue, 08 Jan 2019 03:45:18 -0800 (PST) Received: from localhost.localdomain ([203.100.54.194]) by smtp.gmail.com with ESMTPSA id k24sm107135524pfj.13.2019.01.08.03.45.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Jan 2019 03:45:18 -0800 (PST) From: sunwenjie To: dev@dpdk.org Cc: sunwenjie Date: Tue, 8 Jan 2019 19:45:09 +0800 Message-Id: <20190108114509.31489-1-findtheonlyway@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-Mailman-Approved-At: Wed, 09 Jan 2019 17:50:30 +0100 Subject: [dpdk-dev] [PATCH] vhostuser: 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. To fix it: Unlock the vhost_user.mutex if fdset_try_del fail and relock it when retry. --- lib/librte_vhost/socket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/librte_vhost/socket.c b/lib/librte_vhost/socket.c index 9cf34ad17..a9effa115 100644 --- a/lib/librte_vhost/socket.c +++ b/lib/librte_vhost/socket.c @@ -961,13 +961,12 @@ 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 +980,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;