From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id F1315A04B1 for ; Thu, 5 Nov 2020 13:40:57 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E2E74C80C; Thu, 5 Nov 2020 13:40:56 +0100 (CET) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by dpdk.org (Postfix) with ESMTP id 6625FC806 for ; Thu, 5 Nov 2020 13:40:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1604580053; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f9OJbvX50HjQ3nhZWVI89k7yp32Xd4IRAs6mQKnJhJA=; b=Rz2ST1sDJQlMktrh/9IVw4MdnOrCrLJqTl1f7zamQ1ql/flpg9FYFjOfS2PS3RTCQxRTtK 94ZzIQ8WSltc8tlRQybXjTEQWEJUnqindu5MBuJJl28WLmMciR0CNLo9DbdM/dEuBif00C KqPUOPjRBE/3ZjQS2sNgdTe6Y8UPnTI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-585-c-4l6MDcMtm35Zws4wiOuQ-1; Thu, 05 Nov 2020 07:40:50 -0500 X-MC-Unique: c-4l6MDcMtm35Zws4wiOuQ-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2FEF8186DD31; Thu, 5 Nov 2020 12:40:49 +0000 (UTC) Received: from rh.redhat.com (ovpn-113-249.ams2.redhat.com [10.36.113.249]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BAE35C3E1; Thu, 5 Nov 2020 12:40:47 +0000 (UTC) From: Kevin Traynor To: Yunjian Wang Cc: Ferruh Yigit , dpdk stable Date: Thu, 5 Nov 2020 12:39:18 +0000 Message-Id: <20201105124015.306404-11-ktraynor@redhat.com> In-Reply-To: <20201105124015.306404-1-ktraynor@redhat.com> References: <20201105124015.306404-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=ktraynor@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII" Subject: [dpdk-stable] patch 'net/tap: free mempool when closing' has been queued to LTS release 18.11.11 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.15 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 Sender: "stable" Hi, FYI, your patch has been queued to LTS release 18.11.11 Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet. It will be pushed if I get no objections before 11/10/20. So please shout if anyone has objections. Also note that after the patch there's a diff of the upstream commit vs the patch applied to the branch. This will indicate if there was any rebasing needed to apply to the stable branch. If there were code changes for rebasing (ie: not only metadata diffs), please double check that the rebase was correctly done. Queued patches are on a temporary branch at: https://github.com/kevintraynor/dpdk-stable-queue This queued commit can be viewed at: https://github.com/kevintraynor/dpdk-stable-queue/commit/b2089030c96abc063fc70fe9999b24dd3a003fdc Thanks. Kevin. --- >From b2089030c96abc063fc70fe9999b24dd3a003fdc Mon Sep 17 00:00:00 2001 From: Yunjian Wang Date: Sat, 8 Aug 2020 17:58:43 +0800 Subject: [PATCH] net/tap: free mempool when closing [ upstream commit 05a8e4a35d3ca9c1e5271917ad081ba78cd73fce ] When setup tx queues, we will create a mempool for the 'gso_ctx'. The mempool is not freed when closing tap device. If free the tap device and create it with different name, it will create a new mempool. This maybe cause an OOM. The snprintf function return value is not checked and the mempool name may be truncated. This patch also fix it. Fixes: 050316a88313 ("net/tap: support TSO (TCP Segment Offload)") Signed-off-by: Yunjian Wang Reviewed-by: Ferruh Yigit --- drivers/net/tap/rte_eth_tap.c | 43 +++++++++++++++++++++-------------- drivers/net/tap/rte_eth_tap.h | 1 + 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/drivers/net/tap/rte_eth_tap.c b/drivers/net/tap/rte_eth_tap.c index 62fb542865..6fcdd9480c 100644 --- a/drivers/net/tap/rte_eth_tap.c +++ b/drivers/net/tap/rte_eth_tap.c @@ -1069,4 +1069,7 @@ tap_dev_close(struct rte_eth_dev *dev) } + rte_mempool_free(internals->gso_ctx_mp); + internals->gso_ctx_mp = NULL; + if (internals->ka_fd != -1) { close(internals->ka_fd); @@ -1250,24 +1253,29 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev) uint32_t gso_types; char pool_name[64]; - - /* - * Create private mbuf pool with TAP_GSO_MBUF_SEG_SIZE bytes - * size per mbuf use this pool for both direct and indirect mbufs - */ - - struct rte_mempool *mp; /* Mempool for GSO packets */ + struct pmd_internals *pmd = dev->data->dev_private; + int ret; /* initialize GSO context */ gso_types = DEV_TX_OFFLOAD_TCP_TSO; - snprintf(pool_name, sizeof(pool_name), "mp_%s", dev->device->name); - mp = rte_mempool_lookup((const char *)pool_name); - if (!mp) { - mp = rte_pktmbuf_pool_create(pool_name, TAP_GSO_MBUFS_NUM, - TAP_GSO_MBUF_CACHE_SIZE, 0, + if (!pmd->gso_ctx_mp) { + /* + * Create private mbuf pool with TAP_GSO_MBUF_SEG_SIZE + * bytes size per mbuf use this pool for both direct and + * indirect mbufs + */ + ret = snprintf(pool_name, sizeof(pool_name), "mp_%s", + dev->device->name); + if (ret < 0 || ret >= (int)sizeof(pool_name)) { + TAP_LOG(ERR, + "%s: failed to create mbuf pool name for device %s," + "device name too long or output error, ret: %d\n", + pmd->name, dev->device->name, ret); + return -ENAMETOOLONG; + } + pmd->gso_ctx_mp = rte_pktmbuf_pool_create(pool_name, + TAP_GSO_MBUFS_NUM, TAP_GSO_MBUF_CACHE_SIZE, 0, RTE_PKTMBUF_HEADROOM + TAP_GSO_MBUF_SEG_SIZE, SOCKET_ID_ANY); - if (!mp) { - struct pmd_internals *pmd = dev->data->dev_private; - + if (!pmd->gso_ctx_mp) { TAP_LOG(ERR, "%s: failed to create mbuf pool for device %s\n", @@ -1277,6 +1285,6 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev) } - gso_ctx->direct_pool = mp; - gso_ctx->indirect_pool = mp; + gso_ctx->direct_pool = pmd->gso_ctx_mp; + gso_ctx->indirect_pool = pmd->gso_ctx_mp; gso_ctx->gso_types = gso_types; gso_ctx->gso_size = 0; /* gso_size is set in tx_burst() per packet */ @@ -1771,4 +1779,5 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, pmd->ka_fd = -1; pmd->nlsk_fd = -1; + pmd->gso_ctx_mp = NULL; pmd->ioctl_sock = socket(AF_INET, SOCK_DGRAM, 0); diff --git a/drivers/net/tap/rte_eth_tap.h b/drivers/net/tap/rte_eth_tap.h index dc3579ac0d..cb50745d79 100644 --- a/drivers/net/tap/rte_eth_tap.h +++ b/drivers/net/tap/rte_eth_tap.h @@ -92,4 +92,5 @@ struct pmd_internals { struct rte_intr_handle intr_handle; /* LSC interrupt handle. */ int ka_fd; /* keep-alive file descriptor */ + struct rte_mempool *gso_ctx_mp; /* Mempool for GSO packets */ }; -- 2.26.2 --- Diff of the applied patch vs upstream commit (please double-check if non-empty: --- --- - 2020-11-05 12:38:54.476303685 +0000 +++ 0011-net-tap-free-mempool-when-closing.patch 2020-11-05 12:38:54.170895965 +0000 @@ -1 +1 @@ -From 05a8e4a35d3ca9c1e5271917ad081ba78cd73fce Mon Sep 17 00:00:00 2001 +From b2089030c96abc063fc70fe9999b24dd3a003fdc Mon Sep 17 00:00:00 2001 @@ -5,0 +6,2 @@ +[ upstream commit 05a8e4a35d3ca9c1e5271917ad081ba78cd73fce ] + @@ -15 +16,0 @@ -Cc: stable@dpdk.org @@ -25 +26 @@ -index b19e26ba0e..df16aa4ea7 100644 +index 62fb542865..6fcdd9480c 100644 @@ -28 +29 @@ -@@ -1106,4 +1106,7 @@ tap_dev_close(struct rte_eth_dev *dev) +@@ -1069,4 +1069,7 @@ tap_dev_close(struct rte_eth_dev *dev) @@ -36 +37 @@ -@@ -1353,24 +1356,29 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev) +@@ -1250,24 +1253,29 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev) @@ -81 +82 @@ -@@ -1380,6 +1388,6 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev) +@@ -1277,6 +1285,6 @@ tap_gso_ctx_setup(struct rte_gso_ctx *gso_ctx, struct rte_eth_dev *dev) @@ -90 +91 @@ -@@ -1878,4 +1886,5 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, const char *tap_name, +@@ -1771,4 +1779,5 @@ eth_dev_tap_create(struct rte_vdev_device *vdev, char *tap_name, @@ -97 +98 @@ -index 8d6d53dc0a..ba45de8409 100644 +index dc3579ac0d..cb50745d79 100644