diff mbox

s390-ccw.img: Fix waiting for virtio processing.

Message ID 1377849572-42883-2-git-send-email-cornelia.huck@de.ibm.com
State New
Headers show

Commit Message

Cornelia Huck Aug. 30, 2013, 7:59 a.m. UTC
The guest side must not manipulate the index for the used buffers. Instead,
remember the state of the used buffer locally and wait until it has moved.

Signed-off-by: Cornelia Huck <cornelia.huck@de.ibm.com>
---
 pc-bios/s390-ccw/virtio.c | 10 +++++++---
 pc-bios/s390-ccw/virtio.h |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)

Comments

Paolo Bonzini Aug. 30, 2013, 8:38 a.m. UTC | #1
Il 30/08/2013 09:59, Cornelia Huck ha scritto:
> +    vr->used_idx = vr->used->idx;
> +    /*
> +     * Wait until the used index has moved.
> +     * Note: This is only race-free if the host doesn't start draining
> +     * the queue out of its own accord.
> +     */
> +    while (vr->used->idx == vr->used_idx) {

Can you instead initialize vr->used_idx in virtio_setup_block, and then
update it _after_ the while loop?  This would be race-free.

Paolo
diff mbox

Patch

diff --git a/pc-bios/s390-ccw/virtio.c b/pc-bios/s390-ccw/virtio.c
index 49f2d29..03f6fde 100644
--- a/pc-bios/s390-ccw/virtio.c
+++ b/pc-bios/s390-ccw/virtio.c
@@ -150,8 +150,6 @@  static void vring_send_buf(struct vring *vr, void *p, int len, int flags)
     if (!(flags & VRING_DESC_F_NEXT)) {
         vr->avail->idx++;
     }
-
-    vr->used->idx = vr->next_idx;
 }
 
 static u64 get_clock(void)
@@ -180,7 +178,13 @@  static int vring_wait_reply(struct vring *vr, int timeout)
     struct subchannel_id schid = vr->schid;
     int r = 0;
 
-    while (vr->used->idx == vr->next_idx) {
+    vr->used_idx = vr->used->idx;
+    /*
+     * Wait until the used index has moved.
+     * Note: This is only race-free if the host doesn't start draining
+     * the queue out of its own accord.
+     */
+    while (vr->used->idx == vr->used_idx) {
         vring_notify(schid);
         if (timeout && (get_second() >= target_second)) {
             r = 1;
diff --git a/pc-bios/s390-ccw/virtio.h b/pc-bios/s390-ccw/virtio.h
index 86fdd57..772a63f 100644
--- a/pc-bios/s390-ccw/virtio.h
+++ b/pc-bios/s390-ccw/virtio.h
@@ -115,6 +115,7 @@  struct vring_used {
 struct vring {
     unsigned int num;
     int next_idx;
+    int used_idx;
     struct vring_desc *desc;
     struct vring_avail *avail;
     struct vring_used *used;