Skip to contentSkip to conversation

net: fix __dev_kfree_skb_any() vs drop monitor

PATCH Applied Eric Dumazet 3 participants 3 messages Feb 23, 2023 – Feb 24, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: fix __dev_kfree_skb_any() vs drop monitor

dev_kfree_skb() is aliased to consume_skb().

When a driver is dropping a packet by calling dev_kfree_skb_any() we should propagate the drop reason instead of pretending the packet was consumed.

Note: Now we have enum skb_drop_reason we could remove enum skb_free_reason (for linux-6.4)

v2: added an unlikely(), suggested by Yunsheng Lin.

Fixes e6247027e517 ("net: introduce dev_consume_skb_any()")
Cc Yunsheng Lin <[email protected]>
---
 net/core/dev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/dev.c +3 -1
index 18dc8d75ead9795163ace74e8e86fe35cb9b7552..253584777101f2e6af3fc30107516f1e1197f8d3 100644
@@ -3134,8 +3134,10 @@ void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason)
 {
 	if (in_hardirq() || irqs_disabled())
 		__dev_kfree_skb_irq(skb, reason);
+	else if (unlikely(reason == SKB_REASON_DROPPED))
+		kfree_skb(skb);
 	else
-		dev_kfree_skb(skb);
+		consume_skb(skb);
 }
 EXPORT_SYMBOL(__dev_kfree_skb_any);
 
Signature · 1 line
2.39.2.637.g21b0678d19-goog
Reviewed-by on v2 1/1
#1 lore raw
Quoted 8 lines · Eric Dumazet

dev_kfree_skb() is aliased to consume_skb().

When a driver is dropping a packet by calling dev_kfree_skb_any() we should propagate the drop reason instead of pretending the packet was consumed.

Note: Now we have enum skb_drop_reason we could remove enum skb_free_reason (for linux-6.4)

LGTM.

Quoted 27 lines

v2: added an unlikely(), suggested by Yunsheng Lin.

Fixes e6247027e517 ("net: introduce dev_consume_skb_any()")
Cc Yunsheng Lin <[email protected]>
---
 net/core/dev.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/core/dev.c +3 -1
index 18dc8d75ead9795163ace74e8e86fe35cb9b7552..253584777101f2e6af3fc30107516f1e1197f8d3 100644
@@ -3134,8 +3134,10 @@ void __dev_kfree_skb_any(struct sk_buff *skb, enum skb_free_reason reason)
 {
 	if (in_hardirq() || irqs_disabled())
 		__dev_kfree_skb_irq(skb, reason);
+	else if (unlikely(reason == SKB_REASON_DROPPED))
+		kfree_skb(skb);
 	else
-		dev_kfree_skb(skb);
+		consume_skb(skb);
 }
 EXPORT_SYMBOL(__dev_kfree_skb_any);
 
maintainer Applied
#2 lore raw
In reply to Eric Dumazet
Quoted 10 lines · On Thu, 23 Feb 2023 08:38:45 +0000 Eric Dumazet wrote:

dev_kfree_skb() is aliased to consume_skb().

When a driver is dropping a packet by calling dev_kfree_skb_any() we should propagate the drop reason instead of pretending the packet was consumed.

Note: Now we have enum skb_drop_reason we could remove enum skb_free_reason (for linux-6.4)

v2: added an unlikely(), suggested by Yunsheng Lin.

Applied, thanks!