From patchwork Fri Oct 7 03:27:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gagandeep Singh X-Patchwork-Id: 117546 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id B5D80A00C2; Fri, 7 Oct 2022 05:30:28 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 25C2942BBD; Fri, 7 Oct 2022 05:29:06 +0200 (CEST) Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02on2043.outbound.protection.outlook.com [40.107.247.43]) by mails.dpdk.org (Postfix) with ESMTP id D303C40A80; Fri, 7 Oct 2022 05:29:04 +0200 (CEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=M4qvITKp/Xltx979qoZblIKJvz09Au8TEVmH9wQ7h2lp0WfcfUuTaomBwZg8OJKJgcEM1kgm0e9zL8J/7hLNVZ1arJB/kFPv9ydYWw7IWhlmoqB/T7v378cAvDPV4mL7vXolezNlN5t4fia1s//11dLgLQWIIoVCoPyJTrYCnOWg6loCjD20N7tWAOY+lPo0kQEjLclf1pHCh3PX6lMmS0r3q1PXgMRUORjXQhjnFsM1Gi6y8COU9E7dJaOPu77LZwKLi6aW42PRTLsGKth7t1inn01qgWaJDHTDWZH0a/lQhwVWIpOpV2w1aos5vNmMB9A54EDydlG+QCMIaXiJqw== 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=XIAL+JPKfiUfEWJiJ/7QVa3Jh+ghKJNufpb/DPMEA4E=; b=VGgG7h21Ociue5J2lDiXv4+lAPv/bQ9Kid0Njf754X12ZuyN1jcqLqPIX2maRuTZ2SFRiOquGduVyZzwPqBcVgs/gBOwuv4FqHHhpmhSV6cc43tfULDaDDw36CfhhMG1/9Thxy1A+nu9czGrPsqJjrepCJjcBEyrElabbNSMdv5dUfnEhifXglJKly+GRH26W9TqELBtr4K4696Y92BXj77/H3xQn97nHu08gnHG9b0W6lryaACiR7WS5WkidVdieMcnKwheJqoeIlKm+gZJQ2tpnnMVB9kE1uv0kbQEGWAsBPsoU5y0ZaYuaxO5nL3BFKu+FPyHZYY9AZKygkbKjw== 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=XIAL+JPKfiUfEWJiJ/7QVa3Jh+ghKJNufpb/DPMEA4E=; b=VAvbLTqHLeYRwGE4NavNLrsATxDrH9hdjXEFuT3cpG+Sc7cpjH9DJkj3bZ3p7VR+Clo81MM3HUec9X9XvnAlWXMuVMkjNvMWCo5QY1fq/3ftg5mASuORx3xie25ETnIjrXpn2eovPi0I1r9jYmTxyhBRCEFNCzwCCvDHJ2SJ4CY= 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:04 +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:04 +0000 From: Gagandeep Singh To: ferruh.yigit@amd.com, dev@dpdk.org Cc: Gagandeep Singh , stable@dpdk.org, Hemant Agrawal Subject: [PATCH v2 16/16] net/dpaa: fix buffer free in slow path Date: Fri, 7 Oct 2022 08:57:43 +0530 Message-Id: <20221007032743.2129353-17-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> 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: b7333daa-66de-4937-dd6e-08daa8141555 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wLCeYAz55ZTy3rON678uI/sfbXPL5udu7SZ13fhhrSnjC9mtmEjw/EN+TxRs89poel3mY87K0u9JWvkhCCPV7JGSFJCldk3M5SzYjSoCOk/xYKY7MfoncgRFFlGIln9fsJO4ECZvQMgybBEFobwjPwYX+zI6GaIAgso/LFaMHj23r8wan+pxuU0m/8Z8TOt9iKJLXdIObhH5jC2CEMxhDwE9Ym05dKWsApIVYBs5Kqkju/8rV5aIHDnoV+pSXrYe9KmStORjRn6/GAplgxWP0YPrLdHYG8HLhml02crewuA3TOKhGaXAptrt4opR6gZXp6SrSFfmXUuEOdr2RL8qoeZV7bORKlaiyYYEaK678Ffq+GFJ3Z1o7O/RDwazfvk+ja9okCt6ih8TtngdUJ8bPI0G4hYQ3WiboFlYgpHFe1YxG0aAPYrc6urJRXpCPpB9/8780ONrIxpf8EOecYmJbS/5nI0VuTV5Bhl/2XMhRHEr7fn/hZynY7Jr7+7KATtTkSh9uIaZqGx+UDrqh/BlKuNKD2yI4lqWLQLeU5mUSnSYl2ZBIXkTUeoJJ6TqwxMolfJYMLzhH/xt/EgrVvbcXS8h5Cjf3dMK9EMAm6fLLKbDT4ekNJQFU09pbAxf3rmrWD8FEQ5MGW/6FpmP0SiXlDdhvCb3klMhJcB5adL1WEyBORxliIW/ULczmJq7QHbkYxWO3AbeTjL2Spa/cs6TLmooXP8fH4C1OFFo1eascxLJCjp1rzjMyNaC+B3LJzX/MNu7jlnkGbSGuTvmnVn7yA== 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: PP5LwcC4OvB5fQ4+tbjmKgpRKWvhDPh4/yA4Zq1B6/7B6njBEQ4rYFadGJXI1A2uTmHf+vg4515y26YRLdFCV74USX43W87IG5Xch5GMgcczKT/FUPRNSpc0E9rGQbSXwYUsUcOt8+f+uMO5b7wcGaYFZ3/HCaZiX6EQKjU33NyR70iuFJBahhOLJ4lb2UZ9tG9vk9izk/kna03em0ewe9uAIqM8Bwhg4+JEpkgldylOJOmLUH4EVgk4Ky+jbr3AcEjj3+787FEQMpxCas7FTdN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qdUdKsuE1z9DyXbNp9ANpWFH4/Tfa/O+RQD9noSehNKuMWPJeoc4bCNs6/VUB3KurObjyInbzmNtMpiGo6whzsfnLQ+GaQLKkPPWpkYV7HcD+8hpe9fJmP0+ILZ9aL0DjoYSiZWAU7ZQ5hO7cyaNOsl/DObJxaBiu28zAX4ju7PQ6O99e73M6n244u1qjcb36MdimnUw/zIAR81tBuVh8qRGYYlf+1edUPxUuHnaKCxqQhv1QDGE9qvQIFx X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7333daa-66de-4937-dd6e-08daa8141555 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:03.9137 (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: b0RyRavk8tqs6W/lxTt7irV4mDqfldggOmiVDXnZ0QVY3PglCzIxbuOguOFnIYkb X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB9326 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 If there is any error in packet or taildrop feature is enabled, HW can reject those packets and put them in error queue. Driver poll this error queue to free the buffers. DPAA driver has an issue while freeing these rejected buffers. In case of scatter gather packets, it is preparing the mbuf SG list by scanning the HW descriptors and once the mbuf SG list prepared, it free only first segment of the mbuf SG list by calling the API rte_pktmbuf_free_seg(), This will leak the memory of other segments and mempool can be empty. Also there is one more issue, external buffer's memory may not belong to mempool so driver itself free the external buffer after successfully send the packet to HW to transmit instead of let the HW to free it. So transmit function free all the external buffers. But driver has no check for external buffers while freeing the rejected buffers and this can do double free the memory which can corrupt the user pool and crashes and undefined behaviour of system can be seen. This patch fixes the above mentioned issue by checking each and every segment and freeing all the segments except external. Fixes: 9124e65dd3eb ("net/dpaa: enable Tx queue taildrop") Cc: stable@dpdk.org Signed-off-by: Gagandeep Singh Acked-by: Hemant Agrawal --- drivers/net/dpaa/dpaa_rxtx.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/net/dpaa/dpaa_rxtx.c b/drivers/net/dpaa/dpaa_rxtx.c index 4d285b4f38..ce4f3d6c85 100644 --- a/drivers/net/dpaa/dpaa_rxtx.c +++ b/drivers/net/dpaa/dpaa_rxtx.c @@ -455,7 +455,7 @@ dpaa_free_mbuf(const struct qm_fd *fd) bp_info = DPAA_BPID_TO_POOL_INFO(fd->bpid); format = (fd->opaque & DPAA_FD_FORMAT_MASK) >> DPAA_FD_FORMAT_SHIFT; if (unlikely(format == qm_fd_sg)) { - struct rte_mbuf *first_seg, *prev_seg, *cur_seg, *temp; + struct rte_mbuf *first_seg, *cur_seg; struct qm_sg_entry *sgt, *sg_temp; void *vaddr, *sg_vaddr; int i = 0; @@ -469,32 +469,25 @@ dpaa_free_mbuf(const struct qm_fd *fd) sgt = vaddr + fd_offset; sg_temp = &sgt[i++]; hw_sg_to_cpu(sg_temp); - temp = (struct rte_mbuf *) - ((char *)vaddr - bp_info->meta_data_size); sg_vaddr = DPAA_MEMPOOL_PTOV(bp_info, qm_sg_entry_get64(sg_temp)); - first_seg = (struct rte_mbuf *)((char *)sg_vaddr - bp_info->meta_data_size); first_seg->nb_segs = 1; - prev_seg = first_seg; while (i < DPAA_SGT_MAX_ENTRIES) { sg_temp = &sgt[i++]; hw_sg_to_cpu(sg_temp); - sg_vaddr = DPAA_MEMPOOL_PTOV(bp_info, + if (sg_temp->bpid != 0xFF) { + bp_info = DPAA_BPID_TO_POOL_INFO(sg_temp->bpid); + sg_vaddr = DPAA_MEMPOOL_PTOV(bp_info, qm_sg_entry_get64(sg_temp)); - cur_seg = (struct rte_mbuf *)((char *)sg_vaddr - + cur_seg = (struct rte_mbuf *)((char *)sg_vaddr - bp_info->meta_data_size); - first_seg->nb_segs += 1; - prev_seg->next = cur_seg; - if (sg_temp->final) { - cur_seg->next = NULL; - break; + rte_pktmbuf_free_seg(cur_seg); } - prev_seg = cur_seg; + if (sg_temp->final) + break; } - - rte_pktmbuf_free_seg(temp); rte_pktmbuf_free_seg(first_seg); return 0; }