From nobody Sun Apr 28 19:32:16 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1488171238495536.3407970842778; Sun, 26 Feb 2017 20:53:58 -0800 (PST) Received: from localhost ([::1]:50301 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciDJr-0005VW-H9 for importer@patchew.org; Sun, 26 Feb 2017 23:53:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59912) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ciDJ0-0005Dp-6F for qemu-devel@nongnu.org; Sun, 26 Feb 2017 23:53:03 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ciDIw-0000kM-9b for qemu-devel@nongnu.org; Sun, 26 Feb 2017 23:53:02 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51418 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ciDIw-0000kC-47 for qemu-devel@nongnu.org; Sun, 26 Feb 2017 23:52:58 -0500 Received: from pps.filterd (m0098414.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1R4o8ls015688 for ; Sun, 26 Feb 2017 23:52:56 -0500 Received: from e18.ny.us.ibm.com (e18.ny.us.ibm.com [129.33.205.208]) by mx0b-001b2d01.pphosted.com with ESMTP id 28urfuj508-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Sun, 26 Feb 2017 23:52:56 -0500 Received: from localhost by e18.ny.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Sun, 26 Feb 2017 23:52:56 -0500 Received: from d01dlp02.pok.ibm.com (9.56.250.167) by e18.ny.us.ibm.com (146.89.104.205) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Sun, 26 Feb 2017 23:52:51 -0500 Received: from b01cxnp23034.gho.pok.ibm.com (b01cxnp23034.gho.pok.ibm.com [9.57.198.29]) by d01dlp02.pok.ibm.com (Postfix) with ESMTP id 048DC6E803C; Sun, 26 Feb 2017 23:52:22 -0500 (EST) Received: from b01ledav001.gho.pok.ibm.com (b01ledav001.gho.pok.ibm.com [9.57.199.106]) by b01cxnp23034.gho.pok.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1R4qpB522282242; Mon, 27 Feb 2017 04:52:51 GMT Received: from b01ledav001.gho.pok.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id ED4742803D; Sun, 26 Feb 2017 23:52:49 -0500 (EST) Received: from localhost (unknown [9.186.9.18]) by b01ledav001.gho.pok.ibm.com (Postfix) with ESMTP id 9CB022803A; Sun, 26 Feb 2017 23:52:49 -0500 (EST) From: Yongji Xie To: pbonzini@redhat.com, crosthwaite.peter@gmail.com, rth@twiddle.net Date: Mon, 27 Feb 2017 12:52:44 +0800 X-Mailer: git-send-email 1.7.1 X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17022704-0044-0000-0000-000002A8E890 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006690; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000204; SDB=6.00827545; UDB=6.00405498; IPR=6.00605064; BA=6.00005172; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00014451; XFM=3.00000011; UTC=2017-02-27 04:52:54 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022704-0045-0000-0000-000006D5EFB7 Message-Id: <1488171164-28319-1-git-send-email-xyjxie@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-27_03:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=0 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702270048 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH v2] memory: Introduce DEVICE_HOST_ENDIAN for ram device X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, zhong@linux.vnet.ibm.com, aik@ozlabs.ru, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com, alex.williamson@redhat.com, xyjxie@linux.vnet.ibm.com, paulus@samba.org, david@gibson.dropbear.id.au Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" At the moment ram device's memory regions are DEVICE_NATIVE_ENDIAN. It's incorrect. This memory region is backed by a MMIO area in host, so the uint64_t data that MemoryRegionOps read from/write to this area should be host-endian rather than target-endian. Hence, current code does not work when target and host endianness are different which is the most common case on PPC64. To fix it, this introduces DEVICE_HOST_ENDIAN for the ram device. This has been tested on PPC64 BE/LE host/guest in all possible combinations including TCG. Suggested-by: Paolo Bonzini Signed-off-by: Yongji Xie Reviewed-by: David Gibson --- include/exec/cpu-common.h | 6 ++++++ memory.c | 2 +- 2 files changed, 7 insertions(+), 1 deletions(-) diff --git a/include/exec/cpu-common.h b/include/exec/cpu-common.h index bd15853..eef74df 100644 --- a/include/exec/cpu-common.h +++ b/include/exec/cpu-common.h @@ -36,6 +36,12 @@ enum device_endian { DEVICE_LITTLE_ENDIAN, }; =20 +#if defined(HOST_WORDS_BIGENDIAN) +#define DEVICE_HOST_ENDIAN DEVICE_BIG_ENDIAN +#else +#define DEVICE_HOST_ENDIAN DEVICE_LITTLE_ENDIAN +#endif + /* address in the RAM (different from a physical address) */ #if defined(CONFIG_XEN_BACKEND) typedef uint64_t ram_addr_t; diff --git a/memory.c b/memory.c index ed8b5aa..17cfada 100644 --- a/memory.c +++ b/memory.c @@ -1180,7 +1180,7 @@ static void memory_region_ram_device_write(void *opaq= ue, hwaddr addr, static const MemoryRegionOps ram_device_mem_ops =3D { .read =3D memory_region_ram_device_read, .write =3D memory_region_ram_device_write, - .endianness =3D DEVICE_NATIVE_ENDIAN, + .endianness =3D DEVICE_HOST_ENDIAN, .valid =3D { .min_access_size =3D 1, .max_access_size =3D 8, --=20 1.7.1