From: Alexei Starovoitov 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 [ memxor: Name two places where the destructor runs with irqs off, bpf_list_add() and bpf_local_storage_map_free(). ] Signed-off-by: Kumar Kartikeya Dwivedi --- 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