From patchwork Wed Jul 10 23:00:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13729806 X-Patchwork-Delegate: kuba@kernel.org Received: from DUZPR83CU001.outbound.protection.outlook.com (mail-northeuropeazon11013028.outbound.protection.outlook.com [52.101.67.28]) (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 9B97E77F0B; Wed, 10 Jul 2024 23:01:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.67.28 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720652500; cv=fail; b=j4fFxeMgKGr2fWzDY47MvdLlWX/8FE0l9oMYIjUp7uCoe59mynr8109Cd9OMRE7PX8CUZbF+LbZJ2y09vhXxn50P2Dyg/uiTuDDjHbGW1P7yJIKV8aYpx5+LtTWNOk7SbTbGGn4MQg+kXLEc33ZLoAOyWF5LszgwXLcksGUUHsU= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720652500; c=relaxed/simple; bh=Iiqc8RrXXfkC/M93qjIMIEWoKOiGUjbKC4KXEjQiaNo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=KNJv32EMeDHghMNSkjGQC8G66mj7Bj+CkuYjmEhzPw4xlIyEK1buJ5FZoPmJGHZntlKiTaWaIeJqDfLyQnx6n7D4qhJf565Tv0v4GNzvRo9+kCUlVoqlOTZcDT7ERpEaPLsB7vNP9H8lsJ2ivsaDbr1s5TUoOOUJO7Ry0yMdqO0= 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 (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=qONo9SeE; arc=fail smtp.client-ip=52.101.67.28 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 (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="qONo9SeE" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DFeyzavv0ZFTTexIGVicGBSxvnUVX/nsKuawh24ldyKc4SJrf5yXVYJN8PlbKMBBtyWLAdG6zs/Ke+I9GbnQ3HHjkLzBt67D8d3Aj/0U1/N1QbDeOdNkfktc+lQ21AQCnrYUtekpZu6subfOGOQl/fGqErNH7Jb+cX3zyj19BOQgX2sny3zhqbZGllHOl8FGdpjGX4ZZBLwXLtRMbbhUttAgZctlkvVHCKggbLzBEjBOo/5EBGeW+kDqrddCnGOop/wYHY8VMB16eLvnOfiO7z2O4FZIsVuvBaRxX/2/bCS2pBgzdHK80Kix5CUzn7Jee8oVTY4AaU90/NEN4ElTxw== 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=OX5Kxh2i7L1ONCVRUfVtr9VckOT4uj5NsOntuOFlsg0=; b=mz65lWSyHagVd3SjYy3NO4fNxDO1Xr/2VO2TxPBGrZzuUwYKA/+JnBhyWsJkS9t9LYGeFl++RIkvA6SKHvYKKCjH7EYXlu92+aKoJZ1Onm+Mhl36E+wplxIta+JNjbKxxCMvHi8+GhdIcLgAUM1B2WXuiQiyBz889qPIFLkGguY4TvDIkzA3OfC5chRpMb4cCHy0atlDA4Kpfg7j5jec5aBUd2OIS79wQ0/FtMXRJtfzF1IylXPJJoYjzLYWWyO6y2xJyh4GgA5cK3xmAMxsmLC9zSwchh00qBKxUnNkzJTmnGvTtLViRMe2EV9I2kqHq/HiPnUfis7chN40ipgcQg== 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=OX5Kxh2i7L1ONCVRUfVtr9VckOT4uj5NsOntuOFlsg0=; b=qONo9SeEaGG5+sNK5dOd5zghIwJr5FqMuWgTuL6sHzQrFE30aDvCGdrx5Ue9SRAn1ZuqTmfvflyBmve0HYfFHc/SSF3edJFwAS9Jb+iyO/K4IYEpoDMfaAC6r68aEySEpq9QIeJhee7uhw+uEdRENi8pt8EJSlJcg6xSbIDy8qY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from DB7PR04MB4555.eurprd04.prod.outlook.com (2603:10a6:5:33::26) by AM8PR04MB7425.eurprd04.prod.outlook.com (2603:10a6:20b:1d6::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.20; Wed, 10 Jul 2024 23:01:34 +0000 Received: from DB7PR04MB4555.eurprd04.prod.outlook.com ([fe80::86ff:def:c14a:a72a]) by DB7PR04MB4555.eurprd04.prod.outlook.com ([fe80::86ff:def:c14a:a72a%4]) with mapi id 15.20.7741.017; Wed, 10 Jul 2024 23:01:34 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Breno Leitao , Herbert Xu , Madalin Bucur , linux-kernel@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH net-next 1/5] net: dpaa: avoid on-stack arrays of NR_CPUS elements Date: Thu, 11 Jul 2024 02:00:21 +0300 Message-Id: <20240710230025.46487-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240710230025.46487-1-vladimir.oltean@nxp.com> References: <20240710230025.46487-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR0102CA0100.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::41) To DB7PR04MB4555.eurprd04.prod.outlook.com (2603:10a6:5:33::26) 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: DB7PR04MB4555:EE_|AM8PR04MB7425:EE_ X-MS-Office365-Filtering-Correlation-Id: 357708eb-6dee-451e-7117-08dca1343eab X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014|7416014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: 465cMh7tJS1qQIiA4U/auNv6ttb53mLoCwvX0Uo5HpFQ5lQJUimFAlaYkaMb9FLjnCCnXVA+T7Q9FKTgIAX99oDVqexAqO4nWAetTRh3+qemTyjS+LFTc4CDCkpA6FTubM5gwHZBwO1Z+0qQRnOT7I9uQMGlZusS9BjG0sTpR0bqu4Ipu8G7ZO758d3eakGfS9Ng4Uv0n9fAw+QaEG7keuV/QoMaOYVZH+jFmjtEkleEpm9yn/gXqLu6ymugdxAJ2fR9qDZztlST9aW5guUF6Ou/VWAuvfLAN6VlmBAOR7PIZDsfA0cyhS34c89UKzJ3yfX8WQF06v9dpxALCeSJO7EUlMkLjWE5rpKTX7Zlr4VjXScMjDvLTr5oDGC3uGvORKd2hRZyxxXChnh+a/tOYnoS/bDKx+JSUwV81apib7WgPOvugIP7Df7MJ6m7JMfjdTy9YKsUZpNGhcpc16I5e9HT6shUBjvub55A/fsdEuESmbluTnge19laQ3vmVFIu0zQiVWIO6Wka0sr1WZl9mKH1bPF6cS5934kSqXFjzaREktM9QFyOFckjgYycb5FdA+mOIlNW3pmjFPW6Ehh5DBIW/nYj5SP1xwCKZSgcVaqIPmFrVAz54XONCM1vAt+MmwMiQaoFS24p6d+aLvWSdE7f/w0mt+yVE/XgFDyS8O0Ae+zYK+UM81nNOzs2v/c7dKnBRGMTMldmF9DgclIOQDjtkUojfu3Z5uyx7t8wuowae+AN7EdSGCeGM1T0/+cUjnLdn8jzlDF3NDnOcvYxQLySJ1/2bPyzey5W/+bpql6PnWummf/Uaf9t0kKr/obhZo46JTFsVpL34RfeXLk6Gr5hnYMHnkuaHH+ZDpb5CoB2/5qUHx8r+YehLlJweDJQnnZo8EsmBVPiojsIDrgsauUfPnGaPFwqmv9FYNFiCKvNki/LYsKjvfRESHZ8rZpj5EE1KjkEgb7PssvoIYd08r8hccmlkU0KlhEu2/VB9qjgn8iFHWrTvfiV1Pv2yU2FOWPQvj/cX6bwlxuZO61r3qf52cx73VjC3qbc5zIgMC9ACu6RjXFgtUgfYvNijSAotZeQLp3nTh5jfBYSOQtHKuRez6MyuouCnzjlT/oQaKGiIrFWCcfl3PKhvVUojbBUjuunAXvzwmM0eiEf+avyqC+uMu5wM6WA3weQuAJ6+gZTXXmHWqZl7XpxH252+Cu/+OB9nDLNnnwdEKe8rHrH9HWboMy4idXQDnk2r0IxUgf0x4OdfJNDgl/pRM0+nQ8Mq5cKinyVGQs3gr3xCyudMuaMZZclGBcMiytfFyNE02ubLIPmsEvasrA1x3swCa+UHfhbCZbnzAAlwdmyi1wJELn39f3W0tPZwUcUGuQ/kYY= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DB7PR04MB4555.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(1800799024)(376014)(7416014)(52116014)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-M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ck/N/gRv23Oi6u/Ljeu+1llQX0x6JXA6a8cLOb2b+07vuUnFSyCU+G9OZS2Ac+k1Vz2lLxEaTTowR+wEXB6nJp9lD3PErowPS/Pozwca/Po9WoV9/Bca0V3J4KylzW3+ENx0F4fQkenuRaMx3bcp/LCW1mNBgFL8a6hWjHHhYW+YpaiOlVWJsIcvgkEKswm0HTNt6tTO+y3ZCNOOavW9bV/Ho8mxqPibbCPfDdL1sSlEsDX5GSAuzEtmauLXmXmJIT2H4xjqM/g5IRkF7zGfY964Hh2bp5he1fVJkdgS+VDhh0S5brbm1zu1ra66M/IloKT4G3xWa/sP3JktUsJOsPtzDfyv3SMkuV+Qa9IuhpakC3K1grbTp8n1YNXcMYNuJQvSmNBVq58BnI2O0OxTYIFRDMrM4bZBYdjrdzpF9IBiNxTO0CFGpJ+4L37YfZhZvzroxySh9BZgTbCz9CmJWPLgPo5SpCEyEcLJlECRCPzavTKX6Qm+5TIQp0DTBF9dJgElgIUH9SHT8UOBJ0vBH6S55eQb2vTXh56VlahJtouZcg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 357708eb-6dee-451e-7117-08dca1343eab X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4555.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Jul 2024 23:01:34.2935 (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: JrDSoGLKfszAhq/Mjdfu28S4damfoK2xaWXV1nd0TFMCtVwlFTfLvNCR+hsral8oNWaHbtFeFYBGvQKLdg0iMg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8PR04MB7425 X-Patchwork-Delegate: kuba@kernel.org The dpaa-eth driver is written for PowerPC and Arm SoCs which have 1-24 CPUs. It depends on CONFIG_NR_CPUS having a reasonably small value in Kconfig. Otherwise, there are 2 functions which allocate on-stack arrays of NR_CPUS elements, and these can quickly explode in size, leading to warnings such as: drivers/net/ethernet/freescale/dpaa/dpaa_eth.c:3280:12: warning: stack frame size (16664) exceeds limit (2048) in 'dpaa_eth_probe' [-Wframe-larger-than] The problem is twofold: - Reducing the array size to the boot-time num_possible_cpus() (rather than the compile-time NR_CPUS) creates a variable-length array, which should be avoided in the Linux kernel. - Using NR_CPUS as an array size makes the driver blow up in stack consumption with generic, as opposed to hand-crafted, .config files. A simple solution is to use dynamic allocation for num_possible_cpus() elements (aka a small number determined at runtime). Link: https://lore.kernel.org/all/202406261920.l5pzM1rj-lkp@intel.com/ Signed-off-by: Vladimir Oltean Reviewed-by: Breno Leitao --- .../net/ethernet/freescale/dpaa/dpaa_eth.c | 20 ++++++++++++++----- .../ethernet/freescale/dpaa/dpaa_ethtool.c | 10 +++++++++- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c index ddeb0a5f2317..c856b556929d 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_eth.c @@ -931,14 +931,18 @@ static inline void dpaa_setup_egress(const struct dpaa_priv *priv, } } -static void dpaa_fq_setup(struct dpaa_priv *priv, - const struct dpaa_fq_cbs *fq_cbs, - struct fman_port *tx_port) +static int dpaa_fq_setup(struct dpaa_priv *priv, + const struct dpaa_fq_cbs *fq_cbs, + struct fman_port *tx_port) { int egress_cnt = 0, conf_cnt = 0, num_portals = 0, portal_cnt = 0, cpu; const cpumask_t *affine_cpus = qman_affine_cpus(); - u16 channels[NR_CPUS]; struct dpaa_fq *fq; + u16 *channels; + + channels = kcalloc(num_possible_cpus(), sizeof(u16), GFP_KERNEL); + if (!channels) + return -ENOMEM; for_each_cpu_and(cpu, affine_cpus, cpu_online_mask) channels[num_portals++] = qman_affine_channel(cpu); @@ -997,6 +1001,10 @@ static void dpaa_fq_setup(struct dpaa_priv *priv, break; } } + + kfree(channels); + + return 0; } static inline int dpaa_tx_fq_to_id(const struct dpaa_priv *priv, @@ -3416,7 +3424,9 @@ static int dpaa_eth_probe(struct platform_device *pdev) */ dpaa_eth_add_channel(priv->channel, &pdev->dev); - dpaa_fq_setup(priv, &dpaa_fq_cbs, priv->mac_dev->port[TX]); + err = dpaa_fq_setup(priv, &dpaa_fq_cbs, priv->mac_dev->port[TX]); + if (err) + goto free_dpaa_bps; /* Create a congestion group for this netdev, with * dynamically-allocated CGR ID. diff --git a/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c b/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c index 5bd0b36d1feb..3f8cd4a7d845 100644 --- a/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c +++ b/drivers/net/ethernet/freescale/dpaa/dpaa_ethtool.c @@ -457,12 +457,16 @@ static int dpaa_set_coalesce(struct net_device *dev, struct netlink_ext_ack *extack) { const cpumask_t *cpus = qman_affine_cpus(); - bool needs_revert[NR_CPUS] = {false}; struct qman_portal *portal; u32 period, prev_period; u8 thresh, prev_thresh; + bool *needs_revert; int cpu, res; + needs_revert = kcalloc(num_possible_cpus(), sizeof(bool), GFP_KERNEL); + if (!needs_revert) + return -ENOMEM; + period = c->rx_coalesce_usecs; thresh = c->rx_max_coalesced_frames; @@ -485,6 +489,8 @@ static int dpaa_set_coalesce(struct net_device *dev, needs_revert[cpu] = true; } + kfree(needs_revert); + return 0; revert_values: @@ -498,6 +504,8 @@ static int dpaa_set_coalesce(struct net_device *dev, qman_dqrr_set_ithresh(portal, prev_thresh); } + kfree(needs_revert); + return res; }