From patchwork Thu Sep 19 18:29:28 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: kim-phillips X-Patchwork-Id: 20469 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-vb0-f72.google.com (mail-vb0-f72.google.com [209.85.212.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7BE5323906 for ; Thu, 19 Sep 2013 18:29:36 +0000 (UTC) Received: by mail-vb0-f72.google.com with SMTP id f12sf8969611vbg.7 for ; Thu, 19 Sep 2013 11:29:36 -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:date:from:to:cc:subject:message-id :mime-version:x-original-sender:x-original-authentication-results :precedence:mailing-list:list-id:list-post:list-help:list-archive :list-unsubscribe:content-type:content-transfer-encoding; bh=OpUYq8v5VrLZBa39Mf4xAyZ07yjcz5A0KUfNtoi01tw=; b=WZHfg5Jv3uE2uwJ04wREFD2o1bpsAX4LpbAmAsbRBNRdf+fAq6ZvUXWxnpDejBCiUE /FZkmPjFXQNQz5u83daQGIp/sCfxuVnjSOkLOnlugznA+WxxOf53HZ619xbBUV9LGSs1 Tir6u2LYNpB+rvnYpob1uNdwqBtEhTK59fZ5UsYC+edS3/xQLJ5smRnshoo8EFw2dEuJ d0gM+wElheiS+12O9wlJs50Ot5Kr5ZoBUPdQ3/JsC+bii6ETsaoSyXfvP39BtJnYlK9f qAokb42QXutA0cP77gmwslDdAv6CKWNj7utrg5dn4XPQaIMt0Lm2LmqDgyAoRBg+ZJg9 F8xw== X-Gm-Message-State: ALoCoQnccJ4pPFY94Pn+bMfSqPnbLXteg2WS+sNkahd1dZhizbQzOcEL94mnpey7Hk6Km7LWxLGz X-Received: by 10.236.147.18 with SMTP id s18mr1187679yhj.28.1379615375804; Thu, 19 Sep 2013 11:29:35 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.84.201 with SMTP id b9ls3880156qez.62.gmail; Thu, 19 Sep 2013 11:29:35 -0700 (PDT) X-Received: by 10.52.116.145 with SMTP id jw17mr26810vdb.54.1379615375715; Thu, 19 Sep 2013 11:29:35 -0700 (PDT) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id lr1si2106291vcb.94.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Sep 2013 11:29:35 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.181; Received: by mail-ve0-f181.google.com with SMTP id oy12so7017834veb.40 for ; Thu, 19 Sep 2013 11:29:35 -0700 (PDT) X-Received: by 10.58.128.71 with SMTP id nm7mr31757veb.51.1379615375490; Thu, 19 Sep 2013 11:29:35 -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.174.196 with SMTP id u4csp292766vcz; Thu, 19 Sep 2013 11:29:34 -0700 (PDT) X-Received: by 10.220.97.145 with SMTP id l17mr153615vcn.35.1379615374487; Thu, 19 Sep 2013 11:29:34 -0700 (PDT) Received: from mail-vc0-f174.google.com (mail-vc0-f174.google.com [209.85.220.174]) by mx.google.com with ESMTPS id dt10si2092857vdb.138.1969.12.31.16.00.00 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Sep 2013 11:29:34 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.174 is neither permitted nor denied by best guess record for domain of kim.phillips@linaro.org) client-ip=209.85.220.174; Received: by mail-vc0-f174.google.com with SMTP id gd11so6651305vcb.19 for ; Thu, 19 Sep 2013 11:29:34 -0700 (PDT) X-Received: by 10.221.3.200 with SMTP id nz8mr19307vcb.67.1379615374116; Thu, 19 Sep 2013 11:29:34 -0700 (PDT) Received: from ntel ([166.198.230.244]) by mx.google.com with ESMTPSA id uo1sm7993382vec.6.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 19 Sep 2013 11:29:33 -0700 (PDT) Date: Thu, 19 Sep 2013 11:29:28 -0700 From: Kim Phillips To: stable@vger.kernel.org Cc: linaro-networking@linaro.org, patches@linaro.org, linux-kernel@vger.kernel.org, Christoffer Dall , Gleb Natapov , Paolo Bonzini , Russell King , Jonghwan Choi , kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH linux-stable-3.10.y] ARM: KVM: Fix 64-bit coprocessor handling Message-Id: <20130919112928.9ce56f1a150c276a8070747e@linaro.org> X-Mailer: Sylpheed 3.3.0 (GTK+ 2.24.17; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: kim.phillips@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.181 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: , From: Christoffer Dall commit 240e99cbd00aa541b572480e3ea7ecb0d480bc79 upstream. Fixes booting a guest OS on a v3.10 host kernel. Without this, on an arndale board, qemu bails with: Initial read of kernel register state failed kvm_init_vcpu failed: Invalid argument Signed-off-by: Christoffer Dall Signed-off-by: Kim Phillips Cc: Gleb Natapov Cc: Paolo Bonzini Cc: Russell King Cc: Jonghwan Choi Cc: kvmarm@lists.cs.columbia.edu Cc: kvm@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org Cc: linux-kernel@vger.kernel.org Cc: # 3.10.x --- resumbission of: https://lkml.org/lkml/2013/8/23/50 albeit with perhaps a better rationale than 'looks like it should be in the 3.10-stable tree'. arch/arm/kvm/coproc.c | 26 +++++++++++++++++++------- arch/arm/kvm/coproc.h | 3 +++ arch/arm/kvm/coproc_a15.c | 6 +++++- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/arch/arm/kvm/coproc.c b/arch/arm/kvm/coproc.c index 4a51990..db9cf69 100644 --- a/arch/arm/kvm/coproc.c +++ b/arch/arm/kvm/coproc.c @@ -146,7 +146,11 @@ static bool pm_fake(struct kvm_vcpu *vcpu, #define access_pmintenclr pm_fake /* Architected CP15 registers. - * Important: Must be sorted ascending by CRn, CRM, Op1, Op2 + * CRn denotes the primary register number, but is copied to the CRm in the + * user space API for 64-bit register access in line with the terminology used + * in the ARM ARM. + * Important: Must be sorted ascending by CRn, CRM, Op1, Op2 and with 64-bit + * registers preceding 32-bit ones. */ static const struct coproc_reg cp15_regs[] = { /* CSSELR: swapped by interrupt.S. */ @@ -154,8 +158,8 @@ static const struct coproc_reg cp15_regs[] = { NULL, reset_unknown, c0_CSSELR }, /* TTBR0/TTBR1: swapped by interrupt.S. */ - { CRm( 2), Op1( 0), is64, NULL, reset_unknown64, c2_TTBR0 }, - { CRm( 2), Op1( 1), is64, NULL, reset_unknown64, c2_TTBR1 }, + { CRm64( 2), Op1( 0), is64, NULL, reset_unknown64, c2_TTBR0 }, + { CRm64( 2), Op1( 1), is64, NULL, reset_unknown64, c2_TTBR1 }, /* TTBCR: swapped by interrupt.S. */ { CRn( 2), CRm( 0), Op1( 0), Op2( 2), is32, @@ -182,7 +186,7 @@ static const struct coproc_reg cp15_regs[] = { NULL, reset_unknown, c6_IFAR }, /* PAR swapped by interrupt.S */ - { CRn( 7), Op1( 0), is64, NULL, reset_unknown64, c7_PAR }, + { CRm64( 7), Op1( 0), is64, NULL, reset_unknown64, c7_PAR }, /* * DC{C,I,CI}SW operations: @@ -399,12 +403,13 @@ static bool index_to_params(u64 id, struct coproc_params *params) | KVM_REG_ARM_OPC1_MASK)) return false; params->is_64bit = true; - params->CRm = ((id & KVM_REG_ARM_CRM_MASK) + /* CRm to CRn: see cp15_to_index for details */ + params->CRn = ((id & KVM_REG_ARM_CRM_MASK) >> KVM_REG_ARM_CRM_SHIFT); params->Op1 = ((id & KVM_REG_ARM_OPC1_MASK) >> KVM_REG_ARM_OPC1_SHIFT); params->Op2 = 0; - params->CRn = 0; + params->CRm = 0; return true; default: return false; @@ -898,7 +903,14 @@ static u64 cp15_to_index(const struct coproc_reg *reg) if (reg->is_64) { val |= KVM_REG_SIZE_U64; val |= (reg->Op1 << KVM_REG_ARM_OPC1_SHIFT); - val |= (reg->CRm << KVM_REG_ARM_CRM_SHIFT); + /* + * CRn always denotes the primary coproc. reg. nr. for the + * in-kernel representation, but the user space API uses the + * CRm for the encoding, because it is modelled after the + * MRRC/MCRR instructions: see the ARM ARM rev. c page + * B3-1445 + */ + val |= (reg->CRn << KVM_REG_ARM_CRM_SHIFT); } else { val |= KVM_REG_SIZE_U32; val |= (reg->Op1 << KVM_REG_ARM_OPC1_SHIFT); diff --git a/arch/arm/kvm/coproc.h b/arch/arm/kvm/coproc.h index b7301d3..0461d5c 100644 --- a/arch/arm/kvm/coproc.h +++ b/arch/arm/kvm/coproc.h @@ -135,6 +135,8 @@ static inline int cmp_reg(const struct coproc_reg *i1, return -1; if (i1->CRn != i2->CRn) return i1->CRn - i2->CRn; + if (i1->is_64 != i2->is_64) + return i2->is_64 - i1->is_64; if (i1->CRm != i2->CRm) return i1->CRm - i2->CRm; if (i1->Op1 != i2->Op1) @@ -145,6 +147,7 @@ static inline int cmp_reg(const struct coproc_reg *i1, #define CRn(_x) .CRn = _x #define CRm(_x) .CRm = _x +#define CRm64(_x) .CRn = _x, .CRm = 0 #define Op1(_x) .Op1 = _x #define Op2(_x) .Op2 = _x #define is64 .is_64 = true diff --git a/arch/arm/kvm/coproc_a15.c b/arch/arm/kvm/coproc_a15.c index 685063a..cf93472 100644 --- a/arch/arm/kvm/coproc_a15.c +++ b/arch/arm/kvm/coproc_a15.c @@ -114,7 +114,11 @@ static bool access_l2ectlr(struct kvm_vcpu *vcpu, /* * A15-specific CP15 registers. - * Important: Must be sorted ascending by CRn, CRM, Op1, Op2 + * CRn denotes the primary register number, but is copied to the CRm in the + * user space API for 64-bit register access in line with the terminology used + * in the ARM ARM. + * Important: Must be sorted ascending by CRn, CRM, Op1, Op2 and with 64-bit + * registers preceding 32-bit ones. */ static const struct coproc_reg a15_regs[] = { /* MPIDR: we use VMPIDR for guest access. */