From patchwork Sat Jul 13 22:53:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13732538 X-Patchwork-Delegate: kuba@kernel.org Received: from AM0PR83CU005.outbound.protection.outlook.com (mail-westeuropeazon11010054.outbound.protection.outlook.com [52.101.69.54]) (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 C847514EC58; Sat, 13 Jul 2024 22:54:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.69.54 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720911245; cv=fail; b=aUeFLeMpMxecRB8p2tU02iukqVIPSZfhpwN7hKExbNKvoFFFOdg8LnXLEku3garh/WV18RLVWB0XN/IiuQLfThiqMUD1CiUPzqoDkZDe9CRYPZ5YJmQM6+rW/jj/ANOADHzmgeXIgTDOhhRvTaWbkyP6sj13INXvoJ2eDK9usrk= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720911245; c=relaxed/simple; bh=QSFz3uESNfYOSs2ncXNWCBKNFadQevXmRO7H79Vpo0w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=bEu38ICueDyn98bErTUMf5ndOord59xMRnNLFtvhQ7NrIFaD3r0G9v8wK6u46aH9dgy8Cntt2ViRdy1RZHTq9w/A1SCbMEwYiE7nqrPTFGxk0rWDqctiZXOqwwnnGt4hdaZ4hHOfZh7q7v2ZKtdqi9bkvgMEeXSgNdGyWdhdzBo= 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=RqzJCq64; arc=fail smtp.client-ip=52.101.69.54 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="RqzJCq64" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=xADbt9XNZiQdVWOJty964W03pBxMkzZRiQF/9f0SwIXB2uCFx47RhCHhryBfgQq3hwao36vzP5yYFbky9pTn7uelK1Zye2LdEBNSHfkgx0jkboZWMQiVjaVi8Ail0aTWXoJIGk4fKOfVIlbZ+FF9zcpJRB3cCCXfLywN2imsznStlWx2Ba4OlovkgFi/Ru8MoFwNw1RxiluSyvIO2HY58w2+eAXE3NmGPEz/VQxNwGqeGqzOX4wcJ8plhoVUI+VWLJu6b/4xbxyn4YQesQTv4sAsR0WEO37P1JYtGstlnIknX6U6prVaQBiCjwwieFsPvKzfYofRLUhzFXVjrymsdg== 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=l7dK76Tr8COdd1ECnEbBHmfZQR0iA70vm5dbcSZyz8o=; b=GSlIrUWPk/EnBKuXVfl6vSJvjBWTyaws3V+IblALmeglQufFjwvF6ZGBsJ0vGGbjSG3X56KZ6iiBTX2csIZrXgFKIBtGiYfclarYaG9b25UVF1GqqkJGHVZouFBx0dFqlbwaaOj/DqCk1fVajnQirvexoXKQSU0YnYvVLXRV8ushgGEofwTRjEAFsRnMWSDP97y00OSRi580gl5nmfZOgm9y1Ymy7TTwwcWednpmxigQKY3Z1Wd3ICJMcu4X8TYmHn5AYvn/esfsFZsJSaFvNN/m7gC+cHBNVnVR9xsQvdh9Fz0DkBQqYkBIG4uLRJb56YEKR4SQpbi/TeFSNJsOrA== 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=l7dK76Tr8COdd1ECnEbBHmfZQR0iA70vm5dbcSZyz8o=; b=RqzJCq64f9bsFb6qSVTFjUNJ5kcSgDYs6rINyEA8BQqGFPOoRPPd7jHVO/anoD407SRfwjRNz4K6Zd1r5ANrgyJQsnDYlW3F8+6ymuiRwd0Z6W7yC/M6zdl6MiHGo3XWX/8AWLMl0WfbzPbDsTbti/VaRxDT8MjWzpVsVJ+1iS8= 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 PAWPR04MB9911.eurprd04.prod.outlook.com (2603:10a6:102:38b::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7762.24; Sat, 13 Jul 2024 22:53:58 +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; Sat, 13 Jul 2024 22:53:58 +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, Madalin Bucur Subject: [PATCH v2 net-next 1/5] net: dpaa: avoid on-stack arrays of NR_CPUS elements Date: Sun, 14 Jul 2024 01:53:32 +0300 Message-Id: <20240713225336.1746343-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240713225336.1746343-1-vladimir.oltean@nxp.com> References: <20240713225336.1746343-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR07CA0127.eurprd07.prod.outlook.com (2603:10a6:802:16::14) 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_|PAWPR04MB9911:EE_ X-MS-Office365-Filtering-Correlation-Id: f7b49fb1-9534-4dd2-ddf7-08dca38eae0e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|376014|7416014|52116014|366016|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: kDb0474Xu7aduoE/91A5DyPvaWLzXkDAU8n9j+RMceIZfzP76fuPmoQGvcA+pwolegkmGMDSsh7vRBgYWt6TCx5l9S+WZQo21zuGBfc66OWwqY8Xzy0odLVvvmbJyecCckSjyzUCZxQnPHsbSn2rOnd/q8DwSSzBEfV4NLCCmiifqYUk8yMF1aNoj/O+ohTzCq4YjNylgAXbmCeD/T1O7ACciB4URorcSzdMXB7P19hXeD+wKLVV/BttZ4rbr0iv1sIzMkOyefWj4sEHuV5T1eAjqKxZhuiINsKnQHsAuGNXmmTdt4enF4mcO6nIHXHiizyVOvx2LEAdLYKh2dxLycLYljbCGKNjaa4fuKl1hs7U+g+6ZypSUioGFxNKb/yFt+UDx1EwgCPnepoLjg/u4njLkyCdLnV2SnluptU3fm6IHF5df2Bvc5X9Lqu1aFmGkpN094CCw0YQSlXxgyo7MoDkg2pZMxhej8kKwwrNDM5d9zpnX+4LdiryLfqvTxOBQkrGYdU4HBIEbfqVgPKvw+3rGlj6H5fNVMxYV2HElT4uVJ6UZeUrtbzLvP4F9dDDcGXDA1hsxUM/hv/ckjB2go6jHRWUMZGUVXY7j/QpEMq3RRt+kDLlmZzhGx3GY59W0ac4SEurmvNbgTlr8CsVpfJWRTZlZ9bIa8Cj6w6fAboV8T7onDCxIoGza1/RYTMIBbvBEEkwvD0zhwty7DzKp9BWu0O4c+95oPyl7fwpb7b/vcY5CCMneK+JuF1Fn4Om5mrDXuOk8ePSe4rqkiJSSAxMfFE6ljF+EYdPJvi3AhgZuy61dnOQoWUGeZApp/EI0+wOxi2OJjWmRs0BDxORuCQJVkSaCVb8Ekjw3FvSRcZcq2qMkLxSUQ1y7zDJXDBDuYyH5DDP9GJGdrmpV6cUAv49a8XZkUjEFu/AiOhFvseWdJmsmuv9xEDNeJOUxNEIxRMejKIcrsqkXBvvot7dX8Vdp6TpcuMldDCU28e9tbSfKLApVsYXHMLj1z90npmYBhSKCmvgfRVdOxregJTylyolSRyHZxFjvtus6dj/jAhMAa5XbHaXV8uMK155bWOc4z4IoMFE5ddKXsd2W5S322s7LaezP3rTRUgXm5/EIDjqZaiBcxzK6mwRHuEBC5pHfb0Pz2N0foIv2D8eW0NWwikf0naHkfI2OxwOhsPUrOwxHx6IIYxfX+D94WZvcFCf2OTz/3UvF9ZjAwfbPO8SyVtH8+eJshCRIVZ4e4XE39WuaRg7t7G3W49FV6A2u02NsINjLP492ZJ9bOTLQcinrsqMpSLBOq3J6BUErpKAwL47xEORFut2HUGzxP8YQzQlUUgDFZypEJFw4KBotp4kzY2wgUVrPqHGOZsYMq3lE+Y= 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)(376014)(7416014)(52116014)(366016)(1800799024)(38350700014);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-A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m5ad4ZckPEipgb8p25QlgyzlUwz9S8LJ/P4JvNEnHY5ZZ3/E/0wdQRWnvN6RWf+YVCe49bY+M+LZVU1vMpk0pkx6tQEL1cjximZpxaW/SeYNGgjEgXjrnR0683FryMNoOn2jjiMNPPGjfst5a9PWmsh8Nk7trxAKKYzBhpWDkBQHgw4UzTQEzausu9i+blicZcMU817oV3DamGcA9kHBg4sWhLqNGP5XVgpLV/84hXqCJV/B0l0jvApCHgw1Fg3QR26vUM6smPvm5MdatIzBrev3QZ/bh9ZjU9DUYbokFC8iAXccTpwRXP9z0kmbmMGUfOrWBdBjeh+Ua+N+cXZ+NwP5PCldesLF2KHXme2q8eMA3Z4X5vY6phy/cZ7T8OlwtYQktC0ynRVdnu2KkCF8Iv8AHZ9zOemlqcODl0zhxTuviUCeOYXtqWNHNVeMne1lMkzEwbRHICZF5AmKT548lk6MYrGDa/18H3Hw0J8TQmQqN4JStt4cmTIVgy6A7KkOVeOT4QPFbAwcGmA0sR4S5DWx6hJfJiE7ZAYdeEex5hU7xvGNtqng== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f7b49fb1-9534-4dd2-ddf7-08dca38eae0e X-MS-Exchange-CrossTenant-AuthSource: DB7PR04MB4555.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jul 2024 22:53:58.2138 (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: 1z6nr5x0Zflr/Wpxxf8BA4/0ebG4YO4u+qU3+zdPOAqtkT/lGHPXomZvlU8hZ07lMb2XT5zmas+wX2Rsj4BVIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PAWPR04MB9911 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 Acked-by: Madalin Bucur --- v1->v2: none .../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 baa0b3c2ce6f..946c3d3b69d9 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; }