Skip to content

Commit 6af3b42

Browse files
committed
Merge branch 'skb-drop-reasons'
Menglong Dong says: ==================== net: dev: add skb drop reasons to net/core/dev.c In the commit c504e5c ("net: skb: introduce kfree_skb_reason()"), we added the support of reporting the reasons of skb drops to kfree_skb tracepoint. And in this series patches, reasons for skb drops are added to the link layer, which means that 'net/core/dev.c' is our target. Following functions are processed: sch_handle_egress() __dev_xmit_skb() enqueue_to_backlog() do_xdp_generic() sch_handle_ingress() __netif_receive_skb_core() and following new drop reasons are added (what they mean can be see in the document of them): SKB_DROP_REASON_QDISC_EGRESS SKB_DROP_REASON_QDISC_DROP SKB_DROP_REASON_CPU_BACKLOG SKB_DROP_REASON_XDP SKB_DROP_REASON_QDISC_INGRESS SKB_DROP_REASON_PTYPE_ABSENT In order to add skb drop reasons to kfree_skb_list(), the function kfree_skb_list_reason() is introduced in the 2th patch, which will be used in __dev_xmit_skb() in the 3th patch. ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents 9f9919f + 6c2728b commit 6af3b42

File tree

4 files changed

+50
-13
lines changed

4 files changed

+50
-13
lines changed

include/linux/skbuff.h

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,24 @@ enum skb_drop_reason {
394394
* entry is full
395395
*/
396396
SKB_DROP_REASON_NEIGH_DEAD, /* neigh entry is dead */
397+
SKB_DROP_REASON_TC_EGRESS, /* dropped in TC egress HOOK */
398+
SKB_DROP_REASON_QDISC_DROP, /* dropped by qdisc when packet
399+
* outputting (failed to enqueue to
400+
* current qdisc)
401+
*/
402+
SKB_DROP_REASON_CPU_BACKLOG, /* failed to enqueue the skb to
403+
* the per CPU backlog queue. This
404+
* can be caused by backlog queue
405+
* full (see netdev_max_backlog in
406+
* net.rst) or RPS flow limit
407+
*/
408+
SKB_DROP_REASON_XDP, /* dropped by XDP in input path */
409+
SKB_DROP_REASON_TC_INGRESS, /* dropped in TC ingress HOOK */
410+
SKB_DROP_REASON_PTYPE_ABSENT, /* not packet_type found to handle
411+
* the skb. For an etner packet,
412+
* this means that L3 protocol is
413+
* not supported
414+
*/
397415
SKB_DROP_REASON_MAX,
398416
};
399417

@@ -1201,10 +1219,16 @@ static inline void kfree_skb(struct sk_buff *skb)
12011219
}
12021220

12031221
void skb_release_head_state(struct sk_buff *skb);
1204-
void kfree_skb_list(struct sk_buff *segs);
1222+
void kfree_skb_list_reason(struct sk_buff *segs,
1223+
enum skb_drop_reason reason);
12051224
void skb_dump(const char *level, const struct sk_buff *skb, bool full_pkt);
12061225
void skb_tx_error(struct sk_buff *skb);
12071226

1227+
static inline void kfree_skb_list(struct sk_buff *segs)
1228+
{
1229+
kfree_skb_list_reason(segs, SKB_DROP_REASON_NOT_SPECIFIED);
1230+
}
1231+
12081232
#ifdef CONFIG_TRACEPOINTS
12091233
void consume_skb(struct sk_buff *skb);
12101234
#else

include/trace/events/skb.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@
4545
EM(SKB_DROP_REASON_NEIGH_FAILED, NEIGH_FAILED) \
4646
EM(SKB_DROP_REASON_NEIGH_QUEUEFULL, NEIGH_QUEUEFULL) \
4747
EM(SKB_DROP_REASON_NEIGH_DEAD, NEIGH_DEAD) \
48+
EM(SKB_DROP_REASON_TC_EGRESS, TC_EGRESS) \
49+
EM(SKB_DROP_REASON_QDISC_DROP, QDISC_DROP) \
50+
EM(SKB_DROP_REASON_CPU_BACKLOG, CPU_BACKLOG) \
51+
EM(SKB_DROP_REASON_XDP, XDP) \
52+
EM(SKB_DROP_REASON_TC_INGRESS, TC_INGRESS) \
53+
EM(SKB_DROP_REASON_PTYPE_ABSENT, PTYPE_ABSENT) \
4854
EMe(SKB_DROP_REASON_MAX, MAX)
4955

5056
#undef EM

net/core/dev.c

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3759,7 +3759,8 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
37593759

37603760
no_lock_out:
37613761
if (unlikely(to_free))
3762-
kfree_skb_list(to_free);
3762+
kfree_skb_list_reason(to_free,
3763+
SKB_DROP_REASON_QDISC_DROP);
37633764
return rc;
37643765
}
37653766

