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>,
"Andrew Lunn" <andrew+netdev@lunn.ch>,
"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 v2 06/13] virtio-net: rq submits premapped per-buffer
Date: Tue, 5 Nov 2024 15:09:44 +0800 [thread overview]
Message-ID: <1730790584.4657414-1-xuanzhuo@linux.alibaba.com> (raw)
In-Reply-To: <CACGkMEviCSEo4thkFo8gYnv+FCm-v65umJ65fdOwtxbAF_F2Ag@mail.gmail.com>
On Tue, 5 Nov 2024 11:23:50 +0800, Jason Wang <jasowang@redhat.com> wrote:
> On Wed, Oct 30, 2024 at 4:25 PM Xuan Zhuo <xuanzhuo@linux.alibaba.com> wrote:
> >
> > virtio-net rq submits premapped per-buffer by setting sg page to NULL;
> >
> > Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
> > ---
> > drivers/net/virtio_net.c | 24 +++++++++++++-----------
> > 1 file changed, 13 insertions(+), 11 deletions(-)
> >
> > diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
> > index 792e9eadbfc3..09757fa408bd 100644
> > --- a/drivers/net/virtio_net.c
> > +++ b/drivers/net/virtio_net.c
> > @@ -542,6 +542,12 @@ static struct sk_buff *ptr_to_skb(void *ptr)
> > return (struct sk_buff *)((unsigned long)ptr & ~VIRTIO_ORPHAN_FLAG);
> > }
> >
> > +static void sg_fill_dma(struct scatterlist *sg, dma_addr_t addr, u32 len)
> > +{
> > + sg->dma_address = addr;
> > + sg->length = len;
>
> This may work but I think it's better to reuse existing dma sg helpers like:
>
> sg_dma_address(sg) = addr;
> sg_dma_length(sg) = len;
>
> And we probably need to fix the virtio core which only uses
> sg_dma_address() but not sg_dma_length().
>
> This helps us to avoid future issues when CONFIG_NEED_SG_DMA_LENGTH is set.
I don't think so.
For no-premapped mode, we pass the sg as no-dma sg to virtio core,
so the virtio core uses the sg->length directly.
If virtio core do dma map for sg, we do not use the dma_mag_sg_attrs(),
so we must use sg->length directly.
In this case, for the driver, we can not use sg_dma_length(),
if CONFIG_NEED_SG_DMA_LENGTH is set, sg_dma_length() will set sg->dma_length,
but virtio core use sg->length.
For sg->dma_address, it is ok for me to use sg_dma_address or not.
But for consistency to sg->length, I use the sg->dma_address directly.
I noticed this is special, so I put them into an independent function.
Thanks.
>
> Others look good.
>
> Thanks
>
> > +}
> > +
> > static void __free_old_xmit(struct send_queue *sq, struct netdev_queue *txq,
> > bool in_napi, struct virtnet_sq_free_stats *stats)
> > {
> > @@ -915,8 +921,7 @@ static void virtnet_rq_init_one_sg(struct receive_queue *rq, void *buf, u32 len)
> > addr = dma->addr - sizeof(*dma) + offset;
> >
> > sg_init_table(rq->sg, 1);
> > - rq->sg[0].dma_address = addr;
> > - rq->sg[0].length = len;
> > + sg_fill_dma(rq->sg, addr, len);
> > }
> >
> > static void *virtnet_rq_alloc(struct receive_queue *rq, u32 size, gfp_t gfp)
> > @@ -1068,12 +1073,6 @@ static void check_sq_full_and_disable(struct virtnet_info *vi,
> > }
> > }
> >
> > -static void sg_fill_dma(struct scatterlist *sg, dma_addr_t addr, u32 len)
> > -{
> > - sg->dma_address = addr;
> > - sg->length = len;
> > -}
> > -
> > static struct xdp_buff *buf_to_xdp(struct virtnet_info *vi,
> > struct receive_queue *rq, void *buf, u32 len)
> > {
> > @@ -1354,7 +1353,8 @@ static int virtnet_add_recvbuf_xsk(struct virtnet_info *vi, struct receive_queue
> > sg_init_table(rq->sg, 1);
> > sg_fill_dma(rq->sg, addr, len);
> >
> > - err = virtqueue_add_inbuf(rq->vq, rq->sg, 1, xsk_buffs[i], gfp);
> > + err = virtqueue_add_inbuf_premapped(rq->vq, rq->sg, 1, xsk_buffs[i],
> > + NULL, true, gfp);
> > if (err)
> > goto err;
> > }
> > @@ -2431,7 +2431,8 @@ static int add_recvbuf_small(struct virtnet_info *vi, struct receive_queue *rq,
> >
> > virtnet_rq_init_one_sg(rq, buf, vi->hdr_len + GOOD_PACKET_LEN);
> >
> > - err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp);
> > + err = virtqueue_add_inbuf_premapped(rq->vq, rq->sg, 1, buf, ctx,
> > + rq->do_dma, gfp);
> > if (err < 0) {
> > if (rq->do_dma)
> > virtnet_rq_unmap(rq, buf, 0);
> > @@ -2546,7 +2547,8 @@ static int add_recvbuf_mergeable(struct virtnet_info *vi,
> > virtnet_rq_init_one_sg(rq, buf, len);
> >
> > ctx = mergeable_len_to_ctx(len + room, headroom);
> > - err = virtqueue_add_inbuf_ctx(rq->vq, rq->sg, 1, buf, ctx, gfp);
> > + err = virtqueue_add_inbuf_premapped(rq->vq, rq->sg, 1, buf, ctx,
> > + rq->do_dma, gfp);
> > if (err < 0) {
> > if (rq->do_dma)
> > virtnet_rq_unmap(rq, buf, 0);
> > --
> > 2.32.0.3.g01195cf9f
> >
>
next prev parent reply other threads:[~2024-11-05 7:23 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-30 8:24 [PATCH net-next v2 00/13] virtio-net: support AF_XDP zero copy (tx) Xuan Zhuo
2024-10-30 8:24 ` [PATCH net-next v2 01/13] virtio_ring: introduce vring_need_unmap_buffer Xuan Zhuo
2024-10-30 8:24 ` [PATCH net-next v2 02/13] virtio_ring: split: record extras for indirect buffers Xuan Zhuo
2024-11-05 3:42 ` Jason Wang
2024-11-05 6:51 ` Xuan Zhuo
2024-11-06 1:44 ` Jason Wang
2024-11-06 5:58 ` Xuan Zhuo
2024-11-06 7:42 ` Michael S. Tsirkin
2024-11-11 1:27 ` Jason Wang
2024-10-30 8:24 ` [PATCH net-next v2 03/13] virtio_ring: packed: " Xuan Zhuo
2024-10-30 8:24 ` [PATCH net-next v2 04/13] virtio_ring: perform premapped operations based on per-buffer Xuan Zhuo
2024-11-05 4:25 ` Jason Wang
2024-10-30 8:24 ` [PATCH net-next v2 05/13] virtio_ring: introduce add api for premapped Xuan Zhuo
2024-10-31 2:19 ` kernel test robot
2024-11-05 4:28 ` Jason Wang
2024-10-30 8:24 ` [PATCH net-next v2 06/13] virtio-net: rq submits premapped per-buffer Xuan Zhuo
2024-11-05 3:23 ` Jason Wang
2024-11-05 7:09 ` Xuan Zhuo [this message]
2024-11-06 1:56 ` Jason Wang
2024-11-06 5:55 ` Xuan Zhuo
2024-10-30 8:24 ` [PATCH net-next v2 07/13] virtio_ring: remove API virtqueue_set_dma_premapped Xuan Zhuo
2024-11-05 4:29 ` Jason Wang
2024-10-30 8:24 ` [PATCH net-next v2 08/13] virtio_net: refactor the xmit type Xuan Zhuo
2024-10-30 8:24 ` [PATCH net-next v2 09/13] virtio_net: xsk: bind/unbind xsk for tx Xuan Zhuo
2024-10-30 8:24 ` [PATCH net-next v2 10/13] virtio_net: xsk: prevent disable tx napi Xuan Zhuo
2024-10-30 8:24 ` [PATCH net-next v2 11/13] virtio_net: xsk: tx: support xmit xsk buffer Xuan Zhuo
2024-10-30 8:24 ` [PATCH net-next v2 12/13] virtio_net: update tx timeout record Xuan Zhuo
2024-10-30 8:24 ` [PATCH net-next v2 13/13] 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=1730790584.4657414-1-xuanzhuo@linux.alibaba.com \
--to=xuanzhuo@linux.alibaba.com \
--cc=andrew+netdev@lunn.ch \
--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;
as well as URLs for NNTP newsgroup(s).