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 5CC73A00C2 for ; Fri, 7 Oct 2022 05:28:44 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 3C88E4284D; Fri, 7 Oct 2022 05:28:42 +0200 (CEST) Received: from EUR03-VE1-obe.outbound.protection.outlook.com (mail-eopbgr50080.outbound.protection.outlook.com [40.107.5.80]) by mails.dpdk.org (Postfix) with ESMTP id 49A1D4284D; Fri, 7 Oct 2022 05:28:39 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=baPBslC0KKd6kSdgSZAr2YWGYVIiiHUqkQXhXnF6vezwOZ3M7RY9sbF7g7z2wqZ2eamsFJguWVNuYsPHPPz8sQIUKpoOX2EFYkqFxvWg+rhh4w+n18fIVNKjLgqSWJN5TRwvHuFhZi8+v12XVdpTCdhDlxtc9nsZaLapoJoewNAKOcPI2nHfypjkeDFNtsPa6EO5bkB/4ZLbCLBAc8gDDjskUMDp/wH3loNhatCUYNIRqAa8MDoQxLoHidC5ox0CeOshjxD9kwVeNH/owWt3sMC5Wrmsi8fxfzckpEPnsxw+umnLyxCuVNgRXBZX15HIwM95JcTgNwhGnMc7+5e8Jg== 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=i381NBMGbBxvgsHYfql/a8vIgPfkO1waN3NZd84d1+g=; b=Cbh5ddBbZUek16BALW7z0+dzz4IwJV4wt7Vlifu9dqZHlydoA3iX5o9iFT3xoBCcbPkFpfFoaMZVl+T+zQw07DIdTBv/mFHqCyLTdk2iFhGRL1sKUeVRLNY3OCiNoiJ2I56G45hrpJjblM/sdWrpttzL64lldxFCwJZpRVCknGvwNldvfQm4mYUm3vPT+F8L2CMlsxBkPCLkpnClqEhaBYxKyzBzgKRhNd3EzhEpfW6jiJV6GvfxdEbrgB7QY+tXu+C3Ah7uhBbVs1j/cefODEL89//0Rt+ReLMUogQx1JZgSkIR8LbMkxtnQKIdIpwjzCluVkwAQbd0C1+qZApEBQ== 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=i381NBMGbBxvgsHYfql/a8vIgPfkO1waN3NZd84d1+g=; b=oKJbI1SPMdMJW5eKBrPpyLPvLdUr6mW2uzxoi5fU8Cv2fUB6qfLGMLnicc1EF2i+ogbqA7ByZ/ti6OW/MW9fwHV2JnP1gceC+W8IZPXrFk3fMadJyTaTBl6rbbs9x5J524tdBwPwm1Lwb9T2GwAAgJivIRZ1yRUyQyNYXtiECRI= 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 AS8PR04MB8641.eurprd04.prod.outlook.com (2603:10a6:20b:428::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.38; Fri, 7 Oct 2022 03:28:38 +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:38 +0000 From: Gagandeep Singh To: ferruh.yigit@amd.com, dev@dpdk.org Cc: Apeksha Gupta , stable@dpdk.org, Sachin Saxena , Hemant Agrawal Subject: [PATCH v2 03/16] net/enetfec: fix buffer leak issue Date: Fri, 7 Oct 2022 08:57:30 +0530 Message-Id: <20221007032743.2129353-4-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_|AS8PR04MB8641:EE_ X-MS-Office365-Filtering-Correlation-Id: a10a0b47-6502-4ad8-3c34-08daa8140626 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5Pzd56olmN0BI35YnlJZTz3oWnMptLzBLRpZW820gEITsNlkL4m9RCSeNzdXhnzIWKHXxZKbcjhor1fzP59Lnkz6ss0et+ATL9csfT6xuYPHVU5Al4zxHc86aenaAts86B9i1tQaxQ62Mv0EybyqNUq0miSuvSDhOiN87zSy7fS7wfOBcNzP349pSOhgy2TXiJDhTg/wWgMgu5+UVgfojhkPp0y4LxjdwCQ3zX3GDcAnRKIXYHitWGguWsYUVOoGwq8aFuX4qqJw2h+QVvdh97XBBbh+++QUru+Wa9+GKGruYElRPDkAFIWfNWIULsgKTcDPgog6upvj9Rkwf0uaSFTJxpNJ9MF3teaVUU7iEG68DMyNOSKDOiCiPVIdFPCwi5yb9q8jIWQPTAdRpqpcH2L65vM2TY4ZSHnr3urlezyzikzF09KtqUnMNhmr2YDfJtwmtyF1XFrjF2BBMVj5zu8ZlSw3fO9rIcTLhA1ATzhA0gC4Qp1aWeBl9LDpnBZvXbRap1B54m/8ZsPpq95aeOWeaFObt9gEBaiwaHxdrgsAr3tZ1AuOgLxRG9FqY0tY4x5ygHDFZ1SdDJ0ceYIxmgkpFXI+s7Ca61cAyU/CHMSM1qJRSorXpuB/QprpyLdLRc1rgZ6pvHR4ce4fOMCu9wQvfIenWQnC5+uEKVSFaQDH65VQHUd2Mzbs5/THFGxQAgyr0jhgRpxZ0Ozn1ERLdS70xpnG8fDrVjXXRYr3Sb4xBZu9HqsebEYyildjyGNX 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)(39860400002)(136003)(366004)(396003)(376002)(346002)(451199015)(36756003)(54906003)(6486002)(6512007)(52116002)(26005)(83380400001)(6506007)(86362001)(5660300002)(8936002)(41300700001)(2906002)(38100700002)(316002)(38350700002)(8676002)(4326008)(478600001)(186003)(1076003)(6666004)(66476007)(66556008)(2616005)(66946007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?4At18hbDr2eH32t4PqbTHmrBrSJdC/OociiaYzHEaN2wx57amvSAW/qzCCAs?= =?us-ascii?Q?CZqHpXDepC7etP4sPUkI2kx13cvuRUGaDKTe5pfiddeAXs27HRk/2APFFHie?= =?us-ascii?Q?eiyRv6B1gpQop7YNbfgj6wZoebZvw2oqwQ6ZFOWXNSbnEtnJIoVzvKAvmS7M?= =?us-ascii?Q?Te3vaZaLdtmHcNkbNWQSz9XOQ0YYCl33QzF4rBX7ASyQZT8r/J+QRDfXZD56?= =?us-ascii?Q?VwStLAOcw/lAubj0binKjMXHzUUQlxydjETqIi6WgeXl8YgYE1kjaibk//dq?= =?us-ascii?Q?izWmIlBwug5A3tShcLz84zv7tBDkLyKQMe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kg?= =?us-ascii?Q?nb1i1g6676+vuwO02q2mUzYPBWIwX9DWKwe5fG+LcsITlu4YMtvZZdp0WlB4?= =?us-ascii?Q?q4piiqaEuAjipT2/WhEXpgkdX+bzlwPm3IGQHOZEEtUM54GcgbPDOjosuATq?= =?us-ascii?Q?Wbvhk8flP4Cf1el4etTNQfSw/+Ho4MX02fBQJ0Ock01+3xvXyjHngZ34R6kB?= =?us-ascii?Q?XSSKfM4l0sHCYj/GPjmS7dAgS+5onQCDmU+Sl8I81ddL8w1qSziepHGho081?= =?us-ascii?Q?eyT2BAsUweiNuYqXh4/gV3t5LmF1cVdYhJgmj/9B1yzU2CrPF04TI+Lv+hnO?= =?us-ascii?Q?U2f6NhL/sXSitqPJOOzckC39Oo77Y0AqSQk0xYwO89UGqMJp0meF9OBcHiKv?= =?us-ascii?Q?X/65D+knrJGx+I7ajo70YoeirlyY6QaxjGd16rHf?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a10a0b47-6502-4ad8-3c34-08daa8140626 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:38.4671 (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: jQXME1phjtwYoByvRzMpWn6WUKW9Bm5IbMUTyV42NgYvEImvpYYpUyCF0cFHhlfI X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8641 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 From: Apeksha Gupta Driver has no proper handling to free unused allocated mbufs in case of error or when the rx processing complete because of which mempool can be empty after some time. This patch fixes this issue by moving the buffer allocation code to the right place in driver. Fixes: ecae71571b0d ("net/enetfec: support Rx/Tx") Cc: stable@dpdk.org Signed-off-by: Apeksha Gupta Signed-off-by: Sachin Saxena Acked-by: Hemant Agrawal --- drivers/net/enetfec/enet_rxtx.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/drivers/net/enetfec/enet_rxtx.c b/drivers/net/enetfec/enet_rxtx.c index 49b326315d..0aea8b240d 100644 --- a/drivers/net/enetfec/enet_rxtx.c +++ b/drivers/net/enetfec/enet_rxtx.c @@ -39,11 +39,6 @@ enetfec_recv_pkts(void *rxq1, struct rte_mbuf **rx_pkts, if (pkt_received >= nb_pkts) break; - new_mbuf = rte_pktmbuf_alloc(pool); - if (unlikely(new_mbuf == NULL)) { - stats->rx_nombuf++; - break; - } /* Check for errors. */ status ^= RX_BD_LAST; if (status & (RX_BD_LG | RX_BD_SH | RX_BD_NO | @@ -72,6 +67,12 @@ enetfec_recv_pkts(void *rxq1, struct rte_mbuf **rx_pkts, goto rx_processing_done; } + new_mbuf = rte_pktmbuf_alloc(pool); + if (unlikely(new_mbuf == NULL)) { + stats->rx_nombuf++; + break; + } + /* Process the incoming frame. */ stats->ipackets++; pkt_len = rte_le_to_cpu_16(rte_read16(&bdp->bd_datlen)); @@ -193,7 +194,16 @@ enetfec_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) tx_st = 0; break; } + + mbuf = *(tx_pkts); + if (mbuf->nb_segs > 1) { + ENETFEC_DP_LOG(DEBUG, "SG not supported"); + return pkt_transmitted; + } + + tx_pkts++; bdp = txq->bd.cur; + /* First clean the ring */ index = enet_get_bd_index(bdp, &txq->bd); status = rte_le_to_cpu_16(rte_read16(&bdp->bd_sc)); @@ -207,9 +217,6 @@ enetfec_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) txq->tx_mbuf[index] = NULL; } - mbuf = *(tx_pkts); - tx_pkts++; - /* Fill in a Tx ring entry */ last_bdp = bdp; status &= ~TX_BD_STATS; @@ -219,10 +226,6 @@ enetfec_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) stats->opackets++; stats->obytes += buflen; - if (mbuf->nb_segs > 1) { - ENETFEC_DP_LOG(DEBUG, "SG not supported"); - return -1; - } status |= (TX_BD_LAST); data = rte_pktmbuf_mtod(mbuf, void *); for (i = 0; i <= buflen; i += RTE_CACHE_LINE_SIZE) @@ -268,5 +271,5 @@ enetfec_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts) */ txq->bd.cur = bdp; } - return nb_pkts; + return pkt_transmitted; } -- 2.25.1