Re: [PATCH v2] perf/core: Fix cgroup event list management

From: Peter Zijlstra
Date: Mon Dec 13 2021 - 16:09:19 EST


On Sun, Dec 12, 2021 at 10:59:36PM -0800, Namhyung Kim wrote:
> The active cgroup events are managed in the per-cpu cgrp_cpuctx_list.
> This list is accessed from current cpu and not protected by any locks.
> But from the commit ef54c1a476ae ("perf: Rework
> perf_event_exit_event()"), this assumption does not hold true anymore.
>
> In the perf_remove_from_context(), it can remove an event from the
> context without an IPI when the context is not active. I think it
> assumes task event context, but it's possible for cpu event context

Yes, event_function_call() in general doesn't work, but for cpu events
it does.

> only with cgroup events can be inactive at the moment - and it might
> become active soon.

It can't, we're holding ctx->mutex and ctx->lock, and since it's a cpu
event, that's cpuctx.

But yes, cgrp_cpuctx_list relies on being strictly per-cpu and I can't
come up with a better solution either, doing those IPIs suck but...

But please, put in a comment like:

/*
* Cgroup events are per-CPU events, and must IPI because of
* cgrp_cpuctx_list.
*/
if (!ctx->is_active || !is_cgroup_event(event)) {