Skip to contentSkip to conversation

virtio: fix descriptor counting in virtqueue_pop

PATCH In review Wolfgang Bumiller 4 participants 4 messages Sep 20, 2017 – Nov 10, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 virtio: fix descriptor counting in virtqueue_pop

While changing the s/g list allocation, commit 3b3b0628 also changed the descriptor counting to count iovec entries as split by cpu_physical_memory_map(). Previously only the actual descriptor entries were counted and the split into the iovec happened afterwards in virtqueue_map(). Count the entries again instead to avoid erroneous "Looped descriptor" errors.

Fixes 3b3b0628217e ("virtio: slim down allocation of VirtQueueElements")
---
 hw/virtio/virtio.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/virtio/virtio.c +3 -3
index 890b4d7eb7..33bb770177 100644
@@ -834,7 +834,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
     int64_t len;
     VirtIODevice *vdev = vq->vdev;
     VirtQueueElement *elem = NULL;
-    unsigned out_num, in_num;
+    unsigned out_num, in_num, elem_entries;
     hwaddr addr[VIRTQUEUE_MAX_SIZE];
     struct iovec iov[VIRTQUEUE_MAX_SIZE];
     VRingDesc desc;
@@ -852,7 +852,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
     smp_rmb();
 
     /* When we start there are none of either input nor output. */
-    out_num = in_num = 0;
+    out_num = in_num = elem_entries = 0;
 
     max = vq->vring.num;
 
@@ -922,7 +922,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz)
         }
 
         /* If we've got too many, that implies a descriptor loop. */
-        if ((in_num + out_num) > max) {
+        if (++elem_entries > max) {
             virtio_error(vdev, "Looped descriptor");
             goto err_undo_map;
         }
Signature · 1 line
2.11.0
#1 lore raw

Hi,

has somebody reviewed this patch ?

I'm also able de reproduce the vm crash like the proxmox user. This patch is fixing it for me too.

Regards,

Alexandre

----- Mail original -----
De: "Wolfgang Bumiller" <[email protected]>
À: "qemu-devel" <[email protected]>
Cc: "pbonzini" <[email protected]>, "Michael S. Tsirkin" <[email protected]> Envoyé: Mercredi 20 Septembre 2017 08:09:33
Objet: [Qemu-devel] [PATCH] virtio: fix descriptor counting in virtqueue_pop

While changing the s/g list allocation, commit 3b3b0628 also changed the descriptor counting to count iovec entries as split by cpu_physical_memory_map(). Previously only the actual descriptor entries were counted and the split into the iovec happened afterwards in virtqueue_map(). Count the entries again instead to avoid erroneous "Looped descriptor" errors.

Fixes 3b3b0628217e ("virtio: slim down allocation of VirtQueueElements")

---
hw/virtio/virtio.c | 6 +++---

1 file changed, 3 insertions(+), 3 deletions(-) 
hw/virtio/virtio.c +0 -0
index 890b4d7eb7..33bb770177 100644 
@@ -834,7 +834,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) 

int64_t len;
VirtIODevice *vdev = vq->vdev;
VirtQueueElement *elem = NULL;
- unsigned out_num, in_num;
+ unsigned out_num, in_num, elem_entries;
hwaddr addr[VIRTQUEUE_MAX_SIZE];
struct iovec iov[VIRTQUEUE_MAX_SIZE];
VRingDesc desc;
@@ -852,7 +852,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) smp_rmb();

/* When we start there are none of either input nor output. */
- out_num = in_num = 0;
+ out_num = in_num = elem_entries = 0;

max = vq->vring.num;

@@ -922,7 +922,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) }

/* If we've got too many, that implies a descriptor loop. */
- if ((in_num + out_num) > max) {
+ if (++elem_entries > max) {
virtio_error(vdev, "Looped descriptor");
goto err_undo_map;
}

Signature · 1 line
2.11.0 
#2 lore raw
Quoted 6 lines · Alexandre DERUMIER

Hi,

has somebody reviewed this patch ?

I'm also able de reproduce the vm crash like the proxmox user. This patch is fixing it for me too.

This patch should go through Michael Tsirkin's tree. I have pinged him separately in case this email thread got buried in his inbox.

Stefan

Quoted 64 lines

Regards,

Alexandre

----- Mail original -----
De: "Wolfgang Bumiller" <[email protected]>
À: "qemu-devel" <[email protected]>
Cc: "pbonzini" <[email protected]>, "Michael S. Tsirkin" <[email protected]> Envoyé: Mercredi 20 Septembre 2017 08:09:33
Objet: [Qemu-devel] [PATCH] virtio: fix descriptor counting in virtqueue_pop

While changing the s/g list allocation, commit 3b3b0628 also changed the descriptor counting to count iovec entries as split by cpu_physical_memory_map(). Previously only the actual descriptor entries were counted and the split into the iovec happened afterwards in virtqueue_map(). Count the entries again instead to avoid erroneous "Looped descriptor" errors.

Fixes 3b3b0628217e ("virtio: slim down allocation of VirtQueueElements")

---
hw/virtio/virtio.c | 6 +++---

1 file changed, 3 insertions(+), 3 deletions(-) 
hw/virtio/virtio.c +3 -3
index 890b4d7eb7..33bb770177 100644 
@@ -834,7 +834,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) 
 int64_t len; 
 VirtIODevice *vdev = vq->vdev; 
 VirtQueueElement *elem = NULL; 
