]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
bpf: Clean up redundant stack arg checks for non-JITed programs
authorYonghong Song <yonghong.song@linux.dev>
Fri, 15 May 2026 22:51:01 +0000 (15:51 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Sun, 17 May 2026 00:46:16 +0000 (17:46 -0700)
commit98540a12823a016e2e1fa0db15543b22ac1fa056
tree0bdeb3d52c48ec18cc322604f154b62075ed2c61
parentd1dbe443a0abb4ea3ec35a16e36efe6d3bbf72f6
bpf: Clean up redundant stack arg checks for non-JITed programs

Remove a redundant stack_arg_cnt check in __bpf_prog_select_runtime()
and start the stack arg loop from index 0 in bpf_fixup_call_args().
Both changes are no-ops that simplify the code:

In __bpf_prog_select_runtime(), the subprog_info[0].stack_arg_cnt
check is unreachable:
  - when there is only a main program (no bpf-to-bpf calls),
    subprog_info[0].stack_arg_cnt is always 0 because the main
    program's arg_cnt is forced to 1
  - when bpf-to-bpf calls use stack args and JIT succeeds,
    fp->bpf_func is set and this code is skipped
  - when JIT fails, bpf_fixup_call_args() rejects the program
    before we get to __bpf_prog_select_runtime().

In bpf_fixup_call_args(), starting the loop at i=1 skipped subprog 0,
which is safe since the main program always has arg_cnt=1 and thus
bpf_in_stack_arg_cnt() returns 0. Starting at i=0 removes the need
to reason about this invariant.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20260515225101.824054-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/core.c
kernel/bpf/fixups.c