From: Willem de Bruijn <willemdebruijn.kernel@gmail.com>
To: Yunjian Wang <wangyunjian@huawei.com>,
willemdebruijn.kernel@gmail.com, jasowang@redhat.com,
kuba@kernel.org, davem@davemloft.net
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
xudingke@huawei.com, Yunjian Wang <wangyunjian@huawei.com>
Subject: Re: [PATCH net v3] tun: add missing rx stats accounting in tun_xdp_act
Date: Wed, 17 Jan 2024 10:42:24 -0500 [thread overview]
Message-ID: <65a7f560a4643_6ba59294a7@willemb.c.googlers.com.notmuch> (raw)
In-Reply-To: <1705490503-28844-1-git-send-email-wangyunjian@huawei.com>
Yunjian Wang wrote:
> The TUN can be used as vhost-net backend, and it is necessary to count
> the packets transmitted from TUN to vhost-net/virtio-net. However, there
> are some places in the receive path that were not taken into account
> when using XDP. The commit 8ae1aff0b331 ("tuntap: split out XDP logic")
> only includes dropped counter for XDP_DROP, XDP_ABORTED, and invalid
> XDP actions. It would be beneficial to also include new accounting for
> successfully received bytes using dev_sw_netstats_rx_add and introduce
> new dropped counter for XDP errors on XDP_TX and XDP_REDIRECT.
From the description it is clear that these are two separate changes
wrapped into one patch. I should have flagged this previously.
Ack on returning the error counter that was previously present and
matches the Fixes tag.
For the second change, I had to check a few other XDP capable drivers
to verify that it is indeed common to count such packets.
> Fixes: 8ae1aff0b331 ("tuntap: split out XDP logic")
> Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
> ---
> v3: update commit log and code
> v2: add Fixes tag
> ---
> drivers/net/tun.c | 14 +++++++++-----
> 1 file changed, 9 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/tun.c b/drivers/net/tun.c
> index afa5497f7c35..0704a17e74e1 100644
> --- a/drivers/net/tun.c
> +++ b/drivers/net/tun.c
> @@ -1625,18 +1625,15 @@ static struct sk_buff *__tun_build_skb(struct tun_file *tfile,
> static int tun_xdp_act(struct tun_struct *tun, struct bpf_prog *xdp_prog,
> struct xdp_buff *xdp, u32 act)
> {
> - int err;
> + unsigned int datasize = xdp->data_end - xdp->data;
> + int err = 0;
>
> switch (act) {
> case XDP_REDIRECT:
> err = xdp_do_redirect(tun->dev, xdp, xdp_prog);
> - if (err)
> - return err;
> break;
> case XDP_TX:
> err = tun_xdp_tx(tun->dev, xdp);
> - if (err < 0)
> - return err;
> break;
> case XDP_PASS:
> break;
> @@ -1651,6 +1648,13 @@ static int tun_xdp_act(struct tun_struct *tun, struct bpf_prog *xdp_prog,
> break;
> }
>
> + if (err < 0) {
> + act = err;
> + dev_core_stats_rx_dropped_inc(tun->dev);
> + } else if (act == XDP_REDIRECT || act == XDP_TX) {
> + dev_sw_netstats_rx_add(tun->dev, datasize);
> + }
> +
Let's avoid adding yet another branch and just do these operations in
the case statements, like XDP_DROP.
> return act;
> }
>
> --
> 2.41.0
>
next prev parent reply other threads:[~2024-01-17 15:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-17 11:21 [PATCH net v3] tun: add missing rx stats accounting in tun_xdp_act Yunjian Wang
2024-01-17 15:42 ` Willem de Bruijn [this message]
2024-01-18 12:55 ` wangyunjian
2024-01-18 14:44 ` Willem de Bruijn
2024-01-19 8:07 ` wangyunjian
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=65a7f560a4643_6ba59294a7@willemb.c.googlers.com.notmuch \
--to=willemdebruijn.kernel@gmail.com \
--cc=davem@davemloft.net \
--cc=jasowang@redhat.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=wangyunjian@huawei.com \
--cc=xudingke@huawei.com \
/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;
as well as URLs for NNTP newsgroup(s).