From patchwork Wed Feb 12 05:57:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vkamensky X-Patchwork-Id: 24514 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6D75620567 for ; Wed, 12 Feb 2014 06:00:54 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id y10sf18172835pdj.3 for ; Tue, 11 Feb 2014 22:00:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:cc:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:mime-version:sender :errors-to:x-original-sender:x-original-authentication-results :mailing-list:content-type:content-transfer-encoding; bh=WCK9JyvECc8CAEHW85kJiztZSVItiNjw8NtyqKHVZ/c=; b=eRy9R6w9yo1WaYjiELvT8J8U30eRuS+bIhYto+Pj7MLwz68KXtcrx45nI0hUpuUhWo 4vv6ZiMXsQZMRcgMJMFvvQNXcV+vK3q1PS8CeO5BUjEU9tDL5ZqQfJ6RMsXL4Nn8a22v D+o1pYddpkcvCY/WgzV48hopw6skGqJJC8d8y7u9Y16+HUpmiqkFT1ydbZZeD71hB6wD aRDjAHH/SmDw3w9f4Nev4ROG6P6I9RDii77tY2YCVMW2rCHVILXwlJXv4yrIBqqg1P+L knTC+gg9haKRTeeC5JvHw2axzT9NLCp5VXVsrgK2VrqXtO7SOZLfL+ZGKq9CgiDQoTqb GYnQ== X-Gm-Message-State: ALoCoQlcMgYSt8fs/S3kGtduhy3csAAcd+G/GhPebGGzFgnX5L8Yz+v8qdh72wwzkn142E/VeNes X-Received: by 10.68.197.73 with SMTP id is9mr1098045pbc.0.1392184850145; Tue, 11 Feb 2014 22:00:50 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.92.65 with SMTP id a59ls2775541qge.72.gmail; Tue, 11 Feb 2014 22:00:50 -0800 (PST) X-Received: by 10.220.139.136 with SMTP id e8mr92227vcu.34.1392184849980; Tue, 11 Feb 2014 22:00:49 -0800 (PST) Received: from mail-vb0-f41.google.com (mail-vb0-f41.google.com [209.85.212.41]) by mx.google.com with ESMTPS id y6si6938984veb.63.2014.02.11.22.00.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 11 Feb 2014 22:00:49 -0800 (PST) Received-SPF: neutral (google.com: 209.85.212.41 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.212.41; Received: by mail-vb0-f41.google.com with SMTP id g10so6669365vbg.14 for ; Tue, 11 Feb 2014 22:00:49 -0800 (PST) X-Received: by 10.58.204.4 with SMTP id ku4mr183945vec.34.1392184849889; Tue, 11 Feb 2014 22:00:49 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp11620vcz; Tue, 11 Feb 2014 22:00:49 -0800 (PST) X-Received: by 10.112.128.170 with SMTP id np10mr28401301lbb.22.1392184848661; Tue, 11 Feb 2014 22:00:48 -0800 (PST) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id kv5si11741730lbc.21.2014.02.11.22.00.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Feb 2014 22:00:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDSqM-0005xp-Kh; Wed, 12 Feb 2014 05:58:46 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDSqA-0006cU-GO; Wed, 12 Feb 2014 05:58:34 +0000 Received: from mail-ob0-f173.google.com ([209.85.214.173]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WDSq2-0006ZN-Sr for linux-arm-kernel@lists.infradead.org; Wed, 12 Feb 2014 05:58:28 +0000 Received: by mail-ob0-f173.google.com with SMTP id vb8so10127174obc.32 for ; Tue, 11 Feb 2014 21:58:05 -0800 (PST) X-Received: by 10.182.2.170 with SMTP id 10mr387474obv.50.1392184685658; Tue, 11 Feb 2014 21:58:05 -0800 (PST) Received: from kamensky-w530.cisco.com (128-107-239-233.cisco.com. [128.107.239.233]) by mx.google.com with ESMTPSA id tr7sm63581349oec.0.2014.02.11.21.58.00 for (version=TLSv1.2 cipher=AES128-GCM-SHA256 bits=128/128); Tue, 11 Feb 2014 21:58:05 -0800 (PST) From: Victor Kamensky To: kvmarm@lists.cs.columbia.edu, marc.zyngier@arm.com, christoffer.dall@linaro.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/5] ARM64: KVM: set and get of sys registers in BE case Date: Tue, 11 Feb 2014 21:57:20 -0800 Message-Id: <1392184643-6108-3-git-send-email-victor.kamensky@linaro.org> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1392184643-6108-1-git-send-email-victor.kamensky@linaro.org> References: <1392184643-6108-1-git-send-email-victor.kamensky@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140212_005827_006179_5FBE8889 X-CRM114-Status: GOOD ( 12.25 ) X-Spam-Score: 0.4 (/) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (0.4 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.214.173 listed in list.dnswl.org] 3.0 KHOP_BIG_TO_CC Sent to 10+ recipients instaed of Bcc or a list -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linaro-kernel@lists.linaro.org, Victor Kamensky , taras.kondratiuk@linaro.org, will.deacon@arm.com, andre.przywara@linaro.org, ben.dooks@codethink.co.uk, Dave.Martin@arm.com, rmk@arm.linux.org.uk X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 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+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: victor.kamensky@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.212.41 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 Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 This patch fixes issue of reading and writing V8 sys registers in BE case. It is similar to V7 "ARM: kvm one_reg coproc set and get BE fixes" patch. It changes reg_from_user and reg_to_user functions to have strong typed 'u64 *val' argument. And it uses endian angnostic way to pick up righ word from '*val' in case when register size is 4 bytes. Signed-off-by: Victor Kamensky --- arch/arm64/kvm/sys_regs.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 02e9d09..e7c3e24 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -701,18 +701,45 @@ static struct sys_reg_desc invariant_sys_regs[] = { NULL, get_ctr_el0 }, }; -static int reg_from_user(void *val, const void __user *uaddr, u64 id) +static int reg_from_user(u64 *val, const void __user *uaddr, u64 id) { - /* This Just Works because we are little endian. */ - if (copy_from_user(val, uaddr, KVM_REG_SIZE(id)) != 0) + unsigned long regsize = KVM_REG_SIZE(id); + union { + u32 word; + u64 dword; + } tmp = {0}; + + if (copy_from_user(&tmp, uaddr, regsize) != 0) return -EFAULT; + switch (regsize) { + case 4: + *val = tmp.word; + break; + case 8: + *val = tmp.dword; + break; + } return 0; } -static int reg_to_user(void __user *uaddr, const void *val, u64 id) +static int reg_to_user(void __user *uaddr, const u64 *val, u64 id) { - /* This Just Works because we are little endian. */ - if (copy_to_user(uaddr, val, KVM_REG_SIZE(id)) != 0) + unsigned long regsize = KVM_REG_SIZE(id); + union { + u32 word; + u64 dword; + } tmp; + + switch (regsize) { + case 4: + tmp.word = *val; + break; + case 8: + tmp.dword = *val; + break; + } + + if (copy_to_user(uaddr, &tmp, regsize) != 0) return -EFAULT; return 0; }