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 E343242B22; Tue, 16 May 2023 12:49:05 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id C8F9440A8B; Tue, 16 May 2023 12:49:05 +0200 (CEST) Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by mails.dpdk.org (Postfix) with ESMTP id 723284068E; Tue, 16 May 2023 12:49:04 +0200 (CEST) Received: by mail-wm1-f52.google.com with SMTP id 5b1f17b1804b1-3f4449fa085so49090025e9.0; Tue, 16 May 2023 03:49:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684234144; x=1686826144; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=KlNmK/GBY95q7RnNoPmo68XZSWWib0RhkpIkurIT27s=; b=Oou/TqIpGBZgd6KI/u2zA+zUdtwzRcZHBbILwOPu2UntzNXLj2hzYH0xQjxeLz2PAL b1CgqLprcxtqzdPz77YLYFtv+Ku/t8Vq2iNcPc0znikec2nOMJZtyIS7tN+UkTSk6/rp 7LoLEQLAkk9hYu7tM90DBqUcOhcY1MD2+INQZnIouYAOC3YQ8ClWNGoUwR0ARSTczAZl wxQ+yQdG5jWDemOUd0V/wIhhGEo1nX8GV6kbx34mguG+GqKfktO9pnoGbnHxxG8gazTa +LKlwh23uhtAWTa8Ptznh1WzO17Kpk472bN+bepkG4MTxzW7F6cCBb+q4hK+LIasNwe7 BIaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684234144; x=1686826144; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=KlNmK/GBY95q7RnNoPmo68XZSWWib0RhkpIkurIT27s=; b=T0peIAdwdMSeXfqzujmew20HOnubbB7QgBtIynwsg/hwuvVkhlEn36FzUTbFNV5yWc tHrED8NQwwIs+xzQ8izE/ZoqmIGuKp4FdLK9uoR62nPsmqrPxp9sOCbN1rSMjnt3B73v EW2lkzPQQR+Rx0ybQqWoO/Er0aGEC2D9JvhY/RMfmn765pwdflD49vwg+XyzYJpwUaWM O7yxvYYsoO+hpIcoNuD4xXjguG2hpD8FRKkfSs96qyDJi8EQ15SeJcwyjkhVj2YhgQI1 08dv8D4UWTzK3hrgejeX5UWBtc+Q9PHU6dgJIYjghsG47afvyLPL+9LGvADX5i0tsQV3 EaDw== X-Gm-Message-State: AC+VfDwrV852OoqYOGxDICgkd6BNxVGmnp6Y8m04nC8/IwBDBy3VyNzh NQjIg5wu5iqQWILKwmDqJwVg38wbBC0= X-Google-Smtp-Source: ACHHUZ6WYz7DZr1ggWleaGyNcor6sN/jmNVNlwZWCigaNFA+oRLdPhqvjAUwa8/efvCRC+f3R1MQjw== X-Received: by 2002:a05:600c:b4d:b0:3f4:253b:92a7 with SMTP id k13-20020a05600c0b4d00b003f4253b92a7mr20149743wmr.30.1684234143629; Tue, 16 May 2023 03:49:03 -0700 (PDT) Received: from spgw-dpdk.epc.mnc001.mcc001.3gppnetwork.org ([176.236.170.162]) by smtp.gmail.com with ESMTPSA id c22-20020a05600c0ad600b003f50876905dsm1947169wmr.6.2023.05.16.03.49.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 May 2023 03:49:03 -0700 (PDT) From: Yasin CANER To: dev@dpdk.org Cc: stable@dpdk.org, stephen@networkplumber.org Subject: [PATCH] lib/kni : fix memory-leak on rte_kni_rx_burst Date: Tue, 16 May 2023 10:48:53 +0000 Message-Id: <20230516104853.479297-1-yasinncaner@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Coverity issue: Bugzilla ID: 1227 Fixes: Cc: stable@dpdk.org Cc: stephen@networkplumber.org Adding new condition to check buffer is removed or not. it prevent allocation each time when rte_kni_rx_burst function called that cause memory-leak. Signed-off-by: Yasin CANER --- lib/kni/rte_kni.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/kni/rte_kni.c b/lib/kni/rte_kni.c index bfa6a001ff..2244892aae 100644 --- a/lib/kni/rte_kni.c +++ b/lib/kni/rte_kni.c @@ -660,7 +660,8 @@ kni_allocate_mbufs(struct rte_kni *kni) int i, ret; struct rte_mbuf *pkts[MAX_MBUF_BURST_NUM]; void *phys[MAX_MBUF_BURST_NUM]; - int allocq_free; + int allocq_free, allocq_count; + uint32_t allocq; RTE_BUILD_BUG_ON(offsetof(struct rte_mbuf, pool) != offsetof(struct rte_kni_mbuf, pool)); @@ -682,10 +683,26 @@ kni_allocate_mbufs(struct rte_kni *kni) RTE_LOG(ERR, KNI, "No valid mempool for allocating mbufs\n"); return; } - + /* First, getting allocation count from alloc_q. alloc_q is allocated in this function + * and/or kni_alloc function from mempool. + * If alloc_q is completely removed, it shall be allocated again. + * */ + allocq = kni_fifo_count(kni->alloc_q); + /* How many free allocation is possible from mempool. */ allocq_free = kni_fifo_free_count(kni->alloc_q); - allocq_free = (allocq_free > MAX_MBUF_BURST_NUM) ? - MAX_MBUF_BURST_NUM : allocq_free; + /* Allocated alloc_q count shall be max MAX_MBUF_BURST_NUM. */ + allocq_count = MAX_MBUF_BURST_NUM - (int)allocq; + /* Try to figure out how many allocation is possible. allocq_free is max possible.*/ + allocq_free = (allocq_free > MAX_MBUF_BURST_NUM )? MAX_MBUF_BURST_NUM : allocq_free; + /* Buffer is not removed so no need re-allocate*/ + + if(!allocq_count) { + /* Buffer is not removed so no need re-allocation*/ + return; + } else if (allocq_free > allocq_count) { + allocq_free = allocq_count; + } + for (i = 0; i < allocq_free; i++) { pkts[i] = rte_pktmbuf_alloc(kni->pktmbuf_pool); if (unlikely(pkts[i] == NULL)) { -- 2.25.1