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
322 struct tap_dev *tap;322 struct tap_dev *tap;
323 struct tap_queue *q;323 struct tap_queue *q;
324 netdev_features_t features = TAP_FEATURES;324 netdev_features_t features = TAP_FEATURES;
325 enum skb_drop_reason drop_reason;
325 326
326 tap = tap_dev_get_rcu(dev);327 tap = tap_dev_get_rcu(dev);
327 if (!tap)328 if (!tap)
@@ -343,12 +344,16 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) · 15 unmodified lines
343 struct sk_buff *segs = __skb_gso_segment(skb, features, false);344 struct sk_buff *segs = __skb_gso_segment(skb, features, false);
344 struct sk_buff *next;345 struct sk_buff *next;
345 346
346 if (IS_ERR(segs))347 if (IS_ERR(segs)) {
348 drop_reason = SKB_DROP_REASON_SKB_GSO_SEG;
347 goto drop;349 goto drop;
350 }
348 351
349 if (!segs) {352 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;
351 goto drop;355 goto drop;
356 }
352 goto wake_up;357 goto wake_up;
353 }358 }
354 359
@@ -356,8 +361,9 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) · 1 unmodified line
356 skb_list_walk_safe(segs, skb, next) {361 skb_list_walk_safe(segs, skb, next) {
357 skb_mark_not_on_list(skb);362 skb_mark_not_on_list(skb);
358 if (ptr_ring_produce(&q->ring, skb)) {363 if (ptr_ring_produce(&q->ring, skb)) {
359 kfree_skb(skb);364 drop_reason = SKB_DROP_REASON_FULL_RING;
360 kfree_skb_list(next);365 kfree_skb_reason(skb, drop_reason);
366 kfree_skb_list_reason(next, drop_reason);
361 break;367 break;
362 }368 }
363 }369 }
@@ -369,10 +375,14 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb) · 5 unmodified lines
369 */375 */
370 if (skb->ip_summed == CHECKSUM_PARTIAL &&376 if (skb->ip_summed == CHECKSUM_PARTIAL &&
371 !(features & NETIF_F_CSUM_MASK) &&377 !(features & NETIF_F_CSUM_MASK) &&
372 skb_checksum_help(skb))378 skb_checksum_help(skb)) {
379 drop_reason = SKB_DROP_REASON_SKB_CSUM;
373 goto drop;380 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;
375 goto drop;384 goto drop;
385 }
376 }386 }
377 387
378wake_up:388wake_up:
@@ -383,7 +393,7 @@ drop: · 4 unmodified lines
383 /* Count errors/drops only here, thus don't care about args. */393 /* Count errors/drops only here, thus don't care about args. */
384 if (tap->count_rx_dropped)394 if (tap->count_rx_dropped)
385 tap->count_rx_dropped(tap);395 tap->count_rx_dropped(tap);
386 kfree_skb(skb);396 kfree_skb_reason(skb, drop_reason);
387 return RX_HANDLER_CONSUMED;397 return RX_HANDLER_CONSUMED;
388}398}
389EXPORT_SYMBOL_GPL(tap_handle_frame);399EXPORT_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
632 int depth;642 int depth;
633 bool zerocopy = false;643 bool zerocopy = false;
634 size_t linear;644 size_t linear;
645 enum skb_drop_reason drop_reason;
635 646
636 if (q->flags & IFF_VNET_HDR) {647 if (q->flags & IFF_VNET_HDR) {
637 vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);648 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
696 else707 else
697 err = skb_copy_datagram_from_iter(skb, 0, from, len);708 err = skb_copy_datagram_from_iter(skb, 0, from, len);
698 709
699 if (err)710 if (err) {
711 drop_reason = SKB_DROP_REASON_SKB_UCOPY_FAULT;
700 goto err_kfree;712 goto err_kfree;
713 }
701 714
702 skb_set_network_header(skb, ETH_HLEN);715 skb_set_network_header(skb, ETH_HLEN);
703 skb_reset_mac_header(skb);716 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
706 if (vnet_hdr_len) {719 if (vnet_hdr_len) {
707 err = virtio_net_hdr_to_skb(skb, &vnet_hdr,720 err = virtio_net_hdr_to_skb(skb, &vnet_hdr,
708 tap_is_little_endian(q));721 tap_is_little_endian(q));
709 if (err)722 if (err) {
723 drop_reason = SKB_DROP_REASON_DEV_HDR;
710 goto err_kfree;724 goto err_kfree;
725 }
711 }726 }
712 727
713 skb_probe_transport_header(skb);728 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
738 return total_len;753 return total_len;
739 754
740err_kfree:755err_kfree:
741 kfree_skb(skb);756 kfree_skb_reason(skb, drop_reason);
742 757
743err:758err:
744 rcu_read_lock();759 rcu_read_lock();
include/linux/skbuff.h+13−0
@@ -412,6 +412,19 @@ enum skb_drop_reason { · 411 unmodified lines
412 * this means that L3 protocol is412 * this means that L3 protocol is
413 * not supported413 * not supported
414 */414 */
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 */
415 SKB_DROP_REASON_MAX,428 SKB_DROP_REASON_MAX,
416};429};
417 430
include/trace/events/skb.h+5−0
@@ -51,6 +51,11 @@ · 50 unmodified lines
51 EM(SKB_DROP_REASON_XDP, XDP) \51 EM(SKB_DROP_REASON_XDP, XDP) \
52 EM(SKB_DROP_REASON_TC_INGRESS, TC_INGRESS) \52 EM(SKB_DROP_REASON_TC_INGRESS, TC_INGRESS) \
53 EM(SKB_DROP_REASON_PTYPE_ABSENT, PTYPE_ABSENT) \53 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) \
54 EMe(SKB_DROP_REASON_MAX, MAX)59 EMe(SKB_DROP_REASON_MAX, MAX)
55 60
56#undef EM61#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