On Tue, 7 Mar 2023 14:43:45 +0800, Jason Wang <jasowang@xxxxxxxxxx> wrote: > On Thu, Mar 2, 2023 at 7:59 PM Xuan Zhuo <xuanzhuo@xxxxxxxxxxxxxxxxx> wrote: > > > > Separating the logic of allocating indirect desc and checking queue > > status to the upper layer function. > > Note that it looks to me it's not logic separation but a simple moving. I will fix the commit log. Thanks. > > > > > > The proposal of this is convenient to refactor virtqueue_add_packed() > > for premapped. > > > > Signed-off-by: Xuan Zhuo <xuanzhuo@xxxxxxxxxxxxxxxxx> > > --- > > drivers/virtio/virtio_ring.c | 29 ++++++++++++----------------- > > 1 file changed, 12 insertions(+), 17 deletions(-) > > > > diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c > > index 5b186ce73d35..178edf1171e2 100644 > > --- a/drivers/virtio/virtio_ring.c > > +++ b/drivers/virtio/virtio_ring.c > > @@ -1348,25 +1348,14 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq, > > unsigned int out_sgs, > > unsigned int in_sgs, > > void *data, > > - gfp_t gfp) > > + struct vring_packed_desc *desc) > > { > > - struct vring_packed_desc *desc; > > struct scatterlist *sg; > > unsigned int i, n, err_idx; > > u16 head, id; > > dma_addr_t addr; > > > > head = vq->packed.next_avail_idx; > > - desc = alloc_indirect_packed(total_sg, gfp); > > - if (!desc) > > - return -ENOMEM; > > - > > - if (unlikely(vq->vq.num_free < 1)) { > > - pr_debug("Can't add buf len 1 - avail = 0\n"); > > - kfree(desc); > > - END_USE(vq); > > - return -ENOSPC; > > - } > > > > i = 0; > > id = vq->free_head; > > @@ -1488,11 +1477,17 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq, > > BUG_ON(total_sg == 0); > > > > if (virtqueue_use_indirect(vq, total_sg)) { > > - err = virtqueue_add_indirect_packed(vq, sgs, total_sg, out_sgs, > > - in_sgs, data, gfp); > > - if (err != -ENOMEM) { > > - END_USE(vq); > > - return err; > > + desc = alloc_indirect_packed(total_sg, gfp); > > + if (desc) { > > + if (unlikely(vq->vq.num_free < 1)) { > > + pr_debug("Can't add buf len 1 - avail = 0\n"); > > + kfree(desc); > > + END_USE(vq); > > + return -ENOSPC; > > + } > > + > > + return virtqueue_add_indirect_packed(vq, sgs, total_sg, out_sgs, > > + in_sgs, data, desc); > > } > > > > /* fall back on direct */ > > -- > > 2.32.0.3.g01195cf9f > > > _______________________________________________ Virtualization mailing list Virtualization@xxxxxxxxxxxxxxxxxxxxxxxxxx https://lists.linuxfoundation.org/mailman/listinfo/virtualization