@@ -3814,7 +3815,7 @@ static inline int __dev_xmit_skb(struct sk_buff *skb, struct Qdisc *q,
38143815
}
38153816
spin_unlock(root_lock);
38163817
if (unlikely(to_free))
3817-
kfree_skb_list(to_free);
3818+
kfree_skb_list_reason(to_free, SKB_DROP_REASON_QDISC_DROP);
38183819
if (unlikely(contended))
38193820
spin_unlock(&q->busylock);
38203821
return rc;
@@ -3889,7 +3890,7 @@ sch_handle_egress(struct sk_buff *skb, int *ret, struct net_device *dev)
38893890
case TC_ACT_SHOT:
38903891
mini_qdisc_qstats_cpu_drop(miniq);
38913892
*ret = NET_XMIT_DROP;
3892-
kfree_skb(skb);
3893+
kfree_skb_reason(skb, SKB_DROP_REASON_TC_EGRESS);
38933894
return NULL;
38943895
case TC_ACT_STOLEN:
38953896
case TC_ACT_QUEUED:
@@ -4569,10 +4570,12 @@ static bool skb_flow_limit(struct sk_buff *skb, unsigned int qlen)
45694570
static int enqueue_to_backlog(struct sk_buff *skb, int cpu,
45704571
unsigned int *qtail)
45714572
{
4573+
enum skb_drop_reason reason;
45724574
struct softnet_data *sd;
45734575
unsigned long flags;
45744576
unsigned int qlen;
45754577

4578+
reason = SKB_DROP_REASON_NOT_SPECIFIED;
45764579
sd = &per_cpu(softnet_data, cpu);
45774580

45784581
rps_lock_irqsave(sd, &flags);
@@ -4595,13 +4598,14 @@ static int enqueue_to_backlog(struct sk_buff *skb, int cpu,
45954598
napi_schedule_rps(sd);
45964599
goto enqueue;
45974600
}
4601+
reason = SKB_DROP_REASON_CPU_BACKLOG;
45984602

45994603
drop:
46004604
sd->dropped++;
46014605
rps_unlock_irq_restore(sd, &flags);
46024606

46034607
atomic_long_inc(&skb->dev->rx_dropped);
4604-
kfree_skb(skb);
4608+
kfree_skb_reason(skb, reason);
46054609
return NET_RX_DROP;
46064610
}
46074611

@@ -4821,7 +4825,7 @@ int do_xdp_generic(struct bpf_prog *xdp_prog, struct sk_buff *skb)
48214825
}
48224826
return XDP_PASS;
48234827
out_redir:
4824-
kfree_skb(skb);
4828+
kfree_skb_reason(skb, SKB_DROP_REASON_XDP);
48254829
return XDP_DROP;
48264830
}
48274831
EXPORT_SYMBOL_GPL(do_xdp_generic);
@@ -5037,7 +5041,7 @@ sch_handle_ingress(struct sk_buff *skb, struct packet_type **pt_prev, int *ret,
50375041
break;
50385042
case TC_ACT_SHOT:
50395043
mini_qdisc_qstats_cpu_drop(miniq);
5040-
kfree_skb(skb);
5044+
kfree_skb_reason(skb, SKB_DROP_REASON_TC_INGRESS);
50415045
return NULL;
50425046
case TC_ACT_STOLEN:
50435047
case TC_ACT_QUEUED:
@@ -5354,11 +5358,13 @@ static int __netif_receive_skb_core(struct sk_buff **pskb, bool pfmemalloc,
53545358
*ppt_prev = pt_prev;
53555359
} else {
53565360
drop:
5357-
if (!deliver_exact)
5361+
if (!deliver_exact) {
53585362
atomic_long_inc(&skb->dev->rx_dropped);
5359-
else
5363+
kfree_skb_reason(skb, SKB_DROP_REASON_PTYPE_ABSENT);
5364+
} else {
53605365
atomic_long_inc(&skb->dev->rx_nohandler);
5361-
kfree_skb(skb);
5366+
kfree_skb(skb);
5367+
}
53625368
/* Jamal, now you will not able to escape explaining
53635369
* me how you were going to use this. :-)
53645370
*/

net/core/skbuff.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -777,16 +777,17 @@ void kfree_skb_reason(struct sk_buff *skb, enum skb_drop_reason reason)
777777
}
778778
EXPORT_SYMBOL(kfree_skb_reason);
779779

780-
void kfree_skb_list(struct sk_buff *segs)
780+
void kfree_skb_list_reason(struct sk_buff *segs,
781+
enum skb_drop_reason reason)
781782
{
782783
while (segs) {
783784
struct sk_buff *next = segs->next;
784785

785-
kfree_skb(segs);
786+
kfree_skb_reason(segs, reason);
786787
segs = next;
787788
}
788789
}
789-
EXPORT_SYMBOL(kfree_skb_list);
790+
EXPORT_SYMBOL(kfree_skb_list_reason);
790791

791792
/* Dump skb information and contents.
792793
*

0 commit comments

Comments
 (0)