From patchwork Tue Sep 2 15:26:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Greg Kurz X-Patchwork-Id: 385204 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id E4C7214018A for ; Wed, 3 Sep 2014 01:38:41 +1000 (EST) Received: from localhost ([::1]:38915 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOqAJ-0007kp-CB for incoming@patchwork.ozlabs.org; Tue, 02 Sep 2014 11:38:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60528) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOpzA-0007Nj-8l for qemu-devel@nongnu.org; Tue, 02 Sep 2014 11:27:17 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XOpz0-000106-OS for qemu-devel@nongnu.org; Tue, 02 Sep 2014 11:27:08 -0400 Received: from e06smtp17.uk.ibm.com ([195.75.94.113]:52779) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XOpz0-0000yW-Fr for qemu-devel@nongnu.org; Tue, 02 Sep 2014 11:26:58 -0400 Received: from /spool/local by e06smtp17.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 2 Sep 2014 16:26:56 +0100 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp17.uk.ibm.com (192.168.101.147) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Tue, 2 Sep 2014 16:26:53 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id B70741B08061 for ; Tue, 2 Sep 2014 16:27:53 +0100 (BST) Received: from d06av05.portsmouth.uk.ibm.com (d06av05.portsmouth.uk.ibm.com [9.149.37.229]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id s82FQroL36307118 for ; Tue, 2 Sep 2014 15:26:53 GMT Received: from d06av05.portsmouth.uk.ibm.com (localhost [127.0.0.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id s82FQqER000640 for ; Tue, 2 Sep 2014 09:26:53 -0600 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av05.portsmouth.uk.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id s82FQqf4000637; Tue, 2 Sep 2014 09:26:52 -0600 Received: from bahia.lab.toulouse-stg.fr.ibm.com (bahia.lab.toulouse-stg.fr.ibm.com [9.101.4.41]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id 2FF58210FFE; Tue, 2 Sep 2014 17:26:52 +0200 (CEST) From: Greg Kurz To: Marc =?utf-8?b?TWFyw60=?= Date: Tue, 02 Sep 2014 17:26:52 +0200 Message-ID: <20140902152651.14741.51311.stgit@bahia.lab.toulouse-stg.fr.ibm.com> In-Reply-To: <20140902131303.55fd1005@bahia.local> References: <20140902131303.55fd1005@bahia.local> User-Agent: StGit/0.17-dirty MIME-Version: 1.0 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14090215-0542-0000-0000-000000960F4F X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 195.75.94.113 Cc: Paolo Bonzini , qemu-devel@nongnu.org, Stefan Hajnoczi Subject: [Qemu-devel] [PATCH] libqos: fix endianness bug in virtio-blk-test 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 The virtio block request header is in target cpu byte order, which may be different from the host cpu byte order. This patch allows the virtio-blk-test to run with a x86_64 (LE) target on a ppc64 (BE) host. Signed-off-by: Greg Kurz --- tests/virtio-blk-test.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/virtio-blk-test.c b/tests/virtio-blk-test.c index fdc6ffe..588666c 100644 --- a/tests/virtio-blk-test.c +++ b/tests/virtio-blk-test.c @@ -19,6 +19,7 @@ #include "libqos/pci-pc.h" #include "libqos/malloc.h" #include "libqos/malloc-pc.h" +#include "qemu/bswap.h" #define QVIRTIO_BLK_F_BARRIER 0x00000001 #define QVIRTIO_BLK_F_SIZE_MAX 0x00000002 @@ -96,6 +97,21 @@ static QVirtioPCIDevice *virtio_blk_init(QPCIBus *bus) return dev; } +static inline void virtio_blk_fix_request(QVirtioBlkReq *req) +{ +#ifdef HOST_WORDS_BIGENDIAN + bool host_endian = true; +#else + bool host_endian = false; +#endif + + if (qtest_big_endian() != host_endian) { + req->type = bswap32(req->type); + req->ioprio = bswap32(req->ioprio); + req->sector = bswap64(req->sector); + } +} + static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioBlkReq *req, uint64_t data_size) { @@ -105,6 +121,8 @@ static uint64_t virtio_blk_request(QGuestAllocator *alloc, QVirtioBlkReq *req, g_assert_cmpuint(data_size % 512, ==, 0); addr = guest_alloc(alloc, sizeof(*req) + data_size); + virtio_blk_fix_request(req); + memwrite(addr, req, 16); memwrite(addr + 16, req->data, data_size); memwrite(addr + 16 + data_size, &status, sizeof(status));