[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1706695212.333408-3-xuanzhuo@linux.alibaba.com>
Date: Wed, 31 Jan 2024 18:00:12 +0800
From: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
To: Jason Wang <jasowang@...hat.com>
Cc: virtualization@...ts.linux.dev,
Richard Weinberger <richard@....at>,
Anton Ivanov <anton.ivanov@...bridgegreys.com>,
Johannes Berg <johannes@...solutions.net>,
"Michael S. Tsirkin" <mst@...hat.com>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>,
Hans de Goede <hdegoede@...hat.com>,
Ilpo Järvinen <ilpo.jarvinen@...ux.intel.com>,
Vadim Pasternak <vadimp@...dia.com>,
Bjorn Andersson <andersson@...nel.org>,
Mathieu Poirier <mathieu.poirier@...aro.org>,
Cornelia Huck <cohuck@...hat.com>,
Halil Pasic <pasic@...ux.ibm.com>,
Eric Farman <farman@...ux.ibm.com>,
Heiko Carstens <hca@...ux.ibm.com>,
Vasily Gorbik <gor@...ux.ibm.com>,
Alexander Gordeev <agordeev@...ux.ibm.com>,
Christian Borntraeger <borntraeger@...ux.ibm.com>,
Sven Schnelle <svens@...ux.ibm.com>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Jesper Dangaard Brouer <hawk@...nel.org>,
John Fastabend <john.fastabend@...il.com>,
Benjamin Berg <benjamin.berg@...el.com>,
Yang Li <yang.lee@...ux.alibaba.com>,
linux-um@...ts.infradead.org,
netdev@...r.kernel.org,
platform-driver-x86@...r.kernel.org,
linux-remoteproc@...r.kernel.org,
linux-s390@...r.kernel.org,
kvm@...r.kernel.org,
bpf@...r.kernel.org
Subject: Re: [PATCH vhost 03/17] virtio_ring: packed: structure the indirect desc table
On Wed, 31 Jan 2024 17:12:10 +0800, Jason Wang <jasowang@...hat.com> wrote:
> On Tue, Jan 30, 2024 at 7:42 PM Xuan Zhuo <xuanzhuo@...ux.alibaba.com> wrote:
> >
> > This commit structure the indirect desc table.
> > Then we can get the desc num directly when doing unmap.
> >
> > And save the dma info to the struct, then the indirect
> > will not use the dma fields of the desc_extra. The subsequent
> > commits will make the dma fields are optional. But for
> > the indirect case, we must record the dma info.
> >
> > Signed-off-by: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
> > ---
> > drivers/virtio/virtio_ring.c | 63 ++++++++++++++++++++----------------
> > 1 file changed, 35 insertions(+), 28 deletions(-)
> >
> > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > index 7280a1706cca..dd03bc5a81fe 100644
> > --- a/drivers/virtio/virtio_ring.c
> > +++ b/drivers/virtio/virtio_ring.c
> > @@ -72,9 +72,16 @@ struct vring_desc_state_split {
> > struct vring_desc *indir_desc; /* Indirect descriptor, if any. */
> > };
> >
> > +struct vring_packed_desc_indir {
> > + dma_addr_t addr; /* Descriptor Array DMA addr. */
> > + u32 len; /* Descriptor Array length. */
> > + u32 num;
> > + struct vring_packed_desc desc[];
> > +};
> > +
> > struct vring_desc_state_packed {
> > void *data; /* Data for callback. */
> > - struct vring_packed_desc *indir_desc; /* Indirect descriptor, if any. */
> > + struct vring_packed_desc_indir *indir_desc; /* Indirect descriptor, if any. */
> > u16 num; /* Descriptor list length. */
> > u16 last; /* The last desc state in a list. */
> > };
> > @@ -1249,10 +1256,13 @@ static void vring_unmap_desc_packed(const struct vring_virtqueue *vq,
> > DMA_FROM_DEVICE : DMA_TO_DEVICE);
> > }
> >
> > -static struct vring_packed_desc *alloc_indirect_packed(unsigned int total_sg,
> > +static struct vring_packed_desc_indir *alloc_indirect_packed(unsigned int total_sg,
> > gfp_t gfp)
> > {
> > - struct vring_packed_desc *desc;
> > + struct vring_packed_desc_indir *in_desc;
> > + u32 size;
> > +
> > + size = struct_size(in_desc, desc, total_sg);
> >
> > /*
> > * We require lowmem mappings for the descriptors because
> > @@ -1261,9 +1271,10 @@ static struct vring_packed_desc *alloc_indirect_packed(unsigned int total_sg,
> > */
> > gfp &= ~__GFP_HIGHMEM;
> >
> > - desc = kmalloc_array(total_sg, sizeof(struct vring_packed_desc), gfp);
> >
> > - return desc;
> > + in_desc = kmalloc(size, gfp);
> > +
> > + return in_desc;
> > }
> >
> > static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
> > @@ -1274,6 +1285,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
> > void *data,
> > gfp_t gfp)
> > {
> > + struct vring_packed_desc_indir *in_desc;
> > struct vring_packed_desc *desc;
> > struct scatterlist *sg;
> > unsigned int i, n, err_idx;
> > @@ -1281,10 +1293,12 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
> > dma_addr_t addr;
> >
> > head = vq->packed.next_avail_idx;
> > - desc = alloc_indirect_packed(total_sg, gfp);
> > - if (!desc)
> > + in_desc = alloc_indirect_packed(total_sg, gfp);
> > + if (!in_desc)
> > return -ENOMEM;
> >
> > + desc = in_desc->desc;
> > +
> > if (unlikely(vq->vq.num_free < 1)) {
> > pr_debug("Can't add buf len 1 - avail = 0\n");
> > kfree(desc);
> > @@ -1321,17 +1335,15 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
> > goto unmap_release;
> > }
> >
> > + in_desc->num = i;
> > + in_desc->addr = addr;
> > + in_desc->len = total_sg * sizeof(struct vring_packed_desc);
>
> It looks to me if we don't use dma_api we don't even need these steps?
YES
>
> > +
> > vq->packed.vring.desc[head].addr = cpu_to_le64(addr);
> > vq->packed.vring.desc[head].len = cpu_to_le32(total_sg *
> > sizeof(struct vring_packed_desc));
> > vq->packed.vring.desc[head].id = cpu_to_le16(id);
> >
> > - if (vring_need_unmap_buffer(vq)) {
> > - vq->packed.desc_extra[id].addr = addr;
> > - vq->packed.desc_extra[id].len = total_sg *
> > - sizeof(struct vring_packed_desc);
> > - }
> > -
> > vq->packed.desc_extra[id].flags = VRING_DESC_F_INDIRECT |
> > vq->packed.avail_used_flags;
> >
> > @@ -1362,7 +1374,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
> > /* Store token and indirect buffer state. */
> > vq->packed.desc_state[id].num = 1;
> > vq->packed.desc_state[id].data = data;
> > - vq->packed.desc_state[id].indir_desc = desc;
> > + vq->packed.desc_state[id].indir_desc = in_desc;
> > vq->packed.desc_state[id].last = id;
> >
> > vq->num_added += 1;
> > @@ -1381,7 +1393,7 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
> > vring_unmap_desc_packed(vq, &desc[i]);
> >
> > free_desc:
> > - kfree(desc);
> > + kfree(in_desc);
> >
> > END_USE(vq);
> > return -ENOMEM;
> > @@ -1595,7 +1607,6 @@ static void detach_buf_packed(struct vring_virtqueue *vq,
> > unsigned int id, void **ctx)
> > {
> > struct vring_desc_state_packed *state = NULL;
> > - struct vring_packed_desc *desc;
> > unsigned int i, curr;
> > u16 flags;
> >
> > @@ -1621,28 +1632,24 @@ static void detach_buf_packed(struct vring_virtqueue *vq,
> >
> > if (ctx)
> > *ctx = state->indir_desc;
> > +
>
> Unnecessary changes.
Could you say more?
You do not like this patch?
Thanks.
>
> Thanks
>
Powered by blists - more mailing lists