From patchwork Tue Oct 15 12:58:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Fang X-Patchwork-Id: 13836376 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2072.outbound.protection.outlook.com [40.107.20.72]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3D5F122737B; Tue, 15 Oct 2024 13:14:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.72 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728998080; cv=fail; b=PY8yP6l+u0kI9JwqZqAyU7zbb7CyZHeUtEl/ZEMHyozNsyqhGN+LpJpoJCV/Pc2fdrmwei0IQFI9XGA/tK5pFhiii8ivKjFFEDX0cQEQqBpYFfh0ESPXy53xI01Nmgq6W3618RvDMm0qc3uC63GLG3A8uYsFkfUi0V1IAqJCNK8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728998080; c=relaxed/simple; bh=sQLdV0v06zyyvLzB9Nv1+dtWHHhm+b8u8Jz1UJzn52w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Kv9BIF7wpvJUIPbVlwXFklnPfQqOXRTmE+5dM+EPl7RCmCoFcvKhGszsIhpcFAO7a5NUotTSOywglWmHkqor3gilxRsYYSsumgJf2IXbxCzFlWPyUCzMPqPZB9c0kA1VlSIb/wz2u3darc1L83Dyp94VWa8AA3BrGyOyMDzuCn8= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=jjZ0zksH; arc=fail smtp.client-ip=40.107.20.72 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="jjZ0zksH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=J9KS28CbWM0YmuUJ7wWY/ENFUHT1jwpgx5EfitvQ+YzI8Zz/CQAzGdWaXfFaezgyAPJYyuuqxTrIRzjIW82tv/FrwG2H0NgUMPQSNvnkd7WH8ZoIHt8GCAz3SHGPa7IM0QXZAiC4mCEPO5DZv631LczagKhJpon4Y6nlSosIZRMQT3eiVtM8BVbL3nH4ZFzV3E9gL5TcA7PJQYsyi10ToLldGkxOrtRyu4GfhUdrmHrBv371yXoqPXX2aJqrPu7JJG0LbjfMSTCeQNQuwcsO0as0h/wvBJLh1AjtuE4r5qjkdX+iUsyp/z3tNi83sQxlHkrQaff9FSIzIOIDQy42XQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=FHPIArrijIa1XkRQC3JI75JkmI699A8/kvPPVkroewg=; b=tufoOw008+l34I56W2wFEV7roylPKgjuVzEVKc/4q+py7fH03ReHUge3B62s/vVi6TmA4jlDqTgtpXYUwsgqo0IUwyTmQmB9pgVXPakwnJ3BBDHeRCv+6flToNEOtuR3UH/u/VPegsCG9NkwfAUloU0BbRPCP5LhJcfO0HtDoRYvjk5aJPDxdemeki6TNpMgwoZ844xLFo5SzAI2TCuFczlGbcOZzcXYEI4gl99RQVvvmN1ArS+HPjWm3+ccPjKtHa1M0nMzuz8QaJ9TVIluV+7VlwgSrKY5RPokulX5/pBQo5Apr2RvGfccdBoF/iEcIlAVh/ZwBtNpcdL8i4wLJw== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FHPIArrijIa1XkRQC3JI75JkmI699A8/kvPPVkroewg=; b=jjZ0zksH9CeiS2YWrDltypzkCbo8OX+CY6tyJHOsBgy7YOv4YstNrFkk95ITbgKg/6Z7KuSpxJz9dyrP0A+EhxKI/oDNtKyu/GBKQirnHWg64l/2HLKPPmHZeRPHfie7dP4flr2cq1pXJUWsG7jE3sZy0ulN6eyAM1xhRQhi9aKEMXiGDzOfC6cKGy+1wpe7evebsxl/C2bblckBW2tEE7Nvn3vpjQfPuxNiVbBt0UvWwJTooSpi26LDujPWv+WWjK4s4REUDRgxl3rhavusMWzruM96GMCwrRNOAM2uOGdpz5SUSHb++6uDVkNVQLp8YNqeG8IhXP/ygmDwMjmxbA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from PAXPR04MB8510.eurprd04.prod.outlook.com (2603:10a6:102:211::7) by AS5PR04MB9876.eurprd04.prod.outlook.com (2603:10a6:20b:678::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8048.25; Tue, 15 Oct 2024 13:14:35 +0000 Received: from PAXPR04MB8510.eurprd04.prod.outlook.com ([fe80::a7c2:e2fa:8e04:40db]) by PAXPR04MB8510.eurprd04.prod.outlook.com ([fe80::a7c2:e2fa:8e04:40db%7]) with mapi id 15.20.8026.019; Tue, 15 Oct 2024 13:14:35 +0000 From: Wei Fang To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, vladimir.oltean@nxp.com, claudiu.manoil@nxp.com, xiaoning.wang@nxp.com, Frank.Li@nxp.com, christophe.leroy@csgroup.eu, linux@armlinux.org.uk, bhelgaas@google.com, horms@kernel.org Cc: imx@lists.linux.dev, netdev@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org Subject: [PATCH v2 net-next 11/13] net: enetc: optimize the allocation of tx_bdr Date: Tue, 15 Oct 2024 20:58:39 +0800 Message-Id: <20241015125841.1075560-12-wei.fang@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241015125841.1075560-1-wei.fang@nxp.com> References: <20241015125841.1075560-1-wei.fang@nxp.com> X-ClientProxiedBy: SI1PR02CA0008.apcprd02.prod.outlook.com (2603:1096:4:1f7::14) To PAXPR04MB8510.eurprd04.prod.outlook.com (2603:10a6:102:211::7) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PAXPR04MB8510:EE_|AS5PR04MB9876:EE_ X-MS-Office365-Filtering-Correlation-Id: 4491cf10-da53-43eb-5e23-08dced1b50ae X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|52116014|376014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: oM6SOMveA6PZWgteFpFYx6F2/61csWTw9D+jS8HhqPQmH/PkbpYbohhmPiSObY3qeE71EGTA4n4K2I1obZrRfEAYpihQv1ofJMDawXkEyJYzAjzfbGleCQbUF6kbJbwKUabeYTiowc1PKX7HFQlw01R7Slvfit+YOKHRWjk7WKXg82i0KsPocq6xJTebWyeNd1lqMv4pTvkOKBqIt20uxtAvF8gIY3bgqqRX+hOStx+axnCZ1dy6+KVjiQuPlkzZt10+XiN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eQr6l9PODnCqThIRGyLk0a7aUr6g== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PAXPR04MB8510.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(7416014)(52116014)(376014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: j2Wd9MlnApb339V6tYn2R6zNFiY7J4N+hn6G0JC7xj5nwMR7fzOyZU4wTRfnMeQldO1cnOSHlwdmPXYTxL6MM4OwzpRkPO7NGeN2gGcZ5cEYrIixuu7Z5on4ANoaOUkFdNGcMPF5xsQcgUQBH0pXofjCJ7FSqGJrFVHQ+BMtjZvK6CLoJJ7Nu5RbnaKDecTdDv2kAg0JZIFdtAtrKGvCbILS49WfP8jkVE09USGerOAr0idnppP7JS9GF+tU5N85lUapo6pInb0ChRFCv7wBzgVYEnwennpCNMvyZ603Dl/AqtHOBibWqizEj9Aufu6yIcLgtSZUBWPQYlLYvdnZy2UCO9BKNbkIOQDjGOWmTlpHb6j41qVWmtQgMWAo2ti8E0by4f4n61W5X2s4LKw6Ms3y+Ijl/oTZ17nT/okLJOdjM1mr27ZwAGbuDlLA/tSY0qx7VBCHU/MvSFbw5xEqL4qQYp8jNNuoyYAlrChiFhO/dxjy51p8kzfxvRxnSUZ4axrb2RMylFNNd/3cuhYVA78y4Il2e79OZS4AqmHXdefpRA1ELuZdKofcOVgFX7ZrXbdSMRNDiautA3Ek0u03G42hAzgYYuulpxrGi6uWhjIFszbuIisuQ7TKvqjOOlAbOU9jE7potcciwdtvL7gU/JdXMRi8NcIf3EpptgwfUzCFsFOTP3dSnLvWTtn/Stx4y80CCwEnTwvzN0EI4YpT1eT+i6/B4oxnoKKPwqcWNrknJhYcv2xhg1g0P6pPSGkYk/DQx6Aw4KmYzvZdU4kLQTuGMxPK/Zbupxa+RRSqMn133rkibc83xcp+H0Z2qKiVOVYIYzDvDtUa6GPAuu3y+drwvSM+KxjZhAbRqk/TFRjYLXGzwnarpSf7pQyIVQ9D/roovhRv0WiwSa0UcFAaOQl3LCiAedBKk1lXvbvoFXJlWo69zo2J3KGhXp/oHD7jS9ePP21HQSusiUTLDY5jGwe0kdWzuHFvc4/wqrkxAIIlA3eiW2kAJtenkLJyIpzrzCWs4mYhXcyfQqSLSnNx5kkaY7T+auJ6Epb0ASBjBLSsBQGtVFwRZnm2BHxCqX/tFHFlvTuY25TqNjfbqWHMDPOzddXgPTgLKy3XT2R6XN5dqXQJIxR+dcSINyrbnaXgNY6lCxFaDmZQPigHsxeUeb5Bx91HQNwgSlL0FulaXZNJT9ArUhg2saxoYEu+Edn8nr91hL3mlSVE+nLhpy2xds1WbyBAAxpIFduUictluOND3k8lqCeb+EwyGVhzHVrNiFTbUQZccLB90S+Yuim96AyanxS00bFFAOzhX2TfxODpoLKYIEknWzzv9soQ8pjmmzJQHdBhXCGtgWK1+DmaprEElgK35eewUC3arfBPCTvC28RRwLuVaz1bh9A17K49FXBaNWcr9u7BDxOHvyvyU9Uwds9e5F+kK2Fuczz+9+jYwddsgaIP/xyvGw9aTffQiOdsuAFkJkbZg4Hg0CoPy66yckcRxDwr0LAojXXJjcwXE3K/QAFeDwrEEcR/KgYEgZnoiMoUm7KPcmsl2OTQ5eBk2pRvokZ6GS9GfdACxwi6N8ESVMMJ9Zx4cMfKkwc8 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4491cf10-da53-43eb-5e23-08dced1b50ae X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8510.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Oct 2024 13:14:35.5579 (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: OKZMAqT8JImtYCkY/v0MHeJLALRdiMTYeFIo/tG6Ytu2O3gjnBWEjqX/em9W3J0+vJMFaZSTCG8KmsF3pt83pA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS5PR04MB9876 X-Patchwork-Delegate: kuba@kernel.org From: Clark Wang There is a situation where num_tx_rings cannot be divided by bdr_int_num. For example, num_tx_rings is 8 and bdr_int_num is 3. According to the previous logic, this results in two tx_bdr corresponding memories not being allocated, so when sending packets to tx ring 6 or 7, wild pointers will be accessed. Of course, this issue doesn't exist on LS1028A, because its num_tx_rings is 8, and bdr_int_num is either 1 or 2. However, there is a risk for the upcoming i.MX95. Therefore, it is necessary to ensure that each tx_bdr can be allocated to the corresponding memory. Signed-off-by: Clark Wang Signed-off-by: Wei Fang Reviewed-by: Claudiu Manoil Reviewed-by: Frank Li --- v2 changes: This patch is separated from v1 patch 9 ("net: enetc: optimize the allocation of tx_bdr"). Only the optimized part is kept. --- drivers/net/ethernet/freescale/enetc/enetc.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index d36af3f8ba31..72ddf8b16271 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -3049,10 +3049,10 @@ static void enetc_int_vector_destroy(struct enetc_ndev_priv *priv, int i) int enetc_alloc_msix(struct enetc_ndev_priv *priv) { struct pci_dev *pdev = priv->si->pdev; + int v_tx_rings, v_remainder; int num_stack_tx_queues; int first_xdp_tx_ring; int i, n, err, nvec; - int v_tx_rings; nvec = ENETC_BDR_INT_BASE_IDX + priv->bdr_int_num; /* allocate MSIX for both messaging and Rx/Tx interrupts */ @@ -3066,10 +3066,14 @@ int enetc_alloc_msix(struct enetc_ndev_priv *priv) /* # of tx rings per int vector */ v_tx_rings = priv->num_tx_rings / priv->bdr_int_num; + v_remainder = priv->num_tx_rings % priv->bdr_int_num; - for (i = 0; i < priv->bdr_int_num; i++) - if (enetc_int_vector_init(priv, i, v_tx_rings)) + for (i = 0; i < priv->bdr_int_num; i++) { + int num_tx_rings = i < v_remainder ? v_tx_rings + 1 : v_tx_rings; + + if (enetc_int_vector_init(priv, i, num_tx_rings)) goto fail; + } num_stack_tx_queues = enetc_num_stack_tx_queues(priv);