From patchwork Thu Oct 17 07:46:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Fang X-Patchwork-Id: 13839595 X-Patchwork-Delegate: kuba@kernel.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2073.outbound.protection.outlook.com [40.107.20.73]) (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 CF9741D95B1; Thu, 17 Oct 2024 08:03:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.20.73 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152195; cv=fail; b=Y9qgAAdlyxVNGQTpiHOxyKJjlInwTDZbFLSAu5MTVttT51Hxdidp0EDCgkQZyzKgFU4gRfgqndBfvC8Db6ovIONV4PnudifPK1UnRqZpfycoLLG5qSAnUxcoaa22qNxCK669c05XIB/R+Zu7fb1UDbgAtKJt8yAmHNc5SKFlkl4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729152195; c=relaxed/simple; bh=abo+Ldkgms1WGf+D6U/EWtSvOZ8tOEprokNyhD7z0oI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=c0QjbdQ9347Fny2d/B7Q2gMaqo/vPiA/CLDLkW2r6ttV1vYAxMspG0CLZ+hRkuTFkLKPzYP/tk9O0zE7II1MdI8X54CO+zhszkvPCBbMTrMU8spRth3K3X+g03Jy0Afaf6lcYKek6DLj/38H23sJoA3FYM2rARnLzM0P57SGWMM= 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=GCXWIt/s; arc=fail smtp.client-ip=40.107.20.73 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="GCXWIt/s" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=WM7r7JqK5wTBGRBSkwIm6G7wkUBpHnuE2gnGztrUVKmeXpaCqBrjbZsmkVQ4LvOMx8Vf1aI3OfOprjJ4nwDYVCutB9wcdJHBC989sY9k8ArkQ5cwXztLhm8SjfTDswnFXDjcibfyuaYvKeUAmFhP4V741RNBh18SSnbCadGlTxHy96o/FGaIBbfZ4t8ilPH7uqmlCWCUL+18j6poYrcEKHaxUsPCClCXKyUM5G6kfs5++ngP1NkpgcBH6+UITA9P6byNmC8On4FVKRz7T+uyvCUsckvLq/AUEQKpX4ZWeenE061/OcEh7eN8U52tyT54c9VX/9FYH04brBrgrUlKBA== 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=k4602SH6vdfENeBnV7DfPkDPFj5nafh9EYI2M+Fd++4=; b=LaQgdGWzere9yMOJl1ulPxm1UNJyoO9U5zEF5VCwRpN9qoORv2U1+Ht66QWZO0F+jRXjOU19PlNXGYXyabhpd+7hk0bb/i4HRaUhVHB9P2IQRBfwT+eTbOb/bIaxVu63tlRyNLRNIwKvWAp1WChAfepwUibEvrjR/bawbcWEVEpTZbM+2dpdrIWdGAy+QNmhLb+muW7PP/4JhKGTLcXjV+WySH7ay9X6hyIIwXi46g6ooi03I8OtH2fZvBYaZDFYKzfwabBrcdftozUM6ng5+JtI5Pw6cJzHbS8CUefc7GhtxCcztyAxRfikTj2e/MAfg8kuOUKrwzYh8PNrCrgAHg== 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=k4602SH6vdfENeBnV7DfPkDPFj5nafh9EYI2M+Fd++4=; b=GCXWIt/s4q6+kyzOfgkVqMqxnuY98fpzQ/KaWd6Y7ZJBzoCVC4lxwgaZEJVETuWa4NEBa/lOD+Rfuhe4poA+Vc9TiyDUQMKCuhQ7WcFmbYV4sRONmikcdQcGCfi6MpvG/lm4yHRrrtxY31QQY8bq6b4ey/fFZmt9i8qCicQSMDxGWjk32YBmybV913nfc9mdVjhGw/isMetiKaPZtIL/CGLdlhYX7I3ODUJFklQxuBUVLnjGBlnPCy4NFVTrD6hQWPkSkzJWvDjoJJkIh69LVTWXIes9yVdpE/+zwElxPN/Q929KzCsvN8WPFRqNnCCfeG0+XklwFy5bjJ5Ucf2bYw== 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 DBAPR04MB7304.eurprd04.prod.outlook.com (2603:10a6:10:1ab::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8069.18; Thu, 17 Oct 2024 08:03:09 +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.8048.020; Thu, 17 Oct 2024 08:03:09 +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 v3 net-next 11/13] net: enetc: optimize the allocation of tx_bdr Date: Thu, 17 Oct 2024 15:46:35 +0800 Message-Id: <20241017074637.1265584-12-wei.fang@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241017074637.1265584-1-wei.fang@nxp.com> References: <20241017074637.1265584-1-wei.fang@nxp.com> X-ClientProxiedBy: SI2PR01CA0051.apcprd01.prod.exchangelabs.com (2603:1096:4:193::6) 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_|DBAPR04MB7304:EE_ X-MS-Office365-Filtering-Correlation-Id: d110e7b5-4e9f-46f5-1d7f-08dcee822389 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|7416014|366016|376014|1800799024|52116014|921020|38350700014; X-Microsoft-Antispam-Message-Info: BA0o6dDcmHwqoY1FIUW0I+lzV3WGqzWvvbhXIgvAhZC4M503mG/oG66lddwn8V2wiexiUXrZsArFXZlDeQqcXtz9r3rvn6tWeYCfwn1kbw/jn8Ql/g4NiMtCox8Oz0Nr3Hn+h0HJTyTzmasPwKDWqNbiYL1bI7K+wJN+WYjpCwb3STIFzioKHIQKBvcqcx1usWLrd8EDmbjE6CHlmnPDctTUKEPlnXsTKa0dgR2Y82vy46m62HO574KW3DD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EBC0KUguurVDdHynwok/Fsyz86oKAp/+rkcEznA7jIYuF68pazIqQjQ29tliA4FZ7pUL6G1Zpv8vOEbjCzFKP+K//+h 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)(7416014)(366016)(376014)(1800799024)(52116014)(921020)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: rGf7Q5saLr78mNEYDOJVTSiQ4V918+PQ/65SKvpRzugm6EFe05hTuz/4o4F38hchxZvyISydgEMJH6ry9thHO5Lc1gyLsHTWKnNFQhLGFdYuCIdZMSmM3oSdY87JYXhoqEeZRbwx7LGToHx2cNM3uLxBC7nI2ugLbMfSwIlsEmgU8SYyHXehxg5XFkzaYoPd2WanB5UxV3s5RLSSyOb82CHqhSFamOiOJmUOzZBxwqNMtHS0N/roGwKZdnOUhRtdfSq7rOaeKfmc7tCN/f3VjgpSUWBv+ABsnE7LlFNFcgCkmkcKZnavIRc2T951m8jstmk/CkuLpgJl4TcbHuoGRG7K9wgvWqGxmKJUaYyZen52i/qvpOZanvTKz91Vvezomb0kKxBmkMuhaboe1jQ8HBUoCD2INGGOMn3jungj7Ar9JeaEgkn5a1ilNjBKP11s5V3NPlXK3jwC2mZWOOJEnnS+0+fdIRbJdu0p6czCNPgFfwWSqmgZ/f1zzLEhNHrOgiLVkYr/qklABbedM3SFqBXBuxzlkozTyhJFHeHH+4NLxJxES4HGa07F8ixa4zLZr+wcko0eYW6ipufTvEHsllEh6b+AM6uYFrXHz5fPivhkir6WwaMQt0i864PqzyBKFo2Gk5KOv6E275EOaTxfggfyBmaGs2fbZsT6Y2dF5YBY+R9+zs7RwSz9hsOke823WhMYaaEbwVBhFmI9zCStzemLqLa1l0mR8xesmV1/g/Fzyz/k/1l1bQb1bbEHu9s2bCHeVcTyWnlmreqYNizqfo5X1NvPZWPKoYV/hL11KW6ezyZSSygo4gl8dXl9m9q+B+8W93DDqd1g0jZhJVb8XBqZ7mMs9G06H+DxQHXTs8u9epRd1SW/wO4rgduRiZ1nBfv5n1DU9AYNzT4FOQWMOg4LKRtV3KAw+Sjr0JeWC+J6wbakysVKzIc4TtW/reB5aNVaVNHV4/crNXEDCgF/0Dpj59PLGezy2GrpVsOSTA5b3POuHBOn3QEke/lzDeRJdDpXpgazlWDGeofxxl3+huyVXLlq/9j65ZChah1j0RFkKscpCnLRQ9jOP8qXXlOLzj90RK3K0+6f+2m+hfTvqZwR8AIxVeie9gmTMmSdr8JTFyKoiD7oZi3e+cfd9Yufv63SMBWwSj6bQbRXmUSaD5jIN/Pudq1+h7c3i2xYzRZIMSnbdpvH2TWBhjZzF9kXcA44QP3wvt3gAD3SGYG413WqPx4iUOgGxoB/Z22cxX3JrotJmHfcSkMMm6lZBH4AvqKBrF4/JAEr8DM1T3Vu05UppSJ/vS20VnaiDYcz/POUREtGMB8sY0umu7SRTd1uKZbXt+LBEXGGP//9luKKSTkRzOngsXOnUlXC/2MY689j/YIZk9BCvNgm2iFM6bAM+lvNY4cK99CG4SFBuwn413rJsfQn/PQQmVu881xaqs15bpvSxEDv3gHtd+/GfYavULXgJqhGLcJUkXXnYRx06B5JZZgQ6YHpAz+DOguZFXPlFd8hUMDNPWgoFKEKK4TQCi8r5/g5Ddo7125hjhsEBki38Norgk41O2X6THqhhO7p1Bdr0oPUNpZPKyKViGuR X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d110e7b5-4e9f-46f5-1d7f-08dcee822389 X-MS-Exchange-CrossTenant-AuthSource: PAXPR04MB8510.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Oct 2024 08:03:09.1652 (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: YC+DvxTf89wnDtH3BMQbKdYzD/qEIOQHd+rgS+n6PHpL4zmEmPO52aO9pz3jITenwZZaSVt6NA2QCrEgbZiGuQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBAPR04MB7304 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. v3: no changes, just rebase the patch from the previous one. --- drivers/net/ethernet/freescale/enetc/enetc.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/freescale/enetc/enetc.c b/drivers/net/ethernet/freescale/enetc/enetc.c index bd725561b8a2..bccbeb1f355c 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,9 +3066,12 @@ 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); + 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; }