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 DB0B5A04FF for ; Thu, 5 May 2022 10:19:37 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id CFBA84281C; Thu, 5 May 2022 10:19:37 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id 189C840042; Thu, 5 May 2022 10:19:34 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1651738775; x=1683274775; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=afqoiUa1fa2ZJIuIUci8aH1Wu7gOk77W/4d77Kokb9g=; b=R3aF23FqikQDrmS6ojcAUis3iU8tK1tfw37PvTbtQXxrDdANRVaLWbCj QX06PwHXYA0WlPDwUJDOHePjNC/cBbN0UAUC5zurcVZESj/VJ/3FPxItg 8tTzWYfSpgplOmfaPaVhrzvJdm2/E9P43LrUKtWlRy2y1z86LG0vjF6m8 W4boom84DQJ7GzUqQ4um3mBU5aliK6jb46X91JbIvDM+lkIiUcI33FHAo 9lt6MnR5gZ61Ozb9JaCNNiJXKnvxNWXB6mMXXRl/D3pnx+mnoZ9WHgT1K gZ54CwR/OxJiYFLxG/SCN/G02zZSEIBfG2LcQiq2AVzzOqKcHUSibByG4 g==; X-IronPort-AV: E=McAfee;i="6400,9594,10337"; a="354474855" X-IronPort-AV: E=Sophos;i="5.91,200,1647327600"; d="scan'208";a="354474855" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 01:19:34 -0700 X-IronPort-AV: E=Sophos;i="5.91,200,1647327600"; d="scan'208";a="585204819" Received: from unknown (HELO localhost.localdomain) ([10.239.251.209]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 May 2022 01:19:31 -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 v2] vhost: fix deadlock when handling user messages Date: Thu, 5 May 2022 16:17:25 +0000 Message-Id: <20220505161725.7333-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: stable@dpdk.org X-Mailman-Version: 2.1.29 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 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