public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] statmount: reduce runtime stack usage
@ 2023-12-12 21:48 Arnd Bergmann
  2023-12-13  1:13 ` Ian Kent
  0 siblings, 1 reply; 3+ messages in thread
From: Arnd Bergmann @ 2023-12-12 21:48 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner
  Cc: Arnd Bergmann, Jan Kara, Miklos Szeredi, Ian Kent,
	Seth Forshee (DigitalOcean), Dave Chinner, Amir Goldstein,
	linux-fsdevel, linux-kernel

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(-)

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)
 {
-- 
2.39.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-13  7:40 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-12 21:48 [PATCH] statmount: reduce runtime stack usage Arnd Bergmann
2023-12-13  1:13 ` Ian Kent
2023-12-13  7:40   ` Arnd Bergmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox