Message ID | 20221209164446.1972014-2-james.clark@arm.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp881475wrr; Fri, 9 Dec 2022 08:49:26 -0800 (PST) X-Google-Smtp-Source: AA0mqf7kqASx8dTDM6EDaktFAPl1V9jqFXx1GvK3mS8Ntj365fVbWQZzHOb0ecm4ZXXNNch/jl1L X-Received: by 2002:a17:902:7407:b0:189:5b2b:3df4 with SMTP id g7-20020a170902740700b001895b2b3df4mr6186003pll.24.1670604566105; Fri, 09 Dec 2022 08:49:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670604566; cv=none; d=google.com; s=arc-20160816; b=mWccfwCNd7UATA9HAU0ngND2HFm/EF8IhC3/ZaVcnHCx2o+D9JwOpVMCDnEGQ+gH6L jMTBXiaeYwWj/zRoB1GKwAwTnNgu3MSLo1fsp93xqSTDbkY2EjgNa3pjXXDvfhZ9s4X2 y2KSO++H1uftP6D3H/huQT2hlqrI1qXS4DzhOIxLQtTmF0wevlvH57/swXnrA+rc/FjS qB2sLPgdo79qv+6f1wIzfTKEUq642cE3pMOaSCk73TG/JvAVHkHU3kDxBKaZ4Fk4lwK6 Iz1dhslycMt0e5D1ehdTgQ1mo0Mw3+VW8PVq2E/l1hKjesJo48hA04ziAXgcCmvBUztq jJsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=oynctOzENr0XjdFbsuLte8H+uJMqZq4Idj0g0UQwvQk=; b=A/p6F/9KAmMP4IXudi7cImwbQAMyVXcxChaP8AYekup/HfsUNqwxgDJlI6rFNDSFa7 brn4CyQ+26AC9oxKBkzvkDdDamRmABLLTPLYNdh74HzlMFwcgYJTCYfAOeU17Yb7EJFi vR4V8ZKyek1dzciirdpERmJ9NLlKjubzy5nikYmpOvQsaZirJ5errag0laL08xhzc1DJ M90zFottysLQkoreVfFxgc9HdH/237QUCztYSTe7C4ORoTkwVxO4WLm8Xc+vtLFABI1z vRJQTkccrtlU78n93vVEMYpR8JKX29MAtphV3EoxVWj2X/Ah3eMqc7IFo1McqLeKCC4n nX8Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x15-20020a170902ec8f00b001870dc9ef5asi2061659plg.285.2022.12.09.08.49.10; Fri, 09 Dec 2022 08:49:26 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229714AbiLIQpS (ORCPT <rfc822;sophiezhao968@gmail.com> + 99 others); Fri, 9 Dec 2022 11:45:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbiLIQpO (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 9 Dec 2022 11:45:14 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D47102EF22 for <linux-kernel@vger.kernel.org>; Fri, 9 Dec 2022 08:45:13 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 68027D6E; Fri, 9 Dec 2022 08:45:20 -0800 (PST) Received: from e126815.warwick.arm.com (e126815.arm.com [10.32.32.26]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id E3C1A3F73D; Fri, 9 Dec 2022 08:45:11 -0800 (PST) From: James Clark <james.clark@arm.com> To: kvmarm@lists.linux.dev Cc: James Clark <james.clark@arm.com>, Marc Zyngier <maz@kernel.org>, James Morse <james.morse@arm.com>, Alexandru Elisei <alexandru.elisei@arm.com>, Suzuki K Poulose <suzuki.poulose@arm.com>, Oliver Upton <oliver.upton@linux.dev>, Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org Subject: [PATCH 1/1] KVM: arm64: PMU: Fix PMCR_EL0 reset value Date: Fri, 9 Dec 2022 16:44:46 +0000 Message-Id: <20221209164446.1972014-2-james.clark@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221209164446.1972014-1-james.clark@arm.com> References: <20221209164446.1972014-1-james.clark@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751755665366385403?= X-GMAIL-MSGID: =?utf-8?q?1751755853933255623?= |
Series |
KVM: arm64: PMU: Fix PMCR_EL0 reset value
|
|
Commit Message
James Clark
Dec. 9, 2022, 4:44 p.m. UTC
ARMV8_PMU_PMCR_N_MASK is an unshifted value which results in the wrong
reset value for PMCR_EL0, so shift it to fix it.
This fixes the following error when running qemu:
$ qemu-system-aarch64 -cpu host -machine type=virt,accel=kvm -kernel ...
target/arm/helper.c:1813: pmevcntr_rawwrite: Assertion `counter < pmu_num_counters(env)' failed.
Fixes: 292e8f149476 ("KVM: arm64: PMU: Simplify PMCR_EL0 reset handling")
Signed-off-by: James Clark <james.clark@arm.com>
---
arch/arm64/kvm/sys_regs.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Comments
On Fri, Dec 09, 2022 at 04:44:46PM +0000, James Clark wrote: > ARMV8_PMU_PMCR_N_MASK is an unshifted value which results in the wrong > reset value for PMCR_EL0, so shift it to fix it. That's just mean. *_MASK tends to be a shifted mask, although it would appear that asm/perf_event.h does not follow this convention. Fixing that would be nice (as I'm sure somebody else will get burned by this), but for the sake of an immediate fix: > This fixes the following error when running qemu: > > $ qemu-system-aarch64 -cpu host -machine type=virt,accel=kvm -kernel ... > > target/arm/helper.c:1813: pmevcntr_rawwrite: Assertion `counter < pmu_num_counters(env)' failed. > > Fixes: 292e8f149476 ("KVM: arm64: PMU: Simplify PMCR_EL0 reset handling") > Signed-off-by: James Clark <james.clark@arm.com> Reviewed-by: Oliver Upton <oliver.upton@linux.dev> -- Thanks, Oliver > --- > arch/arm64/kvm/sys_regs.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > index d5ee52d6bf73..c6cbfe6b854b 100644 > --- a/arch/arm64/kvm/sys_regs.c > +++ b/arch/arm64/kvm/sys_regs.c > @@ -646,7 +646,7 @@ static void reset_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) > return; > > /* Only preserve PMCR_EL0.N, and reset the rest to 0 */ > - pmcr = read_sysreg(pmcr_el0) & ARMV8_PMU_PMCR_N_MASK; > + pmcr = read_sysreg(pmcr_el0) & (ARMV8_PMU_PMCR_N_MASK << ARMV8_PMU_PMCR_N_SHIFT); > if (!kvm_supports_32bit_el0()) > pmcr |= ARMV8_PMU_PMCR_LC; > > -- > 2.25.1 >
On Fri, 09 Dec 2022 17:58:31 +0000, Oliver Upton <oliver.upton@linux.dev> wrote: > > On Fri, Dec 09, 2022 at 04:44:46PM +0000, James Clark wrote: > > ARMV8_PMU_PMCR_N_MASK is an unshifted value which results in the wrong > > reset value for PMCR_EL0, so shift it to fix it. > > That's just mean. *_MASK tends to be a shifted mask, although it would > appear that asm/perf_event.h does not follow this convention. Fixing > that would be nice (as I'm sure somebody else will get burned by this), > but for the sake of an immediate fix: Well, that'll teach me the usual lesson: last minute changes without full non-regression testing are bound to end in disaster. > > > This fixes the following error when running qemu: > > > > $ qemu-system-aarch64 -cpu host -machine type=virt,accel=kvm -kernel ... > > > > target/arm/helper.c:1813: pmevcntr_rawwrite: Assertion `counter < pmu_num_counters(env)' failed. > > > > Fixes: 292e8f149476 ("KVM: arm64: PMU: Simplify PMCR_EL0 reset handling") > > Signed-off-by: James Clark <james.clark@arm.com> > > Reviewed-by: Oliver Upton <oliver.upton@linux.dev> Thanks both. I'll queue that ASAP as a fix. M.
On 12/9/22 23:28, Oliver Upton wrote: > On Fri, Dec 09, 2022 at 04:44:46PM +0000, James Clark wrote: >> ARMV8_PMU_PMCR_N_MASK is an unshifted value which results in the wrong >> reset value for PMCR_EL0, so shift it to fix it. > > That's just mean. *_MASK tends to be a shifted mask, although it would > appear that asm/perf_event.h does not follow this convention. Fixing > that would be nice (as I'm sure somebody else will get burned by this), > but for the sake of an immediate fix: New arch/arm64/tools/sysreg generates shifted i.e in place masks for register fields. Once all these PMU registers move into arch/arm64/tools/sysreg, this problem will be solved. > >> This fixes the following error when running qemu: >> >> $ qemu-system-aarch64 -cpu host -machine type=virt,accel=kvm -kernel ... >> >> target/arm/helper.c:1813: pmevcntr_rawwrite: Assertion `counter < pmu_num_counters(env)' failed. >> >> Fixes: 292e8f149476 ("KVM: arm64: PMU: Simplify PMCR_EL0 reset handling") >> Signed-off-by: James Clark <james.clark@arm.com> > > Reviewed-by: Oliver Upton <oliver.upton@linux.dev> > > -- > Thanks, > Oliver > >> --- >> arch/arm64/kvm/sys_regs.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c >> index d5ee52d6bf73..c6cbfe6b854b 100644 >> --- a/arch/arm64/kvm/sys_regs.c >> +++ b/arch/arm64/kvm/sys_regs.c >> @@ -646,7 +646,7 @@ static void reset_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) >> return; >> >> /* Only preserve PMCR_EL0.N, and reset the rest to 0 */ >> - pmcr = read_sysreg(pmcr_el0) & ARMV8_PMU_PMCR_N_MASK; >> + pmcr = read_sysreg(pmcr_el0) & (ARMV8_PMU_PMCR_N_MASK << ARMV8_PMU_PMCR_N_SHIFT); >> if (!kvm_supports_32bit_el0()) >> pmcr |= ARMV8_PMU_PMCR_LC; >> >> -- >> 2.25.1 >> > > _______________________________________________ > linux-arm-kernel mailing list > linux-arm-kernel@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
On Fri, Dec 09, 2022 at 05:58:31PM +0000, Oliver Upton wrote: > On Fri, Dec 09, 2022 at 04:44:46PM +0000, James Clark wrote: > > ARMV8_PMU_PMCR_N_MASK is an unshifted value which results in the wrong > > reset value for PMCR_EL0, so shift it to fix it. > > That's just mean. *_MASK tends to be a shifted mask, although it would > appear that asm/perf_event.h does not follow this convention. Fixing > that would be nice (as I'm sure somebody else will get burned by this), > but for the sake of an immediate fix: > Even kvm-unit-tests does this: arm/pmu.c: #define PMU_PMCR_N_SHIFT 11 #define PMU_PMCR_N_MASK 0x1f > > This fixes the following error when running qemu: > > > > $ qemu-system-aarch64 -cpu host -machine type=virt,accel=kvm -kernel ... > > > > target/arm/helper.c:1813: pmevcntr_rawwrite: Assertion `counter < pmu_num_counters(env)' failed. > > > > Fixes: 292e8f149476 ("KVM: arm64: PMU: Simplify PMCR_EL0 reset handling") > > Signed-off-by: James Clark <james.clark@arm.com> > > Reviewed-by: Oliver Upton <oliver.upton@linux.dev> > > -- > Thanks, > Oliver > > > --- > > arch/arm64/kvm/sys_regs.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c > > index d5ee52d6bf73..c6cbfe6b854b 100644 > > --- a/arch/arm64/kvm/sys_regs.c > > +++ b/arch/arm64/kvm/sys_regs.c > > @@ -646,7 +646,7 @@ static void reset_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) > > return; > > > > /* Only preserve PMCR_EL0.N, and reset the rest to 0 */ > > - pmcr = read_sysreg(pmcr_el0) & ARMV8_PMU_PMCR_N_MASK; > > + pmcr = read_sysreg(pmcr_el0) & (ARMV8_PMU_PMCR_N_MASK << ARMV8_PMU_PMCR_N_SHIFT); > > if (!kvm_supports_32bit_el0()) > > pmcr |= ARMV8_PMU_PMCR_LC; > > > > -- > > 2.25.1 > > > _______________________________________________ > kvmarm mailing list > kvmarm@lists.cs.columbia.edu > https://lists.cs.columbia.edu/mailman/listinfo/kvmarm
diff --git a/arch/arm64/kvm/sys_regs.c b/arch/arm64/kvm/sys_regs.c index d5ee52d6bf73..c6cbfe6b854b 100644 --- a/arch/arm64/kvm/sys_regs.c +++ b/arch/arm64/kvm/sys_regs.c @@ -646,7 +646,7 @@ static void reset_pmcr(struct kvm_vcpu *vcpu, const struct sys_reg_desc *r) return; /* Only preserve PMCR_EL0.N, and reset the rest to 0 */ - pmcr = read_sysreg(pmcr_el0) & ARMV8_PMU_PMCR_N_MASK; + pmcr = read_sysreg(pmcr_el0) & (ARMV8_PMU_PMCR_N_MASK << ARMV8_PMU_PMCR_N_SHIFT); if (!kvm_supports_32bit_el0()) pmcr |= ARMV8_PMU_PMCR_LC;