virtualization.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: "Michael S. Tsirkin" <mst@redhat.com>
To: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: Jesper Dangaard Brouer <hawk@kernel.org>,
	Daniel Borkmann <daniel@iogearbox.net>,
	netdev@vger.kernel.org, John Fastabend <john.fastabend@gmail.com>,
	Alexei Starovoitov <ast@kernel.org>,
	virtualization@lists.linux-foundation.org,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>,
	bpf@vger.kernel.org, Paolo Abeni <pabeni@redhat.com>,
	"David S. Miller" <davem@davemloft.net>
Subject: Re: [PATCH net-next v4 12/15] virtio_net: small: avoid double counting in xdp scenarios
Date: Thu, 27 Apr 2023 21:08:25 -0400	[thread overview]
Message-ID: <20230427210802-mutt-send-email-mst@kernel.org> (raw)
In-Reply-To: <20230427030534.115066-13-xuanzhuo@linux.alibaba.com>

On Thu, Apr 27, 2023 at 11:05:31AM +0800, Xuan Zhuo wrote:
> Avoid the problem that some variables(headroom and so on) will repeat
> the calculation when process xdp.
> 
> Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> Acked-by: Jason Wang <jasowang@redhat.com>


this is "code duplication" not "double counting".


> ---
>  drivers/net/virtio_net.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> index b8ec642899c9..f832ab8a3e6e 100644
> --- a/drivers/net/virtio_net.c
> +++ b/drivers/net/virtio_net.c
> @@ -1027,11 +1027,10 @@ static struct sk_buff *receive_small(struct net_device *dev,
>  	struct sk_buff *skb;
>  	struct bpf_prog *xdp_prog;
>  	unsigned int xdp_headroom = (unsigned long)ctx;
> -	unsigned int header_offset = VIRTNET_RX_PAD + xdp_headroom;
> -	unsigned int headroom = vi->hdr_len + header_offset;
> -	unsigned int buflen = SKB_DATA_ALIGN(GOOD_PACKET_LEN + headroom) +
> -			      SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
>  	struct page *page = virt_to_head_page(buf);
> +	unsigned int header_offset;
> +	unsigned int headroom;
> +	unsigned int buflen;
>  
>  	len -= vi->hdr_len;
>  	stats->bytes += len;
> @@ -1059,6 +1058,11 @@ static struct sk_buff *receive_small(struct net_device *dev,
>  	rcu_read_unlock();
>  
>  skip_xdp:
> +	header_offset = VIRTNET_RX_PAD + xdp_headroom;
> +	headroom = vi->hdr_len + header_offset;
> +	buflen = SKB_DATA_ALIGN(GOOD_PACKET_LEN + headroom) +
> +		SKB_DATA_ALIGN(sizeof(struct skb_shared_info));
> +
>  	skb = build_skb(buf, buflen);
>  	if (!skb)
>  		goto err;
> -- 
> 2.32.0.3.g01195cf9f

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

  reply	other threads:[~2023-04-28  1:08 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-27  3:05 [PATCH net-next v4 00/15] virtio_net: refactor xdp codes Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 01/15] virtio_net: mergeable xdp: put old page immediately Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 02/15] virtio_net: introduce mergeable_xdp_get_buf() Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 03/15] virtio_net: optimize mergeable_xdp_get_buf() Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 04/15] virtio_net: introduce virtnet_xdp_handler() to seprate the logic of run xdp Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 05/15] virtio_net: separate the logic of freeing xdp shinfo Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 06/15] virtio_net: separate the logic of freeing the rest mergeable buf Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 07/15] virtio_net: virtnet_build_xdp_buff_mrg() auto release xdp shinfo Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 08/15] virtio_net: introduce receive_mergeable_xdp() Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 09/15] virtio_net: merge: remove skip_xdp Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 10/15] virtio_net: introduce receive_small_xdp() Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 11/15] virtio_net: small: remove the delta Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 12/15] virtio_net: small: avoid double counting in xdp scenarios Xuan Zhuo
2023-04-28  1:08   ` Michael S. Tsirkin [this message]
2023-04-28  1:54     ` Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 13/15] virtio_net: small: remove skip_xdp Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 14/15] virtio_net: introduce receive_small_build_xdp Xuan Zhuo
2023-04-27  3:05 ` [PATCH net-next v4 15/15] virtio_net: introduce virtnet_build_skb() Xuan Zhuo
2023-04-27  6:55 ` [PATCH net-next v4 00/15] virtio_net: refactor xdp codes Paolo Abeni

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=20230427210802-mutt-send-email-mst@kernel.org \
    --to=mst@redhat.com \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hawk@kernel.org \
    --cc=john.fastabend@gmail.com \
    --cc=kuba@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=virtualization@lists.linux-foundation.org \
    --cc=xuanzhuo@linux.alibaba.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).