BPF List
 help / color / mirror / Atom feed
From: Kumar Kartikeya Dwivedi <memxor@gmail.com>
To: bpf@vger.kernel.org
Cc: Alexei Starovoitov <ast@kernel.org>,
	Andrii Nakryiko <andrii@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Eduard Zingerman <eddyz87@gmail.com>,
	Emil Tsalapatis <emil@etsalapatis.com>,
	Ihor Solodrai <ihor.solodrai@linux.dev>,
	kkd@meta.com, kernel-team@meta.com
Subject: [PATCH bpf-next v1 07/73] bpf: Let a callback unwind out of a helper that has an unwind label
Date: Tue,  1 Dec 2026 05:38:34 +0100	[thread overview]
Message-ID: <e041104e5829b2f0b9d8dff4cd117b1667c19dca.1796099737.git.memxor@gmail.com> (raw)
In-Reply-To: <cover.1796099737.git.memxor@gmail.com>

Currently the verifier rejects a callback that reaches unwind_exit with
"callback cannot unwind". A helper that calls its callback with
bpf_call_cb() can now pass the unwinding on: it leaves from its unwind
label to the unwind_goto after its own call, with the R0 of the callback.

Treat the call of a helper or kfunc whose callback can unwind like the
call of a subprog that can unwind: unwind_goto may follow the call, and
it has to follow when the callback can unwind. Here cb is the callback of
bpf_loop():

        call bpf_loop           <- 1. enters cb      3. visited again
        unwind_goto +1          <- 4. taken
        exit
        r0 += 41                <- R0 is 5 here
        exit
  cb:
        r0 = 5
        unwind_exit             <- 2. back to the call, marked unwound

The verifier models the call of a helper with a callback as a loop: each
time the callback exits, the state goes back to the call insn. A state
that leaves the callback with unwind_exit goes back too, marked
state->unwound, because the helper has effects of its own on its way out:
bpf_rbtree_add(), for example, takes the node from the program whichever
way it leaves. On this second visit the call starts no further iteration,
applies the effects of the helper and keeps R0 as the callback left it.
The marked state then takes the unwind_goto.

check_cb_unwind() checks the call where the verifier enters a callback
that can unwind, in this order:

- No unwind_goto follows the call: "no unwind_goto after the call of
  bpf_loop()", -EINVAL.
- The kernel has no unwind labels (BPF_HAS_CB_PADS is 0): "callback
  cannot unwind: the helpers have no pads", -ENOTSUPP. This comes second,
  so that a missing unwind_goto gets the same message on every kernel.
- This helper has no unwind label: "callback cannot unwind", -EINVAL.
  helper_has_cb_pad() and kfunc_has_cb_pad() list those that have one.
  Both lists are empty, so every such program is still rejected.

The code at the target of unwind_goto gets R0 in the state that the
callback unwound with, as after the call of a subprog. The helper passes
that value on bit for bit, so the range of a callback's return value does
not apply to it, and a pointer keeps its type and its reference. What a
callback can leave in R0 this way it can already store through
callback_ctx.

These cases need care:

- The dynptr of bpf_user_ringbuf_drain() and the key of an array element
  live in the frame of the helper. The exit of the callback invalidates
  them and everything derived from them, in R0 too.
- A callback passes on R0 alone, whatever its prototype says. R2 stays
  the caller's, because the second visit of the call reads an argument
  there.
- A callback can unwind without an unwind_exit of its own. The check of
  the stack at the start of a recursive subprog leaves with unwind_exit
  when unwind_goto follows every call of the subprog that the verifier
  found before the main pass (bail_unwinds). The call of a helper that
  takes its callback from an array of function addresses in read-only
  data is not among them. So check_cb_unwind() asks the new
  bpf_subprog_unwinds(): can_unwind, or recursive with bail_unwinds.
- No speculative state gets to unwind_exit of a callback. Only a load
  without CAP_PERFMON has such states, and its program has no
  unwind_exit.

