Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp5669747rdb; Wed, 13 Dec 2023 16:12:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IFTN0Ideyf4QIxEaVt2U8YO+IBIyADuuVA444Ffh31jLobrXEz8l3Zc81jgPGxASiy79kNL X-Received: by 2002:a05:6358:e49b:b0:16b:c467:695f with SMTP id by27-20020a056358e49b00b0016bc467695fmr6134695rwb.9.1702512750293; Wed, 13 Dec 2023 16:12:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702512750; cv=none; d=google.com; s=arc-20160816; b=XaItnwbXoLoHo6EQfF3KhP6JODqpzPHB8/3UK+HtA07ysVyDY/+KYvkdZsr6+Y/JJ4 cF432EABmzZiYnTzd2E3WHs/d3xrgDQfCnmK4WdM/4cd4genin0NNf2VTd29kK11q12/ mf4neaay3b9VI05qU/iO9BJyWnqwhXNdozY+tqvD3Hp6gPcdd6N3H23ssCdEkEn0Rwph pnxiunPH+TDaWKTSdAqOp3/XjzS6DInBmHCoLCZFoSAjL4xnfVbvpFIcluJ8NF3UdTAI BgXecGuR0JO3MRlaLRtZNBLgr40xJyFNBolUxFbnzoC5Uc6e7kgwUtvVUOA7dU/S9OkS JiGQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:feedback-id:dkim-signature:dkim-signature; bh=VAqYPxgc+/bKFX3mKOr2AnsJnWJikiX4oD9KxuWgxIo=; fh=8EoQs3IKtzrq8J3jIaI/LcYmlxqkFBB3eTaQqXZiDwk=; b=BOw7xqoJjEesMh3xLweJ88YqwnCPg93p36RiU8F/5C9kUBXRDJy47Hs3jgmuJZjMz8 id0b8AYJrKF/SB4Kp1osSYoWe8FT9v5/TYyiRmZ71XclQgsVj2GBI+g1ORcRtiTccpTC hgqss/RLCPVYqGW7F1dGt0Xg5oEcjzQ0z5IVmWUdMiJugaRgkCFZM0YpWiTAhD+x7Svi wPT5sWgHPES7g7LCuq5uSDAmgklwnbZIU8IoYy7AulRLmpcV8l7qOjdWFcDhpy+mY82P 3GxPJCQ5Ce9Je6g/mHjkq1G4xDmVlp1PhTUdfIDIjSTSDTDHYFWL/aKW+KS3MyfWgPyP FF8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@themaw.net header.s=fm3 header.b=byuu6jSj; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=U29m5jOi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=themaw.net Return-Path: Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id bq5-20020a056a02044500b005c5e2331ba9si10928552pgb.324.2023.12.13.16.12.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Dec 2023 16:12:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@themaw.net header.s=fm3 header.b=byuu6jSj; dkim=pass header.i=@messagingengine.com header.s=fm1 header.b=U29m5jOi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=themaw.net Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 60A03809217D; Wed, 13 Dec 2023 16:11:58 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234081AbjLNALk (ORCPT + 99 others); Wed, 13 Dec 2023 19:11:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49790 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229706AbjLNALi (ORCPT ); Wed, 13 Dec 2023 19:11:38 -0500 Received: from wout4-smtp.messagingengine.com (wout4-smtp.messagingengine.com [64.147.123.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6C31FDD; Wed, 13 Dec 2023 16:11:45 -0800 (PST) Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.west.internal (Postfix) with ESMTP id 5633E3200B69; Wed, 13 Dec 2023 19:11:41 -0500 (EST) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 13 Dec 2023 19:11:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=themaw.net; h=cc :cc:content-transfer-encoding:content-type:content-type:date :date:from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm3; t=1702512700; x=1702599100; bh=VAqYPxgc+/bKFX3mKOr2AnsJnWJikiX4oD9KxuWgxIo=; b= byuu6jSjOxjC+6XDHeFG1ZaEupTQmCuFgV0DOt7qy+j07zlLKyF0jnc528VrLrpt TCZtN6GFGeGgszzhnKckZ3JDLHvLEIrjjjr+1EdrFP4l04IszvRMAh1a6MLTSw4o znV8LMdLRX0PeFiW7NLKS0KU470oVDid33bJ+uhnM17IV5Mv1KoBZ/7HqmI/Dtrz lfvHgdabRyv5NRNYB+GklM15/p+w2qJVrbl2qyO6aAVypQFaH8t4pR56NwJM8RC6 M5CAQ/gKgVNu9ifnNHZVdLAlHktykFF+y0RW54m7E/IIwzk3fnCznVPEB5+u79A8 GlF91Vqv0q+dsqtqxkvKpw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1702512700; x= 1702599100; bh=VAqYPxgc+/bKFX3mKOr2AnsJnWJikiX4oD9KxuWgxIo=; b=U 29m5jOibtqGsH6gPzE+6te4lbuhC1mza/WeIFvjyWNKrd8Up3yvCx1uhSXRmCnQA fjoWrTxIhETsvsi0foyo6gtWUqL/2uS2yrrLLdr4jdWfpu66IhmQalr3BcQR1X9J ZeNcWKKTa2dwe6hWR63Z5dcP1CdoWYIajnRHLPwCCWi7NdagUXoF3Iv9M403s+Ki 9ACHT8VA++iGJZ0E9rJLOz1vyDzdFCiYfBO4wr1flFw8OuTnXfRW3i+3CGW2FYCu b2H2gK5r5xv2BMUGdIPdAbapRA1PCOLrcfF8V2QTdEA89LNh1T3SLLtYt1FXWNtV AMPPg437q9XnVB+8Q22DA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvkedrudelkedgudelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvvehfhfgjtgfgsehtjeertddtfeejnecuhfhrohhmpefkrghn ucfmvghnthcuoehrrghvvghnsehthhgvmhgrfidrnhgvtheqnecuggftrfgrthhtvghrnh epuefhueeiieejueevkefgiedtteehgfdutdelfffhleeflefhudeuvdefhfeghfehnecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprhgrvhgvnh esthhhvghmrgifrdhnvght X-ME-Proxy: Feedback-ID: i31e841b0:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Wed, 13 Dec 2023 19:11:36 -0500 (EST) Message-ID: <6608665d-a255-7b1d-653f-1d13d2b3fa2e@themaw.net> Date: Thu, 14 Dec 2023 08:11:32 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Subject: Re: [PATCH] [v2] statmount: reduce runtime stack usage To: Arnd Bergmann , Alexander Viro , Christian Brauner Cc: Arnd Bergmann , Jan Kara , Miklos Szeredi , "Seth Forshee (DigitalOcean)" , Dave Chinner , Amir Goldstein , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org References: <20231213090015.518044-1-arnd@kernel.org> Content-Language: en-US From: Ian Kent In-Reply-To: <20231213090015.518044-1-arnd@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Wed, 13 Dec 2023 16:11:58 -0800 (PST) On 13/12/23 17:00, Arnd Bergmann wrote: > From: Arnd Bergmann > > prepare_kstatmount() constructs a copy of 'struct kstatmount' on the stack > and copies it into the local variable on the stack of its caller. Because > of the size of this structure, this ends up overflowing the limit for > a single function's stack frame when prepare_kstatmount() gets inlined > and both copies are on the same frame without the compiler being able > to collapse them into one: > > fs/namespace.c:4995:1: error: stack frame size (1536) exceeds limit (1024) in '__se_sys_statmount' [-Werror,-Wframe-larger-than] > 4995 | SYSCALL_DEFINE4(statmount, const struct mnt_id_req __user *, req, > > Replace the assignment with an in-place memset() plus assignment that > should always be more efficient for both stack usage and runtime cost. Cunning plan, to use the work efficient instead of inefficient, ;( But, TBH, the libc integration seems complex but I also feel there's no choice and this looks fine too. > > Fixes: 49889374ab92 ("statmount: simplify string option retrieval") > Signed-off-by: Arnd Bergmann > --- > fs/namespace.c | 15 ++++++--------- > 1 file changed, 6 insertions(+), 9 deletions(-) > > diff --git a/fs/namespace.c b/fs/namespace.c > index d036196f949c..159f1df379fc 100644 > --- a/fs/namespace.c > +++ b/fs/namespace.c > @@ -4957,15 +4957,12 @@ static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, > if (!access_ok(buf, bufsize)) > return -EFAULT; > > - *ks = (struct kstatmount){ > - .mask = kreq->param, > - .buf = buf, > - .bufsize = bufsize, > - .seq = { > - .size = seq_size, > - .buf = kvmalloc(seq_size, GFP_KERNEL_ACCOUNT), > - }, > - }; > + memset(ks, 0, sizeof(*ks)); > + ks->mask = kreq->param; > + ks->buf = buf; > + ks->bufsize = bufsize; > + ks->seq.size = seq_size; > + ks->seq.buf = kvmalloc(seq_size, GFP_KERNEL_ACCOUNT); > if (!ks->seq.buf) > return -ENOMEM; > return 0; This looks much better than what it replaces IMHO. Reviewed-by: Ian Kent Ian