Skip to contentSkip to conversation

drm/virtio: fix vq wait_event condition

PATCH In review Gerd Hoffmann 3 participants 7 messages Apr 3, 2018 – Apr 23, 2018

Subsystems (5)
lore
Share & tools
lore

Gerd Hoffmann

author maintainer
#0 lore raw

PATCH 1/1 drm/virtio: fix vq wait_event condition

Wait until we have enough space in the virt queue to actually queue up our request. Avoids the guest spinning in case we have a non-zero amount of free entries but not enough for the request.

---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_vq.c +2 -2
index 48e4f1df6e..020070d483 100644
@@ -293,7 +293,7 @@ static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
 	ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC);
 	if (ret == -ENOSPC) {
 		spin_unlock(&vgdev->ctrlq.qlock);
-		wait_event(vgdev->ctrlq.ack_queue, vq->num_free);
+		wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= outcnt + incnt);
 		spin_lock(&vgdev->ctrlq.qlock);
 		goto retry;
 	} else {
@@ -368,7 +368,7 @@ static int virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev,
 	ret = virtqueue_add_sgs(vq, sgs, outcnt, 0, vbuf, GFP_ATOMIC);
 	if (ret == -ENOSPC) {
 		spin_unlock(&vgdev->cursorq.qlock);
-		wait_event(vgdev->cursorq.ack_queue, vq->num_free);
+		wait_event(vgdev->cursorq.ack_queue, vq->num_free >= outcnt);
 		spin_lock(&vgdev->cursorq.qlock);
 		goto retry;
 	} else {
Signature · 1 line
2.9.3
#1 lore raw

Hi.

[This is an automated email]

This commit has been processed because it contains a -stable tag. The stable tag indicates that it's relevant for the following trees: all

The bot has also determined it's probably a bug fixing patch. (score: 97.5752)

The bot has tested the following trees: v4.15.15, v4.14.32, v4.9.92, v4.4.126,

v4.15.15: Build OK!
v4.14.32: Build OK!
v4.9.92: Build OK!
v4.4.126: Build OK!

Please let us know if you'd like to have this patch included in a stable tree.

author maintainer
#2 lore raw
In reply to Gerd Hoffmann
Quoted 3 lines · Gerd Hoffmann

Wait until we have enough space in the virt queue to actually queue up our request. Avoids the guest spinning in case we have a non-zero amount of free entries but not enough for the request.

Ping airlied, can you please either pick it up or review so I can commit myself?

thanks,
Gerd

Quoted 32 lines
---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_vq.c +2 -2
index 48e4f1df6e..020070d483 100644
@@ -293,7 +293,7 @@ static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
 	ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC);
 	if (ret == -ENOSPC) {
 		spin_unlock(&vgdev->ctrlq.qlock);
-		wait_event(vgdev->ctrlq.ack_queue, vq->num_free);
+		wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= outcnt + incnt);
 		spin_lock(&vgdev->ctrlq.qlock);
 		goto retry;
 	} else {
@@ -368,7 +368,7 @@ static int virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev,
 	ret = virtqueue_add_sgs(vq, sgs, outcnt, 0, vbuf, GFP_ATOMIC);
 	if (ret == -ENOSPC) {
 		spin_unlock(&vgdev->cursorq.qlock);
-		wait_event(vgdev->cursorq.ack_queue, vq->num_free);
+		wait_event(vgdev->cursorq.ack_queue, vq->num_free >= outcnt);
 		spin_lock(&vgdev->cursorq.qlock);
 		goto retry;
 	} else {
Signature · 1 line
2.9.3
author maintainer
#3 lore raw
In reply to Gerd Hoffmann
Quoted 3 lines · Gerd Hoffmann

Wait until we have enough space in the virt queue to actually queue up our request. Avoids the guest spinning in case we have a non-zero amount of free entries but not enough for the request.

Ping airlied, can you please either pick it up or review so I can commit myself?

thanks,
Gerd

Quoted 32 lines
---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_vq.c +2 -2
index 48e4f1df6e..020070d483 100644
@@ -293,7 +293,7 @@ static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
 	ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC);
 	if (ret == -ENOSPC) {
 		spin_unlock(&vgdev->ctrlq.qlock);
-		wait_event(vgdev->ctrlq.ack_queue, vq->num_free);
+		wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= outcnt + incnt);
 		spin_lock(&vgdev->ctrlq.qlock);
 		goto retry;
 	} else {
@@ -368,7 +368,7 @@ static int virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev,
 	ret = virtqueue_add_sgs(vq, sgs, outcnt, 0, vbuf, GFP_ATOMIC);
 	if (ret == -ENOSPC) {
 		spin_unlock(&vgdev->cursorq.qlock);
-		wait_event(vgdev->cursorq.ack_queue, vq->num_free);
+		wait_event(vgdev->cursorq.ack_queue, vq->num_free >= outcnt);
 		spin_lock(&vgdev->cursorq.qlock);
 		goto retry;
 	} else {
Signature · 1 line
2.9.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer Reviewed-by
#4 lore raw
Quoted 48 lines · On Fri., 20 Apr. 2018, 17:23 Gerd Hoffmann, <[email protected]> wrote:
Quoted 3 lines · Gerd Hoffmann

Wait until we have enough space in the virt queue to actually queue up our request. Avoids the guest spinning in case we have a non-zero amount of free entries but not enough for the request.

Ping airlied, can you please either pick it up or review so I can commit myself?

thanks,
Gerd

Review

Quoted 8 lines
---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/virtio/virtgpu_vq.c

drivers/gpu/drm/virtio/virtgpu_vq.c static int

Quoted 4 lines

index 48e4f1df6e..020070d483 100644

drivers/gpu/drm/virtio/virtgpu_vq.c +0 -0
@@ -293,7 +293,7 @@ static int

virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,

drivers/gpu/drm/virtio/virtgpu_vq.c static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,

Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_vq.c +1 -1
      ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC);
      if (ret == -ENOSPC) {
              spin_unlock(&vgdev->ctrlq.qlock);
-             wait_event(vgdev->ctrlq.ack_queue, vq->num_free);
+             wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= outcnt

+ incnt);

drivers/gpu/drm/virtio/virtgpu_vq.c static int virtio_gpu_queue_cursor(struct

Quoted 4 lines
drivers/gpu/drm/virtio/virtgpu_vq.c +0 -0
              spin_lock(&vgdev->ctrlq.qlock);
              goto retry;
      } else {
@@ -368,7 +368,7 @@ static int virtio_gpu_queue_cursor(struct

virtio_gpu_device *vgdev,

drivers/gpu/drm/virtio/virtgpu_vq.c static int virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev,

Quoted 5 lines
drivers/gpu/drm/virtio/virtgpu_vq.c +1 -1
      ret = virtqueue_add_sgs(vq, sgs, outcnt, 0, vbuf, GFP_ATOMIC);
      if (ret == -ENOSPC) {
              spin_unlock(&vgdev->cursorq.qlock);
-             wait_event(vgdev->cursorq.ack_queue, vq->num_free);
+             wait_event(vgdev->cursorq.ack_queue, vq->num_free >=

outcnt);

Quoted 6 lines
drivers/gpu/drm/virtio/virtgpu_vq.c +0 -1
              spin_lock(&vgdev->cursorq.qlock);
              goto retry;
      } else {
--

2.9.3

Quoted 5 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

maintainer Reviewed-by
#5 lore raw
In reply to Gerd Hoffmann
Quoted 7 lines · Gerd Hoffmann
Quoted 3 lines · Gerd Hoffmann

Wait until we have enough space in the virt queue to actually queue up our request. Avoids the guest spinning in case we have a non-zero amount of free entries but not enough for the request.

Ping airlied, can you please either pick it up or review so I can commit myself?

Just in case it got lost from my phone,

Quoted 40 lines

thanks,
Gerd

Quoted 30 lines
---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_vq.c +2 -3
index 48e4f1df6e..020070d483 100644
@@ -293,7 +293,7 @@ static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
      ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC);
      if (ret == -ENOSPC) {
              spin_unlock(&vgdev->ctrlq.qlock);
-             wait_event(vgdev->ctrlq.ack_queue, vq->num_free);
+             wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= outcnt + incnt);
              spin_lock(&vgdev->ctrlq.qlock);
              goto retry;
      } else {
@@ -368,7 +368,7 @@ static int virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev,
      ret = virtqueue_add_sgs(vq, sgs, outcnt, 0, vbuf, GFP_ATOMIC);
      if (ret == -ENOSPC) {
              spin_unlock(&vgdev->cursorq.qlock);
-             wait_event(vgdev->cursorq.ack_queue, vq->num_free);
+             wait_event(vgdev->cursorq.ack_queue, vq->num_free >= outcnt);
              spin_lock(&vgdev->cursorq.qlock);
              goto retry;
      } else {
--
Quoted 2 lines

2.9.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer Reviewed-by
#6 lore raw
In reply to Gerd Hoffmann
Quoted 7 lines · Gerd Hoffmann
Quoted 3 lines · Gerd Hoffmann

Wait until we have enough space in the virt queue to actually queue up our request. Avoids the guest spinning in case we have a non-zero amount of free entries but not enough for the request.

Ping airlied, can you please either pick it up or review so I can commit myself?

Just in case it got lost from my phone,

Quoted 40 lines

thanks,
Gerd

Quoted 30 lines
---
 drivers/gpu/drm/virtio/virtgpu_vq.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/gpu/drm/virtio/virtgpu_vq.c +2 -3
index 48e4f1df6e..020070d483 100644
@@ -293,7 +293,7 @@ static int virtio_gpu_queue_ctrl_buffer_locked(struct virtio_gpu_device *vgdev,
      ret = virtqueue_add_sgs(vq, sgs, outcnt, incnt, vbuf, GFP_ATOMIC);
      if (ret == -ENOSPC) {
              spin_unlock(&vgdev->ctrlq.qlock);
-             wait_event(vgdev->ctrlq.ack_queue, vq->num_free);
+             wait_event(vgdev->ctrlq.ack_queue, vq->num_free >= outcnt + incnt);
              spin_lock(&vgdev->ctrlq.qlock);
              goto retry;
      } else {
@@ -368,7 +368,7 @@ static int virtio_gpu_queue_cursor(struct virtio_gpu_device *vgdev,
      ret = virtqueue_add_sgs(vq, sgs, outcnt, 0, vbuf, GFP_ATOMIC);
      if (ret == -ENOSPC) {
              spin_unlock(&vgdev->cursorq.qlock);
-             wait_event(vgdev->cursorq.ack_queue, vq->num_free);
+             wait_event(vgdev->cursorq.ack_queue, vq->num_free >= outcnt);
              spin_lock(&vgdev->cursorq.qlock);
              goto retry;
      } else {
--
Quoted 2 lines

2.9.3

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel