Skip to contentSkip to conversation

virtio_ring: mark ring unused on error

PATCH In review Michael S. Tsirkin 3 participants 3 messages Jan 6, 2022 – Jan 7, 2022 virtio core

lore
Share & tools
lore

Michael S. Tsirkin

author maintainer
#0 lore raw

PATCH 1/1 virtio_ring: mark ring unused on error

A recently added error path does not mark ring unused when exiting on OOM, which will lead to BUG on the next entry in debug builds.

TODO: refactor code so we have START_USE and END_USE in the same function.

Fixes fc6d70f40b3d ("virtio_ring: check desc == NULL when using indirect with packed")
Cc "Xuan Zhuo" <[email protected]>
Cc Jiasheng Jiang <[email protected]>
---
 drivers/virtio/virtio_ring.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/virtio/virtio_ring.c +3 -1
index 028b05d44546..962f1477b1fa 100644
@@ -1197,8 +1197,10 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
 	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)
+		if (err != -ENOMEM) {
+			END_USE(vq);
 			return err;
+		}
 
 		/* fall back on direct */
 	}
Signature · 1 line
MST
reviewer Reviewed-by on v1 1/1
#1 lore raw
Quoted 9 lines · Michael S. Tsirkin

A recently added error path does not mark ring unused when exiting on OOM, which will lead to BUG on the next entry in debug builds.

TODO: refactor code so we have START_USE and END_USE in the same function.

Fixes fc6d70f40b3d ("virtio_ring: check desc == NULL when using indirect with packed")
Cc "Xuan Zhuo" <[email protected]>
Cc Jiasheng Jiang <[email protected]>

LGTM

Quoted 21 lines
---
 drivers/virtio/virtio_ring.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/virtio/virtio_ring.c +3 -2
index 028b05d44546..962f1477b1fa 100644
@@ -1197,8 +1197,10 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
 	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)
+		if (err != -ENOMEM) {
+			END_USE(vq);
 			return err;
+		}
 
 		/* fall back on direct */
 	}
--
Quoted 2 lines

MST

_______________________________________________
Virtualization mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/virtualization

Acked-by on v1 1/1
#2 lore raw
In reply to Michael S. Tsirkin
Quoted 10 lines · Michael S. Tsirkin

A recently added error path does not mark ring unused when exiting on OOM, which will lead to BUG on the next entry in debug builds.

TODO: refactor code so we have START_USE and END_USE in the same function.

Fixes fc6d70f40b3d ("virtio_ring: check desc == NULL when using indirect with packed")
Cc "Xuan Zhuo" <[email protected]>
Cc Jiasheng Jiang <[email protected]>
Quoted 23 lines
---
 drivers/virtio/virtio_ring.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/virtio/virtio_ring.c +3 -2
index 028b05d44546..962f1477b1fa 100644
@@ -1197,8 +1197,10 @@ static inline int virtqueue_add_packed(struct virtqueue *_vq,
        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)
+               if (err != -ENOMEM) {
+                       END_USE(vq);
                        return err;
+               }
 
                /* fall back on direct */
        }
--

MST