From patchwork Tue Dec 12 21:48:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnd Bergmann X-Patchwork-Id: 13490027 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC79E65A98 for ; Tue, 12 Dec 2023 21:48:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="dHuBGdEk" 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 To: Alexander Viro , Christian Brauner Cc: Arnd Bergmann , Jan Kara , Miklos Szeredi , Ian Kent , "Seth Forshee (DigitalOcean)" , Dave Chinner , Amir Goldstein , 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 Precedence: bulk X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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, 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 --- 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) {