From patchwork Tue Apr 26 15:52:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 102452 Delivered-To: patch@linaro.org Received: by 10.140.93.198 with SMTP id d64csp1691810qge; Tue, 26 Apr 2016 08:53:39 -0700 (PDT) X-Received: by 10.98.31.21 with SMTP id f21mr4569347pff.134.1461686018989; Tue, 26 Apr 2016 08:53:38 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 84si3875696pfc.6.2016.04.26.08.53.38; Tue, 26 Apr 2016 08:53:38 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752257AbcDZPxh (ORCPT + 29 others); Tue, 26 Apr 2016 11:53:37 -0400 Received: from mout.kundenserver.de ([212.227.126.131]:52087 "EHLO mout.kundenserver.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751829AbcDZPxf (ORCPT ); Tue, 26 Apr 2016 11:53:35 -0400 Received: from wuerfel.lan. ([78.42.132.4]) by mrelayeu.kundenserver.de (mreue002) with ESMTPA (Nemesis) id 0MHQA7-1ayi3q0LK7-00E3ii; Tue, 26 Apr 2016 17:53:17 +0200 From: Arnd Bergmann To: Saeed Mahameed , Matan Barak , Leon Romanovsky Cc: Arnd Bergmann , "David S. Miller" , Achiad Shochat , Or Gerlitz , Amir Vadai , Tariq Toukan , netdev@vger.kernel.org, linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] net/mlx5e: avoid stack overflow in mlx5e_open_channels Date: Tue, 26 Apr 2016 17:52:33 +0200 Message-Id: <1461685993-1049370-1-git-send-email-arnd@arndb.de> X-Mailer: git-send-email 2.7.0 X-Provags-ID: V03:K0:a0aPHsfXeeaGadVYveFGo14mVHJ7KR+dTQlS+RWgzv3cVjCh3qF YlSZMxsoEZys6J8Ml3zxgziWzKtxoiYfDMRoSi8qcZxyjlQqkOEm8rwXYO0zxCx5EcsADAV hwPVEH1Zj64SGGbXcxXuQmdwe69oCTwNMRudQOX0bYc52Ygf5+PEdn7ds1cM1XP/yxqlivd 5OMV7C9P1gZToJII02w1Q== X-UI-Out-Filterresults: notjunk:1; V01:K0:12M9WatbZlQ=:IASnJbsXhDL/CLDAu8SOiz Ae7TecpZ3yHhzNj3PREZkl+XWZAx6A3TI6vbMBkzOubN2drFyFxqJ5b1SvbOJ9V7UhpXTouov jbaGzrE1B5/QWzliCZrcnh7OjmoHQTmRRTp2hp2Gsd1qmrVi5eNxsY14PkSjpvGZvEo3c9oyw Bz0VMHOeAOq6+VZtrpjhNkml5SiOwceeJ8rstJv/PHH6EPfx8T2a2vtsAgdPZJrJbU1UHVNKH U7iYi3pWmyoH9DhdT7dmnyhvnMmXyNpfz78SapAQzhRMfI7HLaIyIbZmO7i2bG7Ilj0GiH+KG 6spAwwR8mAhse2w/EH4KsdoR151B3/vIw5FCVxzYypvQgfS+14RFCt9DSKFdFsXL1xScNWExB P11R27f8y/vBOt2GvUPMBhjb3OGbkKNsF+2zDA2jGUECKGh13snAKvFZQSst9oIXs1w8uImhM ogO+Nz374z4E5vuAd1TdeAs+KwkqBQe/IBUospunip/sfiGSFHSQLCalDuMd3LR+bXyI8kTfz 44Uk1c9VRVayoAr+ELY7CmsToBQfQdVyq+h26K+U1edQ2UnhhrMsJCvXVqhpznxledDtoZBxq 8cIGKnfwMSW+7U5Ha9lKBsW1MxCJ8M2eD4/PLH6lHDYLBfAWJKC1HnOV2OY3ixZ/Sdratv2QU 9R6L+Ryz7oiOgUhJwHVjUsmwO0LE4q2HTCMx2jT3bCdfN0w/6eM8OSaoaZpAXssMFgno= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org struct mlx5e_channel_param is a large structure that is allocated on the stack of mlx5e_open_channels, and with a recent change it has grown beyond the warning size for the maximum stack that a single function should use: mellanox/mlx5/core/en_main.c: In function 'mlx5e_open_channels': mellanox/mlx5/core/en_main.c:1325:1: error: the frame size of 1072 bytes is larger than 1024 bytes [-Werror=frame-larger-than=] The function is already using dynamic allocation and is not in a fast path, so the easiest workaround is to use another kzalloc for allocating the channel parameters. Signed-off-by: Arnd Bergmann Fixes: d3c9bc2743dc ("net/mlx5e: Added ICO SQs") --- v2: move allocation back into caller, as suggested by Saeed Mahameed drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) -- 2.7.0 diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index af8c54d2e99c..7106006c792b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -1266,13 +1266,10 @@ static void mlx5e_build_icosq_param(struct mlx5e_priv *priv, param->icosq = true; } -static void mlx5e_build_channel_param(struct mlx5e_priv *priv, - struct mlx5e_channel_param *cparam) +static void mlx5e_build_channel_param(struct mlx5e_priv *priv, struct mlx5e_channel_param *cparam) { u8 icosq_log_wq_sz = MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE; - memset(cparam, 0, sizeof(*cparam)); - mlx5e_build_rq_param(priv, &cparam->rq); mlx5e_build_sq_param(priv, &cparam->sq); mlx5e_build_icosq_param(priv, &cparam->icosq, icosq_log_wq_sz); @@ -1283,7 +1280,7 @@ static void mlx5e_build_channel_param(struct mlx5e_priv *priv, static int mlx5e_open_channels(struct mlx5e_priv *priv) { - struct mlx5e_channel_param cparam; + struct mlx5e_channel_param *cparam; int nch = priv->params.num_channels; int err = -ENOMEM; int i; @@ -1295,12 +1292,15 @@ static int mlx5e_open_channels(struct mlx5e_priv *priv) priv->txq_to_sq_map = kcalloc(nch * priv->params.num_tc, sizeof(struct mlx5e_sq *), GFP_KERNEL); - if (!priv->channel || !priv->txq_to_sq_map) + cparam = kzalloc(sizeof(struct mlx5e_channel_param), GFP_KERNEL); + + if (!priv->channel || !priv->txq_to_sq_map || !cparam) goto err_free_txq_to_sq_map; - mlx5e_build_channel_param(priv, &cparam); + mlx5e_build_channel_param(priv, cparam); + for (i = 0; i < nch; i++) { - err = mlx5e_open_channel(priv, i, &cparam, &priv->channel[i]); + err = mlx5e_open_channel(priv, i, cparam, &priv->channel[i]); if (err) goto err_close_channels; } @@ -1311,6 +1311,7 @@ static int mlx5e_open_channels(struct mlx5e_priv *priv) goto err_close_channels; } + kfree(cparam); return 0; err_close_channels: @@ -1320,6 +1321,7 @@ err_close_channels: err_free_txq_to_sq_map: kfree(priv->txq_to_sq_map); kfree(priv->channel); + kfree(cparam); return err; }