Thread (4 messages) flat view 4 messages, 2 authors, 2021-10-25

Re: [PATCH v7 2/2] virtio_ring: check desc == NULL when using indirect with packed

From: Jason Wang <hidden>
Date: 2021-10-25 02:31:19

On Mon, Oct 25, 2021 at 9:56 AM Xuan Zhuo [off-list ref] wrote:
When using indirect with packed, we don't check for allocation failures.
This patch checks that and fall back on direct.

Fixes: 1ce9e6055fa0 ("virtio_ring: introduce packed ring support")
Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
---
Acked-by: Jason Wang <redacted>
quoted hunk ↗ jump to hunk
 drivers/virtio/virtio_ring.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index 91a46c4da87d..bc92a2faa28f 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -1065,6 +1065,8 @@ static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,

        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");
@@ -1176,6 +1178,7 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
        unsigned int i, n, c, descs_used, err_idx;
        __le16 head_flags, flags;
        u16 head, id, prev, curr, avail_used_flags;
+       int err;

        START_USE(vq);
@@ -1191,9 +1194,14 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,

        BUG_ON(total_sg == 0);

-       if (virtqueue_use_indirect(_vq, total_sg))
-               return virtqueue_add_indirect_packed(vq, sgs, total_sg,
-                               out_sgs, in_sgs, data, gfp);
+       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)
+                       return err;
+
+               /* fall back on direct */
+       }

        head = vq->packed.next_avail_idx;
        avail_used_flags = vq->packed.avail_used_flags;
--
2.31.0
_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help