Skip to contentSkip to conversation

KVM: arm64: PMU: Fix PMCR_EL0 reset value

PATCH Applied James Clark 5 participants 8 messages Dec 9, 2022 – Jan 3, 2023

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover KVM: arm64: PMU: Fix PMCR_EL0 reset value

Hi,

We noticed qemu failing to run because of an assert on our CI. I don't see the issue anymore with this fix.

Applies to kvmarm/next (753d734f3f34)

Thanks

James Clark (1):
KVM: arm64: PMU: Fix PMCR_EL0 reset value

 arch/arm64/kvm/sys_regs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/1 KVM: arm64: PMU: Fix PMCR_EL0 reset value

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")
---
 arch/arm64/kvm/sys_regs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +1 -1
index d5ee52d6bf73..c6cbfe6b854b 100644
@@ -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;
 
Signature · 1 line
2.25.1
Reviewed-by on v1 1/1
#2 lore raw
Quoted 2 lines · James Clark

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:

Quoted 8 lines

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")

--
Thanks,
Oliver

Quoted 20 lines
---
 arch/arm64/kvm/sys_regs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +1 -1
index d5ee52d6bf73..c6cbfe6b854b 100644
@@ -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;
 
Signature · 1 line
2.25.1

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer
#3 lore raw
Quoted 9 lines · Oliver Upton
Quoted 2 lines · James Clark

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.

Quoted 11 lines
Quoted 9 lines

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")

Thanks both. I'll queue that ASAP as a fix.

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
#4 lore raw
In reply to Oliver Upton
Quoted 8 lines · Oliver Upton
Quoted 2 lines · James Clark

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.

Quoted 41 lines
Quoted 9 lines

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")

--
Thanks,
Oliver

Quoted 20 lines
---
 arch/arm64/kvm/sys_regs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +1 -1
index d5ee52d6bf73..c6cbfe6b854b 100644
@@ -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;
 
Signature · 1 line
2.25.1

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#5 lore raw
In reply to Oliver Upton
Quoted 9 lines · Oliver Upton
Quoted 2 lines · James Clark

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

Quoted 39 lines
Quoted 8 lines

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")

--
Thanks,
Oliver

Quoted 20 lines
---
 arch/arm64/kvm/sys_regs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm64/kvm/sys_regs.c +1 -1
index d5ee52d6bf73..c6cbfe6b854b 100644
@@ -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;
 
Signature · 1 line
2.25.1

_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm

maintainer Applied
#6 lore raw
In reply to James Clark
Quoted 8 lines · James Clark

We noticed qemu failing to run because of an assert on our CI. I don't see the issue anymore with this fix.

Applies to kvmarm/next (753d734f3f34)

Thanks

[...]

Applied to fixes, thanks!

[1/1] KVM: arm64: PMU: Fix PMCR_EL0 reset value

      commit: aff234839f8b80ac101e6c2f14d0e44b236efa48

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.
maintainer Applied
#7 lore raw
In reply to James Clark
Quoted 8 lines · James Clark

We noticed qemu failing to run because of an assert on our CI. I don't see the issue anymore with this fix.

Applies to kvmarm/next (753d734f3f34)

Thanks

[...]

Applied to fixes, thanks!

[1/1] KVM: arm64: PMU: Fix PMCR_EL0 reset value

      commit: edb4929ea9ba48cd91e3867041f49e4c34d729ed

Cheers,

	M.
Signature · 1 line
Without deviation from the norm, progress is not possible.