Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp333099ybi; Fri, 24 May 2019 04:39:07 -0700 (PDT) X-Google-Smtp-Source: APXvYqwQfXYjumgfCKp6npFMt+L1WF7yelMEeE9LYs9ZfOobl8AfEFFLnjyNNgNMSa3AWd7Wk6gl X-Received: by 2002:a17:902:f096:: with SMTP id go22mr106264938plb.49.1558697947836; Fri, 24 May 2019 04:39:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558697947; cv=none; d=google.com; s=arc-20160816; b=0yGAefWKiZQE8BVMLAUrHD+nrx2jeahaCzrWo5U7KqxfLzmYNwCaHHK6XvtuBicXIA EI2Pmhxg6GV859t9vIuXwn7A0HV55YQm3ktcZpjgt8hPxd/9Z4oPaV6ROfROJ0dgHNLh vXLCY016T/yZ882TCpbqhA1V8J+r3eLRkkPsEAFCbn8O//sfhKVlMC1M1rWVeCqnKblg EA0HL19ZEPcCwt1fij2r15InJ5oFfibwkR0KmCzPiEQ6DmFOgcrVIxAh9qN+lFLjoc0T WQPmnsRx3RMl4lpQ20GIlceEQhnd0A6pub/5HgZBxZPGTBuBadye4ryCWSaUTm1ZpIoB teWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=J7lfRxbd67XKClJOax5iF7zTMltK+dEyZCcIr3p1dcs=; b=GA18EX3d90Ho7mA3AX8aLEp49TjSMgM35bgYhC7PEoxz3uXWgvcpgvjvdU0yJwDU1M WdFLab/BRlUi3u2JoV0LULo1IbkHmzlrn9BXZeIfSC+d/DnHu/9DUyDsdS+qBVgGqzjn ekc9PYgtRta1WihxBxsWp41c/+tpp+8Wa/JcbyW6/nQBYB7HZz5cpFsrxpP7czwlQa/E /gBKynb65rjhMcapi2PDRZouHefUDpXvN/ZYM1XxaPRv/NGCmdt+8YpNCILBEzInOW8H jq6Jraa805hLkqMMGbA9fzaJ6X/rAa8gNxISE9WurV3J+/w0a78mF342bhSLeJmxM2Ys YJow== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m11si3493841pjr.100.2019.05.24.04.38.51; Fri, 24 May 2019 04:39:07 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2391265AbfEXLgb (ORCPT + 99 others); Fri, 24 May 2019 07:36:31 -0400 Received: from usa-sjc-mx-foss1.foss.arm.com ([217.140.101.70]:41010 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390760AbfEXLg2 (ORCPT ); Fri, 24 May 2019 07:36:28 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id F26B2374; Fri, 24 May 2019 04:36:27 -0700 (PDT) Received: from [10.1.197.45] (e112298-lin.cambridge.arm.com [10.1.197.45]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id E50BB3F703; Fri, 24 May 2019 04:36:25 -0700 (PDT) Subject: Re: [PATCH v2 05/15] arm64: KVM: add access handler for SPE system registers To: Sudeep Holla , kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Christoffer Dall , Marc Zyngier , James Morse , Suzuki K Pouloze , Catalin Marinas , Will Deacon References: <20190523103502.25925-1-sudeep.holla@arm.com> <20190523103502.25925-6-sudeep.holla@arm.com> From: Julien Thierry Message-ID: Date: Fri, 24 May 2019 12:36:24 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <20190523103502.25925-6-sudeep.holla@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Sudeep, On 23/05/2019 11:34, Sudeep Holla wrote: > SPE Profiling Buffer owning EL is configurable and when MDCR_EL2.E2PB > is configured to provide buffer ownership to EL1, the control registers > are trapped. > > Add access handlers for the Statistical Profiling Extension(SPE) > Profiling Buffer controls registers. This is need to support profiling > using SPE in the guests. > > Signed-off-by: Sudeep Holla > --- > arch/arm64/include/asm/kvm_host.h | 13 ++++++++++++ > arch/arm64/kvm/sys_regs.c | 35 +++++++++++++++++++++++++++++++ > include/kvm/arm_spe.h | 15 +++++++++++++ > 3 files changed, 63 insertions(+) > > diff --git a/arch/arm64/include/asm/kvm_host.h b/arch/arm64/include/asm/kvm_host.h > index 611a4884fb6c..559aa6931291 100644 > --- a/arch/arm64/include/asm/kvm_host.h > +++ b/arch/arm64/include/asm/kvm_host.h > @@ -147,6 +147,19 @@ enum vcpu_sysreg { > MDCCINT_EL1, /* Monitor Debug Comms Channel Interrupt Enable Reg */ > DISR_EL1, /* Deferred Interrupt Status Register */ > > + /* Statistical Profiling Extension Registers */ > + > + PMSCR_EL1, > + PMSICR_EL1, > + PMSIRR_EL1, > + PMSFCR_EL1, > + PMSEVFR_EL1, > + PMSLATFR_EL1, > + PMSIDR_EL1, > + PMBLIMITR_EL1, > + PMBPTR_EL1, > + PMBSR_EL1, > + > /* Performance Monitors Registers */ > PMCR_EL0, /* Control Register */ > PMSELR_EL0, /* Event Counter Selection Register */ > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index 857b226bcdde..dbf5056828d3 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -646,6 +646,30 @@ static void reset_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) > __vcpu_sys_reg(vcpu, PMCR_EL0) = val; > } > > +static bool access_pmsb_val(struct kvm_vcpu *vcpu, struct sys_reg_params *p, > + const struct sys_reg_desc *r) > +{ > + if (p->is_write) > + vcpu_write_sys_reg(vcpu, p->regval, r->reg); > + else > + p->regval = vcpu_read_sys_reg(vcpu, r->reg); > + > + return true; > +} > + > +static void reset_pmsb_val(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) > +{ > + if (!kvm_arm_support_spe_v1()) { > + __vcpu_sys_reg(vcpu, r->reg) = 0; > + return; > + } > + > + if (r->reg == PMSIDR_EL1) If only PMSIDR_EL1 has a non-zero reset value, it feels a bit weird to share the reset function for all these registers. I would suggest only having a reset_pmsidr() function, and just use reset_val() with sys_reg_desc->val set to 0 for all the others. > + __vcpu_sys_reg(vcpu, r->reg) = read_sysreg_s(SYS_PMSIDR_EL1); > + else > + __vcpu_sys_reg(vcpu, r->reg) = 0; > +} > + > static bool check_pmu_access_disabled(struct kvm_vcpu *vcpu, u64 flags) > { > u64 reg = __vcpu_sys_reg(vcpu, PMUSERENR_EL0); > @@ -1513,6 +1537,17 @@ static const struct sys_reg_desc sys_reg_descs[] = { > { SYS_DESC(SYS_FAR_EL1), access_vm_reg, reset_unknown, FAR_EL1 }, > { SYS_DESC(SYS_PAR_EL1), NULL, reset_unknown, PAR_EL1 }, > > + { SYS_DESC(SYS_PMSCR_EL1), access_pmsb_val, reset_pmsb_val, PMSCR_EL1 }, > + { SYS_DESC(SYS_PMSICR_EL1), access_pmsb_val, reset_pmsb_val, PMSICR_EL1 }, > + { SYS_DESC(SYS_PMSIRR_EL1), access_pmsb_val, reset_pmsb_val, PMSIRR_EL1 }, > + { SYS_DESC(SYS_PMSFCR_EL1), access_pmsb_val, reset_pmsb_val, PMSFCR_EL1 }, > + { SYS_DESC(SYS_PMSEVFR_EL1), access_pmsb_val, reset_pmsb_val, PMSEVFR_EL1}, > + { SYS_DESC(SYS_PMSLATFR_EL1), access_pmsb_val, reset_pmsb_val, PMSLATFR_EL1 }, > + { SYS_DESC(SYS_PMSIDR_EL1), access_pmsb_val, reset_pmsb_val, PMSIDR_EL1 }, > + { SYS_DESC(SYS_PMBLIMITR_EL1), access_pmsb_val, reset_pmsb_val, PMBLIMITR_EL1 }, > + { SYS_DESC(SYS_PMBPTR_EL1), access_pmsb_val, reset_pmsb_val, PMBPTR_EL1 }, > + { SYS_DESC(SYS_PMBSR_EL1), access_pmsb_val, reset_pmsb_val, PMBSR_EL1 }, > + > { SYS_DESC(SYS_PMINTENSET_EL1), access_pminten, reset_unknown, PMINTENSET_EL1 }, > { SYS_DESC(SYS_PMINTENCLR_EL1), access_pminten, NULL, PMINTENSET_EL1 }, > > diff --git a/include/kvm/arm_spe.h b/include/kvm/arm_spe.h > index 8c96bdfad6ac..2440ff02f747 100644 > --- a/include/kvm/arm_spe.h > +++ b/include/kvm/arm_spe.h > @@ -8,6 +8,7 @@ > > #include > #include > +#include > > struct kvm_spe { > int irq; > @@ -15,4 +16,18 @@ struct kvm_spe { > bool created; /* SPE KVM instance is created, may not be ready yet */ > }; > > +#ifdef CONFIG_KVM_ARM_SPE > + > +static inline bool kvm_arm_support_spe_v1(void) > +{ > + u64 dfr0 = read_sanitised_ftr_reg(SYS_ID_AA64DFR0_EL1); > + > + return !!cpuid_feature_extract_unsigned_field(dfr0, > + ID_AA64DFR0_PMSVER_SHIFT); > +} > +#else > + > +#define kvm_arm_support_spe_v1() (false) > +#endif /* CONFIG_KVM_ARM_SPE */ > + > #endif /* __ASM_ARM_KVM_SPE_H */ > Cheers, -- Julien Thierry