Skip to contentSkip to conversation

packet: uses kfree_skb() for drop.

PATCH In review Weongyo Jeong 2 participants 3 messages Apr 6, 2016

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

PATCH 1/1 packet: uses kfree_skb() for drop.

consume_skb() isn't for drop or error cases. kfree_skb() is more proper one.

---
 net/packet/af_packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/packet/af_packet.c +1 -1
index 1ecfa71..a75d5bf 100644
@@ -2141,7 +2141,7 @@ drop_n_restore:
 		skb->len = skb_len;
 	}
 drop:
-	consume_skb(skb);
+	kfree_skb(skb);
 	return 0;
 }
 
Signature · 1 line
2.1.3
maintainer
#1 lore raw
Quoted 12 lines · Weongyo Jeong

consume_skb() isn't for drop or error cases. kfree_skb() is more proper one.

---
 net/packet/af_packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/packet/af_packet.c +0 -0
index 1ecfa71..a75d5bf 100644

net/packet/af_packet.c drop_n_restore: · line 2144

Quoted 5 lines
net/packet/af_packet.c +1 -1
@@ -2141,7 +2141,7 @@ drop_n_restore:
                skb->len = skb_len;
        }
 drop:
-       consume_skb(skb);
+       kfree_skb(skb);

This does show an inconsistency between packet_rcv and tpacket_rcv, which calls kfree_skb.

A comment at consume_skb mentions that kfree_skb is intended for drops that signal a failure condition, and indeed, that makes it a useful way to track errors (e.g., with perf record -a -g -e skb:kfree_skb).

This drop path is not always an error path, though. These network taps will legitimately drop references to any packets not destined to them. To be precise, only the drop_n_acct label cases are delivery errors (drops after the filter accepted the packet). Changing unconditionally to kfree_skb does pollute that useful counter with false positives. A pedantic solution is to change both functions to only call kfree_skb on drop_n_acct and consume_skb otherwise.

This shorthand change does at least makes packet_rcv and tpacket_rcv more alike.

#2 lore raw
Quoted 34 lines · Willem de Bruijn
Quoted 12 lines · Weongyo Jeong

consume_skb() isn't for drop or error cases. kfree_skb() is more proper one.

---
 net/packet/af_packet.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/packet/af_packet.c +0 -0
index 1ecfa71..a75d5bf 100644

net/packet/af_packet.c drop_n_restore: · line 2144

Quoted 5 lines
net/packet/af_packet.c +1 -1
@@ -2141,7 +2141,7 @@ drop_n_restore:
                skb->len = skb_len;
        }
 drop:
-       consume_skb(skb);
+       kfree_skb(skb);

This does show an inconsistency between packet_rcv and tpacket_rcv, which calls kfree_skb.

A comment at consume_skb mentions that kfree_skb is intended for drops that signal a failure condition, and indeed, that makes it a useful way to track errors (e.g., with perf record -a -g -e skb:kfree_skb).

This drop path is not always an error path, though. These network taps will legitimately drop references to any packets not destined to them. To be precise, only the drop_n_acct label cases are delivery errors (drops after the filter accepted the packet). Changing unconditionally to kfree_skb does pollute that useful counter with false positives. A pedantic solution is to change both functions to only call kfree_skb on drop_n_acct and consume_skb otherwise.

Quoted 1 line

This shorthand change does at least makes packet_rcv and tpacket_rcv more alike.

Thank you for comments. I'll try to submit patch v2 for this case.

Regards,
Weongyo Jeong