@@ -280,14 +280,27 @@ QVRingIndirectDesc *qvring_indirect_desc_setup(QTestState *qs, QVirtioDevice *d,
indirect->elem = elem;
indirect->desc = guest_alloc(alloc, sizeof(struct vring_desc) * elem);
- for (i = 0; i < elem - 1; ++i) {
+ for (i = 0; i < elem; ++i) {
/* indirect->desc[i].addr */
qvirtio_writeq(d, qs, indirect->desc + (16 * i), 0);
- /* indirect->desc[i].flags */
- qvirtio_writew(d, qs, indirect->desc + (16 * i) + 12,
- VRING_DESC_F_NEXT);
- /* indirect->desc[i].next */
- qvirtio_writew(d, qs, indirect->desc + (16 * i) + 14, i + 1);
+
+ /*
+ * If it's not the last element of the ring, set
+ * the chain (VRING_DESC_F_NEXT) flag and
+ * desc->next. Clear the last element - there's
+ * no guarantee that guest_alloc() will do it.
+ */
+ if (i != elem - 1) {
+ /* indirect->desc[i].flags */
+ qvirtio_writew(d, qs, indirect->desc + (16 * i) + 12,
+ VRING_DESC_F_NEXT);
+
+ /* indirect->desc[i].next */
+ qvirtio_writew(d, qs, indirect->desc + (16 * i) + 14, i + 1);
+ } else {
+ qvirtio_writew(d, qs, indirect->desc + (16 * i) + 12, 0);
+ qvirtio_writew(d, qs, indirect->desc + (16 * i) + 14, 0);
+ }
}
return indirect;