Skip to content

Commit c53795d

Browse files
Yan Zhaidavem330
authored andcommitted
net: add rx_sk to trace_kfree_skb
skb does not include enough information to find out receiving sockets/services and netns/containers on packet drops. In theory skb->dev tells about netns, but it can get cleared/reused, e.g. by TCP stack for OOO packet lookup. Similarly, skb->sk often identifies a local sender, and tells nothing about a receiver. Allow passing an extra receiving socket to the tracepoint to improve the visibility on receiving drops. Signed-off-by: Yan Zhai <[email protected]> Acked-by: Jesper Dangaard Brouer <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6f46fc9 commit c53795d

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

include/trace/events/skb.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,29 @@ DEFINE_DROP_REASON(FN, FN)
2424
TRACE_EVENT(kfree_skb,
2525

2626
TP_PROTO(struct sk_buff *skb, void *location,
27-
enum skb_drop_reason reason),
27+
enum skb_drop_reason reason, struct sock *rx_sk),
2828

29-
TP_ARGS(skb, location, reason),
29+
TP_ARGS(skb, location, reason, rx_sk),
3030

3131
TP_STRUCT__entry(
3232
__field(void *, skbaddr)
3333
__field(void *, location)
34+
__field(void *, rx_sk)
3435
__field(unsigned short, protocol)
3536
__field(enum skb_drop_reason, reason)
3637
),
3738

3839
TP_fast_assign(
3940
__entry->skbaddr = skb;
4041
__entry->location = location;
42+
__entry->rx_sk = rx_sk;
4143
__entry->protocol = ntohs(skb->protocol);
4244
__entry->reason = reason;
4345
),
4446

45-
TP_printk("skbaddr=%p protocol=%u location=%pS reason: %s",
46-
__entry->skbaddr, __entry->protocol, __entry->location,
47+
TP_printk("skbaddr=%p rx_sk=%p protocol=%u location=%pS reason: %s",
48+
__entry->skbaddr, __entry->rx_sk, __entry->protocol,
49+
__entry->location,
4750
__print_symbolic(__entry->reason,
4851
DEFINE_DROP_REASON(FN, FNe)))
4952
);

net/core/dev.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5234,7 +5234,7 @@ static __latent_entropy void net_tx_action(struct softirq_action *h)
52345234
trace_consume_skb(skb, net_tx_action);
52355235
else
52365236
trace_kfree_skb(skb, net_tx_action,
5237-
get_kfree_skb_cb(skb)->reason);
5237+
get_kfree_skb_cb(skb)->reason, NULL);
52385238

52395239
if (skb->fclone != SKB_FCLONE_UNAVAILABLE)
52405240
__kfree_skb(skb);

net/core/drop_monitor.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ static u32 net_dm_queue_len = 1000;
109109
struct net_dm_alert_ops {
110110
void (*kfree_skb_probe)(void *ignore, struct sk_buff *skb,
111111
void *location,
112-
enum skb_drop_reason reason);
112+
enum skb_drop_reason reason,
113+
struct sock *rx_sk);
113114
void (*napi_poll_probe)(void *ignore, struct napi_struct *napi,
114115
int work, int budget);
115116
void (*work_item_func)(struct work_struct *work);
@@ -264,7 +265,8 @@ static void trace_drop_common(struct sk_buff *skb, void *location)
264265

265266
static void trace_kfree_skb_hit(void *ignore, struct sk_buff *skb,
266267
void *location,
267-
enum skb_drop_reason reason)
268+
enum skb_drop_reason reason,
269+
struct sock *rx_sk)
268270
{
269271
trace_drop_common(skb, location);
270272
}
@@ -491,7 +493,8 @@ static const struct net_dm_alert_ops net_dm_alert_summary_ops = {
491493
static void net_dm_packet_trace_kfree_skb_hit(void *ignore,
492494
struct sk_buff *skb,
493495
void *location,
494-
enum skb_drop_reason reason)
496+
enum skb_drop_reason reason,
497+
struct sock *rx_sk)
495498
{
496499
ktime_t tstamp = ktime_get_real();
497500
struct per_cpu_dm_data *data;

net/core/skbuff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1203,7 +1203,7 @@ bool __kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
12031203
if (reason == SKB_CONSUMED)
12041204
trace_consume_skb(skb, __builtin_return_address(0));
12051205
else
1206-
trace_kfree_skb(skb, __builtin_return_address(0), reason);
1206+
trace_kfree_skb(skb, __builtin_return_address(0), reason, NULL);
12071207
return true;
12081208
}
12091209

0 commit comments

Comments
 (0)