From: David Ahern <dsahern@gmail.com>
To: Dongli Zhang <dongli.zhang@oracle.com>,
netdev@vger.kernel.org, Eric Dumazet <edumazet@google.com>
Cc: linux-kernel@vger.kernel.org, davem@davemloft.net,
kuba@kernel.org, rostedt@goodmis.org, mingo@redhat.com,
ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org,
imagedong@tencent.com, joao.m.martins@oracle.com,
joe.jin@oracle.com
Subject: Re: [PATCH 1/2] net: tap: track dropped skb via kfree_skb_reason()
Date: Mon, 7 Feb 2022 20:47:26 -0800 [thread overview]
Message-ID: <53282d15-1e73-9aef-6384-3f76812480e6@gmail.com> (raw)
In-Reply-To: <20220208035510.1200-2-dongli.zhang@oracle.com>
On 2/7/22 7:55 PM, Dongli Zhang wrote:
> diff --git a/drivers/net/tap.c b/drivers/net/tap.c
> index 8e3a28ba6b28..232572289e63 100644
> --- a/drivers/net/tap.c
> +++ b/drivers/net/tap.c
> @@ -322,6 +322,7 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb)
> struct tap_dev *tap;
> struct tap_queue *q;
> netdev_features_t features = TAP_FEATURES;
> + int drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
maybe I missed an exit path, but I believe drop_reason is always set
before a goto jump, so this init is not needed.
>
> tap = tap_dev_get_rcu(dev);
> if (!tap)
> @@ -343,12 +344,16 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb)
> struct sk_buff *segs = __skb_gso_segment(skb, features, false);
> struct sk_buff *next;
>
> - if (IS_ERR(segs))
> + if (IS_ERR(segs)) {
> + drop_reason = SKB_DROP_REASON_SKB_GSO_SEGMENT;
This reason points to a line of code, not the real reason for the drop.
If you unwind __skb_gso_segment the only failure there is ENOMEM. The
reason code needs to be meaningful to users, not just code references.
> goto drop;
> + }
>
> if (!segs) {
> - if (ptr_ring_produce(&q->ring, skb))
> + if (ptr_ring_produce(&q->ring, skb)) {
> + drop_reason = SKB_DROP_REASON_PTR_FULL;
similar comment to Eric - PTR_FULL needs to be more helpful.
> goto drop;
> + }
> goto wake_up;
> }
>
> @@ -369,10 +374,14 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb)
> */
> if (skb->ip_summed == CHECKSUM_PARTIAL &&
> !(features & NETIF_F_CSUM_MASK) &&
> - skb_checksum_help(skb))
> + skb_checksum_help(skb)) {
> + drop_reason = SKB_DROP_REASON_SKB_CHECKSUM;
That is not helpful explanation of the root cause; it is more of a code
reference.
> goto drop;
> - if (ptr_ring_produce(&q->ring, skb))
> + }
> + if (ptr_ring_produce(&q->ring, skb)) {
> + drop_reason = SKB_DROP_REASON_PTR_FULL;
ditto above comment
> goto drop;
> + }
> }
>
> wake_up:
> @@ -383,7 +392,7 @@ rx_handler_result_t tap_handle_frame(struct sk_buff **pskb)
> /* Count errors/drops only here, thus don't care about args. */
> if (tap->count_rx_dropped)
> tap->count_rx_dropped(tap);
> - kfree_skb(skb);
> + kfree_skb_reason(skb, drop_reason);
> return RX_HANDLER_CONSUMED;
> }
> EXPORT_SYMBOL_GPL(tap_handle_frame);
> @@ -632,6 +641,7 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
> int depth;
> bool zerocopy = false;
> size_t linear;
> + int drop_reason = SKB_DROP_REASON_NOT_SPECIFIED;
>
> if (q->flags & IFF_VNET_HDR) {
> vnet_hdr_len = READ_ONCE(q->vnet_hdr_sz);
> @@ -696,8 +706,10 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
> else
> err = skb_copy_datagram_from_iter(skb, 0, from, len);
>
> - if (err)
> + if (err) {
> + drop_reason = SKB_DROP_REASON_SKB_COPY_DATA;
As mentioned above, plus unwind the above functions and give a more
explicit description of why the above fails.
> goto err_kfree;
> + }
>
> skb_set_network_header(skb, ETH_HLEN);
> skb_reset_mac_header(skb);
> @@ -706,8 +718,10 @@ static ssize_t tap_get_user(struct tap_queue *q, void *msg_control,
> if (vnet_hdr_len) {
> err = virtio_net_hdr_to_skb(skb, &vnet_hdr,
> tap_is_little_endian(q));
> - if (err)
> + if (err) {
> + drop_reason = SKB_DROP_REASON_VIRTNET_HDR;
and here too.
next prev parent reply other threads:[~2022-02-08 5:32 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-08 3:55 [PATCH 0/2] tun/tap: use kfree_skb_reason() to trace dropped skb Dongli Zhang
2022-02-08 3:55 ` [PATCH 1/2] net: tap: track dropped skb via kfree_skb_reason() Dongli Zhang
2022-02-08 4:32 ` Eric Dumazet
2022-02-08 16:42 ` Dongli Zhang
2022-02-08 4:47 ` David Ahern [this message]
2022-02-08 17:20 ` Dongli Zhang
2022-02-08 3:55 ` [PATCH 2/2] net: tun: " Dongli Zhang
2022-02-08 5:03 ` David Ahern
2022-02-08 18:08 ` Dongli Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=53282d15-1e73-9aef-6384-3f76812480e6@gmail.com \
--to=dsahern@gmail.com \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=dongli.zhang@oracle.com \
--cc=edumazet@google.com \
--cc=imagedong@tencent.com \
--cc=joao.m.martins@oracle.com \
--cc=joe.jin@oracle.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=rostedt@goodmis.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox