Skip to contentSkip to conversation

udp: do not use skb_release_head_state() before skb_attempt_defer_free()

PATCH Superseded Eric Dumazet 1 participant 1 message Oct 14, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 udp: do not use skb_release_head_state() before skb_attempt_defer_free()

Michal reported and bisected an issue after recent adoption of skb_attempt_defer_free() in UDP.

The issue here is that skb_release_head_state() is called twice per skb, one time from skb_consume_udp(), then a second time from skb_defer_free_flush() and napi_consume_skb().

As Sabrina suggested, remove skb_release_head_state() call from skb_consume_udp() before calling skb_attempt_defer_free().

Add three DEBUG_NET_WARN_ON_ONCE() to check that dst, destructor and skb_nfct() are not set at this point.

Many thanks to Michal, Sabrina and Paolo for their help.

---
v2: Adopted Sabrina suggestion.
v1: https://lore.kernel.org/netdev/aO3_hBg5expKNv6v@krikkit/T/#m8a88669b801d85f57b73710cdb0c8ee63854af11

 net/ipv4/udp.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
net/ipv4/udp.c +7 -2
index 95241093b7f0..d66f273f9070 100644
@@ -1851,8 +1851,13 @@ void skb_consume_udp(struct sock *sk, struct sk_buff *skb, int len)
 		sk_peek_offset_bwd(sk, len);
 
 	if (!skb_shared(skb)) {
-		if (unlikely(udp_skb_has_head_state(skb)))
-			skb_release_head_state(skb);
+		/* Make sure that this skb has no dst, destructor
+		 * or conntracking parts, because it might stay
+		 * in a remote cpu list for a very long time.
+		 */
+		DEBUG_NET_WARN_ON_ONCE(skb_dst(skb));
+		DEBUG_NET_WARN_ON_ONCE(skb->destructor);
+		DEBUG_NET_WARN_ON_ONCE(skb_nfct(skb));
 		skb_attempt_defer_free(skb);
 		return;
 	}
Signature · 1 line
2.51.0.788.g6d19910ace-goog