From patchwork Tue Feb 2 08:38:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wan Junjie X-Patchwork-Id: 87623 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 E9C9DA052A; Tue, 2 Feb 2021 09:38:59 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7E4B62402D1; Tue, 2 Feb 2021 09:38:59 +0100 (CET) Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by mails.dpdk.org (Postfix) with ESMTP id 2F7162402D0 for ; Tue, 2 Feb 2021 09:38:58 +0100 (CET) Received: by mail-pj1-f44.google.com with SMTP id e9so1922695pjj.0 for ; Tue, 02 Feb 2021 00:38:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EcO/JaA6Fwm9Qk6Ym2QdRzX6PMKGI2NBmXyYusRXQIg=; b=K9/AwNI/xFJGCluVKewkoYsjiM0I9Zth8BWScH8KQSWSeFy6845wuMvzUqvp3cdHsu 4fMaGdEgMlnKS9PoYS1WSR5VdgteZWAyHu9TJWVDsA3JvHQ3CEc0AZ68EVvL8yGbJGh/ t3nyLcxhVXQVpptORl//wl4u5FWxeVf5ODNucJjxy2FiXtzFb0/EYay5D5pq0RTyIxJM cAcxIBUWb2CKm4cYi3bkBhJdC/H1G7PRqStt8RCnnkyCxf/BrN9hDQY36/jvsfTQ7auC ajS9P2X8hilDICao+xBcP+jc6/tf6DKVwKOB918ahd62FVtFsulVk2QuD2n24rVaQk+m uHYw== 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:in-reply-to :references:mime-version:content-transfer-encoding; bh=EcO/JaA6Fwm9Qk6Ym2QdRzX6PMKGI2NBmXyYusRXQIg=; b=j4IaBKfLjsGX/3YQMx+SHQpj2GC2u68AxSimE+qPCnC7NxbtLtxQqoTqNln9tqFw99 6OAAdzJuJtcUHrDBbDYEyUk2VP9e+WDdwPgp1wZlgYWCdToMRU3X5Cer88YW3PAXaSlb AJ8KKQZThKppdp3uKHFVseT3bU0odtQFxYUQxM7xASuzGLekThsm+4q7hY3V43g2e6Mv joxrjNBZaJey+3UG3VAU0+PWj1LCNfh5U4qf5+f2cgr7vTILOomZnViYX9+6bh4b+Zhw hpAnIX1i7HNWJvuzuMrfo74dUOP1L5+FgwxA6MVP0SRL8YahZeUpTMPBqZrZv5fcDXXR O9Dg== X-Gm-Message-State: AOAM533bRAghybbV552eqQpv3AtAPL/QSiN9vL7wEiZMZWoDbclPPpZF 8uNhn7JlPW8Hua365WCDa+zZug== X-Google-Smtp-Source: ABdhPJzT6S7wvp/d+rHRay9E6q3NQBwSByM0QqRc8NPVzKwGFLfn1FDcLVnfAi7yZVHE4RcxAQPMug== X-Received: by 2002:a17:902:7847:b029:df:d889:252c with SMTP id e7-20020a1709027847b02900dfd889252cmr21380849pln.76.1612255137327; Tue, 02 Feb 2021 00:38:57 -0800 (PST) Received: from C02Z10J4LVCK.bytedance.net ([139.177.225.233]) by smtp.gmail.com with ESMTPSA id u4sm1994010pjx.49.2021.02.02.00.38.54 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Feb 2021 00:38:56 -0800 (PST) From: Wan Junjie To: Chenbo Xia , Maxime Coquelin Cc: dev@dpdk.org, Wan Junjie , Peng He , Zhihong Wang Date: Tue, 2 Feb 2021 16:38:45 +0800 Message-Id: <20210202083845.79726-1-wanjunjie@bytedance.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210129163909.35970-1-wanjunjie@bytedance.com> References: <20210129163909.35970-1-wanjunjie@bytedance.com> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2] vhost: avoid iotlb mempool allocation while IOMMU disabled 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" If vhost device's IOMMU feature is disabled, iotlb mempool allocation is unnecessary. Reported-by: Peng He Signed-off-by: Wan Junjie Reviewed-by: Zhihong Wang Reviewed-by: Chenbo Xia Reviewed-by: Maxime Coquelin --- lib/librte_vhost/vhost.c | 4 ++-- lib/librte_vhost/vhost_user.c | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c index b83cf639e..e5341ab98 100644 --- a/lib/librte_vhost/vhost.c +++ b/lib/librte_vhost/vhost.c @@ -352,7 +352,8 @@ free_vq(struct virtio_net *dev, struct vhost_virtqueue *vq) vhost_free_async_mem(vq); } rte_free(vq->batch_copy_elems); - rte_mempool_free(vq->iotlb_pool); + if (vq->iotlb_pool) + rte_mempool_free(vq->iotlb_pool); rte_free(vq); } @@ -556,7 +557,6 @@ init_vring_queue(struct virtio_net *dev, uint32_t vring_idx) vq->callfd = VIRTIO_UNINITIALIZED_EVENTFD; vq->notif_enable = VIRTIO_UNINITIALIZED_NOTIF; - vhost_user_iotlb_init(dev, vring_idx); /* Backends are set to -1 indicating an inactive device. */ vq->backend = -1; } diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c index 45c8ac09d..81cbb9797 100644 --- a/lib/librte_vhost/vhost_user.c +++ b/lib/librte_vhost/vhost_user.c @@ -470,6 +470,10 @@ 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; } @@ -575,7 +579,7 @@ numa_realloc(struct virtio_net *dev, int index) dev->virtqueue[index] = vq; vhost_devices[dev->vid] = dev; - if (old_vq != vq) + if (old_vq != vq && (dev->features & (1ULL << VIRTIO_F_IOMMU_PLATFORM))) vhost_user_iotlb_init(dev, index); return dev;