lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CACGkMEu=BC5eYoExaUqLp-QZFKq31BrGvvEy0xvAwfCg28690Q@mail.gmail.com>
Date: Tue, 1 Jul 2025 15:25:26 +0800
From: Jason Wang <jasowang@...hat.com>
To: "Michael S. Tsirkin" <mst@...hat.com>
Cc: xuanzhuo@...ux.alibaba.com, eperezma@...hat.com, 
	virtualization@...ts.linux.dev, linux-kernel@...r.kernel.org
Subject: Re: [PATCH V3 14/19] virtio_ring: determine descriptor flags at one time

On Tue, Jul 1, 2025 at 2:42 PM Michael S. Tsirkin <mst@...hat.com> wrote:
>
> On Mon, Jun 16, 2025 at 04:25:12PM +0800, Jason Wang wrote:
> > Let's determine the last descriptor by counting the number of sg. This
> > would be consistent with packed virtqueue implementation and ease the
> > future in-order implementation.
> >
> > Reviewed-by: Xuan Zhuo <xuanzhuo@...ux.alibaba.com>
> > Signed-off-by: Jason Wang <jasowang@...hat.com>
> > ---
> >  drivers/virtio/virtio_ring.c | 25 +++++++++++++------------
> >  1 file changed, 13 insertions(+), 12 deletions(-)
> >
> > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
> > index af32d1a1a1db..d5e4d4cd2487 100644
> > --- a/drivers/virtio/virtio_ring.c
> > +++ b/drivers/virtio/virtio_ring.c
> > @@ -570,7 +570,7 @@ static inline int virtqueue_add_split(struct vring_virtqueue *vq,
> >       struct vring_desc_extra *extra;
> >       struct scatterlist *sg;
> >       struct vring_desc *desc;
> > -     unsigned int i, n, avail, descs_used, prev, err_idx;
> > +     unsigned int i, n, c, avail, descs_used, err_idx;
> >       int head;
> >       bool indirect;
> >
> > @@ -626,46 +626,47 @@ static inline int virtqueue_add_split(struct vring_virtqueue *vq,
> >               return -ENOSPC;
> >       }
> >
> > +     c = 0;
>
> initialize at point of declaration?

Fine.

>
> >       for (n = 0; n < out_sgs; n++) {
> > +             sg = sgs[n];
> >               for (sg = sgs[n]; sg; sg = sg_next(sg)) {
> >                       dma_addr_t addr;
> >                       u32 len;
> > +                     u16 flags = 0;
> >
> >                       if (vring_map_one_sg(vq, sg, DMA_TO_DEVICE, &addr, &len, premapped))
> >                               goto unmap_release;
> >
> > -                     prev = i;
> > +                     if (++c != total_sg)
> > +                             flags = VRING_DESC_F_NEXT;
> > +
>
> Don't like it how the logic is split.
> flags isn't used before that.
> So I prefer:
>
>         flags = ++c == total_sg ? 0 : VRING_DESC_F_NEXT;
>
> and at that point, we do not really need flags anymore:
>
>
> >                       /* Note that we trust indirect descriptor
> >                        * table since it use stream DMA mapping.
> >                        */
> >                       i = virtqueue_add_desc_split(vq, desc, extra, i, addr, len,
> > -                                                  VRING_DESC_F_NEXT,
> > +                                                  flags,
>
> So just:
>
>
>         i = virtqueue_add_desc_split(vq, desc, extra, i, addr, len,
>                                      ++c == total_sg ? 0 : VRING_DESC_F_NEXT,
>
> here and we are done.
>
>
> >                                                    premapped);
> >               }
> >       }
> >       for (; n < (out_sgs + in_sgs); n++) {
> >               for (sg = sgs[n]; sg; sg = sg_next(sg)) {
> > +                     u16 flags = VRING_DESC_F_WRITE;
> >                       dma_addr_t addr;
> >                       u32 len;
> >
> >                       if (vring_map_one_sg(vq, sg, DMA_FROM_DEVICE, &addr, &len, premapped))
> >                               goto unmap_release;
> >
> > -                     prev = i;
> > +                     if (++c != total_sg)
> > +                             flags |= VRING_DESC_F_NEXT;
> > +
>
> Don't like it that above it's "=" here it is "|=".
> And flags isn't used before that.
> So I prefer:
>
>         flags = ++c == total_sg ? VRING_DESC_F_WRITE : VRING_DESC_F_WRITE | VRING_DESC_F_NEXT;
>
> and again we don't really need the variable:
>
>
> >                       /* Note that we trust indirect descriptor
> >                        * table since it use stream DMA mapping.
> >                        */
> >                       i = virtqueue_add_desc_split(vq, desc, extra, i, addr, len,
> > -                                                  VRING_DESC_F_NEXT |
> > -                                                  VRING_DESC_F_WRITE,
>
>
> so just:
>
>                 i = virtqueue_add_desc_split(vq, desc, extra, i, addr, len,
>                                              (++c == total_sg ? 0 : VRING_DESC_F_NEXT) |
>                                              VRING_DESC_F_WRITE,
>
>
> is clearer, and the patch smaller.

Right, I just copy the logic of packed.

Let me do that for both split and packed for the next version.

Thanks

>
>
>
> > -                                                  premapped);
> > +                                                  flags, premapped);
> >               }
> >       }
> > -     /* Last one doesn't continue. */
> > -     desc[prev].flags &= cpu_to_virtio16(vq->vq.vdev, ~VRING_DESC_F_NEXT);
> > -     if (!indirect && vring_need_unmap_buffer(vq, &extra[prev]))
> > -             vq->split.desc_extra[prev & (vq->split.vring.num - 1)].flags &=
> > -                     ~VRING_DESC_F_NEXT;
> >
> >       if (indirect) {
> >               /* Now that the indirect table is filled in, map it. */
> > --
> > 2.34.1
>


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