Message ID | 20231212214819.247611-1-arnd@kernel.org |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp8021991vqy; Tue, 12 Dec 2023 13:48:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgK0JlCL8KP3qiaxaZEWmNyD6g72cxv7EZPfPmEYhj3CyRHeT48JlQBC3Hq5po/tqkQ7dc X-Received: by 2002:a05:6a20:9694:b0:18f:97c:826c with SMTP id hp20-20020a056a20969400b0018f097c826cmr3372025pzc.118.1702417711340; Tue, 12 Dec 2023 13:48:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702417711; cv=none; d=google.com; s=arc-20160816; b=LBmqKSVGF4BiydDpm+JGclsWRSB2QQR3y+M72dd6zJW7tMx3eyzqHANCpN3uZmsnDQ J/grvu2zlC6B5sz17Kdfc5KC6lw1bifBxEBkcn89+vHzV4mYUqj8zM03R+6moYThtasf kTGJNBv75hGUPn3TrlHAXXIU9ozXk15TmZvQS8/gWZ5cqV3sAe7PmQzZ8PWDCMJJqwL4 ov1R1hPEepnHQ34RDd3Pgz+6clez+EF0gX1pD1K8wydzrL0kP4Rdxw8rLbkASpbGyUyV nqM0LT4lyTD1SZHalkOCAizMhgoFktOqZtVF2i/oYwBNQH59rZWzfq7angf/fAq7EkWs wZ+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=LLguFo0A2SJ+EeJZZNqWOr9Ska0rwQa50gdWeKd1ZTM=; fh=DpgPwUtzIkokEDDfvunhcUNPmPsND4Ce1iQGirL5A8c=; b=Q+0hPX0x3UxNCwmh5pv9G1IOFmUfe7+sJflOUZDcW+z0Z4AKeMj1VpT0lmjkYVCLui MAXIoPZ8wjfIDU/WSjCUwWhMt0Ri/8THBr2bz1PfrmdJMZMVz5jh2ABF5YwssmQvgP3b YhVJrrTWxv/oUND2jXWRzE6r/7UD9cvXy2oibaUQJYlDLwDGbpXqdLgjigwLt4z+2Aki uPVF9RXzIn0S4YQDrQiLAF/ald9UXfvULy0G+IulZVVtvXycqFVP2TKngGHcLWiu/NEL tDIMG2QImElqK/exoC05lD/kPTeBoR1BqKtHf97sBiZ2A9+5nkWwK2crpqlku52gJ/fL UlZA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dHuBGdEk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id b13-20020a170902d50d00b001d0b5aa3000si8599756plg.456.2023.12.12.13.48.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 13:48:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=dHuBGdEk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 75F3E810757C; Tue, 12 Dec 2023 13:48:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377532AbjLLVsT (ORCPT <rfc822;dexuan.linux@gmail.com> + 99 others); Tue, 12 Dec 2023 16:48:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235165AbjLLVsS (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 12 Dec 2023 16:48:18 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2F8BAB for <linux-kernel@vger.kernel.org>; Tue, 12 Dec 2023 13:48:25 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D95D0C433C8; Tue, 12 Dec 2023 21:48:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1702417705; bh=wVW4B4dpDL0SVJV6h8hwO86hfQnu7Dv3P3WCPwRyals=; h=From:To:Cc:Subject:Date:From; b=dHuBGdEkvGgWZiAVBXqaCQtFzOWV7PsCszdXbNCNkEUvgKH8OVVjrYnWfaVAxhVXH nxl1ZdNew2m2TsOP5tA7cLqvsJ5J8dqSUyUKPJm8wn4d7tjLbXT3iC+93GoFvOYsyY HJUiu8QPgOeXlFOZluNyO0Sf5PpyVqldWe2Bci+UwgkJRzQAjtJzLJVfEf3gQKymX0 kYk4qwKeKsaTyCueQKXHGgDIiL6Son3oeM/n7Mc8fVqBnx9ejiWwALrrNbGPW3i9Wj yAnerwoiQCcNHhiwIjqpbJkxkPeafpbWQeDnFr/LfKLIDTNOVUYelIzMFhUHPYgcRh 5dq9/NoIxKdIg== From: Arnd Bergmann <arnd@kernel.org> To: Alexander Viro <viro@zeniv.linux.org.uk>, Christian Brauner <brauner@kernel.org> Cc: Arnd Bergmann <arnd@arndb.de>, Jan Kara <jack@suse.cz>, Miklos Szeredi <mszeredi@redhat.com>, Ian Kent <raven@themaw.net>, "Seth Forshee (DigitalOcean)" <sforshee@kernel.org>, Dave Chinner <dchinner@redhat.com>, Amir Goldstein <amir73il@gmail.com>, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] statmount: reduce runtime stack usage Date: Tue, 12 Dec 2023 22:48:13 +0100 Message-Id: <20231212214819.247611-1-arnd@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, 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 morse.vger.email Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 12 Dec 2023 13:48:28 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785114353949857822 X-GMAIL-MSGID: 1785114353949857822 |
Series |
statmount: reduce runtime stack usage
|
|
Commit Message
Arnd Bergmann
Dec. 12, 2023, 9:48 p.m. UTC
From: Arnd Bergmann <arnd@arndb.de> 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, Mark the inner function as noinline_for_stack so the second copy is freed before calling do_statmount() enters filesystem specific code. The extra copy of the structure is a bit inefficient, but this system call should not be performance critical. Fixes: 49889374ab92 ("statmount: simplify string option retrieval") Signed-off-by: Arnd Bergmann <arnd@arndb.de> --- fs/namespace.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
Comments
On 13/12/23 05:48, Arnd Bergmann wrote: > From: Arnd Bergmann <arnd@arndb.de> > > 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, > > Mark the inner function as noinline_for_stack so the second copy is > freed before calling do_statmount() enters filesystem specific code. > The extra copy of the structure is a bit inefficient, but this > system call should not be performance critical. Are you sure this is not performance sensitive, or is the performance critical comment not related to the system call being called many times? It's going to be a while (if ever) before callers change there ways. Consider what happens when a bunch of mounts are being mounted. First there are a lot of events and making the getting of mount info. more efficient means more of those events get processed (itself an issue that's going to need notification sub-system improvement) resulting in the system call being called even more. There are 3 or 4 common programs that monitor the mounts, systemd is one of those, it usually has 3 processes concurrently listening for mount table events and every one of these processes grabs the entire table. Thing is systemd is actually quite good at handling events and can process a lot of them if they are being occuring. So this system call will be called a lot. Ian > > Fixes: 49889374ab92 ("statmount: simplify string option retrieval") > Signed-off-by: Arnd Bergmann <arnd@arndb.de> > --- > fs/namespace.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/fs/namespace.c b/fs/namespace.c > index d036196f949c..e22fb5c4a9bb 100644 > --- a/fs/namespace.c > +++ b/fs/namespace.c > @@ -4950,7 +4950,8 @@ static inline bool retry_statmount(const long ret, size_t *seq_size) > return true; > } > > -static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, > +static int noinline_for_stack > +prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, > struct statmount __user *buf, size_t bufsize, > size_t seq_size) > {
On Wed, Dec 13, 2023, at 02:13, Ian Kent wrote: > On 13/12/23 05:48, Arnd Bergmann wrote: >> From: Arnd Bergmann <arnd@arndb.de> >> >> 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, >> >> Mark the inner function as noinline_for_stack so the second copy is >> freed before calling do_statmount() enters filesystem specific code. >> The extra copy of the structure is a bit inefficient, but this >> system call should not be performance critical. > > Are you sure this is not performance sensitive, or is the performance > critical comment not related to the system call being called many times? > > > It's going to be a while (if ever) before callers change there ways. > > Consider what happens when a bunch of mounts are being mounted. > > > First there are a lot of events and making the getting of mount info. > more efficient means more of those events get processed (itself an issue > that's going to need notification sub-system improvement) resulting in > the system call being called even more. Ok, I'll send a v2 that is more efficent. I expected it to look uglier, but I don't think it's actually that bad: --- 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;
diff --git a/fs/namespace.c b/fs/namespace.c index d036196f949c..e22fb5c4a9bb 100644 --- a/fs/namespace.c +++ b/fs/namespace.c @@ -4950,7 +4950,8 @@ static inline bool retry_statmount(const long ret, size_t *seq_size) return true; } -static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, +static int noinline_for_stack +prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, struct statmount __user *buf, size_t bufsize, size_t seq_size) {