From patchwork Thu May 13 12:28:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chenbo Xia X-Patchwork-Id: 93254 X-Patchwork-Delegate: maxime.coquelin@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 6F1C0A0A02; Thu, 13 May 2021 14:38:10 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 519594069D; Thu, 13 May 2021 14:38:10 +0200 (CEST) Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by mails.dpdk.org (Postfix) with ESMTP id A45FD4003F for ; Thu, 13 May 2021 14:38:08 +0200 (CEST) IronPort-SDR: Bfyti3GdGqTe7xS15Sz3tOh+lWU12uMusuIEboyF0l8LAgZvy9ZqDhIy751djtqE1Ssk7g1T/q 5iGLVnCvHKqw== X-IronPort-AV: E=McAfee;i="6200,9189,9982"; a="285440702" X-IronPort-AV: E=Sophos;i="5.82,296,1613462400"; d="scan'208";a="285440702" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 May 2021 05:38:06 -0700 IronPort-SDR: xw0QDHebCiXaWNdSooLKdA7fKksrqaqaShtEw6WqYQzF47c42ECQbNUSXsT5/prc+YuKIO7EYH xe9M4LJI8/aQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,296,1613462400"; d="scan'208";a="623617609" Received: from npg-dpdk-virtio-xiachenbo-nw.sh.intel.com ([10.67.118.225]) by fmsmga006.fm.intel.com with ESMTP; 13 May 2021 05:38:05 -0700 From: Chenbo Xia To: dev@dpdk.org Cc: maxime.coquelin@redhat.com, david.marchand@redhat.com Date: Thu, 13 May 2021 20:28:26 +0800 Message-Id: <20210513122826.49910-1-chenbo.xia@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [dpdk-dev] [PATCH] vhost: fix wrong IOTLB initialization 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 Sender: "dev" This patch fixes an issue of application crash because of vhost iotlb not initialized when virtio has multiqueue enabled. iotlb messages will be sent when some queues are not enabled. If we initialize iotlb in vhost_user_set_vring_num, it could happen that iotlb update comes when iotlb pool of disabled queues are not initialized. Fixes: 968bbc7e2e50 ("vhost: avoid IOTLB mempool allocation while IOMMU disabled") Signed-off-by: Chenbo Xia Reported-by: Pei Zhang --- lib/vhost/vhost_user.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c index 611ff209e3..ae4df8eb69 100644 --- a/lib/vhost/vhost_user.c +++ b/lib/vhost/vhost_user.c @@ -311,6 +311,7 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg, uint64_t features = msg->payload.u64; uint64_t vhost_features = 0; struct rte_vdpa_device *vdpa_dev; + uint32_t i; if (validate_msg_fds(msg, 0) != 0) return RTE_VHOST_MSG_RESULT_ERR; @@ -389,6 +390,14 @@ vhost_user_set_features(struct virtio_net **pdev, struct VhostUserMsg *msg, vdpa_dev->ops->set_features(dev->vid); dev->flags &= ~VIRTIO_DEV_FEATURES_FAILED; + + if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) { + for (i = 0; i < dev->nr_vring; i++) { + if (vhost_user_iotlb_init(dev, i)) + return RTE_VHOST_MSG_RESULT_ERR; + } + } + return RTE_VHOST_MSG_RESULT_OK; } @@ -469,10 +478,6 @@ vhost_user_set_vring_num(struct virtio_net **pdev, return RTE_VHOST_MSG_RESULT_ERR; } - if (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM)) { - if (vhost_user_iotlb_init(dev, msg->payload.state.index)) - return RTE_VHOST_MSG_RESULT_ERR; - } return RTE_VHOST_MSG_RESULT_OK; }