BPF List
 help / color / mirror / Atom feed
* [PATCH bpf v2] bpf: net_sched: Let bpf_kfree_skb() run with irqs off
@ 2026-11-23 19:58 Kumar Kartikeya Dwivedi
  2026-11-23 20:16 ` sashiko-bot
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kumar Kartikeya Dwivedi @ 2026-11-23 19:58 UTC (permalink / raw)
  To: bpf
  Cc: Alexei Starovoitov, Andrii Nakryiko, Daniel Borkmann,
	Eduard Zingerman, Emil Tsalapatis, Ihor Solodrai, kkd,
	kernel-team

From: Alexei Starovoitov <ast@kernel.org>

bpf_kfree_skb() is also the destructor of an skb kptr. A destructor runs
wherever an object or a map value with such a field is freed. That can be
with irqs off, for example:

 - bpf_list_add() drops the new node when @prev is not in the list, while
   the program holds the bpf_spin_lock of the list, which keeps irqs off.
   The drop frees a node that has no other reference, with its fields.

 - bpf_local_storage_map_free() frees the fields of each value under the
   lock of its bucket, which bpf_selem_unlink_nofail() takes with
   raw_res_spin_lock_irqsave(). A qdisc program can keep an skb in task
   storage.

Currently bpf_kfree_skb() calls kfree_skb(), which is not made for that.
The destructor of the skb may enable softirqs, or take a lock that sleeps
on PREEMPT_RT.

Use dev_kfree_skb_any(). With irqs on it is kfree_skb(). With irqs off the
skb goes to the completion queue of the cpu, and NET_TX_SOFTIRQ frees it.

Fixes: 870c28588afa ("bpf: net_sched: Add basic bpf qdisc kfuncs")
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com>
---
 net/sched/bpf_qdisc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/sched/bpf_qdisc.c b/net/sched/bpf_qdisc.c
index 5691c13781a8..e041383a848f 100644
--- a/net/sched/bpf_qdisc.c
+++ b/net/sched/bpf_qdisc.c
@@ -196,10 +196,13 @@ __bpf_kfunc u32 bpf_skb_get_hash(struct sk_buff *skb)
 
 /* bpf_kfree_skb - Release an skb's reference and drop it immediately.
  * @skb: The skb whose reference to be released and dropped.
+ *
+ * Also the destructor of an skb kptr, which runs wherever an object or a map
+ * value with such a field is freed: under a bpf_spin_lock too, with irqs off.
  */
 __bpf_kfunc void bpf_kfree_skb(struct sk_buff *skb)
 {
-	kfree_skb(skb);
+	dev_kfree_skb_any(skb);
 }
 
 __bpf_kfunc void bpf_kfree_skb_dtor(void *skb)

base-commit: 84afebd853437e44cb71f718be11d90e4c1a59dd
-- 
2.53.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-11-24  6:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-23 19:58 [PATCH bpf v2] bpf: net_sched: Let bpf_kfree_skb() run with irqs off Kumar Kartikeya Dwivedi
2026-11-23 20:16 ` sashiko-bot
2026-11-23 20:33 ` bot+bpf-ci
2026-11-24  6:32 ` Alexei Starovoitov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox