Skip to content

Commit a8e32bb

Browse files
committed
net: introduce sk_skb_reason_drop function
JIRA: https://issues.redhat.com/browse/RHEL-48648 Upstream Status: net-next.git Conflicts:\ - Context difference due to missing upstream commit 1cface5 ("net: add skb_data_unref() helper") in c9s. commit ba8de79 Author: Yan Zhai <yan@cloudflare.com> Date: Mon Jun 17 11:09:09 2024 -0700 net: introduce sk_skb_reason_drop function Long used destructors kfree_skb and kfree_skb_reason do not pass receiving socket to packet drop tracepoints trace_kfree_skb. This makes it hard to track packet drops of a certain netns (container) or a socket (user application). The naming of these destructors are also not consistent with most sk/skb operating functions, i.e. functions named "sk_xxx" or "skb_xxx". Introduce a new functions sk_skb_reason_drop as drop-in replacement for kfree_skb_reason on local receiving path. Callers can now pass receiving sockets to the tracepoints. kfree_skb and kfree_skb_reason are still usable but they are now just inline helpers that call sk_skb_reason_drop. Note it is not feasible to do the same to consume_skb. Packets not dropped can flow through multiple receive handlers, and have multiple receiving sockets. Leave it untouched for now. Suggested-by: Eric Dumazet <edumazet@google.com> Signed-off-by: Yan Zhai <yan@cloudflare.com> Acked-by: Jesper Dangaard Brouer <hawk@kernel.org> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Antoine Tenart <atenart@redhat.com>
1 parent 283c6d9 commit a8e32bb

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

include/linux/skbuff.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,8 +1159,14 @@ static inline bool skb_unref(struct sk_buff *skb)
11591159
return true;
11601160
}
11611161

1162-
void __fix_address
1163-
kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason);
1162+
void __fix_address sk_skb_reason_drop(struct sock *sk, struct sk_buff *skb,
1163+
enum skb_drop_reason reason);
1164+
1165+
static inline void
1166+
kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
1167+
{
1168+
sk_skb_reason_drop(NULL, skb, reason);
1169+
}
11641170

11651171
/**
11661172
* kfree_skb - free an sk_buff with 'NOT_SPECIFIED' reason

net/core/skbuff.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,8 @@ void __kfree_skb(struct sk_buff *skb)
10311031
EXPORT_SYMBOL(__kfree_skb);
10321032

10331033
static __always_inline
1034-
bool __kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
1034+
bool __sk_skb_reason_drop(struct sock *sk, struct sk_buff *skb,
1035+
enum skb_drop_reason reason)
10351036
{
10361037
if (unlikely(!skb_unref(skb)))
10371038
return false;
@@ -1044,26 +1045,27 @@ bool __kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
10441045
if (reason == SKB_CONSUMED)
10451046
trace_consume_skb(skb, __builtin_return_address(0));
10461047
else
1047-
trace_kfree_skb(skb, __builtin_return_address(0), reason, NULL);
1048+
trace_kfree_skb(skb, __builtin_return_address(0), reason, sk);
10481049
return true;
10491050
}
10501051

10511052
/**
1052-
* kfree_skb_reason - free an sk_buff with special reason
1053+
* sk_skb_reason_drop - free an sk_buff with special reason
1054+
* @sk: the socket to receive @skb, or NULL if not applicable
10531055
* @skb: buffer to free
10541056
* @reason: reason why this skb is dropped
10551057
*
1056-
* Drop a reference to the buffer and free it if the usage count has
1057-
* hit zero. Meanwhile, pass the drop reason to 'kfree_skb'
1058-
* tracepoint.
1058+
* Drop a reference to the buffer and free it if the usage count has hit
1059+
* zero. Meanwhile, pass the receiving socket and drop reason to
1060+
* 'kfree_skb' tracepoint.
10591061
*/
10601062
void __fix_address
1061-
kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
1063+
sk_skb_reason_drop(struct sock *sk, struct sk_buff *skb, enum skb_drop_reason reason)
10621064
{
1063-
if (__kfree_skb_reason(skb, reason))
1065+
if (__sk_skb_reason_drop(sk, skb, reason))
10641066
__kfree_skb(skb);
10651067
}
1066-
EXPORT_SYMBOL(kfree_skb_reason);
1068+
EXPORT_SYMBOL(sk_skb_reason_drop);
10671069

10681070
#define KFREE_SKB_BULK_SIZE 16
10691071

@@ -1102,7 +1104,7 @@ kfree_skb_list_reason(struct sk_buff *segs, enum skb_drop_reason reason)
11021104
while (segs) {
11031105
struct sk_buff *next = segs->next;
11041106

1105-
if (__kfree_skb_reason(segs, reason)) {
1107+
if (__sk_skb_reason_drop(NULL, segs, reason)) {
11061108
skb_poison_list(segs);
11071109
kfree_skb_add_bulk(segs, &sa, reason);
11081110
}

0 commit comments

Comments
 (0)