Skip to contentSkip to conversation

arm: pmu: Fix failing PMU test when no PMU is available

PATCH In review Marc Zyngier 3 participants 4 messages Mar 24, 2021

Subsystems (2)
lore
Share & tools
lore

Marc Zyngier

author maintainer
#0 lore raw

PATCH 1/1 arm: pmu: Fix failing PMU test when no PMU is available

The PMU unit tests fail with an UNDEF exception when no PMU is available (although KVM hasn't been totally consistent with that in the past).

This is caused by PMCR_EL0 being read *before* ID_AA64DFR0_EL1 is checked for the PMU version.

Move the PMCR_EL0 access to a reasonable place, which allows the test to soft-fail gracefully.

Fixes 784ee933fa5f ("arm: pmu: Introduce defines for PMU versions")
---
 arm/pmu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arm/pmu.c +2 -1
index cc959e6..15c542a 100644
@@ -988,7 +988,7 @@ static void pmccntr64_test(void)
 /* Return FALSE if no PMU found, otherwise return TRUE */
 static bool pmu_probe(void)
 {
-	uint32_t pmcr = get_pmcr();
+	uint32_t pmcr;
 	uint8_t implementer;
 
 	pmu.version = get_pmu_version();
@@ -997,6 +997,7 @@ static bool pmu_probe(void)
 
 	report_info("PMU version: 0x%x", pmu.version);
 
+	pmcr = get_pmcr();
 	implementer = (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK;
 	report_info("PMU implementer/ID code: %#"PRIx32"(\"%c\")/%#"PRIx32,
 		    (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK,
Signature · 6 lines
2.30.0

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

Hi Marc,

Thank you for the patch! I have already sent a patch for this [1], which was queued by Drew [2], but apparently has not landed in master yet.

[1] https://www.spinics.net/lists/kvm-arm/msg44084.html
[2]
https://gitlab.com/rhdrjones/kvm-unit-tests/-/commit/241dac4cadfd7d7ace8c8c3f0613376311b4e785

Thanks,

Alex

Quoted 31 lines · Marc Zyngier

The PMU unit tests fail with an UNDEF exception when no PMU is available (although KVM hasn't been totally consistent with that in the past).

This is caused by PMCR_EL0 being read *before* ID_AA64DFR0_EL1 is checked for the PMU version.

Move the PMCR_EL0 access to a reasonable place, which allows the test to soft-fail gracefully.

Fixes 784ee933fa5f ("arm: pmu: Introduce defines for PMU versions")
---
 arm/pmu.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
arm/pmu.c +1 -1
index cc959e6..15c542a 100644
@@ -988,7 +988,7 @@ static void pmccntr64_test(void)
 /* Return FALSE if no PMU found, otherwise return TRUE */
 static bool pmu_probe(void)
 {
-	uint32_t pmcr = get_pmcr();
+	uint32_t pmcr;
 	uint8_t implementer;
 
 	pmu.version = get_pmu_version();

arm/pmu.c static bool pmu_probe(void) · line 1003

Quoted 7 lines
arm/pmu.c +1 -0
@@ -997,6 +997,7 @@ static bool pmu_probe(void)
 
 	report_info("PMU version: 0x%x", pmu.version);
 
+	pmcr = get_pmcr();
 	implementer = (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK;
 	report_info("PMU implementer/ID code: %#"PRIx32"(\"%c\")/%#"PRIx32,
 		    (pmcr >> PMU_PMCR_IMP_SHIFT) & PMU_PMCR_IMP_MASK,

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

#2 lore raw
Quoted 8 lines · Alexandru Elisei

Hi Marc,

Thank you for the patch! I have already sent a patch for this [1], which was queued by Drew [2], but apparently has not landed in master yet.

[1] https://www.spinics.net/lists/kvm-arm/msg44084.html
[2]
https://gitlab.com/rhdrjones/kvm-unit-tests/-/commit/241dac4cadfd7d7ace8c8c3f0613376311b4e785

Thanks to you both for the patch and sorry for not getting Alexandru's patch in early enough to avoid the double reporting and fixing. I plan to send Paolo an MR as soon as tomorrow that includes the patch and many others.

Thanks,
drew

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

author maintainer
#3 lore raw
Quoted 7 lines · Andrew Jones
Quoted 5 lines · Alexandru Elisei

Hi Marc,

Thank you for the patch! I have already sent a patch for this [1], which was queued by Drew [2], but apparently has not landed in master yet.

Quoted 8 lines
Quoted 3 lines

[1] https://www.spinics.net/lists/kvm-arm/msg44084.html
[2]
https://gitlab.com/rhdrjones/kvm-unit-tests/-/commit/241dac4cadfd7d7ace8c8c3f0613376311b4e785

Thanks to you both for the patch and sorry for not getting Alexandru's patch in early enough to avoid the double reporting and fixing. I plan to send Paolo an MR as soon as tomorrow that includes the patch and many others.

No worries. Thanks both!

	M.
Signature · 5 lines
Without deviation from the norm, progress is not possible.
_______________________________________________
kvmarm mailing list
[email protected]
https://lists.cs.columbia.edu/mailman/listinfo/kvmarm