From patchwork Mon Jul 6 02:17:42 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shannon Zhao X-Patchwork-Id: 50684 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 ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 6EF59229E5 for ; Mon, 6 Jul 2015 02:21:13 +0000 (UTC) Received: by lagh6 with SMTP id h6sf42467649lag.0 for ; Sun, 05 Jul 2015 19:21:12 -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=pbykdeQ12wivD1de6wQWwk1BZydD+XgXEbg6iAA6i9w=; b=WInCEEge9AFC1BCrKoG/sl+RhCqnaBO+zygZtVAANF9RqouOIEMRhjkbhrm476KdDk dzKVOSUuIMi2tQInNpupveIOxVDA2WJIvQbu+zG47Hshvv3jJ4/BJbS9uGd/2M1ZT3w4 QMhxHoNLqDzubFSf3qg8VvCOtTsRcDz0hKILNaD8Gb49L0SLkZv8yhsbZq3KPZ4pC8Fc jv4jHVr7+MgKpz6CtPH34RXKZ+LWw8bB74ckNif620PW+vhdMHy90UomYVaQJpox16NK jXEpXgTU76WEhCZFUQ+oDJrfGdIH1olwkrFimrQ13eU6xhSYi79ZLmD7vb8VhgkWs0cj Clbg== X-Gm-Message-State: ALoCoQkSl7cgW2t5LfZIqRA5kW9Wo43VJ+o+udgnDnNED/Um6he2Fq21iR8P53xPQ2NZHK2fXtPR X-Received: by 10.194.5.229 with SMTP id v5mr12602496wjv.0.1436149272342; Sun, 05 Jul 2015 19:21:12 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.28.4 with SMTP id x4ls643406lag.100.gmail; Sun, 05 Jul 2015 19:21:12 -0700 (PDT) X-Received: by 10.112.146.97 with SMTP id tb1mr47771794lbb.12.1436149272183; Sun, 05 Jul 2015 19:21:12 -0700 (PDT) Received: from mail-la0-f43.google.com (mail-la0-f43.google.com. [209.85.215.43]) by mx.google.com with ESMTPS id ay4si13972020lab.9.2015.07.05.19.21.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Jul 2015 19:21:12 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.43 as permitted sender) client-ip=209.85.215.43; Received: by laar3 with SMTP id r3so137706243laa.0 for ; Sun, 05 Jul 2015 19:21:12 -0700 (PDT) X-Received: by 10.152.7.7 with SMTP id f7mr47039084laa.106.1436149272077; Sun, 05 Jul 2015 19:21:12 -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.108.230 with SMTP id hn6csp1426379lbb; Sun, 5 Jul 2015 19:21:10 -0700 (PDT) X-Received: by 10.70.0.202 with SMTP id 10mr98889142pdg.41.1436149270127; Sun, 05 Jul 2015 19:21:10 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id mk10si26398815pab.168.2015.07.05.19.21.09 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Jul 2015 19:21:10 -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 1ZBw0m-0007Nn-KW; Mon, 06 Jul 2015 02:20:00 +0000 Received: from mail-pa0-f41.google.com ([209.85.220.41]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZBw01-00066i-Ti for linux-arm-kernel@lists.infradead.org; Mon, 06 Jul 2015 02:19:14 +0000 Received: by pabvl15 with SMTP id vl15so87073664pab.1 for ; Sun, 05 Jul 2015 19:18:53 -0700 (PDT) X-Received: by 10.68.190.41 with SMTP id gn9mr98295391pbc.113.1436149133046; Sun, 05 Jul 2015 19:18:53 -0700 (PDT) Received: from localhost ([120.136.34.248]) by mx.google.com with ESMTPSA id vx5sm16193087pbc.59.2015.07.05.19.18.51 (version=TLSv1 cipher=RC4-SHA bits=128/128); Sun, 05 Jul 2015 19:18:52 -0700 (PDT) From: shannon.zhao@linaro.org To: kvmarm@lists.cs.columbia.edu Subject: [PATCH 12/18] KVM: ARM64: Add reset and access handlers for PMINTENSET_EL1 and PMINTENCLR_EL1 register Date: Mon, 6 Jul 2015 10:17:42 +0800 Message-Id: <1436149068-3784-13-git-send-email-shannon.zhao@linaro.org> X-Mailer: git-send-email 1.9.5.msysgit.1 In-Reply-To: <1436149068-3784-1-git-send-email-shannon.zhao@linaro.org> References: <1436149068-3784-1-git-send-email-shannon.zhao@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150705_191913_998811_D36BB374 X-CRM114-Status: GOOD ( 15.46 ) 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.41 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.220.41 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] -0.0 RCVD_IN_MSPIKE_WL Mailspike good senders 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: kvm@vger.kernel.org, marc.zyngier@arm.com, will.deacon@arm.com, linux-arm-kernel@lists.infradead.org, zhaoshenglong@huawei.com, 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.43 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 From: Shannon Zhao Since the reset value of PMINTENSET_EL1 and PMINTENCLR_EL1 is UNKNOWN, use reset_unknown for its reset handler. Add access handler which emulates writing and reading PMINTENSET_EL1 or PMINTENCLR_EL1 register. When writing to PMINTENSET_EL1, set the interrupt flag true. While writing to PMINTENCLR_EL1, set the interrupt flag false. This flag will be useful for counter overflow interrupt. Signed-off-by: Shannon Zhao --- arch/arm64/kvm/sys_regs.c | 56 +++++++++++++++++++++++++++++++++++++++++++++-- include/kvm/arm_pmu.h | 4 ++++ virt/kvm/arm/pmu.c | 28 ++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 2 deletions(-) diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index c14ec8d..cbc07b8 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -444,6 +444,58 @@ static bool access_pmcntenclr(struct kvm_vcpu *vcpu, return true; } +/* PMINTENSET_EL1 accessor. */ +static bool access_pmintenset(struct kvm_vcpu *vcpu, + const struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + unsigned long val; + + if (p->is_write) { + val = *vcpu_reg(vcpu, p->Rt); + if (!p->is_aarch32) + vcpu_sys_reg(vcpu, r->reg) |= val; + else + vcpu_cp15(vcpu, r->reg) |= val & 0xffffffffUL; + + kvm_pmu_enable_interrupt(vcpu, val); + } else { + if (!p->is_aarch32) + val = vcpu_sys_reg(vcpu, r->reg); + else + val = vcpu_cp15(vcpu, r->reg); + *vcpu_reg(vcpu, p->Rt) = val; + } + + return true; +} + +/* PMINTENCLR_EL1 accessor. */ +static bool access_pmintenclr(struct kvm_vcpu *vcpu, + const struct sys_reg_params *p, + const struct sys_reg_desc *r) +{ + unsigned long val; + + if (p->is_write) { + val = *vcpu_reg(vcpu, p->Rt); + if (!p->is_aarch32) + vcpu_sys_reg(vcpu, r->reg) |= val; + else + vcpu_cp15(vcpu, r->reg) |= val & 0xffffffffUL; + + kvm_pmu_disable_interrupt(vcpu, val); + } else { + if (!p->is_aarch32) + val = vcpu_sys_reg(vcpu, r->reg); + else + val = vcpu_cp15(vcpu, r->reg); + *vcpu_reg(vcpu, p->Rt) = val; + } + + 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 */ \ @@ -595,10 +647,10 @@ static const struct sys_reg_desc sys_reg_descs[] = { /* PMINTENSET_EL1 */ { Op0(0b11), Op1(0b000), CRn(0b1001), CRm(0b1110), Op2(0b001), - trap_raz_wi }, + access_pmintenset, reset_unknown, PMINTENSET_EL1 }, /* PMINTENCLR_EL1 */ { Op0(0b11), Op1(0b000), CRn(0b1001), CRm(0b1110), Op2(0b010), - trap_raz_wi }, + access_pmintenclr, reset_unknown, PMINTENCLR_EL1 }, /* MAIR_EL1 */ { Op0(0b11), Op1(0b000), CRn(0b1010), CRm(0b0010), Op2(0b000), diff --git a/include/kvm/arm_pmu.h b/include/kvm/arm_pmu.h index 2cfd9be..dee8356 100644 --- a/include/kvm/arm_pmu.h +++ b/include/kvm/arm_pmu.h @@ -51,6 +51,8 @@ unsigned long kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, unsigned long select_idx); void kvm_pmu_disable_counter(struct kvm_vcpu *vcpu, unsigned long val); void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, unsigned long val); +void kvm_pmu_disable_interrupt(struct kvm_vcpu *vcpu, unsigned long val); +void kvm_pmu_enable_interrupt(struct kvm_vcpu *vcpu, unsigned long val); void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, unsigned long data, unsigned long select_idx); void kvm_pmu_init(struct kvm_vcpu *vcpu); @@ -65,6 +67,8 @@ unsigned long kvm_pmu_get_counter_value(struct kvm_vcpu *vcpu, } void kvm_pmu_disable_counter(struct kvm_vcpu *vcpu, unsigned long val) {} void kvm_pmu_enable_counter(struct kvm_vcpu *vcpu, unsigned long val) {} +void kvm_pmu_disable_interrupt(struct kvm_vcpu *vcpu, unsigned long val) {} +void kvm_pmu_enable_interrupt(struct kvm_vcpu *vcpu, unsigned long val) {} void kvm_pmu_set_counter_event_type(struct kvm_vcpu *vcpu, unsigned long data, unsigned long select_idx) {} static inline void kvm_pmu_init(struct kvm_vcpu *vcpu) {} diff --git a/virt/kvm/arm/pmu.c b/virt/kvm/arm/pmu.c index cf59998..7023ad5 100644 --- a/virt/kvm/arm/pmu.c +++ b/virt/kvm/arm/pmu.c @@ -175,6 +175,34 @@ void kvm_pmu_disable_counter(struct kvm_vcpu *vcpu, unsigned long val) } /** + * kvm_pmu_enable_interrupt - enable selected PMU counter interrupt + * @vcpu: The vcpu pointer + * @val: the value guest writes to PMINTENSET_EL0 register + */ +void kvm_pmu_enable_interrupt(struct kvm_vcpu *vcpu, unsigned long val) +{ + int select_idx = find_first_bit(&val, 32); + struct kvm_pmu *pmu = &vcpu->arch.pmu; + struct kvm_pmc *pmc = &pmu->pmc[select_idx]; + + pmc->interrupt = true; +} + +/** + * kvm_pmu_disable_interrupt - disable selected PMU counter interrupt + * @vcpu: The vcpu pointer + * @val: the value guest writes to PMINTENCLR_EL0 register + */ +void kvm_pmu_disable_interrupt(struct kvm_vcpu *vcpu, unsigned long val) +{ + int select_idx = find_first_bit(&val, 32); + struct kvm_pmu *pmu = &vcpu->arch.pmu; + struct kvm_pmc *pmc = &pmu->pmc[select_idx]; + + pmc->interrupt = false; +} + +/** * kvm_pmu_find_hw_event - find hardware event * @pmu: The pmu pointer * @event_select: The number of selected event type