]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Add helper functions for r11-based stack argument insns
authorYonghong Song <yonghong.song@linux.dev>
Wed, 13 May 2026 04:50:05 +0000 (21:50 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 13 May 2026 16:27:30 +0000 (09:27 -0700)
Add three static inline helper functions — is_stack_arg_ldx(),
is_stack_arg_st(), and is_stack_arg_stx() — that identify r11-based
(BPF_REG_PARAMS) instructions used for stack argument passing. These
helpers encapsulate the detailed encoding requirements (operand size,
register, offset alignment and sign) and hide raw BPF_REG_PARAMS usage
from the verifier, making call sites more readable and explicit.

A later patch ("bpf: Enable r11 based insns") will wire these helpers
into the verifier. Until then, check_and_resolve_insns() rejects any
r11-based registers.

Signed-off-by: Yonghong Song <yonghong.song@linux.dev>
Link: https://lore.kernel.org/r/20260513045005.2383881-1-yonghong.song@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
include/linux/filter.h

index b77d0b06db6ebce538dc78cb5fded71a841cbfef..918d9b34eac6a4b61aba3787addf8f63484d0ae7 100644 (file)
@@ -749,6 +749,27 @@ static inline u32 bpf_prog_run_pin_on_cpu(const struct bpf_prog *prog,
        return ret;
 }
 
+static inline bool is_stack_arg_ldx(const struct bpf_insn *insn)
+{
+       return insn->code == (BPF_LDX | BPF_MEM | BPF_DW) &&
+              insn->src_reg == BPF_REG_PARAMS &&
+              insn->off > 0 && insn->off % 8 == 0;
+}
+
+static inline bool is_stack_arg_st(const struct bpf_insn *insn)
+{
+       return insn->code == (BPF_ST | BPF_MEM | BPF_DW) &&
+              insn->dst_reg == BPF_REG_PARAMS &&
+              insn->off < 0 && insn->off % 8 == 0;
+}
+
+static inline bool is_stack_arg_stx(const struct bpf_insn *insn)
+{
+       return insn->code == (BPF_STX | BPF_MEM | BPF_DW) &&
+              insn->dst_reg == BPF_REG_PARAMS &&
+              insn->off < 0 && insn->off % 8 == 0;
+}
+
 #define BPF_SKB_CB_LEN QDISC_CB_PRIV_LEN
 
 struct bpf_skb_data_end {