From patchwork Wed Oct 30 09:39:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Fang X-Patchwork-Id: 13856207 X-Patchwork-Delegate: kuba@kernel.org Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011046.outbound.protection.outlook.com [52.101.65.46]) (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 C083F1EABDC; Wed, 30 Oct 2024 09:55:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730282150; cv=fail; b=ICIJf9PI8hWhlLIUxJl0+/QxFO96UYUGDWSyif49O+ms8yCINa8ngaZHjjTw7OuPBIeN9SLMKFPH4VJRlx0XI/murKLWxx3J1oVP5e4xps8KNIvw+NaUI5pW5MzL/vZpPKsKg47FyMiCrwT+LqjgYZ2imRuBI3NOaWgN3PYA6AQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730282150; c=relaxed/simple; bh=HoBm1EzDooAKHys1FjB6qVsFv9CMTg4Qgxw1LVvF0Z4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Y+ZbgrO/7jgJD47ACw/yC4rv/uzutfBuwstGWbEX/yDD0bL5bF2CWQHOxzW6rCiuLUZ3EwHABhf8v34aZc8WfHRk6zEFDLip70cqCzGO3CzgI6fBOJUZimNw9FeTiOPS9p/CJln4MRNgP1haaUcv1ezlGOvfL0oBJJJXZrr5kwQ= 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=cWKdImBI; arc=fail smtp.client-ip=52.101.65.46 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="cWKdImBI" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=tQPm+ZDXwhKAA/WLv0GnYyWWhxuYqGJ9iaF4hXS4t+vxOtz3J53UoyuYA1W7/BUnKnwfgyK/HfA3Co8hXQEHlrAkiTMkOmGaq3WDJ556adqkPW8P3iU2mBjKMnudDOfIpHAvGDmNBU2wrGXc4cGJ6BE7XdsEV6PVoij7Js+gE55fvKvFaeGmX6wlz2ZJnBlPmlPJv3njNFYRzW2tQMWi/D/pmZ+qZf64zAG3y/8UALnhQPvbc9RTqdQT+oNLb9dFGr3CavSLHpUnCScQR5jHjqGzR5gHjXhzFD3syEVhEts9RYKiVCAxsKnfPscvyPGcRVkHvSEhK5PxzK2hBuRFMA== 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=ZCq20NAtgk0hyXkMNIIn0r67H4ms8Djwh3AFS5QawQs=; b=bHgrvUkcO/VRTS72lp/UfideXnOA9aznPXsBbdQQyFTw58b/P/HbFGSFmqPslhCEyiF5hCsBi0NUiWDpC7bqcIQJHY3fbFeRKeU/90dC66r3AIyLJDmjYvMz/bDPbBD2pNCTTA0kZ4RBzkdptfavA4o+qWxrYLh6UOawRjcRKUqFqjwTt3K9aJrTJrK9vS/dVHt/VYZipFqu4lHGcEW/rMt59TwLnoN4VrdDC/88fwnWjPiEdUaqP8pmAnrF129NAcJxuLnFm+PXlUEcpE2au0gNOHqmOIwzef1M/efwas/NHuekIr/SKNGmWFtZfk3OjLSjCJ/EiWyLfiK+ATm0pw== 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=ZCq20NAtgk0hyXkMNIIn0r67H4ms8Djwh3AFS5QawQs=; b=cWKdImBIgJM13nCoUfYSs55GnngHVPPe4cyRtm8cL4F1Q2ljSPGKL7Gi2atZNh6N12z1maNFQ2OKqPD+YL2JHabAaPKmlZXnV1Iv3sMIJ4TrF/OLR15KbQ0vOvJUu8g5rxvLGyKurhMfTfL//SLvtgnUGNN8y2NZ/mkknOWPa4j7BMJQpl2rue82SGbTb9gO118eBmjdYE8t7eBLgWwoJeMM9J//ZnRqdJ3/t4o3bj9OUuVyVd2gvf9pFHkfBz14RuxaJBR4THwvJyYRkDOGlh9Juf/VeB1CleInIAHiZU/RvG3N26sj4wQAabfSD7ZVLooLAvXLQfrji4kYh7XPbw== 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 PAXPR04MB8912.eurprd04.prod.outlook.com (2603:10a6:102:20f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8114.20; Wed, 30 Oct 2024 09:55:44 +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.8093.027; Wed, 30 Oct 2024 09:55:44 +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, 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, alexander.stein@ew.tq-group.com Subject: [PATCH v6 net-next 10/12] net: enetc: optimize the allocation of tx_bdr Date: Wed, 30 Oct 2024 17:39:21 +0800 Message-Id: <20241030093924.1251343-11-wei.fang@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241030093924.1251343-1-wei.fang@nxp.com> References: <20241030093924.1251343-1-wei.fang@nxp.com> X-ClientProxiedBy: SG3P274CA0009.SGPP274.PROD.OUTLOOK.COM (2603:1096:4:be::21) 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_|PAXPR04MB8912:EE_ X-MS-Office365-Filtering-Correlation-Id: b3c2dcc4-7e37-4a04-d197-08dcf8c90595 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|7416014|376014|52116014|1800799024|38350700014|921020; X-Microsoft-Antispam-Message-Info: lYinEs4DKPoMnmXmWcKdqEfUeTEcOBACqFtS+uVyX2kodH/gZ+di5pNrrbg5AsxgSGtK0vT3tYEQAzX8fDXSnJKjj9dgJAzpxuHVEfCRzniFp0GY8EIGusyp+aQ7rVlbT/xqazCEGB/YH6C0ZX6Ft6hvph99cLUSO3iBXCvJVU1dqHFSWAuXTHB3luHFfrMLlT0Aqj4+11I5ZlYMncgXI0K07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nCdC2zrbIdwzRcFOTmLZSAphG71onrj8yohpdVru1Cfw2DXqVjwz6JMDiP5m9Y+P/EQ4cIz84OJtK7Sa2IvXM6R7dEIz+w56VcAPA 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)(376014)(52116014)(1800799024)(38350700014)(921020);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xC3mkSs7xLfBQif7vfS2d1jRCOyaapXDOn7YM1HzOnp9fyzR3F7+Knx9nH3nMB/9tctV33Ex8QYBhRz3R9Dz2N+7B2UFnOZyC2gGEk2x2VvP0C0ngVmqSbcuEOHVYX3uxFkxxAPOdJ5U8/nYdbezfWF0/cpvcBB7KSCm99DIeCuWNCrePbldBsajRuHzd+K08jzS57G20u1lGYdMVwRTwalDySTfCDXo58i+tPEcq2iDTKpPRilY2Ol4ioqHJ+eMCqbcH3Hs99iKgURKPXDMAqbSlY2xaUZdSNC6ll04Vu0AP7imvFdnZwRuNUo63zygaKPgRU15OzuSJUxXZPtmV2QAy/0hYnTl/bKw9r7a2Zy/owmntte16830dNiRltWpM+LTCx/gg7ZZR18YE32bsPA72geWYS4F7SfF0L9O5TWpRihmN8c79XwGrRI5G37wWXCKVJJCqJiQq8+ujL06KqFok0UVawj3uk1Rgq/YHS6HfAlpdsCkS6empC52Tg7ojzur7aaborTy61bTIvucvddiPhKvU8FoZwreDMLuM1PESz+goVR2gvkqKDrPEEjJs4dnkOA9dniknH6m1BwzmGl/URIcjb9YKEChbBAppat8zchURZx3GQhc10YOOfu1kTTjS9/5gNBqVFNBMs2NQnzWkCykHcmKUyrFqiQsChU17F3WSBkTJMDrmBtzcjx7noXZ9E/ESPZEOrsYsHcAwCSuUVXct8yb0Tmb0x5g4rzU4+eeP2v/ebVPHw2fmjohrmYF3u/PJBXThz44ehZIDg49hsgd2uQiGbMFEEONEF0rXmGD6Xk0Y2hkv1xs2HIJJ3qwOKA8MKGOiNykhlUcp/kMUpetfZlMiq9dMBb+YFXQ1hfGZvAXY7MmGILuZ6nRt88w/D4rLmNv79mJFfT4WwfDowCcoVKIMn1Gsq6VJaRtpKESDwXCkOkiHDRAWt9YD7IX7+X/6IzmisLcwzf4M5gv/6Z921v8OjU+JlEhuQHmy8zcEvLbLmyen8ISZWUN9y7Im/rEO6xwspVJZXSWyDHDzAY6P8ttvtHXBsXtBpwxzm0YGkb7wIEOVFoD/0kyqFIiafwDD468H36hb/vR+5mUnN/4YieY1jjGq3aS1UYXGXhWTmc+G2/ZeY5yohp9d1JANNRSrdP1ZM+ePB7qmqkXOxE92WbccXiTm1kaJcCwt3yKlwFU8jaJN0LbdBy4tsgrG6M4400NmxEVcM5S6J41UrFj5eWAjqiIRrpHMw0ZWIsTJiKDK4Dm0EF0+bGhr8o0KQjWelLMLAqNf8m+PCGqHx7BneNMBhiI94oGH8h6u2bYfzt92Bih9ojClYA/hWBi4hlbaycBWEnhDYT9tJybb7jXXWZcAp8OqOqiWm9u4boiBx4HwwdVomfkRA0J10wUB5D0s94JksAfUTLr188CVtG/xFoWma466nZ3XSf+Md/yrKPai4Ko+LeViLJXbsjkshuaQnIi2Juhzyt3vZ2MWlWLH7AH6hTuXLr6PTwQ7qKaDTJuKL3wK90ZyVlzquEuj7EfJYBZKZddV0Ec2Dp5CC+7qxuXnDO/zICF4w3psqEd6hUj/zPBqfcO5SeP X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b3c2dcc4-7e37-4a04-d197-08dcf8c90595 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8510.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Oct 2024 09:55:44.7699 (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: Pzvj64BcERSAWlYkr1qA93pCJgzY5i1tvAJIXlAcrdXgZG2xyjhYeyyYbFK4SZwKGIf0CZmcswbBYSqb2RftKQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAXPR04MB8912 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 --- v6: only add a opening comment in the code --- drivers/net/ethernet/freescale/enetc/enetc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index f292c5ef27b7..89d919c713df 100644 --- a/drivers/net/ethernet/freescale/enetc/enetc.c +++ b/drivers/net/ethernet/freescale/enetc/enetc.c @@ -3084,10 +3084,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 */ @@ -3101,9 +3101,15 @@ 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++) { - err = enetc_int_vector_init(priv, i, v_tx_rings); + /* Distribute the remaining TX rings to the first v_remainder + * interrupt vectors + */ + int num_tx_rings = i < v_remainder ? v_tx_rings + 1 : v_tx_rings; + + err = enetc_int_vector_init(priv, i, num_tx_rings); if (err) goto fail; }