BPF List
 help / color / mirror / Atom feed
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: [RFC net-next v1 07/12] virtio_net: refactor the xmit type
Date: Tue, 24 Sep 2024 19:39:27 +0800	[thread overview]
Message-ID: <1727177967.6466465-1-xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <CACGkMEtbNrwbxhRbjHGiEQeQbWUb2iL0ZtyosXs4_+GoZY-Gsw@mail.gmail.com>

On Tue, 24 Sep 2024 15:35:03 +0800, Jason Wang <jasowang@redhat.com> wrote:
> On Tue, Sep 24, 2024 at 9:32 AM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
> >
> > Because the af-xdp will introduce a new xmit type, so I refactor the
> > xmit type mechanism first.
> >
> > In general, pointers are aligned to 4 or 8 bytes.
>
> I think this needs some clarification, the alignment seems to depend
> on the lowest common multiple between the alignments of all struct
> members. So we know both xdp_frame and sk_buff are at least 4 bytes
> aligned.
>
> If we want to reuse the lowest bit of pointers in AF_XDP, the
> alignment of the data structure should be at least 4 bytes.

YES, for AF_XDP. See more in #10.


>
> > If it is aligned to 4
> > bytes, then only two bits are free for a pointer. But there are 4 types
> > here, so we can't use bits to distinguish them. And 2 bits is enough for
> > 4 types:
> >
> >     00 for skb
> >     01 for SKB_ORPHAN
> >     10 for XDP
> >     11 for af-xdp tx
> >
> > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > ---
> >  drivers/net/virtio_net.c | 90 +++++++++++++++++++++++-----------------
> >  1 file changed, 51 insertions(+), 39 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 630e5b21ad69..41a5ea9b788d 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -45,9 +45,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)
> > -#define VIRTIO_ORPHAN_FLAG     BIT(1)
> > -
> >  /* 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-
> > @@ -512,34 +509,35 @@ static struct sk_buff *virtnet_skb_append_frag(struct sk_buff *head_skb,
> >                                                struct page *page, void *buf,
> >                                                int len, int truesize);
> >
> > -static bool is_xdp_frame(void *ptr)
> > -{
> > -       return (unsigned long)ptr & VIRTIO_XDP_FLAG;
> > -}
> > +enum virtnet_xmit_type {
> > +       VIRTNET_XMIT_TYPE_SKB,
> > +       VIRTNET_XMIT_TYPE_SKB_ORPHAN,
> > +       VIRTNET_XMIT_TYPE_XDP,
> > +};
> >
> > -static void *xdp_to_ptr(struct xdp_frame *ptr)
> > -{
> > -       return (void *)((unsigned long)ptr | VIRTIO_XDP_FLAG);
> > -}
> > +/* We use the last two bits of the pointer to distinguish the xmit type. */
> > +#define VIRTNET_XMIT_TYPE_MASK (BIT(0) | BIT(1))
> >
> > -static struct xdp_frame *ptr_to_xdp(void *ptr)
> > +static enum virtnet_xmit_type virtnet_xmit_ptr_strip(void **ptr)
>
> Nit: not a native speaker but I think something like pack/unpack might
> be better.


Will fix.

Thanks

>
> With those changes.
>
> Acked-by: Jason Wang <jasowang@redhat.com>
>
> Thanks
>

  reply	other threads:[~2024-09-24 11:41 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-24  1:31 [RFC net-next v1 00/12] virtio-net: support AF_XDP zero copy (tx) Xuan Zhuo
2024-09-24  1:31 ` [RFC net-next v1 01/12] virtio_ring: introduce vring_need_unmap_buffer Xuan Zhuo
2024-09-24  1:31 ` [RFC net-next v1 02/12] virtio_ring: split: record extras for indirect buffers Xuan Zhuo
2024-09-24  7:34   ` Jason Wang
2024-09-24  8:32     ` Xuan Zhuo
2024-09-24  1:31 ` [RFC net-next v1 03/12] virtio_ring: packed: " Xuan Zhuo
2024-09-24  1:31 ` [RFC net-next v1 04/12] virtio_ring: perform premapped operations based on per-buffer Xuan Zhuo
2024-09-24  7:35   ` Jason Wang
2024-09-24  8:22     ` Xuan Zhuo
2024-09-24  1:31 ` [RFC net-next v1 05/12] virtio-net: rq submits premapped per-buffer Xuan Zhuo
2024-09-24  1:31 ` [RFC net-next v1 06/12] virtio_ring: remove API virtqueue_set_dma_premapped Xuan Zhuo
2024-09-24  1:31 ` [RFC net-next v1 07/12] virtio_net: refactor the xmit type Xuan Zhuo
2024-09-24  7:35   ` Jason Wang
2024-09-24 11:39     ` Xuan Zhuo [this message]
2024-09-24  1:32 ` [RFC net-next v1 08/12] virtio_net: xsk: bind/unbind xsk for tx Xuan Zhuo
2024-09-24  7:35   ` Jason Wang
2024-09-24  9:22     ` Xuan Zhuo
2024-09-24  1:32 ` [RFC net-next v1 09/12] virtio_net: xsk: prevent disable tx napi Xuan Zhuo
2024-09-24  1:32 ` [RFC net-next v1 10/12] virtio_net: xsk: tx: support xmit xsk buffer Xuan Zhuo
2024-09-24  7:35   ` Jason Wang
2024-09-24 11:41     ` Xuan Zhuo
2024-09-24  1:32 ` [RFC net-next v1 11/12] virtio_net: update tx timeout record Xuan Zhuo
2024-09-24  1:32 ` [RFC net-next v1 12/12] virtio_net: xdp_features add NETDEV_XDP_ACT_XSK_ZEROCOPY 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=1727177967.6466465-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