Skip to contentSkip to conversation

perf: arm_cspmu: Reject events meant for other PMUs

PATCH Applied Ilkka Koskinen 6 participants 9 messages Nov 3, 2023 – Nov 8, 2023 Arm PMU profiling and debugging

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 perf: arm_cspmu: Reject events meant for other PMUs

Coresight PMU driver didn't reject events meant for other PMUs. This caused some of the Core PMU events disappearing from the output of "perf list". In addition, trying to run e.g.

     $ perf stat -e r2 sleep 1

made Coresight PMU driver to handle the event instead of letting Core PMU driver to deal with it.

Fixes e37dfd65731d ("perf: arm_cspmu: Add support for ARM CoreSight PMU driver")
---
 drivers/perf/arm_cspmu/arm_cspmu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/perf/arm_cspmu/arm_cspmu.c +3 -0
index 42b72042f6b3..2cc35dded007 100644
@@ -676,6 +676,9 @@ static int arm_cspmu_event_init(struct perf_event *event)
 
 	cspmu = to_arm_cspmu(event->pmu);
 
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+
 	/*
 	 * Following other "uncore" PMUs, we do not support sampling mode or
 	 * attach to a task (per-process mode).
Signature · 1 line
2.40.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Ilkka,

Thanks for fixing it.

Regards,
Besar

Quoted 49 lines

-----Original Message-----
From: Ilkka Koskinen <[email protected]>
Sent: Thursday, November 2, 2023 7:17 PM
To: Besar Wicaksono <[email protected]>; Suzuki K Poulose <[email protected]>; Robin Murphy <[email protected]>; Will Deacon <[email protected]>; Mark Rutland <[email protected]>; Raag Jadav <[email protected]>; Ilkka Koskinen <[email protected]>
Cc: [email protected]; [email protected]
Subject: [PATCH] perf: arm_cspmu: Reject events meant for other PMUs

External email: Use caution opening links or attachments

Coresight PMU driver didn't reject events meant for other PMUs. This caused some of the Core PMU events disappearing from the output of "perf list". In addition, trying to run e.g.

     $ perf stat -e r2 sleep 1

made Coresight PMU driver to handle the event instead of letting Core PMU driver to deal with it.

Fixes e37dfd65731d ("perf: arm_cspmu: Add support for ARM CoreSight

PMU driver")

---
 drivers/perf/arm_cspmu/arm_cspmu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/perf/arm_cspmu/arm_cspmu.c +3 -0
index 42b72042f6b3..2cc35dded007 100644
@@ -676,6 +676,9 @@ static int arm_cspmu_event_init(struct perf_event
 *event)
 
        cspmu = to_arm_cspmu(event->pmu);
 
+       if (event->attr.type != event->pmu->type)
+               return -ENOENT;
+
        /*
         * Following other "uncore" PMUs, we do not support sampling mode or

* attach to a task (per-process mode).
--
2.40.1

Reviewed-by on v1 1/1
#2 lore raw
In reply to Ilkka Koskinen
Quoted 21 lines · Ilkka Koskinen

Coresight PMU driver didn't reject events meant for other PMUs. This caused some of the Core PMU events disappearing from the output of "perf list". In addition, trying to run e.g.

     $ perf stat -e r2 sleep 1

made Coresight PMU driver to handle the event instead of letting Core PMU driver to deal with it.

Fixes e37dfd65731d ("perf: arm_cspmu: Add support for ARM CoreSight PMU driver")
---
 drivers/perf/arm_cspmu/arm_cspmu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/perf/arm_cspmu/arm_cspmu.c +0 -0
index 42b72042f6b3..2cc35dded007 100644

drivers/perf/arm_cspmu/arm_cspmu.c static int arm_cspmu_event_init(struct perf_event *event) · line 684

Quoted 9 lines
drivers/perf/arm_cspmu/arm_cspmu.c +3 -0
@@ -676,6 +676,9 @@ static int arm_cspmu_event_init(struct perf_event *event)
 
 	cspmu = to_arm_cspmu(event->pmu);
 
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+
 	/*
 	 * Following other "uncore" PMUs, we do not support sampling mode or
 	 * attach to a task (per-process mode).

LGTM

maintainer Acked-by on v1 1/1
#3 lore raw
In reply to Ilkka Koskinen
Quoted 4 lines · Ilkka Koskinen

Coresight PMU driver didn't reject events meant for other PMUs. This caused some of the Core PMU events disappearing from the output of "perf list". In addition, trying to run e.g.

Quoted 8 lines
     $ perf stat -e r2 sleep 1

made Coresight PMU driver to handle the event instead of letting Core PMU driver to deal with it.

Fixes e37dfd65731d ("perf: arm_cspmu: Add support for ARM CoreSight PMU driver")

Will, are you happy to pick this up?

Mark.

Quoted 21 lines
---
 drivers/perf/arm_cspmu/arm_cspmu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/perf/arm_cspmu/arm_cspmu.c +3 -0
index 42b72042f6b3..2cc35dded007 100644
@@ -676,6 +676,9 @@ static int arm_cspmu_event_init(struct perf_event *event)
 
 	cspmu = to_arm_cspmu(event->pmu);
 
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+
 	/*
 	 * Following other "uncore" PMUs, we do not support sampling mode or
 	 * attach to a task (per-process mode).
Signature · 1 line
2.40.1
maintainer Acked-by on v1 1/1
#4 lore raw
In reply to Ilkka Koskinen

[+Catalin]

Quoted 21 lines · Ilkka Koskinen

Coresight PMU driver didn't reject events meant for other PMUs. This caused some of the Core PMU events disappearing from the output of "perf list". In addition, trying to run e.g.

     $ perf stat -e r2 sleep 1

made Coresight PMU driver to handle the event instead of letting Core PMU driver to deal with it.

Fixes e37dfd65731d ("perf: arm_cspmu: Add support for ARM CoreSight PMU driver")
---
 drivers/perf/arm_cspmu/arm_cspmu.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/perf/arm_cspmu/arm_cspmu.c +0 -0
index 42b72042f6b3..2cc35dded007 100644

drivers/perf/arm_cspmu/arm_cspmu.c static int arm_cspmu_event_init(struct perf_event *event) · line 681

Quoted 6 lines
drivers/perf/arm_cspmu/arm_cspmu.c +3 -0
@@ -676,6 +676,9 @@ static int arm_cspmu_event_init(struct perf_event *event)
 
 	cspmu = to_arm_cspmu(event->pmu);
 
+	if (event->attr.type != event->pmu->type)
+		return -ENOENT;
+

Catalin -- please can you pick this up as a fix in the arm64 tree?

Cheers,

Will

#5 lore raw
In reply to Ilkka Koskinen
Quoted 10 lines · Ilkka Koskinen

Coresight PMU driver didn't reject events meant for other PMUs. This caused some of the Core PMU events disappearing from the output of "perf list". In addition, trying to run e.g.

     $ perf stat -e r2 sleep 1

made Coresight PMU driver to handle the event instead of letting Core PMU driver to deal with it.

[...]

Applied to arm64 (for-next/core), thanks!

[1/1] perf: arm_cspmu: Reject events meant for other PMUs

      https://git.kernel.org/arm64/c/15c7ef7341a2
Signature · 1 line
Catalin
#6 lore raw

Hi Catalin,

Quoted 5 lines · Catalin Marinas
Quoted 4 lines · Ilkka Koskinen

Coresight PMU driver didn't reject events meant for other PMUs. This caused some of the Core PMU events disappearing from the output of "perf list". In addition, trying to run e.g.

Quoted 8 lines
Quoted 6 lines
     $ perf stat -e r2 sleep 1

made Coresight PMU driver to handle the event instead of letting Core PMU driver to deal with it.

[...]

Applied to arm64 (for-next/core), thanks!

Just wanted to ask if you are planning to submit this patch for 6.7-rcX as a fix? We have found out that one can even crash AmpereOne by running "perf stat -C 1 sleep 1" without the patch.

Cheers, Ilkka

Quoted 8 lines

[1/1] perf: arm_cspmu: Reject events meant for other PMUs

     https://git.kernel.org/arm64/c/15c7ef7341a2
Signature · 1 line
Catalin
#7 lore raw
Quoted 11 lines · Ilkka Koskinen
Quoted 10 lines · Catalin Marinas
Quoted 9 lines · Ilkka Koskinen

Coresight PMU driver didn't reject events meant for other PMUs. This caused some of the Core PMU events disappearing from the output of "perf list". In addition, trying to run e.g.

     $ perf stat -e r2 sleep 1

made Coresight PMU driver to handle the event instead of letting Core PMU driver to deal with it.

Quoted 7 lines
Quoted 3 lines
Quoted 1 line

[...]

Applied to arm64 (for-next/core), thanks!

Just wanted to ask if you are planning to submit this patch for 6.7-rcX as a fix? We have found out that one can even crash AmpereOne by running "perf stat -C 1 sleep 1" without the patch.

Yes, I'll send it for 6.7-rc1 (probably tomorrow).

Signature · 1 line
Catalin
#8 lore raw
Quoted 14 lines · Catalin Marinas
Quoted 13 lines · Ilkka Koskinen
Quoted 12 lines · Catalin Marinas
Quoted 10 lines · Ilkka Koskinen

Coresight PMU driver didn't reject events meant for other PMUs. This caused some of the Core PMU events disappearing from the output of "perf list". In addition, trying to run e.g.

     $ perf stat -e r2 sleep 1

made Coresight PMU driver to handle the event instead of letting Core PMU driver to deal with it.

[...]

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

Applied to arm64 (for-next/core), thanks!

Just wanted to ask if you are planning to submit this patch for 6.7-rcX as a fix? We have found out that one can even crash AmpereOne by running "perf stat -C 1 sleep 1" without the patch.

Yes, I'll send it for 6.7-rc1 (probably tomorrow).

Sounds perfert. Thanks a lot!

--Ilkka

Quoted 4 lines
Signature · 2 lines
-- 
Catalin