From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D085C2F37 for ; Sun, 12 Mar 2023 14:57:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AD1FC433D2; Sun, 12 Mar 2023 14:57:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678633039; bh=qJ5BK1F+lRey4DO9Tjmz6kg1okLxjpkyWFTuaPCfnyQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NKoUh21KgGjhr4+NXfaA+3sBE2xmbHr5kvVF9lfrsYzzvpaUFwOBUCLVSOJTtRITj kD6RagUwSH/Q8bZOZkuYM/5h0Ce++rR75KAafZ9TlvDPO9dpirpuB8N5wtcmQQ293J BUkEPu5rIIgnlrDpI5LHIXwaJeXR8EvcQ//dn6pKvOuXqjQAOD5iJfT5ploT+7Jd6Y eV8iZY981jkaN4MSH0W86QTxbqapD1Po+wZWJ9G3yQMgMuDWdtyiYMPeCaTE+8uDK5 w6siGdVyVQ2RfS8OaYB+wxijCs1tvhJClGCj6Os+vp3hLNmMCN+Q4RGGMKbZTF/2rP SOWNsR/N6JQ2g== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pbN8P-00H0t3-Eh; Sun, 12 Mar 2023 14:57:17 +0000 Date: Sun, 12 Mar 2023 14:57:17 +0000 Message-ID: <87zg8i3tma.wl-maz@kernel.org> From: Marc Zyngier To: Reiji Watanabe Cc: Oliver Upton , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Zenghui Yu , Suzuki K Poulose , Paolo Bonzini , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , Will Deacon Subject: Re: [PATCH 1/2] KVM: arm64: PMU: Fix GET_ONE_REG for vPMC regs to return the current value In-Reply-To: <20230302055033.3081456-2-reijiw@google.com> References: <20230302055033.3081456-1-reijiw@google.com> <20230302055033.3081456-2-reijiw@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) Precedence: bulk X-Mailing-List: kvmarm@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") Content-Type: text/plain; charset=US-ASCII X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: reijiw@google.com, oliver.upton@linux.dev, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, alexandru.elisei@arm.com, yuzenghui@huawei.com, suzuki.poulose@arm.com, pbonzini@redhat.com, ricarkol@google.com, jingzhangos@google.com, rananta@google.com, will@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false On Thu, 02 Mar 2023 05:50:32 +0000, Reiji Watanabe wrote: > > Have KVM_GET_ONE_REG for vPMU counter (vPMC) registers (PMCCNTR_EL0 > and PMEVCNTR_EL0) return the sum of the register value in the sysreg > file and the current perf event counter value. > > Values of vPMC registers are saved in sysreg files on certain occasions. > These saved values don't represent the current values of the vPMC > registers if the perf events for the vPMCs count events after the save. > The current values of those registers are the sum of the sysreg file > value and the current perf event counter value. But, when userspace > reads those registers (using KVM_GET_ONE_REG), KVM returns the sysreg > file value to userspace (not the sum value). > > Fix this to return the sum value for KVM_GET_ONE_REG. > > Signed-off-by: Reiji Watanabe > --- > arch/arm64/kvm/sys_regs.c | 21 +++++++++++++++++++-- > 1 file changed, 19 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index c6cbfe6b854b..c48c053d6146 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -765,6 +765,22 @@ static bool pmu_counter_idx_valid(struct kvm_vcpu *vcpu, u64 idx) > return true; > } > > +static int get_pmu_evcntr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, > + u64 *val) > +{ > + u64 idx; > + > + if (r->CRn == 9 && r->CRm == 13 && r->Op2 == 0) > + /* PMCCNTR_EL0 */ > + idx = ARMV8_PMU_CYCLE_IDX; > + else > + /* PMEVCNTRn_EL0 */ > + idx = ((r->CRm & 3) << 3) | (r->Op2 & 7); > + > + *val = kvm_pmu_get_counter_value(vcpu, idx); > + return 0; It is a bit odd not to return an error when no PMU present, but this is already filtered out by the top-level accessors. > +} > + > static bool access_pmu_evcntr(struct kvm_vcpu *vcpu, > struct sys_reg_params *p, > const struct sys_reg_desc *r) > @@ -981,7 +997,7 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, > /* Macro to expand the PMEVCNTRn_EL0 register */ > #define PMU_PMEVCNTR_EL0(n) \ > { PMU_SYS_REG(SYS_PMEVCNTRn_EL0(n)), \ > - .reset = reset_pmevcntr, \ > + .reset = reset_pmevcntr, .get_user = get_pmu_evcntr, \ > .access = access_pmu_evcntr, .reg = (PMEVCNTR0_EL0 + n), } > > /* Macro to expand the PMEVTYPERn_EL0 register */ > @@ -1745,7 +1761,8 @@ static const struct sys_reg_desc sys_reg_descs[] = { > { PMU_SYS_REG(SYS_PMCEID1_EL0), > .access = access_pmceid, .reset = NULL }, > { PMU_SYS_REG(SYS_PMCCNTR_EL0), > - .access = access_pmu_evcntr, .reset = reset_unknown, .reg = PMCCNTR_EL0 }, > + .access = access_pmu_evcntr, .reset = reset_unknown, > + .reg = PMCCNTR_EL0, .get_user = get_pmu_evcntr}, > { PMU_SYS_REG(SYS_PMXEVTYPER_EL0), > .access = access_pmu_evtyper, .reset = NULL }, > { PMU_SYS_REG(SYS_PMXEVCNTR_EL0), Reviewed-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible. From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0B063C6FA99 for ; Sun, 12 Mar 2023 14:58:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Subject:Cc:To:From:Message-ID:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9QFCv7scxWLgsBphL4xQ1+c2M3sG8YQfcxsQrmT38pc=; b=1YtKxEYbpOrKSU cbHWDsS1OPbZOYqEWWndmlv+JyFxmniPR7oMNOoJMDUzwJUeV/zLmACeASE9BdzY9M/mIGvI7A4or 6nObrEd7l4JUS99GzV/NfDPbQj4SDpnf9WpIGbgZ00x6Ju4Y4Ynwjzb5vvorXauLNdWuePSmNudWd yLTzfsBAmifs75pk4c9NBmxCdA3eqlbiXhLPj4XOtqaTjzYkIYpqhfrDHSdHVO/fgHdDLVTovvWrg yuQ8lakcjEv3DFciap8V9GUD12ivRfkvIwFUeOL514iOvMI93qIFzsP+1vjxrAj90MnMRPVr51QiC Ba3D3S4Mp8+F0+Ta14Pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbN8Y-002iA1-Cx; Sun, 12 Mar 2023 14:57:26 +0000 Received: from dfw.source.kernel.org ([139.178.84.217]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pbN8S-002i9T-L2 for linux-arm-kernel@lists.infradead.org; Sun, 12 Mar 2023 14:57:25 +0000 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 1E58F60EBF; Sun, 12 Mar 2023 14:57:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7AD1FC433D2; Sun, 12 Mar 2023 14:57:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678633039; bh=qJ5BK1F+lRey4DO9Tjmz6kg1okLxjpkyWFTuaPCfnyQ=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=NKoUh21KgGjhr4+NXfaA+3sBE2xmbHr5kvVF9lfrsYzzvpaUFwOBUCLVSOJTtRITj kD6RagUwSH/Q8bZOZkuYM/5h0Ce++rR75KAafZ9TlvDPO9dpirpuB8N5wtcmQQ293J BUkEPu5rIIgnlrDpI5LHIXwaJeXR8EvcQ//dn6pKvOuXqjQAOD5iJfT5ploT+7Jd6Y eV8iZY981jkaN4MSH0W86QTxbqapD1Po+wZWJ9G3yQMgMuDWdtyiYMPeCaTE+8uDK5 w6siGdVyVQ2RfS8OaYB+wxijCs1tvhJClGCj6Os+vp3hLNmMCN+Q4RGGMKbZTF/2rP SOWNsR/N6JQ2g== Received: from sofa.misterjones.org ([185.219.108.64] helo=wait-a-minute.misterjones.org) by disco-boy.misterjones.org with esmtpsa (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1pbN8P-00H0t3-Eh; Sun, 12 Mar 2023 14:57:17 +0000 Date: Sun, 12 Mar 2023 14:57:17 +0000 Message-ID: <87zg8i3tma.wl-maz@kernel.org> From: Marc Zyngier To: Reiji Watanabe Cc: Oliver Upton , kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, James Morse , Alexandru Elisei , Zenghui Yu , Suzuki K Poulose , Paolo Bonzini , Ricardo Koller , Jing Zhang , Raghavendra Rao Anata , Will Deacon Subject: Re: [PATCH 1/2] KVM: arm64: PMU: Fix GET_ONE_REG for vPMC regs to return the current value In-Reply-To: <20230302055033.3081456-2-reijiw@google.com> References: <20230302055033.3081456-1-reijiw@google.com> <20230302055033.3081456-2-reijiw@google.com> User-Agent: Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM-LB/1.14.9 (=?UTF-8?B?R29qxY0=?=) APEL-LB/10.8 EasyPG/1.0.0 Emacs/27.1 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) MIME-Version: 1.0 (generated by SEMI-EPG 1.14.7 - "Harue") X-SA-Exim-Connect-IP: 185.219.108.64 X-SA-Exim-Rcpt-To: reijiw@google.com, oliver.upton@linux.dev, kvmarm@lists.linux.dev, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, james.morse@arm.com, alexandru.elisei@arm.com, yuzenghui@huawei.com, suzuki.poulose@arm.com, pbonzini@redhat.com, ricarkol@google.com, jingzhangos@google.com, rananta@google.com, will@kernel.org X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230312_075720_814158_6D314708 X-CRM114-Status: GOOD ( 29.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Thu, 02 Mar 2023 05:50:32 +0000, Reiji Watanabe wrote: > > Have KVM_GET_ONE_REG for vPMU counter (vPMC) registers (PMCCNTR_EL0 > and PMEVCNTR_EL0) return the sum of the register value in the sysreg > file and the current perf event counter value. > > Values of vPMC registers are saved in sysreg files on certain occasions. > These saved values don't represent the current values of the vPMC > registers if the perf events for the vPMCs count events after the save. > The current values of those registers are the sum of the sysreg file > value and the current perf event counter value. But, when userspace > reads those registers (using KVM_GET_ONE_REG), KVM returns the sysreg > file value to userspace (not the sum value). > > Fix this to return the sum value for KVM_GET_ONE_REG. > > Signed-off-by: Reiji Watanabe > --- > arch/arm64/kvm/sys_regs.c | 21 +++++++++++++++++++-- > 1 file changed, 19 insertions(+), 2 deletions(-) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index c6cbfe6b854b..c48c053d6146 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -765,6 +765,22 @@ static bool pmu_counter_idx_valid(struct kvm_vcpu *vcpu, u64 idx) > return true; > } > > +static int get_pmu_evcntr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r, > + u64 *val) > +{ > + u64 idx; > + > + if (r->CRn == 9 && r->CRm == 13 && r->Op2 == 0) > + /* PMCCNTR_EL0 */ > + idx = ARMV8_PMU_CYCLE_IDX; > + else > + /* PMEVCNTRn_EL0 */ > + idx = ((r->CRm & 3) << 3) | (r->Op2 & 7); > + > + *val = kvm_pmu_get_counter_value(vcpu, idx); > + return 0; It is a bit odd not to return an error when no PMU present, but this is already filtered out by the top-level accessors. > +} > + > static bool access_pmu_evcntr(struct kvm_vcpu *vcpu, > struct sys_reg_params *p, > const struct sys_reg_desc *r) > @@ -981,7 +997,7 @@ static bool access_pmuserenr(struct kvm_vcpu *vcpu, struct sys_reg_params *p, > /* Macro to expand the PMEVCNTRn_EL0 register */ > #define PMU_PMEVCNTR_EL0(n) \ > { PMU_SYS_REG(SYS_PMEVCNTRn_EL0(n)), \ > - .reset = reset_pmevcntr, \ > + .reset = reset_pmevcntr, .get_user = get_pmu_evcntr, \ > .access = access_pmu_evcntr, .reg = (PMEVCNTR0_EL0 + n), } > > /* Macro to expand the PMEVTYPERn_EL0 register */ > @@ -1745,7 +1761,8 @@ static const struct sys_reg_desc sys_reg_descs[] = { > { PMU_SYS_REG(SYS_PMCEID1_EL0), > .access = access_pmceid, .reset = NULL }, > { PMU_SYS_REG(SYS_PMCCNTR_EL0), > - .access = access_pmu_evcntr, .reset = reset_unknown, .reg = PMCCNTR_EL0 }, > + .access = access_pmu_evcntr, .reset = reset_unknown, > + .reg = PMCCNTR_EL0, .get_user = get_pmu_evcntr}, > { PMU_SYS_REG(SYS_PMXEVTYPER_EL0), > .access = access_pmu_evtyper, .reset = NULL }, > { PMU_SYS_REG(SYS_PMXEVCNTR_EL0), Reviewed-by: Marc Zyngier M. -- Without deviation from the norm, progress is not possible. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel