From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CF572A050A; Sat, 7 May 2022 07:30:03 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 815C940395; Sat, 7 May 2022 07:30:03 +0200 (CEST) Received: from mga06.intel.com (mga06b.intel.com [134.134.136.31]) by mails.dpdk.org (Postfix) with ESMTP id 64AEA4014F; Sat, 7 May 2022 07:30:01 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651901401; x=1683437401; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=afqoiUa1fa2ZJIuIUci8aH1Wu7gOk77W/4d77Kokb9g=; b=Rts2IpqTxVLTR8r40GxXYFbOrluIqup6rpeVdeFUPX118ELOgwMURUml x31rQCBG0XfAQJnU1RPCyGr3k59vuYBZEhofu8d2eydM7jWOkfD/lvU2z 84Hn0RQnZRgfCjJGUYg9qNCxXi319+JKK069fqd4gD2kHDMhsZ1Wn73Sw EBR72boRpAGGQHe1cVAOP/wppeQZ2vUiSKJQ6MpafbprqdA1LAkJCJRMY rx5NQ1WuHxBCuaKlC3XJaoemPUj3m1WXELTeBssBgOAM2ekMZIUlmvRHJ gk1X3VwfzzjyJzhsr1pdCpZO3Qzywg0vvdzUfV6he/8dn9va4Zz/BYZnu A==; X-IronPort-AV: E=McAfee;i="6400,9594,10339"; a="329202917" X-IronPort-AV: E=Sophos;i="5.91,206,1647327600"; d="scan'208";a="329202917" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 22:29:58 -0700 X-IronPort-AV: E=Sophos;i="5.91,206,1647327600"; d="scan'208";a="586366213" Received: from unknown (HELO localhost.localdomain) ([10.239.251.209]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 May 2022 22:29:55 -0700 From: Wenwu Ma To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, dev@dpdk.org Cc: jiayu.hu@intel.com, yinan.wang@intel.com, xingguang.he@intel.com, Wenwu Ma , stable@dpdk.org Subject: [PATCH v3] vhost: fix deadlock when message handling failed Date: Sat, 7 May 2022 13:27:53 +0000 Message-Id: <20220507132753.11357-1-wenwux.ma@intel.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505134008.2865-1-wenwux.ma@intel.com> References: <20220505134008.2865-1-wenwux.ma@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org In vhost_user_msg_handler(), if vhost message handling failed, we should check whether the queue is locked and release the lock before returning. Or, it will cause a deadlock later. Fixes: 7f31d4ea05ca ("vhost: fix lock on device readiness notification") Cc: stable@dpdk.org Signed-off-by: Wenwu Ma --- lib/vhost/vhost_user.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 1d390677fa..4baf969ee0 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -2976,7 +2976,6 @@ vhost_user_msg_handler(int vid, int fd) return -1; } - ret = 0; request = ctx.msg.request.master; if (request > VHOST_USER_NONE && request < VHOST_USER_MAX && vhost_message_str[request]) { @@ -3113,9 +3112,11 @@ vhost_user_msg_handler(int vid, int fd) send_vhost_reply(dev, fd, &ctx); } else if (ret == RTE_VHOST_MSG_RESULT_ERR) { VHOST_LOG_CONFIG(ERR, "(%s) vhost message handling failed.\n", dev->ifname); - return -1; + ret = -1; + goto unlock; } + ret = 0; for (i = 0; i < dev->nr_vring; i++) { struct vhost_virtqueue *vq = dev->virtqueue[i]; bool cur_ready = vq_is_ready(dev, vq); @@ -3126,10 +3127,11 @@ vhost_user_msg_handler(int vid, int fd) } } +unlock: if (unlock_required) vhost_user_unlock_all_queue_pairs(dev); - if (!virtio_is_ready(dev)) + if (ret != 0 || !virtio_is_ready(dev)) goto out; /* @@ -3156,7 +3158,7 @@ vhost_user_msg_handler(int vid, int fd) } out: - return 0; + return ret; } static int process_slave_message_reply(struct virtio_net *dev, -- 2.25.1