From patchwork Thu Jun 12 16:30:08 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victor Kamensky X-Patchwork-Id: 4343541 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 6FD87BEEAA for ; Thu, 12 Jun 2014 16:35:29 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id B596B2034C for ; Thu, 12 Jun 2014 16:35:28 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 82A82202FF for ; Thu, 12 Jun 2014 16:35:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wv7vf-0000Fd-96; Thu, 12 Jun 2014 16:32:43 +0000 Received: from mail-pb0-f43.google.com ([209.85.160.43]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Wv7u6-0007se-Qd for linux-arm-kernel@lists.infradead.org; Thu, 12 Jun 2014 16:31:08 +0000 Received: by mail-pb0-f43.google.com with SMTP id up15so1171147pbc.30 for ; Thu, 12 Jun 2014 09:30:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Jfk+ObXPcx2mi0NMagDC/dTi5OgdQxURM+j1RbACeGg=; b=jflUd8M4aNJn2vnwuAAdzK+Yq6tNY4/v6PzZu71Kgwq2k/dbTaGbo78drWXztxDeRH NeL3Ck7xXsjhd382Vi+eYma6LRZMNBHKOwzUIUbDxz8e01B8iUGBkAaWtA4kAtwlbfSi CRUdYjY2oqe693o2dFSO1/oN0uBKFrzhHMZ6zP8fCk7XskJzyJZIjXO8sIU+bOayRBcz 5FgVlTCXyuanA2tMSen4fXdvzWN84DifznYy430fEeTB4LdWBxsi8W23s6EHwugbZqbY 2sYHkvYb3+42fRoAJ8RWdoa/GH6TPqodPz3ruHM0Nnx4bcd6bUj9WNvn2JMzvIo1nz+R 9Qew== X-Gm-Message-State: ALoCoQlkP//Y6GIPSHjyGAzpk1MSIRvQTmC1CxdxVNHTwM4dWUAbylsowqZrT3SnF8EvM287Fznx X-Received: by 10.66.97.4 with SMTP id dw4mr22070590pab.55.1402590645746; Thu, 12 Jun 2014 09:30:45 -0700 (PDT) Received: from kamensky-w530.cisco.com (128-107-239-235.cisco.com. [128.107.239.235]) by mx.google.com with ESMTPSA id nh8sm81278030pbc.25.2014.06.12.09.30.44 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jun 2014 09:30:45 -0700 (PDT) From: Victor Kamensky To: kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com, agraf@suse.de Subject: [PATCH v4 09/14] ARM64: KVM: MMIO support BE host running LE code Date: Thu, 12 Jun 2014 09:30:08 -0700 Message-Id: <1402590613-3341-10-git-send-email-victor.kamensky@linaro.org> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1402590613-3341-1-git-send-email-victor.kamensky@linaro.org> References: <1402590613-3341-1-git-send-email-victor.kamensky@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140612_093106_906047_8FF3B416 X-CRM114-Status: GOOD ( 10.10 ) X-Spam-Score: -0.7 (/) Cc: taras.kondratiuk@linaro.org, linaro-kernel@lists.linaro.org, linux-arm-kernel@lists.infradead.org, Victor Kamensky X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In case of guest CPU running in LE mode and host runs in BE mode we need byteswap data, so read/write is emulated correctly. Signed-off-by: Victor Kamensky Reviewed-by: Christoffer Dall Reviewed-by: Marc Zyngier --- arch/arm64/include/asm/kvm_emulate.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/arch/arm64/include/asm/kvm_emulate.h b/arch/arm64/include/asm/kvm_emulate.h index dd8ecfc..fdc3e21 100644 --- a/arch/arm64/include/asm/kvm_emulate.h +++ b/arch/arm64/include/asm/kvm_emulate.h @@ -213,6 +213,17 @@ static inline unsigned long vcpu_data_guest_to_host(struct kvm_vcpu *vcpu, default: return be64_to_cpu(data); } + } else { + switch (len) { + case 1: + return data & 0xff; + case 2: + return le16_to_cpu(data & 0xffff); + case 4: + return le32_to_cpu(data & 0xffffffff); + default: + return le64_to_cpu(data); + } } return data; /* Leave LE untouched */ @@ -233,6 +244,17 @@ static inline unsigned long vcpu_data_host_to_guest(struct kvm_vcpu *vcpu, default: return cpu_to_be64(data); } + } else { + switch (len) { + case 1: + return data & 0xff; + case 2: + return cpu_to_le16(data & 0xffff); + case 4: + return cpu_to_le32(data & 0xffffffff); + default: + return cpu_to_le64(data); + } } return data; /* Leave LE untouched */