From: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
To: Jason Wang <jasowang@redhat.com>
Cc: netdev@vger.kernel.org, "Michael S. Tsirkin" <mst@redhat.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"David S. Miller" <davem@davemloft.net>,
"Eric Dumazet" <edumazet@google.com>,
"Jakub Kicinski" <kuba@kernel.org>,
"Paolo Abeni" <pabeni@redhat.com>,
"Alexei Starovoitov" <ast@kernel.org>,
"Daniel Borkmann" <daniel@iogearbox.net>,
"Jesper Dangaard Brouer" <hawk@kernel.org>,
"John Fastabend" <john.fastabend@gmail.com>,
virtualization@lists.linux.dev, bpf@vger.kernel.org
Subject: Re: [PATCH net-next v5 07/15] virtio_net: refactor the xmit type
Date: Mon, 17 Jun 2024 15:21:14 +0800 [thread overview]
Message-ID: <1718608874.0503511-1-xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <CACGkMEtUE8CbdLS1c1b++g=ZxO_gDgOidUpWhuv28ZWgWP6uPw@mail.gmail.com>
On Mon, 17 Jun 2024 13:00:11 +0800, Jason Wang <jasowang@redhat.com> wrote:
> On Fri, Jun 14, 2024 at 2:40 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
> >
> > Because the af-xdp and sq premapped mode will introduce two
> > new xmit type, so I refactor the xmit type mechanism first.
> >
> > We use the last two bits of the pointer to distinguish the xmit type,
> > so we can distinguish four xmit types. Now we have two xmit types:
> > SKB and XDP.
> >
> > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > ---
> > drivers/net/virtio_net.c | 58 +++++++++++++++++++++++++++-------------
> > 1 file changed, 40 insertions(+), 18 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 161694957065..e84a4624549b 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -47,8 +47,6 @@ module_param(napi_tx, bool, 0644);
> > #define VIRTIO_XDP_TX BIT(0)
> > #define VIRTIO_XDP_REDIR BIT(1)
> >
> > -#define VIRTIO_XDP_FLAG BIT(0)
> > -
> > /* RX packet size EWMA. The average packet size is used to determine the packet
> > * buffer size when refilling RX rings. As the entire RX ring may be refilled
> > * at once, the weight is chosen so that the EWMA will be insensitive to short-
> > @@ -491,42 +489,62 @@ struct virtio_net_common_hdr {
> >
> > static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf);
> >
> > -static bool is_xdp_frame(void *ptr)
> > +enum virtnet_xmit_type {
> > + VIRTNET_XMIT_TYPE_SKB,
> > + VIRTNET_XMIT_TYPE_XDP,
> > +};
> > +
> > +#define VIRTNET_XMIT_TYPE_MASK (VIRTNET_XMIT_TYPE_SKB | VIRTNET_XMIT_TYPE_XDP)
> > +
> > +static enum virtnet_xmit_type virtnet_xmit_ptr_strip(void **ptr)
> > {
> > - return (unsigned long)ptr & VIRTIO_XDP_FLAG;
> > + unsigned long p = (unsigned long)*ptr;
> > +
> > + *ptr = (void *)(p & ~VIRTNET_XMIT_TYPE_MASK);
> > +
> > + return p & VIRTNET_XMIT_TYPE_MASK;
> > }
> >
> > -static void *xdp_to_ptr(struct xdp_frame *ptr)
> > +static void *virtnet_xmit_ptr_mix(void *ptr, enum virtnet_xmit_type type)
>
> How about rename this to virtnet_ptr_to_token()?
Will fix.
>
> > {
> > - return (void *)((unsigned long)ptr | VIRTIO_XDP_FLAG);
> > + return (void *)((unsigned long)ptr | type);
> > }
> >
> > -static struct xdp_frame *ptr_to_xdp(void *ptr)
> > +static int virtnet_add_outbuf(struct send_queue *sq, int num, void *data,
> > + enum virtnet_xmit_type type)
> > {
> > - return (struct xdp_frame *)((unsigned long)ptr & ~VIRTIO_XDP_FLAG);
> > + return virtqueue_add_outbuf(sq->vq, sq->sg, num,
> > + virtnet_xmit_ptr_mix(data, type),
> > + GFP_ATOMIC);
>
> Nit: I think we can just open-code this instead of using a helper.
Will fix.
Thanks.
>
> Others look good.
>
> Thanks
>
>
> > }
> >
> > static void __free_old_xmit(struct send_queue *sq, bool in_napi,
> > struct virtnet_sq_free_stats *stats)
> > {
> > + struct xdp_frame *frame;
> > + struct sk_buff *skb;
> > unsigned int len;
> > void *ptr;
> >
> > while ((ptr = virtqueue_get_buf(sq->vq, &len)) != NULL) {
> > ++stats->packets;
> >
> > - if (!is_xdp_frame(ptr)) {
> > - struct sk_buff *skb = ptr;
> > + switch (virtnet_xmit_ptr_strip(&ptr)) {
> > + case VIRTNET_XMIT_TYPE_SKB:
> > + skb = ptr;
> >
> > pr_debug("Sent skb %p\n", skb);
> >
> > stats->bytes += skb->len;
> > napi_consume_skb(skb, in_napi);
> > - } else {
> > - struct xdp_frame *frame = ptr_to_xdp(ptr);
> > + break;
> > +
> > + case VIRTNET_XMIT_TYPE_XDP:
> > + frame = ptr;
> >
> > stats->bytes += xdp_get_frame_len(frame);
> > xdp_return_frame(frame);
> > + break;
> > }
> > }
> > }
> > @@ -1064,8 +1082,7 @@ static int __virtnet_xdp_xmit_one(struct virtnet_info *vi,
> > skb_frag_size(frag), skb_frag_off(frag));
> > }
> >
> > - err = virtqueue_add_outbuf(sq->vq, sq->sg, nr_frags + 1,
> > - xdp_to_ptr(xdpf), GFP_ATOMIC);
> > + err = virtnet_add_outbuf(sq, nr_frags + 1, xdpf, VIRTNET_XMIT_TYPE_XDP);
> > if (unlikely(err))
> > return -ENOSPC; /* Caller handle free/refcnt */
> >
> > @@ -2557,7 +2574,7 @@ static int xmit_skb(struct send_queue *sq, struct sk_buff *skb)
> > return num_sg;
> > num_sg++;
> > }
> > - return virtqueue_add_outbuf(sq->vq, sq->sg, num_sg, skb, GFP_ATOMIC);
> > + return virtnet_add_outbuf(sq, num_sg, skb, VIRTNET_XMIT_TYPE_SKB);
> > }
> >
> > static netdev_tx_t start_xmit(struct sk_buff *skb, struct net_device *dev)
> > @@ -5263,10 +5280,15 @@ static void free_receive_page_frags(struct virtnet_info *vi)
> >
> > static void virtnet_sq_free_unused_buf(struct virtqueue *vq, void *buf)
> > {
> > - if (!is_xdp_frame(buf))
> > + switch (virtnet_xmit_ptr_strip(&buf)) {
> > + case VIRTNET_XMIT_TYPE_SKB:
> > dev_kfree_skb(buf);
> > - else
> > - xdp_return_frame(ptr_to_xdp(buf));
> > + break;
> > +
> > + case VIRTNET_XMIT_TYPE_XDP:
> > + xdp_return_frame(buf);
> > + break;
> > + }
> > }
> >
> > static void free_unused_bufs(struct virtnet_info *vi)
> > --
> > 2.32.0.3.g01195cf9f
> >
>
next prev parent reply other threads:[~2024-06-17 7:22 UTC|newest]
Thread overview: 38+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-14 6:39 [PATCH net-next v5 00/15] virtio-net: support AF_XDP zero copy Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 01/15] virtio_ring: introduce dma map api for page Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 02/15] virtio_ring: introduce vring_need_unmap_buffer Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 03/15] virtio_ring: virtqueue_set_dma_premapped() support to disable Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 04/15] virtio_net: separate virtnet_rx_resize() Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 05/15] virtio_net: separate virtnet_tx_resize() Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 06/15] virtio_net: separate receive_buf Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 07/15] virtio_net: refactor the xmit type Xuan Zhuo
2024-06-17 5:00 ` Jason Wang
2024-06-17 7:21 ` Xuan Zhuo [this message]
2024-06-14 6:39 ` [PATCH net-next v5 08/15] virtio_net: sq support premapped mode Xuan Zhuo
2024-06-17 5:00 ` Jason Wang
2024-06-17 6:28 ` Jason Wang
2024-06-17 7:40 ` Xuan Zhuo
2024-06-18 1:00 ` Jason Wang
2024-06-18 1:31 ` Xuan Zhuo
2024-06-17 7:23 ` Xuan Zhuo
2024-06-18 0:57 ` Jason Wang
2024-06-18 0:59 ` Jason Wang
2024-06-18 1:34 ` Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 09/15] virtio_net: xsk: bind/unbind xsk Xuan Zhuo
2024-06-17 6:19 ` Jason Wang
2024-06-17 7:43 ` Xuan Zhuo
2024-06-18 1:04 ` Jason Wang
2024-06-18 1:36 ` Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 10/15] virtio_net: xsk: prevent disable tx napi Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 11/15] virtio_net: xsk: tx: support xmit xsk buffer Xuan Zhuo
2024-06-17 6:30 ` Jason Wang
2024-06-17 7:51 ` Xuan Zhuo
2024-06-18 1:06 ` Jason Wang
2024-06-18 1:40 ` Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 12/15] virtio_net: xsk: tx: support wakeup Xuan Zhuo
2024-06-17 6:31 ` Jason Wang
2024-06-14 6:39 ` [PATCH net-next v5 13/15] virtio_net: xsk: tx: handle the transmitted xsk buffer Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 14/15] virtio_net: xsk: rx: support fill with " Xuan Zhuo
2024-06-14 6:39 ` [PATCH net-next v5 15/15] virtio_net: xsk: rx: support recv small mode Xuan Zhuo
2024-06-17 7:10 ` Jason Wang
2024-06-17 7:55 ` Xuan Zhuo
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=1718608874.0503511-1-xuanzhuo@linux.alibaba.com \
--to=xuanzhuo@linux.alibaba.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=eperezma@redhat.com \
--cc=hawk@kernel.org \
--cc=jasowang@redhat.com \
--cc=john.fastabend@gmail.com \
--cc=kuba@kernel.org \
--cc=mst@redhat.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=virtualization@lists.linux.dev \
/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