Received: from eggs.gnu.org ([2001:4830:134:3::10]:33533) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmlWx-0001Lf-I5 for qemu-devel@nongnu.org; Fri, 07 Nov 2014 10:33:04 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XmlWo-0000eC-I5 for qemu-devel@nongnu.org; Fri, 07 Nov 2014 10:32:55 -0500 Received: from mail-wg0-x22e.google.com ([2a00:1450:400c:c00::22e]:35831) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XmlWo-0000e0-BE for qemu-devel@nongnu.org; Fri, 07 Nov 2014 10:32:46 -0500 Received: by mail-wg0-f46.google.com with SMTP id x13so4022529wgg.33 for ; Fri, 07 Nov 2014 07:32:45 -0800 (PST) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 7 Nov 2014 16:04:18 +0100 Message-Id: <1415372658-10790-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH] virtio-scsi: work around bug in old BIOSes List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: dgilbert@redhat.com 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. Signed-off-by: Paolo Bonzini --- hw/scsi/virtio-scsi.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/hw/scsi/virtio-scsi.c b/hw/scsi/virtio-scsi.c index fdcacfd..ef48550 100644 --- a/hw/scsi/virtio-scsi.c +++ b/hw/scsi/virtio-scsi.c @@ -118,6 +118,7 @@ static size_t qemu_sgl_concat(VirtIOSCSIReq *req, struct iovec *iov, static int virtio_scsi_parse_req(VirtIOSCSIReq *req, unsigned req_size, unsigned resp_size) { + VirtIODevice *vdev = (VirtIODevice *) req->dev; size_t in_size, out_size; if (iov_to_buf(req->elem.out_sg, req->elem.out_num, 0, @@ -130,8 +131,24 @@ static int virtio_scsi_parse_req(VirtIOSCSIReq *req, resp_size) < resp_size) { return -EINVAL; } + req->resp_size = resp_size; + /* Old BIOSes left some padding by mistake after the req_size/resp_size. + * As a workaround, always consider the first buffer as the virtio-scsi + * request/response, making the payload start at the second element + * of the iovec. + * + * The actual length of the response header, stored in req->resp_size, + * does not change. + * + * TODO: always disable this workaround for virtio 1.0 devices. + */ + if ((vdev->guest_features & VIRTIO_F_ANY_LAYOUT) == 0) { + req_size = req->elem.out_sg[0].iov_len; + resp_size = req->elem.in_sg[0].iov_len; + } + out_size = qemu_sgl_concat(req, req->elem.out_sg, &req->elem.out_addr[0], req->elem.out_num, req_size); -- 1.8.3.1