Skip to content

Commit 0c80570

Browse files
bonzinimdroth
authored andcommitted
virtio-scsi: work around bug in old BIOSes
Old BIOSes left some padding by mistake after the req_size/resp_size. New QEMU does not like it, thinking it is a bidirectional command. As a workaround, we can check if the ANY_LAYOUT bit is set; if not, we always consider the first buffer as the virtio-scsi request/response, because, back when QEMU did not support ANY_LAYOUT, it expected the payload to start at the second element of the iovec. This can show up during migration. Cc: [email protected] Signed-off-by: Paolo Bonzini <[email protected]> (cherry picked from commit 55783a5) Signed-off-by: Michael Roth <[email protected]>
1 parent 14b51b6 commit 0c80570

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

hw/scsi/virtio-scsi.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static size_t qemu_sgl_concat(VirtIOSCSIReq *req, struct iovec *iov,
135135
static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
136136
unsigned req_size, unsigned resp_size)
137137
{
138+
VirtIODevice *vdev = (VirtIODevice *) req->dev;
138139
size_t in_size, out_size;
139140

140141
if (iov_to_buf(req->elem.out_sg, req->elem.out_num, 0,
@@ -147,8 +148,24 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req,
147148
resp_size) < resp_size) {
148149
return -EINVAL;
149150
}
151+
150152
req->resp_size = resp_size;
151153

154+
/* Old BIOSes left some padding by mistake after the req_size/resp_size.
155+
* As a workaround, always consider the first buffer as the virtio-scsi
156+
* request/response, making the payload start at the second element
157+
* of the iovec.
158+
*
159+
* The actual length of the response header, stored in req->resp_size,
160+
* does not change.
161+
*
162+
* TODO: always disable this workaround for virtio 1.0 devices.
163+
*/
164+
if ((vdev->guest_features & VIRTIO_F_ANY_LAYOUT) == 0) {
165+
req_size = req->elem.out_sg[0].iov_len;
166+
resp_size = req->elem.in_sg[0].iov_len;
167+
}
168+
152169
out_size = qemu_sgl_concat(req, req->elem.out_sg,
153170
&req->elem.out_addr[0], req->elem.out_num,
154171
req_size);

0 commit comments

Comments
 (0)