Received: by 2002:ac0:aed5:0:0:0:0:0 with SMTP id t21csp5144416imb; Thu, 7 Mar 2019 08:41:52 -0800 (PST) X-Google-Smtp-Source: APXvYqzykNWKyuqJempXZZE6BADI3LNq/vRmg78pZOSlaAH74glEjzxvcxOSfQLUvyhJ59Lx6HI0 X-Received: by 2002:a17:902:e50b:: with SMTP id ck11mr14034259plb.25.1551976912328; Thu, 07 Mar 2019 08:41:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551976912; cv=none; d=google.com; s=arc-20160816; b=N/5dbhCQMmSKI7OuHUJFdklRcuYgPJOnTlnVavLZ8kf16fflRL48sHB7xQob6PLUoU EjaKYR1pBnsjPGxmVNyFZ3fHcaj5utvkGmgUivxgJAZ237PB/fGMrtTLOBcm3mumTmVq W1KpHESaOL+6vN7urwSjjqud4GUqg8IroMVKpEVKrLvEHCPxNhsEDuMZ3e6WGGDF3Rgp gQOA735QQsX5UXUCsGxt6iPCbbfpiwWBc7RkVtDNDDG26INCTo8rq0e/QckjgmIIX+Gr 5m3jTmQzeOP6iYLYZSvtwlJFSvPx6M5MSX7oWBpmJ7lH61flYH1RqWs4c8oVeoXoGecE 2PPQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=fzn84VhBkXcOzNhA5tSlaf6n5NvNhnsUfKuoqLHlmOA=; b=y+e0Lfvjc+S9thte0BucYBQYKO3ygC1YxrgDXdOoxLjnNHUhiqd82qoyKREtBvc6cs MUNhRq17yGrVBm80+HkMyszNhtQi3RZ9nUqoQ+gLUyUdP77uL1Mj0FTXkJJMhu301oO3 icIXSrkYWKdnFwY9g4FgvIbBuezwFXVv7DE3aIRPhIVjgMgzXVJnlIC6iDBt3TkjRrox ELJeCxaKXplurb5iVVj1RzxTMYbv+FwfZ1Zn6ZCypfOm6FI7rTJqvwDTtPMoGafJJmAI fAOrBHehvFBzOdrKygaEEeX+hFR5uONef7U7L/SE++is6xW5qImCeP726EDE5kopUz++ nq2A== ARC-Authentication-Results: i=1; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s9si4318165pgm.133.2019.03.07.08.41.37; Thu, 07 Mar 2019 08:41:52 -0800 (PST) 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 S1726420AbfCGQlK (ORCPT + 99 others); Thu, 7 Mar 2019 11:41:10 -0500 Received: from mx2.suse.de ([195.135.220.15]:35302 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726172AbfCGQlJ (ORCPT ); Thu, 7 Mar 2019 11:41:09 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id A209DAC9A; Thu, 7 Mar 2019 16:41:07 +0000 (UTC) Received: by unicorn.suse.cz (Postfix, from userid 1000) id BB5ECE1175; Thu, 7 Mar 2019 17:41:06 +0100 (CET) Date: Thu, 7 Mar 2019 17:41:06 +0100 From: Michal Kubecek To: Arnd Bergmann Cc: "David S. Miller" , Florian Fainelli , Jakub Kicinski , Jiri Pirko , Wenwen Wang , netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] [v2] ethtool: reduce stack usage with clang Message-ID: <20190307164106.GD20309@unicorn.suse.cz> References: <20190307160017.3120362-1-arnd@arndb.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190307160017.3120362-1-arnd@arndb.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Mar 07, 2019 at 04:58:35PM +0100, Arnd Bergmann wrote: > clang inlines the dev_ethtool() more aggressively than gcc does, leading > to a larger amount of used stack space: > > net/core/ethtool.c:2536:24: error: stack frame size of 1216 bytes in function 'dev_ethtool' [-Werror,-Wframe-larger-than=] > > Marking the sub-functions that require the most stack space as > noinline_for_stack gives us reasonable behavior on all compilers. > > Signed-off-by: Arnd Bergmann > --- > v2: don't annotate dev_ethtool itself, as pointed out by Michal Kubecek > --- > net/core/ethtool.c | 16 +++++++++------- > 1 file changed, 9 insertions(+), 7 deletions(-) > Reviewed-by: Michal Kubecek In the long term, these three functions would IMHO deserve some rework. While marking them as noinline_for_stack prevents one big stack frame in dev_ethtool(), we still allocate rather big structures on the stack, only it won't be in one stack frame. When we take the dev_ethtool ethtool_set_perqueue ethtool_[gs]et_per_queue_coalesce path, there will still be two 512-byte arrays on the stack, one inside struct ethtool_per_queue_op in ethtool_set_per_queue() and one as the queue_mask bitmap in ethtool_[gs]et_per_queue_coalesce() (MAX_NUM_QUEUE is 4096 now). In other words, actual stack consumption might be approximately the same after this change as it was before, only divided into three stack frames. Michal Kubecek > diff --git a/net/core/ethtool.c b/net/core/ethtool.c > index d4918ffddda8..b1eb32419732 100644 > --- a/net/core/ethtool.c > +++ b/net/core/ethtool.c > @@ -2319,9 +2319,10 @@ static int ethtool_set_tunable(struct net_device *dev, void __user *useraddr) > return ret; > } > > -static int ethtool_get_per_queue_coalesce(struct net_device *dev, > - void __user *useraddr, > - struct ethtool_per_queue_op *per_queue_opt) > +static noinline_for_stack int > +ethtool_get_per_queue_coalesce(struct net_device *dev, > + void __user *useraddr, > + struct ethtool_per_queue_op *per_queue_opt) > { > u32 bit; > int ret; > @@ -2349,9 +2350,10 @@ static int ethtool_get_per_queue_coalesce(struct net_device *dev, > return 0; > } > > -static int ethtool_set_per_queue_coalesce(struct net_device *dev, > - void __user *useraddr, > - struct ethtool_per_queue_op *per_queue_opt) > +static noinline_for_stack int > +ethtool_set_per_queue_coalesce(struct net_device *dev, > + void __user *useraddr, > + struct ethtool_per_queue_op *per_queue_opt) > { > u32 bit; > int i, ret = 0; > @@ -2405,7 +2407,7 @@ static int ethtool_set_per_queue_coalesce(struct net_device *dev, > return ret; > } > > -static int ethtool_set_per_queue(struct net_device *dev, > +static int noinline_for_stack ethtool_set_per_queue(struct net_device *dev, > void __user *useraddr, u32 sub_cmd) > { > struct ethtool_per_queue_op per_queue_opt;