Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp31867pxb; Tue, 7 Sep 2021 16:53:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwflYTvc6EXQG28poYZFuVke3R8GAIpbDOnxEZKdyLd6iNltxEEGbLCCO40tSRLrkqNMPcN X-Received: by 2002:a17:907:3e05:: with SMTP id hp5mr968133ejc.527.1631058822652; Tue, 07 Sep 2021 16:53:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631058822; cv=none; d=google.com; s=arc-20160816; b=V1Cpn4Bx4oQbwcYxi48zkpb2zfUkD2uy0tpHretF+EAUtUmf6Rpkx2vuvrBOezs6E7 Oo26XyN2jEJArnny16vH8NAVXKAK+nT7vrp8pEvyUzgTA/yI7Y5X95yH86CXTGBdsimd E4n4dl5/EP8tfQ1f9oUPiWK8LZzZgBn876E6Rq6R+gKnglqp5/Z0MQHDwFBifT4/AYFG 2msUo8DrfPGn1HZ29eviY3B7dkgjWrkJiN1kVCzo9+nICAJ2P7exPxFuqzlcYspJn07J vgaRF+daIjReiJguQ9BkwjfztUfuXpd9BOpmnXoU/Petyeuoz1u1VwTJ/1kjd5Aw6psq zMgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Qu1CuxnsrjZOSqfDn82IwL4wxf06fWvlZCuvRJG8DNA=; b=px3DYhKsvDssYz1tThf85RkmwBC9Q1JlGpvCXUXzd5J4S+RknRjJQdh86w7zb/D95U O1PQkZp9f/6KYSOxVGB59XXPD3sWGeDoMR7mlKgAPFivgwE9ESa4CNPOPcRSJCpk29OH 0k4xyppqCvSS61qISDwQDwBxMNKVGtE4nWf83HyVR1rZFHcUbDpwhn0oBSY0MfVdiGcE Vj/M6SZFRoQ+/uKF4yE2c8v7e84Olr7JjsNvFek5ZmZw/p5+KZ2vT0rrO42ku7w3RjjB hFIi8ZQRO3h/xrRP9iyDrcSNy2OHkwOuYleJ/QdmefGj6gcAaQiZRc7b/ciUWZw3JT4v tgsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=hzQgvbQo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w10si521616ejv.584.2021.09.07.16.53.18; Tue, 07 Sep 2021 16:53:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=hzQgvbQo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245273AbhIGXU5 (ORCPT + 99 others); Tue, 7 Sep 2021 19:20:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234094AbhIGXU5 (ORCPT ); Tue, 7 Sep 2021 19:20:57 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBE15C061575 for ; Tue, 7 Sep 2021 16:19:49 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id g14so307019ljk.5 for ; Tue, 07 Sep 2021 16:19:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Qu1CuxnsrjZOSqfDn82IwL4wxf06fWvlZCuvRJG8DNA=; b=hzQgvbQopbro6AglKsBmSTDKv6F+qPyX8TeMb058Rd87Lc3krIRE6cpNxBGVVXV5hv ow698KDv/VdCJ1d5QUePaIv46jMP9hBRJ4ZESDYDaJSOD+o9ncJwozDx3JIOUMeAqk2X js/TMcfWBMGX83+VrnL66WmNMwh8cgbazm+R8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Qu1CuxnsrjZOSqfDn82IwL4wxf06fWvlZCuvRJG8DNA=; b=TxftWpM0eyqQuyzrmR4+yUp4Drd/iQP/vuKVQeaprElBrCMG6ADM0aL1+pykONDEFN okuQqqoYBxNOfre7dCnI//KPTW7kLB5uDFoH5CaUDEbQYkoI6etkVU4qhhXElfwtdO5X RZPmqTMmy92OO91ddpX9SUJU7LinAWdpTIhHye635i+hPMK/uMe+XARNF9WV7F18iZfq oIpSPAaUx5gmJ+3NvTv7h8G4TtMZNeSKus/15PrYDZ3WdyeWYaVojyksjMQXGWRRrwxY 3Ap444XM3lYWzOxRULXgPSnvi9GBSd7I7H2IKwsC59lOgcEC317xYx5YgfXXvf7yLTX+ nf0g== X-Gm-Message-State: AOAM531LA98E1tQYCFEN1mCS5FJn1CP3b2Y/fe9Wnq/qwv5GlTvmzov+ dM+smjgSU3XgsmeiXmjJugtqe7AZIfgT1iDT/ng= X-Received: by 2002:a2e:9b14:: with SMTP id u20mr506661lji.21.1631056787953; Tue, 07 Sep 2021 16:19:47 -0700 (PDT) Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com. [209.85.208.170]) by smtp.gmail.com with ESMTPSA id p1sm27392lfo.255.2021.09.07.16.19.47 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 07 Sep 2021 16:19:47 -0700 (PDT) Received: by mail-lj1-f170.google.com with SMTP id g14so306966ljk.5 for ; Tue, 07 Sep 2021 16:19:47 -0700 (PDT) X-Received: by 2002:a2e:96c7:: with SMTP id d7mr471237ljj.191.1631056480289; Tue, 07 Sep 2021 16:14:40 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Linus Torvalds Date: Tue, 7 Sep 2021 16:14:24 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: ipv4/tcp.c:4234:1: error: the frame size of 1152 bytes is larger than 1024 bytes [-Werror=frame-larger-than=] To: Naresh Kamboju , Mathias Nyman , Johannes Berg , Jakub Kicinski , Shuah Khan , Brendan Higgins , Ariel Elior , GR-everest-linux-l2@marvell.com, Wei Liu Cc: Linux ARM , open list , Netdev , lkft-triage@lists.linaro.org, Arnd Bergmann , "David S. Miller" , Greg Kroah-Hartman , Nick Desaulniers , Nathan Chancellor , Daniel Borkmann , Alexei Starovoitov , Eric Dumazet Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Added maintainers for various bits and pieces, since I spent the time trying to look at why those bits and pieces wasted stack-space and caused problems ] On Tue, Sep 7, 2021 at 3:16 PM Linus Torvalds wrote: > > None of these seem to be new. That said, all but one of them seem to be (a) very much worth fixing and (b) easy to fix. The do_tcp_getsockopt() one in tpc.c is a classic case of "lots of different case statements, many of them with their own struct allocations on stack, and all of them disjoint". So the fix for that would be the traditional one of just making helper functions for the cases that aren't entirely trivial. We've done that before, and it not only fixes stack usage problems, it results in code that is easier to read, and generally actually performs better too (exactly because it avoids sparse stacks and extra D$ use) The pe_test_uints() one is the same horrendous nasty Kunit pattern that I fixed in commit 4b93c544e90e ("thunderbolt: test: split up test cases in tb_test_credit_alloc_all") that had an even worse case. The KUNIT macros create all these individually reasonably small initialized structures on stack, and when you have more than a small handful of them the KUNIT infrastructure just makes the stack space explode. Sometimes the compiler will be able to re-use the stack slots, but it seems to be an iffy proposition to depend on it - it seems to be a combination of luck and various config options. I detest code that exists for debugging or for testing, and that violates fundamental rules and causes more problems in the process. The mac802.11 one seems to be due to 'struct ieee802_11_elems' being big, and allocated on the stack. I think it's probably made worse there with inlining, ie - ieee80211_sta_rx_queued_mgmt() has one copy - ieee80211_rx_mgmt_beacon() is possibly inlined, and has its own copy but even if it isn't due to that kind of duplication due to inlining, that code is dangerous. Exactly because it has two nested stack frames with that big structure, and they are active at the same time in the callchain whether inlined or not. And it's *pointlessly* dangerous, because the 'struct ieee802_11_elems elems' in ieee80211_sta_rx_queued_mgmt() is only used for the IEEE80211_STYPE_ACTION case, so it is entirely disjoint from the IEEE80211_STYPE_BEACON case, and those stack allocations simply should not nest like that in the first place. Making the IEEE80211_STYPE_ACTION case be its own function - like the other cases - and moving the struct there should fix it. Possibly a "noinline" or two necessary to make sure that the compiler doesn't then undo the "these two cases are disjoint" thing. The qede_config_rx_mode() has a fairly big 'struct qed_filter_params' structure on stack (it's mainly just a union of two other structures). That one is a bit silly, because the very same function *alsu* does a temporary allocation for the 'uc_macs[]' array, and I think it could have literally made that allocation just do both the params and the uc_macs[] array together. But that "a bit silly" is actually *doubly* silly, because that big structure allocated for the stack that is actually a union, uses the QED_FILTER_TYPE_RX_MODE type of the union. Which in turn is literally *one*single*enum*field*. So the qede_config_rx_mode() case uses that chunk of kernel stack for a big union for no good reason. It really only wants two words, but the way the code is written, it uses a lot, because the union also has a 'struct qed_filter_mcast_params' member that has an array of [64][ETH_ALEN] bytes in it. So that's about 400 bytes of stack space entirely wasted if I read the code correctly. The xhci_reserve_bandwidth() one is because it has an array of 31 'struct xhci_bw_info' on the stack. It's not a huge structure (six 32-bit words), but when you have 31 of those in an array, it's about 750 bytes right there. It should likely just be dynamically allocated - it doesn't seem to be some super-important critical thing where an allocation cannot be done. The do_sys_poll() thing is a bit sad. The code has been tweaked to basically use 1kB of stack space in one configuration. It overflows it in a lot of other configs. Using stack space for those kinds of top-level functions that are guaranteed to have an empty stack is pretty much the best possible situation, but it's one where we don't really have a good way to try to have some kind of dynamic feedback from the compiler for how much other stack space it is using. So that do_sys_poll() case is the only one I see where the stack usage is actually fine and explicitly expected. We *aim* for 1kB of stack, and then in some - probably quite a few - situations we go over. There are many more of these cases. I've seen Hyper-V allocate 'struct cpumask' on the stack, which is once again an absolute no-no that people have apparently just ignored the warning for. When you have NR_CPUS being the maximum of 8k, those bits add up, and a single cpumask is 1kB in size. Which is why you should never do that on stack, and instead use ' cpumask_var_t mask; alloc_cpumask_var(&mask,..) which will do a much more reasonable job. But the reason I call out hyperv is that as far as I know, hyperv itself doesn't actually support 8192 CPU's. So all that apic noise with 'struct cpumask' that uses 1kB of data when NR_CPUS is set to 8192 is just wasted. Maybe I'm wrong. Adding hyperv people to the cc too. A lot of the stack frame size warnings are hidden by the fact that our default value for warning about stack usage is 2kB for 64-bit builds. Probably exactly because people did things like that cpumask thing, and have these arrays of structures that are often even bigger in the 64-bit world. Linus