From nobody Thu Dec 18 14:27:00 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7114FC4332F for ; Wed, 13 Dec 2023 09:00:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232486AbjLMJAU (ORCPT ); Wed, 13 Dec 2023 04:00:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjLMJAP (ORCPT ); Wed, 13 Dec 2023 04:00:15 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3D736AD for ; Wed, 13 Dec 2023 01:00:22 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 71122C433C9; Wed, 13 Dec 2023 09:00:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702458021; bh=KYg70uTTMCVbbybOUe4N/VTYl2TBfccDvrHX9QOYSpI=; h=From:To:Cc:Subject:Date:From; b=QRMKY1CjqdvbZ0fbr2tBAwGIzwJ4uuPaNCuYkelu9eHILPcC0WvZTScIzOI0dNK6V p1zR4KyknBgnnd5nC0szCG01DrkV10nVXhXEHNpRgKjg6a7oiP96Z57Ac5xlStWol6 NVYSF2Rjf0QHrI7WipJ/iT1qYwm5S7kVASmGKI9t0uZifTt31XCU1DFiWWkMMO6pBo un3hUZCgfnLgjKqP9Bhj6on6scYXyuwRyLSPZKGkH7na7rgPBgSx7s4aeZUv65A7kH eJgltZHbSlNr5p2rGIBgU9stsuQBnnQXq21MW1fKdlqy4KK3mgRuurRBFCKEoqMB66 f/f8r09VGOqxQ== From: Arnd Bergmann To: Alexander Viro , Christian Brauner Cc: Arnd Bergmann , Jan Kara , Ian Kent , Miklos Szeredi , "Seth Forshee (DigitalOcean)" , Dave Chinner , Amir Goldstein , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] [v2] statmount: reduce runtime stack usage Date: Wed, 13 Dec 2023 10:00:03 +0100 Message-Id: <20231213090015.518044-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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. Fixes: 49889374ab92 ("statmount: simplify string option retrieval") Signed-off-by: Arnd Bergmann Reviewed-by: Ian Kent --- 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; =20 - *ks =3D (struct kstatmount){ - .mask =3D kreq->param, - .buf =3D buf, - .bufsize =3D bufsize, - .seq =3D { - .size =3D seq_size, - .buf =3D kvmalloc(seq_size, GFP_KERNEL_ACCOUNT), - }, - }; + memset(ks, 0, sizeof(*ks)); + ks->mask =3D kreq->param; + ks->buf =3D buf; + ks->bufsize =3D bufsize; + ks->seq.size =3D seq_size; + ks->seq.buf =3D kvmalloc(seq_size, GFP_KERNEL_ACCOUNT); if (!ks->seq.buf) return -ENOMEM; return 0; --=20 2.39.2