bpf, arm64: Allow programs 2 KiB of stack

The arm64 JIT sets up a frame with an add/sub immediate, which encodes
up to 4 KiB directly, addresses the BPF stack relative to SP or the
private stack pointer with offsets that fall back to a scratch register
when they do not fit the load/store immediate, and a tail call pops the
current frame and lands in the target's prologue before the target
sets up its own. The exception callback reuses the frame record of the
main program and does not depend on its size. Report
bpf_jit_supports_large_stack() to give JITed programs the same 2 KiB
budget as on x86-64.

Tested on an emulated arm64 guest with programs loaded and run through
the raw bpf() syscall: a 2 KiB frame, a 2 KiB frame with may_goto, a
chain of four 512-byte frames, and a tail call from a program with a
2 KiB frame into another one; a 2056-byte frame and five 512-byte frames
are rejected. The selftest suite was not run on arm64.

Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Link: https://patch.msgid.link/20260924165740.2146806-18-memxor@gmail.com
This commit is contained in:
Kumar Kartikeya Dwivedi 2026-09-24 18:57:18 +02:00 committed by Alexei Starovoitov
parent 9f3bcf081d
commit 1d5306c11d
No known key found for this signature in database
2 changed files with 11 additions and 5 deletions

View File

@ -223,11 +223,12 @@ Q: How much stack space a BPF program uses?
-------------------------------------------
A: A program may use up to 2 KiB of stack, combined over its call
chain, when the JIT of the architecture reports support for large
stacks (currently x86-64); a single function may use all of it, and
every frame of a program running on a private stack gets the whole
amount. Elsewhere, and whenever the interpreter is used, the limit is
512 bytes. The verifier computes the actual amount of stack used and
both interpreter and most JITed code consume necessary amount.
stacks (currently x86-64 and arm64); a single function may use all of
it, and every frame of a program running on a private stack gets the
whole amount. Elsewhere, and for programs verified for the interpreter,
the limit is 512 bytes; the interpreter itself never runs a frame
larger than that. The verifier computes the actual amount of stack
used and both interpreter and most JITed code consume necessary amount.
Q: Can BPF be offloaded to HW?
------------------------------

View File

@ -2503,6 +2503,11 @@ bool bpf_jit_supports_callx(void)
return true;
}
bool bpf_jit_supports_large_stack(void)
{
return true;
}
static void invoke_bpf_prog(struct jit_ctx *ctx, struct bpf_tramp_node *node,
int bargs_off, int retval_off, int run_ctx_off,
bool save_ret)