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 0321FA00C2 for ; Fri, 7 Oct 2022 05:29:11 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id D727442BBB; Fri, 7 Oct 2022 05:29:05 +0200 (CEST) Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2065.outbound.protection.outlook.com [40.107.247.65]) by mails.dpdk.org (Postfix) with ESMTP id EDB3940A80; Fri, 7 Oct 2022 05:29:03 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ADb98+E1iNYpYYJVdgF7UC/bwx08ZsWabNbgh1KaMpMzZxe4EDNxkUDd4Erv1Z+ko8fgIZS8p42jz+2GOA2sSXLdLzp3qaXrpwoxbvCcCtJCLEQDe702JYlh3YRyyesvRLZRj4CBiS/FMOQew4mw1Qq7xBbwYtMgfAtPBL5E5WWERVXVacuIbmXBGtA1IZLC8dEjtfgZdKZB5DH3jG7fG/ERiRj2qxtb+lkHWj01jjxYjwoBRm90yii8LE3Q3waKFJXEWu3LoXsRE5MSTOtSppxjtgymbo85kjJ7S76URAEbZsTpmf5/j2T6D+uvEzIxe1ajhOEzyHTtJP8aEngyTA== 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=X1A/f4hXDhPmSp0loaIvov2G+3aRgxOhjwepOstdZBs=; b=Vm9UXcgYHj+uXbqEASN9wdPJQGmp2PgcqoUTKDFu595rvf0K1BZxXc45Bl+48P+cZT0V4P+BUHFAhq56K6rT3Qi+4Av+cLLM1oHrMl+LQYtDfW/C3uXHzzuL8KGqiOQoUg+HDnKRzqPgisfU8vfF2Fl4LENS6OSlutMtmDmgi3EJGYNTsoVKOYOefCxDGYMKA24v4x7MGlpUFz1nCVu3YtqPDvOQw9CCR1yi99BCZiBCl3j+Cr0wDWC1R2Zfvve3SdZdJXemXC6FhlgiDw2uryNPmCP+C9jUGkIHS+u5wDq9yy5947z5rmnE3ujJYR2PYuWfFr+AQUY0Bni1uvfdnQ== 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=X1A/f4hXDhPmSp0loaIvov2G+3aRgxOhjwepOstdZBs=; b=AjdGsaoHdwuO3yze0BrMe7A9HcHPFtHDiViJTsvNokvqNo9QudENOuXW5njNep+J6snq4sdCy4PWDEoja9zi8U0Xb2hIePkV54gWbW8qStWdafbDV8K2tSJLBdwq+agx/dx8zlGnpMjJZ4EpsCqYdaM7wCeOSnb1+Xe+RjrEmy8= 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:29:02 +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:29:01 +0000 From: Gagandeep Singh To: ferruh.yigit@amd.com, dev@dpdk.org Cc: Gagandeep Singh , stable@dpdk.org, Hemant Agrawal Subject: [PATCH v2 15/16] net/dpaa: fix buffer free on transmit SG packets Date: Fri, 7 Oct 2022 08:57:42 +0530 Message-Id: <20221007032743.2129353-16-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: e00c1a93-85f1-4d3a-4b5c-08daa8141429 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AHPRDUuEnAddGGgV5QDeCLWC0y9CODI9RXFch2sPv5gcLuws0fVJBGg1tDRjkX94pyA43BejxpXySLdMbfqBAtydbmSrFv1pFvHn8an8hEzrkwwjNpgsUKcbknWvy+IsnUc9IQ/KucULeInIiqlKW9PFqUxwwlMW7KNwvCEhjgdSPp+MQ1PGjP515+1E1zDL1nmpffrvAKyWLEMWtfeHVcuDTwNMdgs7BvY0J0vJ9At6Jy9keqLDSDlVLm1AJKukgilcvVtUE5pqpW7asL1E1KNlSCVVbOtwvKolx6RMZPcOppeVFd/7x677/CAMVQQYcvEooUl2eWjesf9pXHiGRBCD7izkr9x6pQvUCqRjCrC062MZWV0lc8icPorlEXO64dk51COWQnpW2RhnnzVPpLTZB01Op8H3beN08GsbNoDaG94dN6VNyMqeSwBgZPyOcKQfa9ejryVeLrO60wE9St6Woo+1PsMMQDaOtoyevqkXcrGbJPygdwRf7KXUVlDIncWWlJRW/8HZvmKjfRyQXfyJA2BIynXxahiYf+yHCrcwxb6xc7aoej9VpOeG5YdBNS9maqC/j5Bk6+NQBALM6yVLvl69NvKFS10fNHxRCs3/JqqaJvF7B69ezTHA0v7hcrxnNvbOfbVum2rr6LSXV8dHqk2F+vpHu8OUvNRkhnU0IDQDPVtPzxJHnZprGkdAn0wvPPf4uDjcoIOO+rOByulSpTZ5WDTgo5r2RVhlrAk2k/tNiPlwO39OR5gdHKETOdtcG/uXYYik09qPu7v4dQ== 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?oj5t1+YDCDO+RcRvfmv0ZGe6NhmYxvycg3/dlBNlSzYM/ksdOzLjYtMNxHcv?= =?us-ascii?Q?1oQN6DQm+CYKbH5EfwcIgRO598dYSZ+Uohl4/ZKGjEQyRAn9wSY+f4TwYfvT?= =?us-ascii?Q?ca0IsbUivsog/aNeMXTSOYslTnYhM073Nib2KcHsIG5DO2sKz/Ivxy9H15CO?= =?us-ascii?Q?K4w8XLVPMb3w9Ft4G1CD2IsolkZutIkTru8zsW6Ii2m0eAr4Nf637WHK65+U?= =?us-ascii?Q?WYwoMbQxUN02nGGWCcMwixZswoEY0bskr/8+izDQgmRCRiySHmYEwAkBuNcA?= =?us-ascii?Q?vet7h13EiEy5dc+Gu0Pq7SH80CQ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JEiP91HghFB4MdXEliOIwQusHsvzKh9WixMp4XzzZhf4FU97R933kcftHhY?= =?us-ascii?Q?lCdwII1lh9aZ/F3c9EwmZxy9TFEiR7nnKHWFLJ40/ITQGOBqSHJkpD8njD2P?= =?us-ascii?Q?GEIUZ1ZY0z3b92yWxzIVxmAGG5nVHmIBwCiQMsT8PuVURyw+C5JSwUw2NMlT?= =?us-ascii?Q?fTEto+PbxEX3i2RHc28dP8BdFOdoYRty3Ql2GrY1ePbeAUiS9R7NJ3Sz9IqP?= =?us-ascii?Q?R7Hq/4GOFh1xteH9oTmTp+kKn2fp/Uw8miw6ye5F78vjFt6Alp/4dYMoOx1C?= =?us-ascii?Q?aYuHl/GJmR8gRU5q4qTmhecMkXQ1Cs8rEcU7AAfAXfSijsPT1uke6SpmZigg?= =?us-ascii?Q?BwDrNuAbY1BYSMl/KC0saUWn2A83tPb0yysENenY?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e00c1a93-85f1-4d3a-4b5c-08daa8141429 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:29:01.9127 (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: CGWHh6egLu3rjROb0a9hN/7Uu7fLBQamDJimyrysnPkKIM1wgA3uqkdx+VpjNpUU 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 direct buffers and driver free 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 below 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 this, 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 by driver even after transmit packets for non-direct buffer cleanup. This can cause the buffer leak issue. Fixes: f191d5abda54 ("net/dpaa: support external buffers in Tx") Cc: stable@dpdk.org Signed-off-by: Gagandeep Singh Acked-by: Hemant Agrawal --- drivers/net/dpaa/dpaa_ethdev.h | 10 ++++++ drivers/net/dpaa/dpaa_rxtx.c | 61 ++++++++++++++++++++++------------ 2 files changed, 49 insertions(+), 22 deletions(-) diff --git a/drivers/net/dpaa/dpaa_ethdev.h b/drivers/net/dpaa/dpaa_ethdev.h index f9c0554530..502c1c88b8 100644 --- a/drivers/net/dpaa/dpaa_ethdev.h +++ b/drivers/net/dpaa/dpaa_ethdev.h @@ -112,6 +112,16 @@ extern struct rte_mempool *dpaa_tx_sg_pool; +/* structure to free external and indirect + * buffers. + */ +struct dpaa_sw_buf_free { + /* To which packet this segment belongs */ + uint16_t pkt_id; + /* The actual segment */ + struct rte_mbuf *seg; +}; + /* Each network interface is represented by one of these */ struct dpaa_if { int valid; diff --git a/drivers/net/dpaa/dpaa_rxtx.c b/drivers/net/dpaa/dpaa_rxtx.c index e23206bf5c..4d285b4f38 100644 --- a/drivers/net/dpaa/dpaa_rxtx.c +++ b/drivers/net/dpaa/dpaa_rxtx.c @@ -803,9 +803,12 @@ uint16_t dpaa_eth_queue_rx(void *q, static int dpaa_eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf, - struct qm_fd *fd) + struct qm_fd *fd, + struct dpaa_sw_buf_free *free_buf, + uint32_t *free_count, + uint32_t pkt_id) { - struct rte_mbuf *cur_seg = mbuf, *prev_seg = NULL; + struct rte_mbuf *cur_seg = mbuf; struct rte_mbuf *temp, *mi; struct qm_sg_entry *sg_temp, *sgt; int i = 0; @@ -869,10 +872,11 @@ dpaa_eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf, sg_temp->bpid = DPAA_MEMPOOL_TO_BPID(cur_seg->pool); } - 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; sg_temp->bpid = 0xff; - cur_seg = cur_seg->next; } else { /* Get owner MBUF from indirect buffer */ mi = rte_mbuf_from_indirect(cur_seg); @@ -885,11 +889,11 @@ dpaa_eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf, sg_temp->bpid = DPAA_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; if (cur_seg == NULL) { sg_temp->final = 1; cpu_to_hw_sg(sg_temp); @@ -904,7 +908,10 @@ dpaa_eth_mbuf_to_sg_fd(struct rte_mbuf *mbuf, static inline void tx_on_dpaa_pool_unsegmented(struct rte_mbuf *mbuf, struct dpaa_bp_info *bp_info, - struct qm_fd *fd_arr) + struct qm_fd *fd_arr, + struct dpaa_sw_buf_free *buf_to_free, + uint32_t *free_count, + uint32_t pkt_id) { struct rte_mbuf *mi = NULL; @@ -923,6 +930,9 @@ tx_on_dpaa_pool_unsegmented(struct rte_mbuf *mbuf, DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, bp_info->bpid); } } 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; DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, bp_info ? bp_info->bpid : 0xff); } else { @@ -946,7 +956,9 @@ tx_on_dpaa_pool_unsegmented(struct rte_mbuf *mbuf, DPAA_MBUF_TO_CONTIG_FD(mbuf, fd_arr, bp_info ? bp_info->bpid : 0xff); } - rte_pktmbuf_free(mbuf); + buf_to_free[*free_count].seg = mbuf; + buf_to_free[*free_count].pkt_id = pkt_id; + ++*free_count; } if (mbuf->ol_flags & DPAA_TX_CKSUM_OFFLOAD_MASK) @@ -957,16 +969,21 @@ tx_on_dpaa_pool_unsegmented(struct rte_mbuf *mbuf, static inline uint16_t tx_on_dpaa_pool(struct rte_mbuf *mbuf, struct dpaa_bp_info *bp_info, - struct qm_fd *fd_arr) + struct qm_fd *fd_arr, + struct dpaa_sw_buf_free *buf_to_free, + uint32_t *free_count, + uint32_t pkt_id) { DPAA_DP_LOG(DEBUG, "BMAN offloaded buffer, mbuf: %p", mbuf); if (mbuf->nb_segs == 1) { /* Case for non-segmented buffers */ - tx_on_dpaa_pool_unsegmented(mbuf, bp_info, fd_arr); + tx_on_dpaa_pool_unsegmented(mbuf, bp_info, fd_arr, + buf_to_free, free_count, pkt_id); } else if (mbuf->nb_segs > 1 && mbuf->nb_segs <= DPAA_SGT_MAX_ENTRIES) { - if (dpaa_eth_mbuf_to_sg_fd(mbuf, fd_arr)) { + if (dpaa_eth_mbuf_to_sg_fd(mbuf, fd_arr, buf_to_free, + free_count, pkt_id)) { DPAA_PMD_DEBUG("Unable to create Scatter Gather FD"); return 1; } @@ -1070,7 +1087,8 @@ dpaa_eth_queue_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) uint16_t state; int ret, realloc_mbuf = 0; uint32_t seqn, index, flags[DPAA_TX_BURST_SIZE] = {0}; - struct rte_mbuf **orig_bufs = bufs; + struct dpaa_sw_buf_free buf_to_free[DPAA_MAX_SGS * DPAA_MAX_DEQUEUE_NUM_FRAMES]; + uint32_t free_count = 0; if (unlikely(!DPAA_PER_LCORE_PORTAL)) { ret = rte_dpaa_portal_init((void *)0); @@ -1153,7 +1171,10 @@ dpaa_eth_queue_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) } indirect_buf: state = tx_on_dpaa_pool(mbuf, bp_info, - &fd_arr[loop]); + &fd_arr[loop], + buf_to_free, + &free_count, + loop); if (unlikely(state)) { /* Set frames_to_send & nb_bufs so * that packets are transmitted till @@ -1178,13 +1199,9 @@ dpaa_eth_queue_tx(void *q, struct rte_mbuf **bufs, uint16_t nb_bufs) DPAA_DP_LOG(DEBUG, "Transmitted %d buffers on queue: %p", sent, q); - - loop = 0; - while (loop < sent) { - 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 < sent) + rte_pktmbuf_free_seg(buf_to_free[loop].seg); } return sent; -- 2.25.1