From patchwork Thu Nov 24 08:56:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Huth X-Patchwork-Id: 698767 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tPY326WD7z9t0G for ; Thu, 24 Nov 2016 19:56:14 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3tPY324mgmzDw6D for ; Thu, 24 Nov 2016 19:56:14 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3tPY2z4tkczDw60 for ; Thu, 24 Nov 2016 19:56:11 +1100 (AEDT) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id A92536DD85; Thu, 24 Nov 2016 08:56:09 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-23.ams2.redhat.com [10.36.116.23]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id uAO8u7eq013979; Thu, 24 Nov 2016 03:56:08 -0500 From: Thomas Huth To: slof@lists.ozlabs.org Date: Thu, 24 Nov 2016 09:56:07 +0100 Message-Id: <1479977767-14027-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 24 Nov 2016 08:56:09 +0000 (UTC) Subject: [SLOF] [PATCH] virtio-scsi: Fix descriptor order for SCSI WRITE commands X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" Virtio needs the descriptors ordered: All descriptors for buffers that contain data that should go *to* the device have to be put into the queue first. The descriptors for buffers that read *from* the device have to be sorted in last. For SCSI WRITE commands (which we never used in the past), the order was wrong, so QEMU complains with a "Incorrect order for descriptors" message as soon as we use it for SCSI WRITE commands. Signed-off-by: Thomas Huth --- lib/libvirtio/virtio-scsi.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/libvirtio/virtio-scsi.c b/lib/libvirtio/virtio-scsi.c index 04181b0..36b62d1 100644 --- a/lib/libvirtio/virtio-scsi.c +++ b/lib/libvirtio/virtio-scsi.c @@ -49,18 +49,27 @@ int virtioscsi_send(struct virtio_device *dev, virtio_fill_desc(&vq_desc[id], dev->is_modern, (uint64_t)req, sizeof(*req), VRING_DESC_F_NEXT, (id + 1) % vq_size); - /* Set up virtqueue descriptor for data */ - if (buf && buf_len) { + if (buf == NULL || buf_len == 0) { + /* Set up descriptor for response information */ + virtio_fill_desc(&vq_desc[(id + 1) % vq_size], dev->is_modern, + (uint64_t)resp, sizeof(*resp), + VRING_DESC_F_WRITE, 0); + } else if (is_read) { + /* Set up descriptor for response information */ virtio_fill_desc(&vq_desc[(id + 1) % vq_size], dev->is_modern, (uint64_t)resp, sizeof(*resp), VRING_DESC_F_NEXT | VRING_DESC_F_WRITE, (id + 2) % vq_size); - /* Set up virtqueue descriptor for status */ + /* Set up virtqueue descriptor for data from device */ virtio_fill_desc(&vq_desc[(id + 2) % vq_size], dev->is_modern, - (uint64_t)buf, buf_len, - (is_read ? VRING_DESC_F_WRITE : 0), 0); + (uint64_t)buf, buf_len, VRING_DESC_F_WRITE, 0); } else { + /* Set up virtqueue descriptor for data to device */ virtio_fill_desc(&vq_desc[(id + 1) % vq_size], dev->is_modern, + (uint64_t)buf, buf_len, VRING_DESC_F_NEXT, + (id + 2) % vq_size); + /* Set up descriptor for response information */ + virtio_fill_desc(&vq_desc[(id + 2) % vq_size], dev->is_modern, (uint64_t)resp, sizeof(*resp), VRING_DESC_F_WRITE, 0); }