Add drop reason to kfree_skb calls in tun_xdp_one and ensure that all failing paths properly increment drop counter. Signed-off-by: Jon Kohler --- drivers/net/tun.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/net/tun.c b/drivers/net/tun.c index dcce49a26800..68ad46ab04a4 100644 --- a/drivers/net/tun.c +++ b/drivers/net/tun.c @@ -2392,8 +2392,10 @@ static int tun_xdp_one(struct tun_struct *tun, bool skb_xdp = false; struct page *page; - if (unlikely(datasize < ETH_HLEN)) + if (unlikely(datasize < ETH_HLEN)) { + dev_core_stats_rx_dropped_inc(tun->dev); return -EINVAL; + } xdp_prog = rcu_dereference(tun->xdp_prog); if (xdp_prog) { @@ -2407,6 +2409,7 @@ static int tun_xdp_one(struct tun_struct *tun, act = bpf_prog_run_xdp(xdp_prog, xdp); ret = tun_xdp_act(tun, xdp_prog, xdp, act); if (ret < 0) { + /* tun_xdp_act already handles drop statistics */ put_page(virt_to_head_page(xdp->data)); return ret; } @@ -2435,6 +2438,7 @@ static int tun_xdp_one(struct tun_struct *tun, build: skb = build_skb(xdp->data_hard_start, buflen); if (!skb) { + dev_core_stats_rx_dropped_inc(tun->dev); return -ENOMEM; } @@ -2453,7 +2457,8 @@ static int tun_xdp_one(struct tun_struct *tun, tnl_hdr = (struct virtio_net_hdr_v1_hash_tunnel *)gso; if (tun_vnet_hdr_tnl_to_skb(tun->flags, features, skb, tnl_hdr)) { atomic_long_inc(&tun->rx_frame_errors); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_DEV_HDR); + dev_core_stats_rx_dropped_inc(tun->dev); return -EINVAL; } @@ -2479,7 +2484,8 @@ static int tun_xdp_one(struct tun_struct *tun, if (unlikely(tfile->detached)) { spin_unlock(&queue->lock); - kfree_skb(skb); + kfree_skb_reason(skb, SKB_DROP_REASON_DEV_READY); + dev_core_stats_rx_dropped_inc(tun->dev); return -EBUSY; } -- 2.43.0