One hole is known and stays open. The vma that bpf_find_vma() gives its
callback is valid only under the mmap lock, and a callback that unwinds
with the vma in R0 passes it to code that runs without the lock. A
callback can do the same today when it stores the vma through
callback_ctx. Either way the program holds a PTR_TO_BTF_ID without a
trust flag, and loads through it are fault-safe and can return stale
data. One fix has to close both, and it is not part of this series.

Liveness, the backward slice from an unproven insn and constant folding
learn that R0 flows through a call with a callback when unwind_goto
follows the call.

Co-developed-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
 include/linux/bpf_verifier.h                  |  10 ++
 include/uapi/linux/bpf.h                      |   3 +-
 kernel/bpf/const_fold.c                       |   9 ++
 kernel/bpf/liveness.c                         |   7 +
 kernel/bpf/precision.c                        |  12 +-
 kernel/bpf/verifier.c                         | 147 +++++++++++++++---
 tools/include/uapi/linux/bpf.h                |   3 +-
 .../selftests/bpf/progs/verifier_unwind.c     |   2 +-
 8 files changed, 168 insertions(+), 25 deletions(-)

diff --git a/include/linux/bpf_verifier.h b/include/linux/bpf_verifier.h
index b8617d364f9c..117c3a3f7cbb 100644
--- a/include/linux/bpf_verifier.h
+++ b/include/linux/bpf_verifier.h
@@ -1234,6 +1234,16 @@ struct bpf_subprog_info {
 	u16 max_out_stack_arg_cnt;
 };
 
