Skip to content

Commit 7335c33

Browse files
Peter Zijlstragregkh
authored andcommitted
perf: Fix cgroup state vs ERROR
[ Upstream commit 61988e3 ] While chasing down a missing perf_cgroup_event_disable() elsewhere, Leo Yan found that both perf_put_aux_event() and perf_remove_sibling_event() were also missing one. Specifically, the rule is that events that switch to OFF,ERROR need to call perf_cgroup_event_disable(). Unify the disable paths to ensure this. Fixes: ab43762 ("perf: Allow normal events to output AUX data") Fixes: 9f0c4fa ("perf/core: Add a new PERF_EV_CAP_SIBLING event capability") Reported-by: Leo Yan <[email protected]> Signed-off-by: Peter Zijlstra (Intel) <[email protected]> Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Sasha Levin <[email protected]>
1 parent 456019a commit 7335c33

File tree

1 file changed

+30
-21
lines changed

1 file changed

+30
-21
lines changed

kernel/events/core.c

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2111,8 +2111,9 @@ perf_aux_output_match(struct perf_event *event, struct perf_event *aux_event)
21112111
}
21122112

21132113
static void put_event(struct perf_event *event);
2114-
static void event_sched_out(struct perf_event *event,
2115-
struct perf_event_context *ctx);
2114+
static void __event_disable(struct perf_event *event,
2115+
struct perf_event_context *ctx,
2116+
enum perf_event_state state);
21162117

21172118
static void perf_put_aux_event(struct perf_event *event)
21182119
{
@@ -2145,8 +2146,7 @@ static void perf_put_aux_event(struct perf_event *event)
21452146
* state so that we don't try to schedule it again. Note
21462147
* that perf_event_enable() will clear the ERROR status.
21472148
*/
2148-
event_sched_out(iter, ctx);
2149-
perf_event_set_state(event, PERF_EVENT_STATE_ERROR);
2149+
__event_disable(iter, ctx, PERF_EVENT_STATE_ERROR);
21502150
}
21512151
}
21522152

@@ -2204,18 +2204,6 @@ static inline struct list_head *get_event_list(struct perf_event *event)
22042204
&event->pmu_ctx->flexible_active;
22052205
}
22062206

2207-
/*
2208-
* Events that have PERF_EV_CAP_SIBLING require being part of a group and
2209-
* cannot exist on their own, schedule them out and move them into the ERROR
2210-
* state. Also see _perf_event_enable(), it will not be able to recover
2211-
* this ERROR state.
2212-
*/
2213-
static inline void perf_remove_sibling_event(struct perf_event *event)
2214-
{
2215-
event_sched_out(event, event->ctx);
2216-
perf_event_set_state(event, PERF_EVENT_STATE_ERROR);
2217-
}
2218-
22192207
static void perf_group_detach(struct perf_event *event)
22202208
{
22212209
struct perf_event *leader = event->group_leader;
@@ -2251,8 +2239,15 @@ static void perf_group_detach(struct perf_event *event)
22512239
*/
22522240
list_for_each_entry_safe(sibling, tmp, &event->sibling_list, sibling_list) {
22532241

2242+
/*
2243+
* Events that have PERF_EV_CAP_SIBLING require being part of
2244+
* a group and cannot exist on their own, schedule them out
2245+
* and move them into the ERROR state. Also see
2246+
* _perf_event_enable(), it will not be able to recover this
2247+
* ERROR state.
2248+
*/
22542249
if (sibling->event_caps & PERF_EV_CAP_SIBLING)
2255-
perf_remove_sibling_event(sibling);
2250+
__event_disable(sibling, ctx, PERF_EVENT_STATE_ERROR);
22562251

22572252
sibling->group_leader = sibling;
22582253
list_del_init(&sibling->sibling_list);
@@ -2512,6 +2507,15 @@ static void perf_remove_from_context(struct perf_event *event, unsigned long fla
25122507
event_function_call(event, __perf_remove_from_context, (void *)flags);
25132508
}
25142509

2510+
static void __event_disable(struct perf_event *event,
2511+
struct perf_event_context *ctx,
2512+
enum perf_event_state state)
2513+
{
2514+
event_sched_out(event, ctx);
2515+
perf_cgroup_event_disable(event, ctx);
2516+
perf_event_set_state(event, state);
2517+
}
2518+
25152519
/*
25162520
* Cross CPU call to disable a performance event
25172521
*/
@@ -2526,13 +2530,18 @@ static void __perf_event_disable(struct perf_event *event,
25262530
perf_pmu_disable(event->pmu_ctx->pmu);
25272531
ctx_time_update_event(ctx, event);
25282532

2533+
/*
2534+
* When disabling a group leader, the whole group becomes ineligible
2535+
* to run, so schedule out the full group.
2536+
*/
25292537
if (event == event->group_leader)
25302538
group_sched_out(event, ctx);
2531-
else
2532-
event_sched_out(event, ctx);
25332539

2534-
perf_event_set_state(event, PERF_EVENT_STATE_OFF);
2535-
perf_cgroup_event_disable(event, ctx);
2540+
/*
2541+
* But only mark the leader OFF; the siblings will remain
2542+
* INACTIVE.
2543+
*/
2544+
__event_disable(event, ctx, PERF_EVENT_STATE_OFF);
25362545

25372546
perf_pmu_enable(event->pmu_ctx->pmu);
25382547
}

0 commit comments

Comments
 (0)