Skip to contentSkip to conversation

perf/core: Inherit event_caps

PATCH RESEND Applied Namhyung Kim 2 participants 2 messages Mar 28, 2022 – Apr 5, 2022

Subsystems (2)
lore
Share & tools
lore

Namhyung Kim

author maintainer
#0 lore raw

PATCH RESEND 1/1 perf/core: Inherit event_caps

It was reported that some perf event setup can make fork failed on ARM64. It was the case of a group of mixed hw and sw events and it failed in perf_event_init_task() due to armpmu_event_init().

The ARM PMU code checks if all the events in a group belong to the same PMU except for software events. But it didn't set the event_caps of inherited events and no longer identify them as software events. Therefore the test failed in a child process.

A simple reproducer is:

  $ perf stat -e '{cycles,cs,instructions}' perf bench sched messaging
  # Running 'sched/messaging' benchmark:
  perf: fork(): Invalid argument

The perf stat was fine but the perf bench failed in fork(). Let's inherit the event caps from the parent.

Cc Will Deacon <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Marco Elver <[email protected]>
---
 kernel/events/core.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/events/core.c +3 -0
index afbf388a5176..5baf7f981f23 100644
@@ -11622,6 +11622,9 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
 
 	event->state		= PERF_EVENT_STATE_INACTIVE;
 
+	if (parent_event)
+		event->event_caps = parent_event->event_caps;
+
 	if (event->attr.sigtrap)
 		atomic_set(&event->event_limit, 1);
 
Signature · 1 line
2.35.1.1021.g381101b075-goog
merge bot Applied
#1 lore raw
The following commit has been merged into the perf/urgent branch of tip:

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     e3265a4386428d3d157d9565bb520aabff8b4bf0
Gitweb:        https://git.kernel.org/tip/e3265a4386428d3d157d9565bb520aabff8b4bf0
Author:        Namhyung Kim <[email protected]>
AuthorDate:    Mon, 28 Mar 2022 13:01:12 -07:00
Committer:     Peter Zijlstra <[email protected]>
CommitterDate: Tue, 05 Apr 2022 09:59:44 +02:00

perf/core: Inherit event_caps

It was reported that some perf event setup can make fork failed on ARM64. It was the case of a group of mixed hw and sw events and it failed in perf_event_init_task() due to armpmu_event_init().

The ARM PMU code checks if all the events in a group belong to the same PMU except for software events. But it didn't set the event_caps of inherited events and no longer identify them as software events. Therefore the test failed in a child process.

A simple reproducer is:

  $ perf stat -e '{cycles,cs,instructions}' perf bench sched messaging
  # Running 'sched/messaging' benchmark:
  perf: fork(): Invalid argument

The perf stat was fine but the perf bench failed in fork(). Let's inherit the event caps from the parent.

---
 kernel/events/core.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/events/core.c +3 -0
index cfde994..3980efc 100644
@@ -11635,6 +11635,9 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
 
 	event->state		= PERF_EVENT_STATE_INACTIVE;
 
+	if (parent_event)
+		event->event_caps = parent_event->event_caps;
+
 	if (event->attr.sigtrap)
 		atomic_set(&event->event_limit, 1);