From patchwork Mon Dec 3 22:44:35 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Roth X-Patchwork-Id: 203477 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 30A0B2C0098 for ; Tue, 4 Dec 2012 09:50:55 +1100 (EST) Received: from localhost ([::1]:54948 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tfeqj-0003O8-8S for incoming@patchwork.ozlabs.org; Mon, 03 Dec 2012 17:50:53 -0500 Received: from eggs.gnu.org ([208.118.235.92]:56417) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tfeq8-0002Cv-V4 for qemu-devel@nongnu.org; Mon, 03 Dec 2012 17:50:18 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Tfeq6-0003u8-2L for qemu-devel@nongnu.org; Mon, 03 Dec 2012 17:50:16 -0500 Received: from mail-ie0-f181.google.com ([209.85.223.181]:62360) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Tfeq2-0003qo-FT; Mon, 03 Dec 2012 17:50:10 -0500 Received: by mail-ie0-f181.google.com with SMTP id 16so5379234iea.12 for ; Mon, 03 Dec 2012 14:50:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references; bh=NfGODd7Raens6/S1ld6NSslNjhhYh/xzALS1o4i8efg=; b=CFAua5UnA1ntSWj/UqiA8Zwcs5ksqArHI6LtB/0fSaOxXyuKi/2/EuXqEPdqrsVd7f gFDAiDEJnsIqDGiEnrqYulDg4VD/63OQuESt4EBAVYavSu6h7K8htqa4cU1ztBjofrqO aK+bKunhdvjDbWd3jBiFuE7T2j+p+3n/5KQcIbedEKANxaX1PisK6icn3rFOgoh8S3po p5So9RAp/jNQn7F2FrugciTHXhqM3SH6VSWLI4myuVTxQ2KTStUzJRfnS7TjnU4o14gJ OzNO64bKV2qOkpFWF/vFOjnd5ILX/N7XQT9pByD3V2buniZzBCqsUTTiWgZRS67CmYcp QORA== Received: by 10.50.40.229 with SMTP id a5mr627280igl.59.1354575008730; Mon, 03 Dec 2012 14:50:08 -0800 (PST) Received: from localhost ([32.97.110.59]) by mx.google.com with ESMTPS id ff4sm8197935igc.13.2012.12.03.14.50.07 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 03 Dec 2012 14:50:08 -0800 (PST) From: Michael Roth To: qemu-stable@nongnu.org Date: Mon, 3 Dec 2012 16:44:35 -0600 Message-Id: <1354574681-28954-6-git-send-email-mdroth@linux.vnet.ibm.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1354572547-21271-1-git-send-email-mdroth@linux.vnet.ibm.com> References: <1354572547-21271-1-git-send-email-mdroth@linux.vnet.ibm.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 209.85.223.181 Cc: aliguori@us.ibm.com, qemu-devel@nongnu.org Subject: [Qemu-devel] [PATCH 38/43] virtio-scsi: Fix some endian bugs with virtio-scsi X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: David Gibson The virtio-scsi specification does not specify the correct endianness for fields in the request structure. It's therefore best to assume that it is "guest native" endian since that's the (stupid and poorly defined) norm in virtio. However, the qemu device for virtio-scsi has no byteswaps at all, and so will break if the guest has different endianness from the host. This patch fixes it by adding tswap() calls for the sense_len and resid fields in the request structure. In theory status_qualifier needs swaps as well, but that field is never actually touched. The tag field is a uint64_t, but since its value is completely arbitrary, it might as well be uint8_t[8] and so it does not need swapping. Cc: Paolo Bonzini Cc: Paul 'Rusty' Russell Signed-off-by: David Gibson Signed-off-by: Paolo Bonzini (cherry picked from commit 474ee55a18765e7de8f0b2cc00db5d26286bb24d) Signed-off-by: Michael Roth --- hw/virtio-scsi.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/hw/virtio-scsi.c b/hw/virtio-scsi.c index c1b47a8..c6d5290 100644 --- a/hw/virtio-scsi.c +++ b/hw/virtio-scsi.c @@ -424,15 +424,17 @@ static void virtio_scsi_command_complete(SCSIRequest *r, uint32_t status, size_t resid) { VirtIOSCSIReq *req = r->hba_private; + uint32_t sense_len; req->resp.cmd->response = VIRTIO_SCSI_S_OK; req->resp.cmd->status = status; if (req->resp.cmd->status == GOOD) { - req->resp.cmd->resid = resid; + req->resp.cmd->resid = tswap32(resid); } else { req->resp.cmd->resid = 0; - req->resp.cmd->sense_len = - scsi_req_get_sense(r, req->resp.cmd->sense, VIRTIO_SCSI_SENSE_SIZE); + sense_len = scsi_req_get_sense(r, req->resp.cmd->sense, + VIRTIO_SCSI_SENSE_SIZE); + req->resp.cmd->sense_len = tswap32(sense_len); } virtio_scsi_complete_req(req); }