- unsigned out_num, in_num; 
+ unsigned out_num, in_num, elem_entries; 
 hwaddr addr[VIRTQUEUE_MAX_SIZE]; 
 struct iovec iov[VIRTQUEUE_MAX_SIZE]; 
 VRingDesc desc; 
@@ -852,7 +852,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) 
 smp_rmb(); 
 
 /* When we start there are none of either input nor output. */ 
- out_num = in_num = 0; 
+ out_num = in_num = elem_entries = 0; 
 
 max = vq->vring.num; 
 
@@ -922,7 +922,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) 
 } 
 
 /* If we've got too many, that implies a descriptor loop. */ 
- if ((in_num + out_num) > max) { 
+ if (++elem_entries > max) { 
 virtio_error(vdev, "Looped descriptor"); 
 goto err_undo_map; 
 } 
Signature · 1 line
2.11.0 
#3 lore raw
Quoted 5 lines · Stefan Hajnoczi
Quoted 4 lines · Alexandre DERUMIER

Hi,

has somebody reviewed this patch ?

Quoted 7 lines
Quoted 2 lines

I'm also able de reproduce the vm crash like the proxmox user. This patch is fixing it for me too.

This patch should go through Michael Tsirkin's tree. I have pinged him separately in case this email thread got buried in his inbox.

Stefan

Isn't this upstream?
I see it as commit 37ef70be6af7e9f2a6f852c68f74bd98dac2664b there.

Quoted 64 lines
Quoted 64 lines

Regards,

Alexandre

----- Mail original -----
De: "Wolfgang Bumiller" <[email protected]>
À: "qemu-devel" <[email protected]>
Cc: "pbonzini" <[email protected]>, "Michael S. Tsirkin" <[email protected]> Envoyé: Mercredi 20 Septembre 2017 08:09:33
Objet: [Qemu-devel] [PATCH] virtio: fix descriptor counting in virtqueue_pop

While changing the s/g list allocation, commit 3b3b0628 also changed the descriptor counting to count iovec entries as split by cpu_physical_memory_map(). Previously only the actual descriptor entries were counted and the split into the iovec happened afterwards in virtqueue_map(). Count the entries again instead to avoid erroneous "Looped descriptor" errors.

Fixes 3b3b0628217e ("virtio: slim down allocation of VirtQueueElements")

---
hw/virtio/virtio.c | 6 +++---

1 file changed, 3 insertions(+), 3 deletions(-) 
hw/virtio/virtio.c +3 -3
index 890b4d7eb7..33bb770177 100644 
@@ -834,7 +834,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) 
 int64_t len; 
 VirtIODevice *vdev = vq->vdev; 
 VirtQueueElement *elem = NULL; 
- unsigned out_num, in_num; 
+ unsigned out_num, in_num, elem_entries; 
 hwaddr addr[VIRTQUEUE_MAX_SIZE]; 
 struct iovec iov[VIRTQUEUE_MAX_SIZE]; 
 VRingDesc desc; 
@@ -852,7 +852,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) 
 smp_rmb(); 
 
 /* When we start there are none of either input nor output. */ 
- out_num = in_num = 0; 
+ out_num = in_num = elem_entries = 0; 
 
 max = vq->vring.num; 
 
@@ -922,7 +922,7 @@ void *virtqueue_pop(VirtQueue *vq, size_t sz) 
 } 
 
 /* If we've got too many, that implies a descriptor loop. */ 
- if ((in_num + out_num) > max) { 
+ if (++elem_entries > max) { 
 virtio_error(vdev, "Looped descriptor"); 
 goto err_undo_map; 
 } 
Signature · 1 line
2.11.0