Skip to contentSkip to conversation

perf: arm_pmuv3: Fix chained event check for cycle counter

PATCH In review Rob Herring (Arm) 2 participants 4 messages Jul 10, 2024 – Aug 2, 2024 Arm PMU profiling and debugging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: arm_pmuv3: Fix chained event check for cycle counter

Since commit b7e89b0f5bd7 ("perf: arm_pmu: Remove event index to counter remapping"), armv8pmu_event_is_chained() is incorrectly returning that the cycle counter is chained, but the cycle counter has always been 64-bit. The result is trying to configure counter #30 which typically doesn't exist.

As ARMV8_PMU_MAX_GENERAL_COUNTERS is the number of counters (31), the comparison to the counter index needs to be '<' rather than '<='.

Fixes b7e89b0f5bd7 ("perf: arm_pmu: Remove event index to counter remapping")
---
 drivers/perf/arm_pmuv3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/perf/arm_pmuv3.c +1 -1
index 3b3a3334cc3f..0e22c68fb804 100644
@@ -482,7 +482,7 @@ static bool armv8pmu_event_is_chained(struct perf_event *event)
 	return !armv8pmu_event_has_user_read(event) &&
 	       armv8pmu_event_is_64bit(event) &&
 	       !armv8pmu_has_long_event(cpu_pmu) &&
-	       (idx <= ARMV8_PMU_MAX_GENERAL_COUNTERS);
+	       (idx < ARMV8_PMU_MAX_GENERAL_COUNTERS);
 }
 
 /*
Signature · 1 line
2.43.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 20 lines · Rob Herring (Arm)

Since commit b7e89b0f5bd7 ("perf: arm_pmu: Remove event index to counter remapping"), armv8pmu_event_is_chained() is incorrectly returning that the cycle counter is chained, but the cycle counter has always been 64-bit. The result is trying to configure counter #30 which typically doesn't exist.

As ARMV8_PMU_MAX_GENERAL_COUNTERS is the number of counters (31), the comparison to the counter index needs to be '<' rather than '<='.

Fixes b7e89b0f5bd7 ("perf: arm_pmu: Remove event index to counter remapping")
---
 drivers/perf/arm_pmuv3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/perf/arm_pmuv3.c +0 -0
index 3b3a3334cc3f..0e22c68fb804 100644

drivers/perf/arm_pmuv3.c static bool armv8pmu_event_is_chained(struct perf_event *event) · line 486

Quoted 6 lines
drivers/perf/arm_pmuv3.c +1 -1
@@ -482,7 +482,7 @@ static bool armv8pmu_event_is_chained(struct perf_event *event)
 	return !armv8pmu_event_has_user_read(event) &&
 	       armv8pmu_event_is_64bit(event) &&
 	       !armv8pmu_has_long_event(cpu_pmu) &&
-	       (idx <= ARMV8_PMU_MAX_GENERAL_COUNTERS);
+	       (idx < ARMV8_PMU_MAX_GENERAL_COUNTERS);
 }

Catalin -- please can you pick this up as a fix?

Cheers,

Will

#2 lore raw
Quoted 31 lines · Will Deacon
Quoted 20 lines · Rob Herring (Arm)

Since commit b7e89b0f5bd7 ("perf: arm_pmu: Remove event index to counter remapping"), armv8pmu_event_is_chained() is incorrectly returning that the cycle counter is chained, but the cycle counter has always been 64-bit. The result is trying to configure counter #30 which typically doesn't exist.

As ARMV8_PMU_MAX_GENERAL_COUNTERS is the number of counters (31), the comparison to the counter index needs to be '<' rather than '<='.

Fixes b7e89b0f5bd7 ("perf: arm_pmu: Remove event index to counter remapping")
---
 drivers/perf/arm_pmuv3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/perf/arm_pmuv3.c +0 -0
index 3b3a3334cc3f..0e22c68fb804 100644

drivers/perf/arm_pmuv3.c static bool armv8pmu_event_is_chained(struct perf_event *event) · line 486

Quoted 6 lines
drivers/perf/arm_pmuv3.c +1 -1
@@ -482,7 +482,7 @@ static bool armv8pmu_event_is_chained(struct perf_event *event)
      return !armv8pmu_event_has_user_read(event) &&
             armv8pmu_event_is_64bit(event) &&
             !armv8pmu_has_long_event(cpu_pmu) &&
-            (idx <= ARMV8_PMU_MAX_GENERAL_COUNTERS);
+            (idx < ARMV8_PMU_MAX_GENERAL_COUNTERS);
 }
Quoted 1 line

Catalin -- please can you pick this up as a fix?

No, this is the fix for what Will dropped and said to resend on the v9.4 fixed instruction counter series. Here's the series with the fix in it[1].

Rob

[1] https://lore.kernel.org/all/[email protected]/

maintainer
#3 lore raw
Quoted 32 lines · Rob Herring
Quoted 31 lines · Will Deacon
Quoted 20 lines · Rob Herring (Arm)

Since commit b7e89b0f5bd7 ("perf: arm_pmu: Remove event index to counter remapping"), armv8pmu_event_is_chained() is incorrectly returning that the cycle counter is chained, but the cycle counter has always been 64-bit. The result is trying to configure counter #30 which typically doesn't exist.

As ARMV8_PMU_MAX_GENERAL_COUNTERS is the number of counters (31), the comparison to the counter index needs to be '<' rather than '<='.

Fixes b7e89b0f5bd7 ("perf: arm_pmu: Remove event index to counter remapping")
---
 drivers/perf/arm_pmuv3.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/perf/arm_pmuv3.c +0 -0
index 3b3a3334cc3f..0e22c68fb804 100644

drivers/perf/arm_pmuv3.c static bool armv8pmu_event_is_chained(struct perf_event *event) · line 486

Quoted 6 lines
drivers/perf/arm_pmuv3.c +1 -1
@@ -482,7 +482,7 @@ static bool armv8pmu_event_is_chained(struct perf_event *event)
      return !armv8pmu_event_has_user_read(event) &&
             armv8pmu_event_is_64bit(event) &&
             !armv8pmu_has_long_event(cpu_pmu) &&
-            (idx <= ARMV8_PMU_MAX_GENERAL_COUNTERS);
+            (idx < ARMV8_PMU_MAX_GENERAL_COUNTERS);
 }
Quoted 5 lines
Quoted 1 line

Catalin -- please can you pick this up as a fix?

No, this is the fix for what Will dropped and said to resend on the v9.4 fixed instruction counter series. Here's the series with the fix in it[1].

Urgh, sorry about that, and thanks for pointing it out.

I'd initially marked this as read, but then I was pointed at it the other day and thought I'd missed a fix since "git show b7e89b0f5bd7" still shows the patch, despite pruning the remotes.

I'll queue up the other series for 6.12.

Will