[PATCH] arm64: signal: reduce stack usage in rt_sigreturn
Nick Desaulniers
ndesaulniers at google.com
Thu Dec 3 14:33:12 PST 2026
On Tue, Dec 1, 2026 at 1:09 AM Arnd Bergmann <arnd at kernel.org> wrote:
>
> From: Arnd Bergmann <arnd at arndb.de>
>
> The floating point register state is rather large, and clang may end up
> putting both the fpsimd and sve version on the same stack, which ends
> up larger than most functions:
>
> arch/arm64/kernel/signal.c:1112:1: error: stack frame size (1376) exceeds limit (1280) in '__arm64_sys_rt_sigreturn' [-Werror,-Wframe-larger-than]
> 1112 | SYSCALL_DEFINE0(rt_sigreturn)
> | ^
>
> Since only ever one of the two functions is called here, mark them
> both noinline to ensure that the stack usage stays as low as possible.
> There is no risk of actually overflowing the kernel stack here, but
> addressing the warning helps find real bugs elsewhere if we can reduce
> the warning limit.
>
> Signed-off-by: Arnd Bergmann <arnd at arndb.de>
Ah! I've been poking at kernel stack usage issues in clang recently
(old white whale I can't let go of), and I literally hit this exact
case. `__arm64_sys_rt_sigreturn` is the largest delta between GCC and
clang for stack usage for ARCH=arm64.
i.e. a `struct user_fpsimd_state` (528B) in `restore_fpsimd_context`
which can be inlined into `restore_sve_fpsimd_context` which has it's
own additional `struct user_fpsimd_state` .
This -Wdeclaration-after-statement style of gnu89 C programming is
problematic IMO from a "I also claim to care about minimizing stack
usage" perspective. We ripped that out of the kernel when you moved
us to C11, IIRC?
Moving struct user_fpsimd_state fpsimd; in restore_sve_fpsimd_context
below the if (fpsimd_only) return would let those two 528 B slots
share stack space even when inlined.
$ make LLVM=1 ARCH=arm64 defconfig arch/arm64/kernel/signal.o
$ llvm-objdump -dr --disassemble-symbols=__arm64_sys_rt_sigreturn
arch/arm64/kernel/signal.o | grep sub | grep sp
20: d11303ff sub sp, sp, #0x4c0
```
diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
index 6a06a4e352b1..916a8aa8bb64 100644
--- a/arch/arm64/kernel/signal.c
+++ b/arch/arm64/kernel/signal.c
@@ -431,7 +431,6 @@ static int restore_sve_fpsimd_context(struct
user_ctxs *user)
{
int err = 0;
unsigned int vl, vq;
- struct user_fpsimd_state fpsimd;
u16 user_vl, flags;
bool fpsimd_only;
bool sm;
@@ -516,6 +515,7 @@ static int restore_sve_fpsimd_context(struct
user_ctxs *user)
if (err)
return -EFAULT;
+ struct user_fpsimd_state fpsimd;
err = read_fpsimd_context(&fpsimd, user);
if (err)
return err;
```
$ make LLVM=1 ARCH=arm64 defconfig arch/arm64/kernel/signal.o
$ llvm-objdump -dr --disassemble-symbols=__arm64_sys_rt_sigreturn
arch/arm64/kernel/signal.o | grep sub | grep sp
20: d10ac3ff sub sp, sp, #0x2b0
(scripts/checkstack.pl is _so broken_ at this point, I honestly think
we should delete it. It is totally useless for looking at actual stack
usage. It's also written in perl...)
> ---
> arch/arm64/kernel/signal.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/arm64/kernel/signal.c b/arch/arm64/kernel/signal.c
> index 80398ac83c3b..38774fcd0033 100644
> --- a/arch/arm64/kernel/signal.c
> +++ b/arch/arm64/kernel/signal.c
> @@ -313,7 +313,7 @@ static int read_fpsimd_context(struct user_fpsimd_state *fpsimd,
> return err ? -EFAULT : 0;
> }
>
> -static int restore_fpsimd_context(struct user_ctxs *user)
> +static noinline_for_stack int restore_fpsimd_context(struct user_ctxs *user)
> {
> struct user_fpsimd_state fpsimd;
> int err;
> @@ -427,7 +427,7 @@ static int preserve_sve_context(struct sve_context __user *ctx)
> return err ? -EFAULT : 0;
> }
>
> -static int restore_sve_fpsimd_context(struct user_ctxs *user)
> +static noinline_for_stack int restore_sve_fpsimd_context(struct user_ctxs *user)
> {
> int err = 0;
> unsigned int vl, vq;
> --
> 2.53.0
>
--
Thanks,
~Nick Desaulniers
More information about the linux-arm-kernel
mailing list