All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v7 0/2] virtio_ring: check desc == NULL when using indirect with packed
@ 2021-10-25  1:56 Xuan Zhuo
  2021-10-25  1:56 ` [PATCH v7 1/2] virtio_ring: make virtqueue_add_indirect_packed prettier Xuan Zhuo
  2021-10-25  1:56 ` [PATCH v7 2/2] virtio_ring: check desc == NULL when using indirect with packed Xuan Zhuo
  0 siblings, 2 replies; 4+ messages in thread
From: Xuan Zhuo @ 2021-10-25  1:56 UTC (permalink / raw)
  To: sfr; +Cc: virtualization, David S. Miller, Tiwei Bie, Michael S. Tsirkin

Fix theoretical issues in virtio_ring.

v7:
    Set the SHA1 length of the fixes tag to 12

v6:
    -EAGAIN => -ENOMEM

v5:
    Update commit message.

v4:
    Inside the #2 patch, virtqueue_add_indirect_packed() return -EAGAIN when
    desc == NULL.

v3:
    Update commit message of the #1 patch.

v2:
    Separate the style fix into a single patch.


Xuan Zhuo (2):
  virtio_ring: make virtqueue_add_indirect_packed prettier
  virtio_ring: check desc == NULL when using indirect with packed

 drivers/virtio/virtio_ring.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

--
2.31.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v7 1/2] virtio_ring: make virtqueue_add_indirect_packed prettier
  2021-10-25  1:56 [PATCH v7 0/2] virtio_ring: check desc == NULL when using indirect with packed Xuan Zhuo
@ 2021-10-25  1:56 ` Xuan Zhuo
  2021-10-25  1:56 ` [PATCH v7 2/2] virtio_ring: check desc == NULL when using indirect with packed Xuan Zhuo
  1 sibling, 0 replies; 4+ messages in thread
From: Xuan Zhuo @ 2021-10-25  1:56 UTC (permalink / raw)
  To: sfr; +Cc: virtualization, David S. Miller, Tiwei Bie, Michael S. Tsirkin

Align the arguments of virtqueue_add_indirect_packed() to the open ( to
make it look prettier.

Signed-off-by: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Acked-by: Jason Wang <jasowang@redhat.com>
---
 drivers/virtio/virtio_ring.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c
index dd95dfd85e98..91a46c4da87d 100644
--- a/drivers/virtio/virtio_ring.c
+++ b/drivers/virtio/virtio_ring.c
@@ -1050,12 +1050,12 @@ static struct vring_packed_desc *alloc_indirect_packed(unsigned int total_sg,
 }
 
 static int virtqueue_add_indirect_packed(struct vring_virtqueue *vq,
-				       struct scatterlist *sgs[],
-				       unsigned int total_sg,
-				       unsigned int out_sgs,
-				       unsigned int in_sgs,
-				       void *data,
-				       gfp_t gfp)
+					 struct scatterlist *sgs[],
+					 unsigned int total_sg,
+					 unsigned int out_sgs,
+					 unsigned int in_sgs,
+					 void *data,
+					 gfp_t gfp)
 {
 	struct vring_packed_desc *desc;
 	struct scatterlist *sg;
-- 
2.31.0

_______________________________________________
Virtualization mailing list
Virtualization@lists.linux-foundation.org
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v7 2/2] virtio_ring: check desc == NULL when using indirect with packed
  2021-10-25  1:56 [PATCH v7 0/2] virtio_ring: check desc == NULL when using indirect with packed Xuan Zhuo
  2021-10-25  1:56 ` [PATCH v7 1/2] virtio_ring: make virtqueue_add_indirect_packed prettier Xuan Zhuo
@ 2021-10-25  1:56 ` Xuan Zhuo
  2021-10-25  2:30   ` Jason Wang
  1 sibling, 1 reply; 4+ messages in thread
From: Xuan Zhuo @ 2021-10-25  1:56 UTC (permalink / raw)
  To: sfr; +Cc: virtualization, David S. Miller, Tiwei Bie, Michael S. Tsirkin

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>
---
 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

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v7 2/2] virtio_ring: check desc == NULL when using indirect with packed
  2021-10-25  1:56 ` [PATCH v7 2/2] virtio_ring: check desc == NULL when using indirect with packed Xuan Zhuo
@ 2021-10-25  2:30   ` Jason Wang
  0 siblings, 0 replies; 4+ messages in thread
From: Jason Wang @ 2021-10-25  2:30 UTC (permalink / raw)
  To: Xuan Zhuo
  Cc: sfr, virtualization, David S. Miller, Tiwei Bie, Michael S. Tsirkin

On Mon, Oct 25, 2021 at 9:56 AM Xuan Zhuo <xuanzhuo@linux.alibaba.com> 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 <jasowang@redhat.com>

>  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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-10-25  2:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-25  1:56 [PATCH v7 0/2] virtio_ring: check desc == NULL when using indirect with packed Xuan Zhuo
2021-10-25  1:56 ` [PATCH v7 1/2] virtio_ring: make virtqueue_add_indirect_packed prettier Xuan Zhuo
2021-10-25  1:56 ` [PATCH v7 2/2] virtio_ring: check desc == NULL when using indirect with packed Xuan Zhuo
2021-10-25  2:30   ` Jason Wang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.