[PATCH bpf-next v2 16/22] bpf: Append the hidden subprog through the patch list

From: Qiliang Yuan

Date: Fri Oct 30 2026 - 08:01:21 EST


add_hidden_subprog() appends the subprog for the exception callback by
patching the last instruction of the program with itself followed by
the new instructions.

It does that with bpf_patch_insn_data(), which is going away once all
passes use the patch list.

Queue that patch with bpf_patch_list_add() and commit it right away.

Signed-off-by: Qiliang Yuan <odys.yuan@xxxxxxxxx>
---
kernel/bpf/fixups.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/kernel/bpf/fixups.c b/kernel/bpf/fixups.c
index f55ac904b4e78..84aaaa4632aa3 100644
--- a/kernel/bpf/fixups.c
+++ b/kernel/bpf/fixups.c
@@ -1865,7 +1865,8 @@ int bpf_fixup_call_args(struct bpf_verifier_env *env)
static int add_hidden_subprog(struct bpf_verifier_env *env, struct bpf_insn *patch, int len)
{
struct bpf_subprog_info *info = env->subprog_info;
- int cnt = env->subprog_cnt;
+ int err, cnt = env->subprog_cnt;
+ struct bpf_insn *last;
struct bpf_prog *prog;

/* We only reserve one slot for hidden subprogs in subprog_info. */
@@ -1874,13 +1875,15 @@ static int add_hidden_subprog(struct bpf_verifier_env *env, struct bpf_insn *pat
return -EFAULT;
}
/* We're not patching any existing instruction, just appending the new
- * ones for the hidden subprog. Hence all of the adjustment operations
- * in bpf_patch_insn_data are no-ops.
+ * ones for the hidden subprog.
*/
- prog = bpf_patch_insn_data(env, env->prog->len - 1, patch, len);
- if (!prog)
- return -ENOMEM;
- env->prog = prog;
+ last = bpf_patch_list_add(env, env->prog->len - 1, patch, len);
+ if (IS_ERR(last))
+ return PTR_ERR(last);
+ err = bpf_patch_list_commit(env);
+ if (err)
+ return err;
+ prog = env->prog;
info[cnt + 1].start = info[cnt].start;
info[cnt].start = prog->len - len + 1;
/* The patch ends with the exit. */

--
2.43.0