+/*
+ * The subprog can leave with unwind_exit, so a helper that calls it needs an unwind label, see
+ * check_cb_unwind(). A recursive subprog counts before it has the insn: its stack check gets one
+ * after the main pass.
+ */
+static inline bool bpf_subprog_unwinds(const struct bpf_subprog_info *sub)
+{
+	return sub->can_unwind || (sub->recursive && sub->bail_unwinds);
+}
+
 static inline u16 bpf_in_stack_arg_cnt(const struct bpf_subprog_info *sub)
 {
 	if (sub->stack_args_from_code)
diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h
index 28904c6f0787..95b41ae6584d 100644
--- a/include/uapi/linux/bpf.h
+++ b/include/uapi/linux/bpf.h
@@ -63,7 +63,8 @@ enum bpf_mul_variant {
 enum bpf_cond_pseudo_jmp {
 	BPF_MAY_GOTO = 0,
 	/*
-	 * Follows a call of a bpf subprog. Taken when the subprog left with
+	 * Follows a call of a bpf subprog, callx, or a call of a helper or kfunc
+	 * that calls a callback. Taken when the subprog or the callback left with
 	 * BPF_EXIT that has src_reg == BPF_UNWIND_EXIT.
 	 */
 	BPF_UNWIND_GOTO = 1,
diff --git a/kernel/bpf/const_fold.c b/kernel/bpf/const_fold.c
index 3310a55afa3b..1524166cf6db 100644
--- a/kernel/bpf/const_fold.c
+++ b/kernel/bpf/const_fold.c
@@ -311,6 +311,15 @@ int bpf_compute_const_regs(struct bpf_verifier_env *env)
 		for (r = BPF_REG_0; r < ARRAY_SIZE(aux->const_reg_vals); r++) {
 			struct const_arg_info *c = &ci[r];
 
+			/*
+			 * The revisit of a call with a callback that unwound
+			 * carries the r0 of the callback, see check_helper_call():
+			 * r0 is no constant of that insn.
+			 */
+			if (r == BPF_REG_0 && i + 1 < insn_cnt &&
+			    bpf_is_sync_callback_calling_insn(&insns[i]) &&
+			    bpf_is_unwind_goto(&insns[i + 1]))
+				continue;
 			switch (c->state) {
 			case CONST_ARG_CONST: {
 				u64 val = c->val;
diff --git a/kernel/bpf/liveness.c b/kernel/bpf/liveness.c
index 2c93798e1f15..f6456e5be5fd 100644
--- a/kernel/bpf/liveness.c
+++ b/kernel/bpf/liveness.c
@@ -2832,6 +2832,13 @@ static void compute_insn_live_regs(struct bpf_verifier_env *env,
 			 */
 			if (bpf_is_callx(insn))
 				use = dst;
+			/*
+			 * A callback that unwinds goes back to the call of its helper, see
+			 * check_helper_call(). R0 of the callback has to get through the call to
+			 * the target of the unwind_goto, so it is live before the call.
+			 */
+			if (bpf_is_sync_callback_calling_insn(insn) && bpf_is_unwind_goto(insn + 1))
+				use |= r0;
 			break;
 		default:
 			def = 0;
diff --git a/kernel/bpf/precision.c b/kernel/bpf/precision.c
index 33b180b35c88..f2ef763684f4 100644
--- a/kernel/bpf/precision.c
+++ b/kernel/bpf/precision.c
@@ -767,7 +767,7 @@ static bool compute_insn_deps(struct bpf_verifier_env *env, unsigned long *masks
 	u16 use = aux->use_regs, def = aux->def_regs, args = 0;
 	bool changed = false, stores, reads, loads, call, held_after;
 	struct taken_funcs *taken = &env->precision->taken;
-	u8 class = BPF_CLASS(insn->code), needs;
+	u8 class = BPF_CLASS(insn->code), needs, cb_ret;
 	u16 ptrs = 0;
 	int t, callee;
 
@@ -818,8 +818,14 @@ static bool compute_insn_deps(struct bpf_verifier_env *env, unsigned long *masks
 		reads = is_seed;
 		needs = ret[callee];
 	} else if (callee > 0) {
-		reads |= compute_call_deps(env, masks, ret, callee, needs & ~RET_REGS, &held,
-					   &changed);
+		/*
+		 * The callback returns to the helper, so R0 after the call is the helper's. With an
+		 * unwind_goto after the call it can also be R0 of a callback that unwound, see
+		 * check_cb_unwind().
+		 */
+		cb_ret = bpf_is_unwind_goto(insn + 1) ? BIT(BPF_REG_0) : 0;
+		reads |= compute_call_deps(env, masks, ret, callee, needs & ~(RET_REGS & ~cb_ret),
+					   &held, &changed);
 		needs = ret[callee];
 	} else if (bpf_is_callx(insn) || aux->calls_callback) {
 		changed |= needs & ~taken->needs;
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index f10f3660208f..4b65f537668c 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -10,6 +10,7 @@
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/bpf.h>
+#include <linux/bpf_unwind.h>
 #include <linux/btf.h>
 #include <linux/bpf_verifier.h>
 #include <linux/filter.h>
@@ -3363,6 +3364,8 @@ static int record_callx_edge(struct bpf_verifier_env *env, int caller, int calle
  * 'call foo; unwind_goto pad' goes to the pad when foo left with unwind_exit.
  * JITs don't emit a branch for it. unwind_exit finds the pad by its return
  * address. So unwind_goto has to follow the call and nothing may jump to it.
+ * The call can be of a helper or a kfunc that calls a callback: it leaves the
+ * way the callback does, see check_cb_unwind().
  */
 static int check_unwind_insns(struct bpf_verifier_env *env)
 {
@@ -3388,8 +3391,10 @@ static int check_unwind_insns(struct bpf_verifier_env *env)
 		if (!bpf_is_unwind_goto(insn))
 			continue;
 		seen = true;
-		if (!i || !(bpf_pseudo_call(insn - 1) || bpf_is_callx(insn - 1))) {
-			verbose(env, "unwind_goto at insn %d doesn't follow a call of a subprog\n",
+		if (!i || !(bpf_pseudo_call(insn - 1) || bpf_is_callx(insn - 1) ||
+			    bpf_is_sync_callback_calling_insn(insn - 1))) {
+			verbose(env,
+				"unwind_goto at insn %d doesn't follow a call of a subprog or of a helper with a callback\n",
 				i);
 			return -EINVAL;
 		}
@@ -11448,6 +11453,66 @@ static void leave_callback(struct bpf_func_state *caller)
 		leave_loops(caller, caller->loop_stack_cnt - 1);
 }
 
+/* The helper calls its callback with a pad, see bpf_call_cb(). None yet. */
+static bool helper_has_cb_pad(enum bpf_func_id func_id)
+{
+	return false;
+}
+
+/* The kfunc calls its callback with a pad. None yet. */
+static bool kfunc_has_cb_pad(u32 btf_id)
+{
+	return false;
+}
+
+static bool insn_has_cb_pad(struct bpf_insn *insn)
+{
+	return (bpf_helper_call(insn) && helper_has_cb_pad(insn->imm)) ||
+	       (bpf_pseudo_kfunc_call(insn) && kfunc_has_cb_pad(insn->imm));
+}
+
+/*
+ * A sync callback is called by a helper or a kfunc, a C frame between the
+ * callback and the BPF code that called it. unwind_exit of the callback returns
+ * to the pad of its caller when there is one, and a helper or a kfunc that
+ * calls a callback has one where BPF_HAS_CB_PADS and insn_has_cb_pad(): it
+ * calls the callback with bpf_call_cb(), drops what it holds when the callback
+ * unwinds and leaves to the pad of its own caller with the r0 of the callback.
+ * So a call with such a callback that can unwind is a call of something that
+ * can unwind, and unwind_goto has to follow it.
+ *
+ * A callback has no unwind_exit and unwinds all the same when it is recursive
+ * and unwind_goto follows every call of it that mark_recursive_subprogs() saw:
+ * its check of the recursion leaves with unwind_exit then, see
+ * check_recursion_guard(). The call of a helper that got the callback from a
+ * table of functions is not one of those calls. It is known here.
+ */
+static int check_cb_unwind(struct bpf_verifier_env *env, struct bpf_insn *insn,
+			   int insn_idx, int subprog)
+{
+	if (!bpf_subprog_unwinds(&env->subprog_info[subprog]))
+		return 0;
+	if (!bpf_is_unwind_goto(insn + 1)) {
+		if (bpf_helper_call(insn))
+			verbose(env, "no unwind_goto after the call of %s()\n",
+				func_id_name(insn->imm));
+		else
+			verbose(env, "no unwind_goto after the call of the kfunc at insn %d\n",
+				insn_idx);
+		return -EINVAL;
+	}
+	/* The helpers have unwind labels only with asm goto outputs, see bpf_call_cb(). */
+	if (!BPF_HAS_CB_PADS) {
+		verbose(env, "callback cannot unwind: the helpers have no pads\n");
+		return -ENOTSUPP;
+	}
+	if (!insn_has_cb_pad(insn)) {
+		verbose(env, "callback cannot unwind\n");
+		return -EINVAL;
+	}
+	return 0;
+}
+
 static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
 			      int insn_idx, int subprog,
 			      set_callee_state_fn set_callee_state_cb)
@@ -11457,6 +11522,11 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *ins
 	int err;
 
 	caller = state->frame[state->curframe];
+	/* The callback unwound. This second visit only applies the effects of the helper. */
+	if (state->unwound) {
+		leave_callback(caller);
+		return 0;
+	}
 	err = btf_check_subprog_call(env, subprog);
 	if (err == -EFAULT)
 		return err;
@@ -11527,6 +11597,10 @@ static int push_callback_call(struct bpf_verifier_env *env, struct bpf_insn *ins
 	else
 		env->subprog_info[subprog].is_other_cb = true;
 
+	err = check_cb_unwind(env, insn, insn_idx, subprog);
+	if (err)
+		return err;
+
 	/* for callback functions enqueue entry to callback and
 	 * proceed with next instruction within current frame.
 	 */
@@ -11685,10 +11759,10 @@ static int call_func_on_its_own(struct bpf_verifier_env *env, int subprog, int i
  * A void function can leave a pointer to the stack in r0. The caller cannot read it. That holds
  * for the stack of a caller too: for stack liveness a call returns no pointer to the stack.
  */
-static void hide_returned_stack_ptrs(struct bpf_verifier_env *env, int subprog,
+static void hide_returned_stack_ptrs(struct bpf_verifier_env *env, u32 nregs,
 				     struct bpf_reg_state *regs)
 {
-	u32 i, nregs = bpf_ret_reg_pair(env, subprog) ? 2 : 1;
+	u32 i;
 
 	for (i = 0; i < nregs; i++) {
 		if (regs[ret_regs[i]].type != PTR_TO_STACK)
@@ -11706,7 +11780,8 @@ static int exit_func_on_its_own(struct bpf_verifier_env *env)
 	struct bpf_func_state *callee = state->frame[0];
 	int err;
 
-	hide_returned_stack_ptrs(env, callee->subprogno, callee->regs);
+	hide_returned_stack_ptrs(env, bpf_ret_reg_pair(env, callee->subprogno) ? 2 : 1,
+				 callee->regs);
 	state->unwound |= bpf_is_unwind_exit(&env->prog->insnsi[env->insn_idx]);
 
 	/* Invalidate callee-local dynptrs and their slices before the frame goes away. */
@@ -12463,20 +12538,30 @@ static int prepare_func_exit(struct bpf_verifier_env *env, int *insn_idx)
 	struct bpf_verifier_state *state = env->cur_state;
 	struct bpf_func_state *caller, *callee;
 	struct bpf_reg_state *r0;
+	bool unwinds;
 	u32 i, nregs;
 	int err;
 
 	callee = state->frame[state->curframe];
 	r0 = &callee->regs[BPF_REG_0];
-	nregs = bpf_ret_reg_pair(env, callee->subprogno) ? 2 : 1;
+	/*
+	 * A callback passes on R0 alone, whatever its prototype says, both when it returns to
+	 * the helper and when it unwinds through the unwind label of the helper. R2 stays the
+	 * caller's, because the second visit of the call reads the arguments.
+	 */
+	nregs = !callee->in_callback_fn && bpf_ret_reg_pair(env, callee->subprogno) ? 2 : 1;
 
 	caller = state->frame[state->curframe - 1];
-	if (bpf_is_unwind_exit(&env->prog->insnsi[*insn_idx]) || state->unwound) {
-		/* the helper or the kfunc that called it doesn't expect that */
-		if (callee->in_callback_fn) {
-			verbose(env, "callback cannot unwind\n");
-			return -EINVAL;
-		}
+	unwinds = bpf_is_unwind_exit(&env->prog->insnsi[*insn_idx]) || state->unwound;
+	if (unwinds) {
+		/*
+		 * A callback returns into the helper that called it, and to the
+		 * pad of the helper when the helper has one. check_cb_unwind()
+		 * has seen to that, and to the unwind_goto after the call of
+		 * the helper, where the helper leaves to right away, with the
+		 * r0 of the callback as it is: the pad gets its state, as the
+		 * pad after a subprog call does.
+		 */
 		if (!bpf_is_unwind_goto(&env->prog->insnsi[callee->callsite + 1])) {
 			verbose(env, "unwind_exit, but no unwind_goto after the call at insn %d\n",
 				callee->callsite);
@@ -12484,7 +12569,7 @@ static int prepare_func_exit(struct bpf_verifier_env *env, int *insn_idx)
 		}
 		state->unwound = true;
 	}
-	if (callee->in_callback_fn) {
+	if (callee->in_callback_fn && !unwinds) {
 		/* the helper continues after the barrier of its call */
 		if (state->speculative)
 			return -EACCES;
@@ -12527,7 +12612,7 @@ static int prepare_func_exit(struct bpf_verifier_env *env, int *insn_idx)
 			caller->regs[regno] = callee->regs[regno];
 			bpf_diag_mod_end(env);
 		}
-		hide_returned_stack_ptrs(env, callee->subprogno, caller->regs);
+		hide_returned_stack_ptrs(env, nregs, caller->regs);
 	}
 
 	/* Invalidate callee-local dynptrs and their slices before the frame goes away. */
@@ -12545,6 +12630,11 @@ static int prepare_func_exit(struct bpf_verifier_env *env, int *insn_idx)
 	/* for callbacks like bpf_loop or bpf_for_each_map_elem go back to callsite,
 	 * there function call logic would reschedule callback visit.
 	 */
+	/*
+	 * A callback that unwound goes back to the call too, because the helper has effects of
+	 * its own, such as releasing what it consumed. For a state that is marked unwound the
+	 * call starts no further iteration, and R0 stays what the callback unwound with.
+	 */
 	if (callee->in_callback_fn)
 		*insn_idx = callee->callsite;
 	else
@@ -13011,7 +13101,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
 	const struct bpf_func_proto *fn = NULL;
 	enum bpf_return_type ret_type;
 	enum bpf_type_flag ret_flag;
-	struct bpf_reg_state *regs;
+	struct bpf_reg_state *regs, unwound_r0;
 	struct bpf_call_arg_meta meta;
 	const char *operation;
 	int insn_idx = *insn_idx_p;
@@ -13261,12 +13351,20 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
 
 	/* reset caller saved regs */
 	bpf_diag_record_caller_saved(env, regs);
-	bpf_diag_mod_begin(env, &regs[BPF_REG_0], NULL, BPF_DIAG_MOD_WRITE);
+	/* The callback unwound: the helper leaves with the R0 of the callback, so keep R0. */
+	if (env->cur_state->unwound)
+		unwound_r0 = regs[BPF_REG_0];
+	else
+		bpf_diag_mod_begin(env, &regs[BPF_REG_0], NULL, BPF_DIAG_MOD_WRITE);
 	for (i = 0; i < CALLER_SAVED_REGS; i++) {
 		bpf_mark_reg_not_init(env, &regs[caller_saved[i]]);
 		check_reg_arg(env, caller_saved[i], DST_OP_NO_MARK);
 	}
 	invalidate_outgoing_stack_args(env, cur_func(env));
+	if (env->cur_state->unwound) {
+		regs[BPF_REG_0] = unwound_r0;
+		goto unwound;
+	}
 
 	/* update return register (already marked as written above) */
 	ret_type = fn->ret_type;
@@ -13453,7 +13551,7 @@ static int check_helper_call(struct bpf_verifier_env *env, struct bpf_insn *insn
 		return err;
 
 	bpf_diag_mod_end(env);
-
+unwound:
 	err = check_map_func_compatibility(env, meta.map.ptr, func_id);
 	if (err)
 		return err;
@@ -15827,7 +15925,7 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
 {
 	bool sleepable, rcu_lock, rcu_unlock, preempt_disable, preempt_enable;
 	enum bpf_prog_type prog_type = resolve_prog_type(env->prog);
-	struct bpf_reg_state *regs = cur_regs(env);
+	struct bpf_reg_state *regs = cur_regs(env), unwound_r0;
 	const char *func_name, *ptr_type_name;
 	const struct btf_type *t, *ptr_type;
 	struct bpf_call_arg_meta meta;
@@ -16116,13 +16214,23 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
 	}
 
 	bpf_diag_record_caller_saved(env, regs);
-	bpf_diag_mod_begin(env, &regs[BPF_REG_0], NULL, BPF_DIAG_MOD_WRITE);
+	/* The callback unwound: keep its R0, see check_helper_call(). */
+	if (env->cur_state->unwound) {
+		unwound_r0 = regs[BPF_REG_0];
+		ret_nregs = 0;
+	} else {
+		bpf_diag_mod_begin(env, &regs[BPF_REG_0], NULL, BPF_DIAG_MOD_WRITE);
+	}
 	for (i = 0; i < CALLER_SAVED_REGS; i++) {
 		u32 regno = caller_saved[i];
 
 		bpf_mark_reg_not_init(env, &regs[regno]);
 	}
 	invalidate_outgoing_stack_args(env, cur_func(env));
+	if (env->cur_state->unwound) {
+		regs[BPF_REG_0] = unwound_r0;
+		goto unwound;
+	}
 
 	/* Check return type */
 	t = btf_type_skip_modifiers(desc_btf, meta.func_proto->type, NULL);
@@ -16316,6 +16424,7 @@ static int check_kfunc_call(struct bpf_verifier_env *env, struct bpf_insn *insn,
 		}
 	}
 
+unwound:
 	if (is_kfunc_dynptr_write(&meta) ?
 	    dynptr_write_changes_pkt_data(meta.dynptr_write_type) :
 	    bpf_is_kfunc_pkt_changing(&meta))
diff --git a/tools/include/uapi/linux/bpf.h b/tools/include/uapi/linux/bpf.h
index 28904c6f0787..95b41ae6584d 100644
--- a/tools/include/uapi/linux/bpf.h
+++ b/tools/include/uapi/linux/bpf.h
@@ -63,7 +63,8 @@ enum bpf_mul_variant {
 enum bpf_cond_pseudo_jmp {
 	BPF_MAY_GOTO = 0,
 	/*
-	 * Follows a call of a bpf subprog. Taken when the subprog left with
+	 * Follows a call of a bpf subprog, callx, or a call of a helper or kfunc
+	 * that calls a callback. Taken when the subprog or the callback left with
 	 * BPF_EXIT that has src_reg == BPF_UNWIND_EXIT.
 	 */
 	BPF_UNWIND_GOTO = 1,
diff --git a/tools/testing/selftests/bpf/progs/verifier_unwind.c b/tools/testing/selftests/bpf/progs/verifier_unwind.c
index be3992ed8eed..6fd8e56485ed 100644
--- a/tools/testing/selftests/bpf/progs/verifier_unwind.c
+++ b/tools/testing/selftests/bpf/progs/verifier_unwind.c
@@ -929,7 +929,7 @@ __description("unwind: callback unwinds")
 __arch_x86_64
 __arch_arm64
 __load_if_JITed()
-__failure __msg("callback cannot unwind")
+__failure __msg("no unwind_goto after the call of bpf_loop()")
 __naked int callback_unwinds(void)
 {
 	asm volatile (
-- 
2.53.1-Meta


  parent reply	other threads:[~2026-12-01  4:40 UTC|newest]

Thread overview: 74+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-01  4:38 [PATCH bpf-next v1 00/73] Cancellations Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 01/73] bpf: Refuse a program that is too large for bpf_prog->pages Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 02/73] bpf: Require CAP_PERFMON for unwind_exit and unwind_goto Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 03/73] bpf: Reject bpf_percpu_obj_drop() of a type with special fields Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 04/73] bpf: Drop the edge after bpf_throw() from the control flow graph Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 05/73] bpf: Let a helper call its callback with an unwind label Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 06/73] bpf, x86, arm64: Add landings that redo what follows a helper call Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` Kumar Kartikeya Dwivedi [this message]
2026-12-01  4:38 ` [PATCH bpf-next v1 08/73] bpf: Let the inlined bpf_loop pass on a callback that unwinds Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 09/73] bpf: Give the helpers that call a callback an unwind label Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 10/73] bpf: Let the comparator of bpf_rbtree_add unwind Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 11/73] bpf: Let a state leave its frame at may_goto without an exit insn Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 12/73] bpf: Choose what a cancelled program returns by its type Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 13/73] bpf: Emit landing pads that leave RCU sections Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 14/73] bpf: Release locks and irq flags in landing pads Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 15/73] bpf: Add unwind_goto after calls of subprogs Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 16/73] bpf: Let the kernel cancel a program in a global subprog Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 17/73] bpf: Release references in landing pads Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 18/73] bpf: Release iterators and dynptrs " Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 19/73] bpf: Check pointers for NULL " Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 20/73] bpf: Let the kernel cancel a frame that holds references Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 21/73] bpf: Add unwind_goto after helpers with a callback Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 22/73] bpf: Let a may_goto that the verifier adds go to its landing pad only Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 23/73] bpf: Record why a callee is cancelled when its call gets no landing pad Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 24/73] bpf: Record what each call acquires and releases Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 25/73] bpf: Add hidden stack slots for landing pads Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 26/73] bpf: Use hidden slots for a pointer that has no location at a site Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 27/73] bpf: Restore the sections of the call when a frame is cancelled Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 28/73] bpf: Let hidden slots follow what a subprog does for its caller Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 29/73] bpf: Let a callee hold a reference that its call hands over Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 30/73] bpf: Let a call clear the hidden slot of what its callee releases Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 31/73] bpf: Give a callee a hidden slot for the reference that it is handed Kumar Kartikeya Dwivedi
2026-12-01  4:38 ` [PATCH bpf-next v1 32/73] bpf: Give unwind_goto a 32 bit offset and prepare it for arena accesses Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 33/73] bpf, x86: Go to the landing pad when an access to arena faults Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 34/73] bpf, arm64: " Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 35/73] bpf: Let a register be the location of a lock in a global variable Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 36/73] bpf: Cancel a program at a fault in arena Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 37/73] bpf: Share one landing pad among accesses to arena where nothing is held Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 38/73] bpf: Keep R0, R6-R9 and the stack live at a call of bpf_throw() Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 39/73] bpf: Refuse freplace on a function that can unwind Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 40/73] bpf: Let landing pads pass on the value of unwind_exit Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 41/73] bpf: Keep a reference of the caller that a function finds NULL Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 42/73] bpf: Make bpf_throw() cancel the program through landing pads Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 43/73] bpf, x86: Remove the exception boundary Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 44/73] bpf, arm64: " Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 45/73] s390/bpf: " Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 46/73] powerpc64/bpf: " Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 47/73] bpf: Remove the stack walk of bpf_throw() Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 48/73] bpf: Find at a site that a frame holds more than a landing pad releases Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 49/73] bpf: Cancel the program when the time of its own may_goto is up Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 50/73] bpf: Reject a program that has no landing pad for a fault in arena Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 51/73] bpf: Log why a call is a site and which functions cannot be cancelled Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 52/73] bpf: Add cancel_goto and cancel_exit, which only the verifier emits Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 53/73] bpf: Give the unwind label of a helper a second way in Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 54/73] bpf, x86: Put the landing of unwind_goto after the function Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 55/73] bpf, x86: Return to cancel_goto at cancel_exit Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 56/73] bpf, arm64: " Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 57/73] bpf: Use cancel_exit to leave a frame that the kernel cancels Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 58/73] bpf: Check that a helper whose callback may unwind has an unwind label Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 59/73] bpf: Find the landing pads of a program that can only clean up Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 60/73] bpf: Don't let hidden stack words turn on the private stack Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 61/73] bpf: Add a landing pad per site for frames that are cancelled already Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 62/73] bpf: Verify a cleanup pad for a frame that is cancelled Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 63/73] bpf: Reject a program whose cleanup pad a cancellation cannot enter Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 64/73] bpf: Find the code that a cleanup pad can reach Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 65/73] bpf: Emit the stub, the entry and the remainder of a cleanup pad Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 66/73] bpf: Let the entry of a cleanup pad save the pointers of the frame Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 67/73] bpf: Run the cleanup pads of a program when the kernel cancels it Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 68/73] bpf: End the path at a call of a global subprog that never returns Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 69/73] bpf: Tell struct_ops when a program was cancelled Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 70/73] bpf: Tell struct_ops when cancel_exit returns to the kernel Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 71/73] bpf: Let a struct_ops say what a cancelled program returns Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 72/73] bpf: Give cancelled tcp_congestion_ops programs values that TCP can take Kumar Kartikeya Dwivedi
2026-12-01  4:39 ` [PATCH bpf-next v1 73/73] sched_ext: Treat a cancelled program as a scheduler error Kumar Kartikeya Dwivedi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=e041104e5829b2f0b9d8dff4cd117b1667c19dca.1796099737.git.memxor@gmail.com \
    --to=memxor@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=eddyz87@gmail.com \
    --cc=emil@etsalapatis.com \
    --cc=ihor.solodrai@linux.dev \
    --cc=kernel-team@meta.com \
    --cc=kkd@meta.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox