History

net: tap: track dropped skb via kfree_skb_reason()

The TAP can be used as vhost-net backend. E.g., the tap_handle_frame() is the interface to forward the skb from TAP to vhost-net/virtio-net. However, there are many "goto drop" in the TAP driver. Therefore, the kfree_skb_reason() is involved at each "goto drop" to help userspace ftrace/ebpf to track the reason for the loss of packets. The below reasons are introduced: - SKB_DROP_REASON_SKB_CSUM - SKB_DROP_REASON_SKB_GSO_SEG - SKB_DROP_REASON_SKB_UCOPY_FAULT - SKB_DROP_REASON_DEV_HDR - SKB_DROP_REASON_FULL_RING

Dongli Zhang committed 4 years ago

Commit 736f16d1 parent 925a2423 files · +43 −10Browse files

Unified · Split

3 files
  1. drivers/net/tap.c +25 −10
  2. include/linux/skbuff.h +13 −0
  3. include/trace/events/skb.h +5 −0
drivers/net/tap.c+25−10
@@ -322,6 +322,7 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) · 321 unmodified lines
322322 struct tap_dev *tap;
323323 struct tap_queue *q;
324324 netdev_features_t features = TAP_FEATURES;
325+ enum skb_drop_reason drop_reason;
325326
326327 tap = tap_dev_get_rcu(dev);
327328 if (!tap)
@@ -343,12 +344,16 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) · 15 unmodified lines
343344 struct sk_buff *segs = __skb_gso_segment(skb, features, false);
344345 struct sk_buff *next;
345346
346− if (IS_ERR(segs))
347+ if (IS_ERR(segs)) {
348+ drop_reason = SKB_DROP_REASON_SKB_GSO_SEG;
347349 goto drop;
350+ }
348351
349352 if (!segs) {
350− if (ptr_ring_produce(&q->ring, skb))
353+ if (ptr_ring_produce(&q->ring, skb)) {
354+ drop_reason = SKB_DROP_REASON_FULL_RING;
351355 goto drop;
356+ }
352357 goto wake_up;
353358 }
354359
@@ -356,8 +361,9 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) · 1 unmodified line
356361 skb_list_walk_safe(segs, skb, next) {
357362 skb_mark_not_on_list(skb);
358363 if (ptr_ring_produce(&q->ring, skb)) {
359− kfree_skb(skb);
360− kfree_skb_list(next);
364+ drop_reason = SKB_DROP_REASON_FULL_RING;
365+ kfree_skb_reason(skb, drop_reason);
366+ kfree_skb_list_reason(next, drop_reason);
361367 break;
362368 }
363369 }
@@ -369,10 +375,14 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) · 5 unmodified lines
369375 */
370376 if (skb->ip_summed == CHECKSUM_PARTIAL &&
371377 !(features & NETIF_F_CSUM_MASK) &&
372− skb_checksum_help(skb))
378+ skb_checksum_help(skb)) {
379+ drop_reason = SKB_DROP_REASON_SKB_CSUM;
373380 goto drop;
374− if (ptr_ring_produce(&q->ring, skb))
381+ }
382+ if (ptr_ring_produce(&q->ring, skb)) {
383+ drop_reason = SKB_DROP_REASON_FULL_RING;
375384 goto drop;
385+ }
376386 }
377387
378388 wake_up:
@@ -383,7 +393,7 @@ drop: · 4 unmodified lines
383393 /* Count errors/drops only here, thus don't care about args. */
384394 if (tap->count_rx_dropped)
385395 tap->count_rx_dropped(tap);
386− kfree_skb(skb);
396+ kfree_skb_reason(skb, drop_reason);
387397 return RX_HANDLER_CONSUMED;
388398 }
389399 EXPORT_SYMBOL_GPL(tap_handle_frame);
@@ -632,6 +642,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control, · 242 unmodified lines
632642 int depth;
633643 bool zerocopy = false;
634644 size_t linear;
645+ enum skb_drop_reason drop_reason;
635646
636647 if (q->flags & IFF_VNET_HDR) {
637648 vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);
@@ -696,8 +707,10 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control, · 58 unmodified lines
696707 else
697708 err = skb_copy_datagram_from_iter(skb, 0, from, len);
698709
699− if (err)
710+ if (err) {
711+ drop_reason = SKB_DROP_REASON_SKB_UCOPY_FAULT;
700712 goto err_kfree;
713+ }
701714
702715 skb_set_network_header(skb, ETH_HLEN);
703716 skb_reset_mac_header(skb);
@@ -706,8 +719,10 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control, · 2 unmodified lines
706719 if (vnet_hdr_len) {
707720 err = virtio_net_hdr_to_skb(skb, &vnet_hdr,
708721 tap_is_little_endian(q));
709− if (err)
722+ if (err) {
723+ drop_reason = SKB_DROP_REASON_DEV_HDR;
710724 goto err_kfree;
725+ }
711726 }
712727
713728 skb_probe_transport_header(skb);
@@ -738,7 +753,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control, · 24 unmodified lines
738753 return total_len;
739754
740755 err_kfree:
741− kfree_skb(skb);
756+ kfree_skb_reason(skb, drop_reason);
742757
743758 err:
744759 rcu_read_lock();
include/linux/skbuff.h+13−0
@@ -412,6 +412,19 @@ enum skb_drop_reason { · 411 unmodified lines
412412 * this means that L3 protocol is
413413 * not supported
414414 */
415+ SKB_DROP_REASON_SKB_CSUM, /* sk_buff checksum computation
416+ * error
417+ */
418+ SKB_DROP_REASON_SKB_GSO_SEG, /* gso segmentation error */
419+ SKB_DROP_REASON_SKB_UCOPY_FAULT, /* failed to copy data from
420+ * user space, e.g., via
421+ * zerocopy_sg_from_iter()
422+ * or skb_orphan_frags_rx()
423+ */
424+ SKB_DROP_REASON_DEV_HDR, /* device driver specific
425+ * header/metadata is invalid
426+ */
427+ SKB_DROP_REASON_FULL_RING, /* ring buffer is full */
415428 SKB_DROP_REASON_MAX,
416429 };
417430
include/trace/events/skb.h+5−0
@@ -51,6 +51,11 @@ · 50 unmodified lines
5151 EM(SKB_DROP_REASON_XDP, XDP) \
5252 EM(SKB_DROP_REASON_TC_INGRESS, TC_INGRESS) \
5353 EM(SKB_DROP_REASON_PTYPE_ABSENT, PTYPE_ABSENT) \
54+ EM(SKB_DROP_REASON_SKB_CSUM, SKB_CSUM) \
55+ EM(SKB_DROP_REASON_SKB_GSO_SEG, SKB_GSO_SEG) \
56+ EM(SKB_DROP_REASON_SKB_UCOPY_FAULT, SKB_UCOPY_FAULT) \
57+ EM(SKB_DROP_REASON_DEV_HDR, DEV_HDR) \
58+ EM(SKB_DROP_REASON_FULL_RING, FULL_RING) \
5459 EMe(SKB_DROP_REASON_MAX, MAX)
5560
5661 #undef EM

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t