From patchwork Tue May 13 16:14:05 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: vkamensky X-Patchwork-Id: 30106 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 466FF20560 for ; Tue, 13 May 2014 16:19:18 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id hw13sf1340488qab.11 for ; Tue, 13 May 2014 09:19:18 -0700 (PDT) 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=eL/D7epLTSUzIoLnv2xuT4UoU9LAJ0+NLk6YYGNVsec=; b=WUzT58ke+Q1Bb+9ijRaKYfXGBtHvmb3M3KDrVnx0UGCs+t9f7/U+siHdrHYkHvMj2C ZTGvJjjhFRoNGpckmnt3a6XiPTZA9en6TmMsxSmFBEhscM3sOuQRTUKxUcXltJ60J/y8 uJ6wibMcQBbCsQbhaPiXZycY6FirbEmRc2dst1l4CzYizwQNwWVeZ31rozrinVmBz0K4 3C02YHdtQHlKJ0SJY0KoINff/83uFUutGte8mCctcfwvCgZlOvhfJDundsA0GoFGuP6t 13ppPcb46xWp0RqWxWem53FY3NcFUmATwegiJlD2FZu48lq1XMlX27CfaztRsJaMC1Pu qGFA== X-Gm-Message-State: ALoCoQlrdlLdeRyjm5WZeSRQ+/sw0mph3ry5Qo0iohAhSuCHRqrTvJTMHPzuJdRt0s5QKcBXevHi X-Received: by 10.236.127.35 with SMTP id c23mr14945435yhi.51.1399997958066; Tue, 13 May 2014 09:19:18 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.47.203 with SMTP id m69ls2002445qga.84.gmail; Tue, 13 May 2014 09:19:17 -0700 (PDT) X-Received: by 10.52.53.69 with SMTP id z5mr1715143vdo.42.1399997957936; Tue, 13 May 2014 09:19:17 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id b2si2735044vcy.10.2014.05.13.09.19.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 13 May 2014 09:19:17 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.175 as permitted sender) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id jw12so738792veb.20 for ; Tue, 13 May 2014 09:19:17 -0700 (PDT) X-Received: by 10.221.40.193 with SMTP id tr1mr7922119vcb.31.1399997957855; Tue, 13 May 2014 09:19:17 -0700 (PDT) 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.221.72 with SMTP id ib8csp164268vcb; Tue, 13 May 2014 09:19:17 -0700 (PDT) X-Received: by 10.15.98.68 with SMTP id bi44mr4399087eeb.97.1399997956893; Tue, 13 May 2014 09:19:16 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id r2si13554087eem.66.2014.05.13.09.19.16 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 May 2014 09:19:16 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; 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 1WkFOn-0004Rf-0p; Tue, 13 May 2014 16:17:49 +0000 Received: from mail-pb0-f51.google.com ([209.85.160.51]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WkFMb-0002c7-9J for linux-arm-kernel@lists.infradead.org; Tue, 13 May 2014 16:15:33 +0000 Received: by mail-pb0-f51.google.com with SMTP id ma3so463976pbc.10 for ; Tue, 13 May 2014 09:15:12 -0700 (PDT) X-Received: by 10.66.139.168 with SMTP id qz8mr28681213pab.3.1399997712551; Tue, 13 May 2014 09:15:12 -0700 (PDT) Received: from kamensky-w530.hsd1.ca.comcast.net (c-24-6-79-41.hsd1.ca.comcast.net. [24.6.79.41]) by mx.google.com with ESMTPSA id dd5sm28958360pbc.85.2014.05.13.09.15.11 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 May 2014 09:15:12 -0700 (PDT) From: Victor Kamensky To: kvmarm@lists.cs.columbia.edu, christoffer.dall@linaro.org, marc.zyngier@arm.com, agraf@suse.de Subject: [PATCH v3 13/14] ARM64: KVM: set and get of sys registers in BE case Date: Tue, 13 May 2014 09:14:05 -0700 Message-Id: <1399997646-4716-14-git-send-email-victor.kamensky@linaro.org> X-Mailer: git-send-email 1.8.1.4 In-Reply-To: <1399997646-4716-1-git-send-email-victor.kamensky@linaro.org> References: <1399997646-4716-1-git-send-email-victor.kamensky@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140513_091533_386474_844E0F88 X-CRM114-Status: GOOD ( 13.16 ) X-Spam-Score: -0.7 (/) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-0.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.160.51 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 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.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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.128.175 as permitted sender) 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 addresses issue of reading and writing V8 sys registers in BE case. Since only register size function deals with is 8 bytes, existing code works in both little and big endian cases. Removed comment about little endian. Added BUG_ON that register size should be always 8 bytes. If these functions would ever need to support both 8 bytes and 4 bytes register sizes to deals with them in endian agnostic way code should do something along these lines: 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; } Signed-off-by: Victor Kamensky --- arch/arm64/kvm/sys_regs.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index 0324458..060c3a9 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -776,18 +776,25 @@ 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); + + BUG_ON(regsize != 8); + + if (copy_from_user(val, uaddr, regsize) != 0) return -EFAULT; + 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); + + BUG_ON(regsize != 8); + + if (copy_to_user(uaddr, val, regsize) != 0) return -EFAULT; return 0; }