From patchwork Mon Sep 7 10:52:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 11760589 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 07F3659D for ; Mon, 7 Sep 2020 10:56:57 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EACE22166E for ; Mon, 7 Sep 2020 10:56:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728987AbgIGK4i (ORCPT ); Mon, 7 Sep 2020 06:56:38 -0400 Received: from mga12.intel.com ([192.55.52.136]:22272 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728956AbgIGK4Z (ORCPT ); Mon, 7 Sep 2020 06:56:25 -0400 IronPort-SDR: ecpX33UHRVEzHaSabuW1+xN9eA5VcsJuIEQubFYY10aBjyd2GDfDk0F0ltNbWMwV9McTxz7U77 q8Z/R8m9LYrg== X-IronPort-AV: E=McAfee;i="6000,8403,9736"; a="137503292" X-IronPort-AV: E=Sophos;i="5.76,401,1592895600"; d="scan'208";a="137503292" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2020 03:56:25 -0700 IronPort-SDR: RlfK2hmzUDMq+BUJoWCcda1pTnQZOYWGwj+y9pd31yA7kQp25F1DXYKFPrfHNlh8MGAP7Pp6kO 2zdmw6sVhMAQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,401,1592895600"; d="scan'208";a="303698276" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.192.131]) by orsmga006.jf.intel.com with ESMTP; 07 Sep 2020 03:56:22 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Zhu Lingshan Subject: [PATCH 1/2] vhost: remove mutex ops in vhost_set_backend_features Date: Mon, 7 Sep 2020 18:52:19 +0800 Message-Id: <20200907105220.27776-2-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200907105220.27776-1-lingshan.zhu@intel.com> References: <20200907105220.27776-1-lingshan.zhu@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org In vhost_vdpa ioctl SET_BACKEND_FEATURES path, currect code would try to acquire vhost dev mutex twice (first shown in vhost_vdpa_unlocked_ioctl), which can lead to a dead lock issue. This commit removed mutex operations in vhost_set_backend_features. As a compensation for vhost_net, a followinig commit will add needed mutex lock/unlock operations in a new function vhost_net_set_backend_features() which is a wrap of vhost_set_backend_features(). Signed-off-by: Zhu Lingshan --- drivers/vhost/vhost.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c index b45519ca66a7..e03c9e6f058f 100644 --- a/drivers/vhost/vhost.c +++ b/drivers/vhost/vhost.c @@ -2591,14 +2591,12 @@ void vhost_set_backend_features(struct vhost_dev *dev, u64 features) struct vhost_virtqueue *vq; int i; - mutex_lock(&dev->mutex); for (i = 0; i < dev->nvqs; ++i) { vq = dev->vqs[i]; mutex_lock(&vq->mutex); vq->acked_backend_features = features; mutex_unlock(&vq->mutex); } - mutex_unlock(&dev->mutex); } EXPORT_SYMBOL_GPL(vhost_set_backend_features); From patchwork Mon Sep 7 10:52:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhu, Lingshan" X-Patchwork-Id: 11760591 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CF2E5746 for ; Mon, 7 Sep 2020 10:58:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C1823216C4 for ; Mon, 7 Sep 2020 10:58:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728912AbgIGK6F (ORCPT ); Mon, 7 Sep 2020 06:58:05 -0400 Received: from mga12.intel.com ([192.55.52.136]:22272 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728997AbgIGK4c (ORCPT ); Mon, 7 Sep 2020 06:56:32 -0400 IronPort-SDR: Fi2BxiXIs5V4QkmCjam/RW2oPzFuFNIbW3Kimih4mQP4p+OPoHd8DdQkL6rmUCfDFrEgNC8YvJ Zoz0j+hK5p2Q== X-IronPort-AV: E=McAfee;i="6000,8403,9736"; a="137503293" X-IronPort-AV: E=Sophos;i="5.76,401,1592895600"; d="scan'208";a="137503293" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Sep 2020 03:56:29 -0700 IronPort-SDR: JA86N/wbR8enXwdxb0GTA+atgPjvf+Wnmuy+kBFgiTQNXZb4VlfmWeWv/gmZDumON9bPwmKcPA FjXaRm6BnIcg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.76,401,1592895600"; d="scan'208";a="303698283" Received: from unknown (HELO localhost.localdomain.bj.intel.com) ([10.240.192.131]) by orsmga006.jf.intel.com with ESMTP; 07 Sep 2020 03:56:26 -0700 From: Zhu Lingshan To: jasowang@redhat.com, mst@redhat.com Cc: virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, kvm@vger.kernel.org, Zhu Lingshan Subject: [PATCH 2/2] vhost_net: introduce vhost_net_set_backend_features() Date: Mon, 7 Sep 2020 18:52:20 +0800 Message-Id: <20200907105220.27776-3-lingshan.zhu@intel.com> X-Mailer: git-send-email 2.18.4 In-Reply-To: <20200907105220.27776-1-lingshan.zhu@intel.com> References: <20200907105220.27776-1-lingshan.zhu@intel.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This commit introduced a new function vhost_net_set_backend_features() which is a wrap of vhost_set_backend_features() with necessary mutex lockings. Signed-off-by: Zhu Lingshan --- drivers/vhost/net.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c index 531a00d703cd..e01da77538c8 100644 --- a/drivers/vhost/net.c +++ b/drivers/vhost/net.c @@ -1679,6 +1679,13 @@ static long vhost_net_set_owner(struct vhost_net *n) return r; } +static void vhost_net_set_backend_features(struct vhost_dev *dev, u64 features) +{ + mutex_lock(&dev->mutex); + vhost_set_backend_features(dev, features); + mutex_unlock(&dev->mutex); +} + static long vhost_net_ioctl(struct file *f, unsigned int ioctl, unsigned long arg) { @@ -1715,7 +1722,7 @@ static long vhost_net_ioctl(struct file *f, unsigned int ioctl, return -EFAULT; if (features & ~VHOST_NET_BACKEND_FEATURES) return -EOPNOTSUPP; - vhost_set_backend_features(&n->dev, features); + vhost_net_set_backend_features(&n->dev, features); return 0; case VHOST_RESET_OWNER: return vhost_net_reset_owner(n);