From patchwork Tue Apr 8 15:51:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 28024 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B68C220447 for ; Tue, 8 Apr 2014 15:51:17 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id rl12sf4860885iec.6 for ; Tue, 08 Apr 2014 08:51:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe; bh=Nar6aZBhFocSR1JG+w0tpaioprSOHM+1+1wgwvtpTw0=; b=RV9nw3GirqSRlwN9AABcGO8LZ7rmbnhBp5ICcJMjZoLHBuRanhOo2ppoHkH/7wZ/F3 ybINBXFJp3244MLJdmXRWKzedZDmehyJKuAbIXgFqV/UxrpriZ76DQWhsorZrY8hgbZK dIxyZWNd9jL96EHxxC8/NJvMajaidWNGbiEEXf8pWn84stf+YKEuIArbjILgtdOfwCtR QeQ/SerQNbC6Gd7t8HctgdONv8ab3Q3RT7ofg3sjIdriyk0HXHVK8OsImuHytF2IVykG BtN6uDk++2m8kd61H0/GJKCna0htNiSpmKRS9L+WrUYVJiZjVIgW2GpXyLceA/A4PWQy lVoQ== X-Gm-Message-State: ALoCoQkcM0IvG22bV4stYRG2sM6RgNwATYpBCcrKqp18V9BO+iDvXG9pf4wMVgNQ5e9gcSDphqM2 X-Received: by 10.183.1.7 with SMTP id bc7mr2107153obd.47.1396972277066; Tue, 08 Apr 2014 08:51:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.33.197 with SMTP id j63ls251202qgj.4.gmail; Tue, 08 Apr 2014 08:51:16 -0700 (PDT) X-Received: by 10.220.161.8 with SMTP id p8mr3862019vcx.4.1396972276932; Tue, 08 Apr 2014 08:51:16 -0700 (PDT) Received: from mail-vc0-f177.google.com (mail-vc0-f177.google.com [209.85.220.177]) by mx.google.com with ESMTPS id x18si459146vcf.207.2014.04.08.08.51.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 08 Apr 2014 08:51:16 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.177; Received: by mail-vc0-f177.google.com with SMTP id if17so917769vcb.22 for ; Tue, 08 Apr 2014 08:51:16 -0700 (PDT) X-Received: by 10.58.201.5 with SMTP id jw5mr3718011vec.6.1396972276826; Tue, 08 Apr 2014 08:51:16 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.12.8 with SMTP id v8csp257028vcv; Tue, 8 Apr 2014 08:51:16 -0700 (PDT) X-Received: by 10.194.1.242 with SMTP id 18mr4700615wjp.22.1396972275989; Tue, 08 Apr 2014 08:51:15 -0700 (PDT) Received: from mnementh.archaic.org.uk (mnementh.archaic.org.uk. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id by6si1036270wjb.241.2014.04.08.08.51.15 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 08 Apr 2014 08:51:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of pm215@archaic.org.uk designates 2001:8b0:1d0::1 as permitted sender) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1WXYIp-0005tx-A2; Tue, 08 Apr 2014 16:51:11 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Richard Henderson , =?UTF-8?q?Herv=C3=A9=20Poussineau?= , Alexander Graf , Paolo Bonzini , qemu-ppc@nongnu.org Subject: [PATCH for-2.0] hw/pci-host/prep: Don't reverse IO accesses on bigendian hosts Date: Tue, 8 Apr 2014 16:51:11 +0100 Message-Id: <1396972271-22660-1-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.177 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , The raven_io_read() and raven_io_write() functions pass and return values in little-endian format (since the IO op struct is marked DEVICE_LITTLE_ENDIAN); however they were storing the values in the buffer to pass to address_space_read/write() in host-endian order, which meant that on big-endian hosts the values were inadvertently reversed. Use the *_le_p() accessors instead so that we are consistent regardless of host endianness. Strictly speaking the byte order of the buffer for address_space_rw() is target byte order (which for PPC will be BE) but it doesn't actually matter as long as we are consistent about the marking on the IO op struct and which stl_*_p(). This bug was probably introduced due to confusion caused by the two different versions of ldl_p() and friends: bswap.h defines versions meaning "host endianness access" cpu-all.h defines versions meaning "target endianness access" As a target-independent source file prep.c gets the bswap.h versions; the very similar looking code in ioport.c is compiled per-target and gets the cpu-all.h versions. Signed-off-by: Peter Maydell Reviewed-by: Richard Henderson --- "Why is a raven like a writing desk? Because it is nevar put with the wrong end in front!" -- Lewis Carroll This fixes the endianness test failure on bigendian hosts. HOWEVER I have not actually tested it with a guest :-) and endianness issues are notoriously hard to reason about correctly. Review appreciated. RTH suggests that we rename the cpu-all.h ldl_p &c to ldl_te_p() &c (for 'target endianness') to reduce confusion; I agree but this probably also requires some auditing of users to check for other mistaken uses and in any case is 2.1 material. hw/pci-host/prep.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/hw/pci-host/prep.c b/hw/pci-host/prep.c index d3e746c..4014540 100644 --- a/hw/pci-host/prep.c +++ b/hw/pci-host/prep.c @@ -145,9 +145,9 @@ static uint64_t raven_io_read(void *opaque, hwaddr addr, if (size == 1) { return buf[0]; } else if (size == 2) { - return lduw_p(buf); + return lduw_le_p(buf); } else if (size == 4) { - return ldl_p(buf); + return ldl_le_p(buf); } else { g_assert_not_reached(); } @@ -164,9 +164,9 @@ static void raven_io_write(void *opaque, hwaddr addr, if (size == 1) { buf[0] = val; } else if (size == 2) { - stw_p(buf, val); + stw_le_p(buf, val); } else if (size == 4) { - stl_p(buf, val); + stl_le_p(buf, val); } else { g_assert_not_reached(); }