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 7FA1EA00C2 for ; Fri, 7 Oct 2022 05:28:55 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9A89E42B89; Fri, 7 Oct 2022 05:28:52 +0200 (CEST) Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-eopbgr60043.outbound.protection.outlook.com [40.107.6.43]) by mails.dpdk.org (Postfix) with ESMTP id 675CA42B6C; Fri, 7 Oct 2022 05:28:50 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EMphnMCNjbcJTTEh6G9doxdxddadssUfNWwzu2qpf/FxPJfKmCVkMJ/FupCvpTcnlS/9QI50LFVJpr9Rtlori3Hj/EqeCwftFfLsexuDssXj5uq7TGACJ2KwC8zeAwLBRv11WWAZmKit1Lhscn/DcGF1D3/yPTfJ1cqkamnORF6a3+5W/0nKsa9KRINxq94enR/IomAmPQ7ZuUC1ugwXpWq5NHh38moix6pn5Wur4cvYQKQ53nt8VZHXVGuy6FJmv2xDePOVBJxkWTUIUuYTIsav3zi2aHyUkVQhD4z1bvFlEBcCWPI3WFxJAyP07v8V9v2ojh6yIpBEWcBfXhzJbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=jG08YIgQgpIwe0V98Ceq8mxLKSGaQFCC9AChhNbtezQ=; b=Ax/rmIHIShM/oDhgnJD3E9XkDMDED8HTKPAvwraylcmaOWsKCsP84H5FnRFoq9Bt6j1PpXxAnbAeAIxx7tkw0W+q9bBh+yLJ/sguRBHBipRu7eJ3fwJrcymxcK/6zkApF6JDYJU2L5MKgqkgCBTS6z7j0ncSANYyiddD6SK+dZdrIMzSXWjNVLAznvPlziWJ6551HB8CeVu9qu0G8+gSgBXLoNli9teGhrxpM0qTFy8r9ulMq+SP0hz8p2v/jO0Eglj1OFowDLXlBBn+CvPsqoUFv2Pshw8dq0ix+xY1gZBckelZTM9BxE/a3wI5yQnYUAcAFbgPIhHd2T7/yjbUHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jG08YIgQgpIwe0V98Ceq8mxLKSGaQFCC9AChhNbtezQ=; b=r7t8LjpPmwgztWRXsQgQ4jHxOiFDRKvGLBZJBtn9ka336tZJY1qMXOK2wQ7aOutn6Ao2yHb0rTqi06vLQfDihGanTRlxk9P2U0bkPynJ20eNNRZSe7EtJKq4A/LZWmlRr97JZ6WMIZj5PShjJOvT6YShY+d2iTdt5sYLerm/SKE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8198.eurprd04.prod.outlook.com (2603:10a6:20b:3b0::14) by PAXPR04MB9326.eurprd04.prod.outlook.com (2603:10a6:102:2b8::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.28; Fri, 7 Oct 2022 03:28:48 +0000 Received: from AS8PR04MB8198.eurprd04.prod.outlook.com ([fe80::9ee7:dafa:ba51:c71e]) by AS8PR04MB8198.eurprd04.prod.outlook.com ([fe80::9ee7:dafa:ba51:c71e%7]) with mapi id 15.20.5676.032; Fri, 7 Oct 2022 03:28:48 +0000 From: Gagandeep Singh To: ferruh.yigit@amd.com, dev@dpdk.org Cc: Gagandeep Singh , stable@dpdk.org, Hemant Agrawal Subject: [PATCH v2 08/16] net/dpaa2: fix buffer free on transmit SG packets Date: Fri, 7 Oct 2022 08:57:35 +0530 Message-Id: <20221007032743.2129353-9-g.singh@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221007032743.2129353-1-g.singh@nxp.com> References: <20220928052516.1279442-1-g.singh@nxp.com> <20221007032743.2129353-1-g.singh@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: SG2P153CA0033.APCP153.PROD.OUTLOOK.COM (2603:1096:4:c7::20) To AS8PR04MB8198.eurprd04.prod.outlook.com (2603:10a6:20b:3b0::14) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8198:EE_|PAXPR04MB9326:EE_ X-MS-Office365-Filtering-Correlation-Id: ad853488-c941-46bc-4e72-08daa8140c13 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BFVC5/6sgdpJ9XpvZ5pQYpJiDAA8svdTWCeN0xCSJuZNxOZsJS3ioZgKEwOMczAYRf18Lf6h2X8dzfeSp7Swh8OSDr1wnGKG7T70yXd6JHRgT/uW9LLr/Wuv+guJ1qjfsL6qfAhiA/YxWA7fAh7EwSJpXTzHdUA8EfF3TCZCyBvXZZyNtP/5LKOsXU75SjJ6XPQw+Gu6CqunUhxOVAepvGTRDRkaoQtNg02+x+9+kToVr90QkBvviUI8BVxuCMbANmXjLmbTZyE1+inAHrfeWdYRma0OxTt1TVVcyAkRx2RcSpdXUh5d8fxGK+wSOSnLZ3J1t41ZeS6UPq2Tb1nGuHJzy1HVS1G1GBjc2OGDXA/X9M+SZEfXyuPzOTdS5LCoegWEhMzVxVnnQ2PLfgFAG8Iue936vTl32ZBkEHvA8oUYjnl9you4OP/R1r1RtaLYAP2t/03UTG0ovQ0y5OvGln/ef1Yz47fJKPkGKJA/XGoDDPRn/vrWx6wwyl9gLXSdbN48VmKiTs5ile8kI5AB1Ai4dPJ2PD7Q+NYfZuN52CR9S/I09dSilGcE9z9Ox6ZKyOTQakUG2hSGCUZ5GKsVj3oA+3e12o+S/VjQORSppjJwMo0+Xs9+++XKFF/ngVGLjlGGwMU1E5MdkqFAawvKkIRzwQ03K0XtetUPkgflii10WCWEf8GSfzETZE8p2MFdEsUoRu2lt2YpaRH26uapG/Md53LdvmJIoqaYngK31wTk//bKX+T3Bw2lNzru+RMKxDlYnm82UD65+iwLW2kVcg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB8198.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230022)(4636009)(376002)(136003)(396003)(39860400002)(346002)(366004)(451199015)(2906002)(5660300002)(66946007)(66556008)(66476007)(54906003)(478600001)(8676002)(316002)(86362001)(6486002)(4326008)(41300700001)(6666004)(6506007)(38100700002)(26005)(52116002)(6512007)(38350700002)(83380400001)(8936002)(36756003)(2616005)(1076003)(186003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?19MhoQBTZVYaKCSvy+XTPai69BpFpoHuC74ZfXKpGPwBONpfrxb2upBK0wLE?= =?us-ascii?Q?c999ysza0LSHs32qEaT0iP0aTi+YTMCh0mzSTmtUcBX8JtRQXNxiy6o/Pc9n?= =?us-ascii?Q?b5O+SPVBes+pAbp+0V1l5xO8BiIJm/EfmLZY6ztGA9fZV72NO0M8lM7IMLYV?= =?us-ascii?Q?n5dyUb1+bW6OTGtFX+tDTzxg0A0+hmXTF+fsaLBqm8cP8HtfozKb/t8mugyG?= =?us-ascii?Q?tCnlfb5OQTZQLYNaKfugu5h/k1xKxFPCGBxRLQlJ7HVTkkm4mCHiP4g9o3R8?= =?us-ascii?Q?vKpX3GXKg4Ifoy+Vq7Sq9RgoX3NfHe0dDJEl4stRhAmhiKMoqfSFFQUyXqVp?= =?us-ascii?Q?Qx2Y3+XXUVka825OSVbMkQq5+bwAeVoxSaOKrZXYkSJRluX7Kg8qrJhCUjJa?= =?us-ascii?Q?P0gTncPhwUzIshJPk/xP+heTdDTwnpebHzZAJC5G7M28DO1z3I2ZNT9KHuDK?= =?us-ascii?Q?RCQNVKuLa+A348PMlorVTxu9KT7XXxjxK+QoWpJtdwMcDsp+XjPUhCITjd/X?= =?us-ascii?Q?nMnNUuAsp75PjF0BUx3n02S/G/ps5S4eBvcnOSo5dOdteGrp4zZScTst4Xmg?= =?us-ascii?Q?F9fOrVkBcGseZTgmw4SaABVXvmf29S+2uKR5VnBoflGYBasevKX85mDXpWy1?= =?us-ascii?Q?WLXgrOYvDkPMymugxlvWi9Zu2pZ+uqakJ2jdNVFkE3PtmUd0z/cQqhpHshHe?= =?us-ascii?Q?lSwp1SRILvikIOJrvOXMcuANTJG9nTdQ+bSV7RY0NRMhK7UgUIVb7zA+K7pm?= =?us-ascii?Q?v5IHlL8L85bvZmPzJJGG9yG7Zv707s3M5pvNyj5hYb+IzVgav+kkmHIADXlk?= =?us-ascii?Q?TBjGuNV2NyzCTs7E8zOHuYs5+pTE6l/7JMlEn5JqQhFZxKOwWMJDoQFijPrW?= =?us-ascii?Q?LFiC+Fg+ajs7iUHvGGVQIIHMR+RbwKh6yL90poJvZiUdfr0Wf+FARCtG1LTC?= =?us-ascii?Q?jNcrEDH8qZkLYye34i8ZLxmUgBhozKPPZ07Lp6h5J4H+hBEbRvC0Lp2Hd+wU?= =?us-ascii?Q?clOzb3JuOSoIHFhyiOoB2PCimp+95YLsyzRsK8pMb0ZRkDCzHWlhE012YJ14?= =?us-ascii?Q?ght1bBLS8B7DWoPUpaEyLzgugni7RAaHi5PviWpg9JYf7MGgt36mztiWT9Sj?= =?us-ascii?Q?56eNR0rMfdN1auHiOojzr7qG7DgYFBNYauFgD4AybUnKJKtQ4bF12reDwRDN?= =?us-ascii?Q?uV66XESG0QovxKWW+BOZJd4Dhm2KgZgRMb9DjaD4dwnKYJNw/74+rvM1wG+4?= =?us-ascii?Q?HmCsDKVHfPWWcQe5Nvvol5lY76A8pNstBSfdbB6i3J4eBYjL5L8bS+m0hjcF?= =?us-ascii?Q?nfLPwu/Qi8bLQmO/Vtk5+FYByhddEthddtru6J4uJn6DTJr0k1nPkw0rhkqX?= =?us-ascii?Q?3hfZfl8J5LvL4g+Rb/OY3Rnax7oiPSoZ3DCQsmXGT30GygYl+N1OswaOGfU1?= =?us-ascii?Q?vXiVqQZEnqU1uNkX3Q/nfPjP4qn53NAqYwYdUCtxV8sSlVK4h7GwRdi6Nukj?= =?us-ascii?Q?iiZilfilj9YXd4euPF23KrqkdzLhWFBL+a9m4DvrlGKab9mDVzebzOsgJ2OE?= =?us-ascii?Q?SOq8pHVOYzTK6IMkZ+QmrPtXRar5pZCmIHNpxt7I?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ad853488-c941-46bc-4e72-08daa8140c13 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8198.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Oct 2022 03:28:48.5187 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: C0O+Z8LBxqY9C3SCqUGqigtdXiQ+AQEPX/yPKt3v1P18m2EL1gIwCQ7VwL/mPpXW X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9326 X-BeenThere: stable@dpdk.org X-Mailman-Version: 2.1.29 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 When using SG list to TX with external and direct buffers, HW free the direct buffers and driver free the external buffers. Software scans the complete SG mbuf list to find the external buffers to free, but this is wrong as hardware can free the direct buffers if any present in the list and same can be re-allocated for other purpose in multi thread or high speed running traffic environment with new data in it. So the software which is scanning the SG mbuf list, if that list has any direct buffer present then that direct buffer's next pointer can give wrong pointer value, if already freed by hardware which can do the mempool corruption or memory leak. In this patch instead of relying on user given SG mbuf list we are storing the buffers in an internal list which will be scanned by driver after transmit to free non-direct buffers. This patch also fixes 2 more memory leak issues. Driver is freeing complete SG list by checking external buffer flag in first segment only, but external buffer can be attached to any of the segment. Because of which driver either can double free buffers or there can be memory leak. In case of indirect buffers, driver is modifying the original buffer list to free the indirect buffers but this original buffer list is being used even after transmit packets for software buffer cleanup. This can cause the buffer leak issue. Fixes: 6bfbafe18d15 ("net/dpaa2: support external buffers in Tx") Cc: stable@dpdk.org Signed-off-by: Gagandeep Singh Acked-by: Hemant Agrawal --- drivers/net/dpaa2/dpaa2_ethdev.h | 9 +++ drivers/net/dpaa2/dpaa2_rxtx.c | 111 +++++++++++++++++++++++-------- 2 files changed, 92 insertions(+), 28 deletions(-) diff --git a/drivers/net/dpaa2/dpaa2_ethdev.h b/drivers/net/dpaa2/dpaa2_ethdev.h index 872dced517..c88c8146dc 100644 --- a/drivers/net/dpaa2/dpaa2_ethdev.h +++ b/drivers/net/dpaa2/dpaa2_ethdev.h @@ -129,6 +129,15 @@ extern struct rte_mempool *dpaa2_tx_sg_pool; #define DPAA2_POOL_SIZE 2048 /* SG pool cache size */ #define DPAA2_POOL_CACHE_SIZE 256 +/* structure to free external and indirect + * buffers. + */ +struct sw_buf_free { + /* To which packet this segment belongs */ + uint16_t pkt_id; + /* The actual segment */ + struct rte_mbuf *seg; +}; /* enable timestamp in mbuf*/ extern bool dpaa2_enable_ts[]; diff --git a/drivers/net/dpaa2/dpaa2_rxtx.c b/drivers/net/dpaa2/dpaa2_rxtx.c index 53e06b3884..b0ee58fc9f 100644 --- a/drivers/net/dpaa2/dpaa2_rxtx.c +++ b/drivers/net/dpaa2/dpaa2_rxtx.c @@ -403,9 +403,12 @@ eth_fd_to_mbuf(const struct qbman_fd *fd, static int __rte_noinline __rte_hot eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf, struct qbman_fd *fd, + struct sw_buf_free *free_buf, + uint32_t *free_count, + uint32_t pkt_id, uint16_t bpid) { - struct rte_mbuf *cur_seg = mbuf, *prev_seg, *mi, *temp; + struct rte_mbuf *cur_seg = mbuf, *mi, *temp; struct qbman_sge *sgt, *sge = NULL; int i, offset = 0; @@ -486,10 +489,11 @@ eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf, #endif } } - cur_seg = cur_seg->next; } else if (RTE_MBUF_HAS_EXTBUF(cur_seg)) { + free_buf[*free_count].seg = cur_seg; + free_buf[*free_count].pkt_id = pkt_id; + ++*free_count; DPAA2_SET_FLE_IVP(sge); - cur_seg = cur_seg->next; } else { /* Get owner MBUF from indirect buffer */ mi = rte_mbuf_from_indirect(cur_seg); @@ -503,11 +507,11 @@ eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf, mempool_to_bpid(mi->pool)); rte_mbuf_refcnt_update(mi, 1); } - prev_seg = cur_seg; - cur_seg = cur_seg->next; - prev_seg->next = NULL; - rte_pktmbuf_free(prev_seg); + free_buf[*free_count].seg = cur_seg; + free_buf[*free_count].pkt_id = pkt_id; + ++*free_count; } + cur_seg = cur_seg->next; } DPAA2_SG_SET_FINAL(sge, true); return 0; @@ -515,11 +519,19 @@ eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf, static void eth_mbuf_to_fd(struct rte_mbuf *mbuf, - struct qbman_fd *fd, uint16_t bpid) __rte_unused; + struct qbman_fd *fd, + struct sw_buf_free *buf_to_free, + uint32_t *free_count, + uint32_t pkt_id, + uint16_t bpid) __rte_unused; static void __rte_noinline __rte_hot eth_mbuf_to_fd(struct rte_mbuf *mbuf, - struct qbman_fd *fd, uint16_t bpid) + struct qbman_fd *fd, + struct sw_buf_free *buf_to_free, + uint32_t *free_count, + uint32_t pkt_id, + uint16_t bpid) { DPAA2_MBUF_TO_CONTIG_FD(mbuf, fd, bpid); @@ -540,6 +552,9 @@ eth_mbuf_to_fd(struct rte_mbuf *mbuf, (void **)&mbuf, 1, 0); #endif } else if (RTE_MBUF_HAS_EXTBUF(mbuf)) { + buf_to_free[*free_count].seg = mbuf; + buf_to_free[*free_count].pkt_id = pkt_id; + ++*free_count; DPAA2_SET_FD_IVP(fd); } else { struct rte_mbuf *mi; @@ -549,7 +564,10 @@ eth_mbuf_to_fd(struct rte_mbuf *mbuf, DPAA2_SET_FD_IVP(fd); else rte_mbuf_refcnt_update(mi, 1); - rte_pktmbuf_free(mbuf); + + buf_to_free[*free_count].seg = mbuf; + buf_to_free[*free_count].pkt_id = pkt_id; + ++*free_count; } } @@ -1226,7 +1244,8 @@ dpaa2_dev_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) struct rte_eth_dev_data *eth_data = dpaa2_q->eth_data; struct dpaa2_dev_priv *priv = eth_data->dev_private; uint32_t flags[MAX_TX_RING_SLOTS] = {0}; - struct rte_mbuf **orig_bufs = bufs; + struct sw_buf_free buf_to_free[DPAA2_MAX_SGS * dpaa2_dqrr_size]; + uint32_t free_count = 0; if (unlikely(!DPAA2_PER_LCORE_DPIO)) { ret = dpaa2_affine_qbman_swp(); @@ -1324,11 +1343,17 @@ dpaa2_dev_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) mp = (*bufs)->pool; if (eth_mbuf_to_sg_fd(*bufs, &fd_arr[loop], + buf_to_free, + &free_count, + loop, mempool_to_bpid(mp))) goto send_n_return; } else { eth_mbuf_to_fd(*bufs, - &fd_arr[loop], 0); + &fd_arr[loop], + buf_to_free, + &free_count, + loop, 0); } bufs++; #ifdef RTE_LIBRTE_IEEE1588 @@ -1373,11 +1398,17 @@ dpaa2_dev_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) if (unlikely((*bufs)->nb_segs > 1)) { if (eth_mbuf_to_sg_fd(*bufs, &fd_arr[loop], + buf_to_free, + &free_count, + loop, bpid)) goto send_n_return; } else { eth_mbuf_to_fd(*bufs, - &fd_arr[loop], bpid); + &fd_arr[loop], + buf_to_free, + &free_count, + loop, bpid); } } #ifdef RTE_LIBRTE_IEEE1588 @@ -1410,12 +1441,9 @@ dpaa2_dev_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) } dpaa2_q->tx_pkts += num_tx; - loop = 0; - while (loop < num_tx) { - if (unlikely(RTE_MBUF_HAS_EXTBUF(*orig_bufs))) - rte_pktmbuf_free(*orig_bufs); - orig_bufs++; - loop++; + for (loop = 0; loop < free_count; loop++) { + if (buf_to_free[loop].pkt_id < num_tx) + rte_pktmbuf_free_seg(buf_to_free[loop].seg); } return num_tx; @@ -1445,12 +1473,9 @@ dpaa2_dev_tx(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) skip_tx: dpaa2_q->tx_pkts += num_tx; - loop = 0; - while (loop < num_tx) { - if (unlikely(RTE_MBUF_HAS_EXTBUF(*orig_bufs))) - rte_pktmbuf_free(*orig_bufs); - orig_bufs++; - loop++; + for (loop = 0; loop < free_count; loop++) { + if (buf_to_free[loop].pkt_id < num_tx) + rte_pktmbuf_free_seg(buf_to_free[loop].seg); } return num_tx; @@ -1523,7 +1548,7 @@ dpaa2_dev_tx_multi_txq_ordered(void **queue, struct rte_mbuf **bufs, uint16_t nb_pkts) { /* Function to transmit the frames to multiple queues respectively.*/ - uint32_t loop, retry_count; + uint32_t loop, i, retry_count; int32_t ret; struct qbman_fd fd_arr[MAX_TX_RING_SLOTS]; uint32_t frames_to_send, num_free_eq_desc = 0; @@ -1536,6 +1561,8 @@ dpaa2_dev_tx_multi_txq_ordered(void **queue, struct rte_eth_dev_data *eth_data; struct dpaa2_dev_priv *priv; struct dpaa2_queue *order_sendq; + struct sw_buf_free buf_to_free[DPAA2_MAX_SGS * dpaa2_dqrr_size]; + uint32_t free_count = 0; if (unlikely(!DPAA2_PER_LCORE_DPIO)) { ret = dpaa2_affine_qbman_swp(); @@ -1647,11 +1674,17 @@ dpaa2_dev_tx_multi_txq_ordered(void **queue, if (unlikely((*bufs)->nb_segs > 1)) { if (eth_mbuf_to_sg_fd(*bufs, &fd_arr[loop], + buf_to_free, + &free_count, + loop, bpid)) goto send_frames; } else { eth_mbuf_to_fd(*bufs, - &fd_arr[loop], bpid); + &fd_arr[loop], + buf_to_free, + &free_count, + loop, bpid); } } @@ -1676,6 +1709,10 @@ dpaa2_dev_tx_multi_txq_ordered(void **queue, } } + for (i = 0; i < free_count; i++) { + if (buf_to_free[i].pkt_id < loop) + rte_pktmbuf_free_seg(buf_to_free[i].seg); + } return loop; } @@ -1698,6 +1735,8 @@ dpaa2_dev_tx_ordered(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) int32_t ret; uint16_t num_tx = 0; uint16_t bpid; + struct sw_buf_free buf_to_free[DPAA2_MAX_SGS * dpaa2_dqrr_size]; + uint32_t free_count = 0; if (unlikely(!DPAA2_PER_LCORE_DPIO)) { ret = dpaa2_affine_qbman_swp(); @@ -1810,11 +1849,17 @@ dpaa2_dev_tx_ordered(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) if (unlikely((*bufs)->nb_segs > 1)) { if (eth_mbuf_to_sg_fd(*bufs, &fd_arr[loop], + buf_to_free, + &free_count, + loop, bpid)) goto send_n_return; } else { eth_mbuf_to_fd(*bufs, - &fd_arr[loop], bpid); + &fd_arr[loop], + buf_to_free, + &free_count, + loop, bpid); } } bufs++; @@ -1843,6 +1888,11 @@ dpaa2_dev_tx_ordered(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) nb_pkts -= loop; } dpaa2_q->tx_pkts += num_tx; + for (loop = 0; loop < free_count; loop++) { + if (buf_to_free[loop].pkt_id < num_tx) + rte_pktmbuf_free_seg(buf_to_free[loop].seg); + } + return num_tx; send_n_return: @@ -1867,6 +1917,11 @@ dpaa2_dev_tx_ordered(void *queue, struct rte_mbuf **bufs, uint16_t nb_pkts) } skip_tx: dpaa2_q->tx_pkts += num_tx; + for (loop = 0; loop < free_count; loop++) { + if (buf_to_free[loop].pkt_id < num_tx) + rte_pktmbuf_free_seg(buf_to_free[loop].seg); + } + return num_tx; } -- 2.25.1