]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Refactor record_call_access() to extract per-arg logic
authorYonghong Song <yonghong.song@linux.dev>
Wed, 13 May 2026 04:50:30 +0000 (21:50 -0700)
committerAlexei Starovoitov <ast@kernel.org>
Wed, 13 May 2026 16:27:30 +0000 (09:27 -0700)
Extract the per-argument FP-derived pointer handling from
record_call_access() into a new record_arg_access() helper.

The existing loop body — checking arg_is_fp, querying stack access
bytes, and calling record_stack_access/record_imprecise — will be
reused for stack argument slots in the next patch. Factoring it out
now avoids duplicating the logic.

No functional change.

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

index 58197d73b120108b5bd53f5a10af13ecd2bd5cd3..c81337dfbfc79207e4aa07798e0878ba15523177 100644 (file)
@@ -1343,6 +1343,42 @@ static int record_load_store_access(struct bpf_verifier_env *env,
        return 0;
 }
 
+static int record_arg_access(struct bpf_verifier_env *env,
+                            struct func_instance *instance,
+                            struct bpf_insn *insn,
+                            struct arg_track *at, int arg_idx,
+                            int insn_idx)
+{
+       int depth = instance->depth;
+       int frame = at->frame;
+       int err = 0;
+       s64 bytes;
+
+       if (!arg_is_fp(at))
+               return 0;
+
+       if (bpf_helper_call(insn)) {
+               bytes = bpf_helper_stack_access_bytes(env, insn, arg_idx, insn_idx);
+       } else if (bpf_pseudo_kfunc_call(insn)) {
+               bytes = bpf_kfunc_stack_access_bytes(env, insn, arg_idx, insn_idx);
+       } else {
+               for (int f = 0; f <= depth; f++) {
+                       err = mark_stack_read(instance, f, insn_idx, SPIS_ALL);
+                       if (err)
+                               return err;
+               }
+               return 0;
+       }
+       if (bytes == 0)
+               return 0;
+
+       if (frame >= 0 && frame <= depth)
+               err = record_stack_access(instance, at, bytes, frame, insn_idx);
+       else if (frame == ARG_IMPRECISE)
+               err = record_imprecise(instance, at->mask, insn_idx);
+       return err;
+}
+
 /* Record stack access for a given 'at' state of helper/kfunc 'insn' */
 static int record_call_access(struct bpf_verifier_env *env,
                              struct func_instance *instance,
@@ -1350,9 +1386,8 @@ static int record_call_access(struct bpf_verifier_env *env,
                              int insn_idx)
 {
        struct bpf_insn *insn = &env->prog->insnsi[insn_idx];
-       int depth = instance->depth;
        struct bpf_call_summary cs;
-       int r, err = 0, num_params = 5;
+       int r, err, num_params = 5;
 
        if (bpf_pseudo_call(insn))
                return 0;
@@ -1361,31 +1396,7 @@ static int record_call_access(struct bpf_verifier_env *env,
                num_params = cs.num_params;
 
        for (r = BPF_REG_1; r < BPF_REG_1 + num_params; r++) {
-               int frame = at[r].frame;
-               s64 bytes;
-
-               if (!arg_is_fp(&at[r]))
-                       continue;
-
-               if (bpf_helper_call(insn)) {
-                       bytes = bpf_helper_stack_access_bytes(env, insn, r - 1, insn_idx);
-               } else if (bpf_pseudo_kfunc_call(insn)) {
-                       bytes = bpf_kfunc_stack_access_bytes(env, insn, r - 1, insn_idx);
-               } else {
-                       for (int f = 0; f <= depth; f++) {
-                               err = mark_stack_read(instance, f, insn_idx, SPIS_ALL);
-                               if (err)
-                                       return err;
-                       }
-                       return 0;
-               }
-               if (bytes == 0)
-                       continue;
-
-               if (frame >= 0 && frame <= depth)
-                       err = record_stack_access(instance, &at[r], bytes, frame, insn_idx);
-               else if (frame == ARG_IMPRECISE)
-                       err = record_imprecise(instance, at[r].mask, insn_idx);
+               err = record_arg_access(env, instance, insn, &at[r], r - 1, insn_idx);
                if (err)
                        return err;
        }