From patchwork Thu Sep 24 22:31:09 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 54136 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f70.google.com (mail-la0-f70.google.com [209.85.215.70]) by patches.linaro.org (Postfix) with ESMTPS id 949EB22B1E for ; Thu, 24 Sep 2015 22:34:02 +0000 (UTC) Received: by lacao8 with SMTP id ao8sf36020667lac.3 for ; Thu, 24 Sep 2015 15:34:01 -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:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:cc:mime-version :content-type:content-transfer-encoding:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list; bh=kwghet1xF6bgMcBtiAayUpiWZNO/qtkYCUNn3z5XTpE=; b=Z3T00UcD29yaMFSsb8uqeuhWRpSC1yhk6Pcg1R/Hmi/vaQVg0mVaP8u1oAVRGBeCIl LPUtRKkI6TgbmoPJMoe9kawk4GE/ftsSNXEcRHTWBjwzoDomSiV5cSAS03nFQQMATBc9 sU8C2ex0xpwEeOju+hClrGC01lzr/Pv3mm2NdmcFRQYmM9uFO6DzkX5F9n8bR4nV3PAv IM1VkrSTgrS4SmvGBpOz/tHcjLpiYcN/rg4e/fUQdxIuSbdu17fE8RII19ZTn4W3lD8H OFmoLnfbrSoNT3uyYLeggGG/4ssW5Mjh+YLHupccLdLIcVyKuFuADopkFqN96Ay/ETwP F9kA== X-Gm-Message-State: ALoCoQmI2+pbJQ2VNl8k5F5F1lPd9PDgjRRf3zNfCjfZJUBQRUXzUojk6DhDiIK/zYLULNkktByo X-Received: by 10.152.6.201 with SMTP id d9mr334338laa.6.1443134041583; Thu, 24 Sep 2015 15:34:01 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.10.243 with SMTP id l19ls36622lab.89.gmail; Thu, 24 Sep 2015 15:34:01 -0700 (PDT) X-Received: by 10.25.163.133 with SMTP id m127mr400226lfe.121.1443134041379; Thu, 24 Sep 2015 15:34:01 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id wp2si238695lbb.136.2015.09.24.15.34.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Sep 2015 15:34:01 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by lacdq2 with SMTP id dq2so24595401lac.1 for ; Thu, 24 Sep 2015 15:34:01 -0700 (PDT) X-Received: by 10.112.180.230 with SMTP id dr6mr605109lbc.72.1443134041269; Thu, 24 Sep 2015 15:34:01 -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.112.59.35 with SMTP id w3csp585602lbq; Thu, 24 Sep 2015 15:34:00 -0700 (PDT) X-Received: by 10.68.95.3 with SMTP id dg3mr2608629pbb.35.1443134040093; Thu, 24 Sep 2015 15:34:00 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id z8si677677pbt.196.2015.09.24.15.33.59 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Sep 2015 15:34:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:1868:205::9 as permitted sender) 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 1ZfF4X-0007aA-8u; Thu, 24 Sep 2015 22:33:01 +0000 Received: from mail-pa0-f51.google.com ([209.85.220.51]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZfF3z-0006w6-7b for linux-arm-kernel@lists.infradead.org; Thu, 24 Sep 2015 22:32:28 +0000 Received: by pacfv12 with SMTP id fv12so86485988pac.2 for ; Thu, 24 Sep 2015 15:32:06 -0700 (PDT) X-Received: by 10.66.242.138 with SMTP id wq10mr2681937pac.2.1443133926572; Thu, 24 Sep 2015 15:32:06 -0700 (PDT) Received: from localhost.localdomain ([40.139.248.3]) by smtp.gmail.com with ESMTPSA id ll9sm325723pbc.42.2015.09.24.15.32.01 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 24 Sep 2015 15:32:05 -0700 (PDT) From: Shannon Zhao To: kvmarm@lists.cs.columbia.edu Subject: [PATCH v3 04/20] KVM: ARM64: Add reset and access handlers for PMCR_EL0 register Date: Thu, 24 Sep 2015 15:31:09 -0700 Message-Id: <1443133885-3366-5-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1443133885-3366-1-git-send-email-shannon.zhao@linaro.org> References: <1443133885-3366-1-git-send-email-shannon.zhao@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150924_153227_512191_2BF64BF0 X-CRM114-Status: GOOD ( 16.38 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [209.85.220.51 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [209.85.220.51 listed in wl.mailspike.net] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Cc: wei@redhat.com, kvm@vger.kernel.org, marc.zyngier@arm.com, will.deacon@arm.com, peter.huangpeng@huawei.com, linux-arm-kernel@lists.infradead.org, alex.bennee@linaro.org, christoffer.dall@linaro.org, shannon.zhao@linaro.org 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: shannon.zhao@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.215.42 as permitted sender) smtp.mailfrom=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 Add reset handler which gets host value of PMCR_EL0 and make writable bits architecturally UNKNOWN. Add a common access handler for PMU registers which emulates writing and reading register and add emulation for PMCR. Signed-off-by: Shannon Zhao --- arch/arm64/kvm/sys_regs.c | 81 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 79 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index b41607d..60c0842 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -33,6 +33,7 @@ #include #include #include +#include #include @@ -446,6 +447,53 @@ static void reset_mpidr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) vcpu_sys_reg(vcpu, MPIDR_EL1) = (1ULL << 31) | mpidr; } +static void vcpu_sysreg_write(struct kvm_vcpu *vcpu, + const struct sys_reg_desc *r, u64 val) +{ + if (!vcpu_mode_is_32bit(vcpu)) + vcpu_sys_reg(vcpu, r->reg) = val; + else + vcpu_cp15(vcpu, r->reg) = lower_32_bits(val); +} + +static void reset_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) +{ + u64 pmcr, val; + + asm volatile("mrs %0, pmcr_el0\n" : "=r" (pmcr)); + /* Writable bits of PMCR_EL0 (ARMV8_PMCR_MASK) is reset to UNKNOWN*/ + val = (pmcr & ~ARMV8_PMCR_MASK) | (ARMV8_PMCR_MASK & 0xdecafbad); + vcpu_sysreg_write(vcpu, r, val); +} + +/* PMU registers accessor. */ +static bool access_pmu_regs(struct kvm_vcpu *vcpu, + const struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + unsigned long val; + + if (p->is_write) { + switch (r->reg) { + case PMCR_EL0: { + /* Only update writeable bits of PMCR */ + val = vcpu_sys_reg(vcpu, r->reg); + val &= ~ARMV8_PMCR_MASK; + val |= *vcpu_reg(vcpu, p->Rt) & ARMV8_PMCR_MASK; + vcpu_sys_reg(vcpu, r->reg) = val; + break; + } + default: + vcpu_sys_reg(vcpu, r->reg) = *vcpu_reg(vcpu, p->Rt); + break; + } + } else { + *vcpu_reg(vcpu, p->Rt) = vcpu_sys_reg(vcpu, r->reg); + } + + return true; +} + /* Silly macro to expand the DBG{BCR,BVR,WVR,WCR}n_EL1 registers in one go */ #define DBG_BCR_BVR_WCR_WVR_EL1(n) \ /* DBGBVRn_EL1 */ \ @@ -637,7 +685,7 @@ static const struct sys_reg_desc sys_reg_descs[] = { /* PMCR_EL0 */ { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1100), Op2(0b000), - trap_raz_wi }, + access_pmu_regs, reset_pmcr, PMCR_EL0, }, /* PMCNTENSET_EL0 */ { Op0(0b11), Op1(0b011), CRn(0b1001), CRm(0b1100), Op2(0b001), trap_raz_wi }, @@ -871,6 +919,34 @@ static const struct sys_reg_desc cp14_64_regs[] = { { Op1( 0), CRm( 2), .access = trap_raz_wi }, }; +/* PMU CP15 registers accessor. */ +static bool access_pmu_cp15_regs(struct kvm_vcpu *vcpu, + const struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + unsigned long val; + + if (p->is_write) { + switch (r->reg) { + case c9_PMCR: { + /* Only update writeable bits of PMCR */ + val = vcpu_cp15(vcpu, r->reg); + val &= ~ARMV8_PMCR_MASK; + val |= *vcpu_reg(vcpu, p->Rt) & ARMV8_PMCR_MASK; + vcpu_cp15(vcpu, r->reg) = val; + break; + } + default: + vcpu_cp15(vcpu, r->reg) = *vcpu_reg(vcpu, p->Rt); + break; + } + } else { + *vcpu_reg(vcpu, p->Rt) = vcpu_cp15(vcpu, r->reg); + } + + return true; +} + /* * Trapped cp15 registers. TTBR0/TTBR1 get a double encoding, * depending on the way they are accessed (as a 32bit or a 64bit @@ -899,7 +975,8 @@ static const struct sys_reg_desc cp15_regs[] = { { Op1( 0), CRn( 7), CRm(14), Op2( 2), access_dcsw }, /* PMU */ - { Op1( 0), CRn( 9), CRm(12), Op2( 0), trap_raz_wi }, + { Op1( 0), CRn( 9), CRm(12), Op2( 0), access_pmu_cp15_regs, + reset_pmcr, c9_PMCR }, { Op1( 0), CRn( 9), CRm(12), Op2( 1), trap_raz_wi }, { Op1( 0), CRn( 9), CRm(12), Op2( 2), trap_raz_wi }, { Op1( 0), CRn( 9), CRm(12), Op2( 3), trap_raz_wi },