From: Leo Yan <leo.yan@arm.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: Yeoreum Yun <yeoreum.yun@arm.com>,
mingo@redhat.com, mingo@kernel.org, acme@kernel.org,
namhyung@kernel.org, mark.rutland@arm.com,
alexander.shishkin@linux.intel.com, jolsa@kernel.org,
irogers@google.com, adrian.hunter@intel.com,
kan.liang@linux.intel.com, linux-perf-users@vger.kernel.org,
linux-kernel@vger.kernel.org, David Wang <00107082@163.com>
Subject: Re: [PATCH 1/1] perf/core: fix dangling cgroup pointer in cpuctx
Date: Wed, 4 Jun 2025 11:18:21 +0100 [thread overview]
Message-ID: <20250604101821.GC8020@e132581.arm.com> (raw)
In-Reply-To: <20250604080339.GB35970@noisy.programming.kicks-ass.net>
On Wed, Jun 04, 2025 at 10:03:39AM +0200, Peter Zijlstra wrote:
[...]
> > > My suggestion is not reliable. Roughly read code, except for the
> > > PERF_EVENT_STATE_EXIT case, I think other error cases should also clean
> > > up the cgroup pointer. The reason is I don't see other places to
> > > clean up the cgroup pointer for these error cases:
> > >
> > > PERF_EVENT_STATE_REVOKED
> > > PERF_EVENT_STATE_DEAD
> >
> > Those should be done here; on the first transition into these states.
> >
> > > Only in the PERF_EVENT_STATE_ERROR state, we don't need to cleanup
> > > cgroup as this has already been handled in merge_sched_in().
> > >
> > > So a correct condition would be:
> > >
> > > if (event->state > PERF_EVENT_STATE_OFF ||
> > > event->state <= PERF_EVENT_STATE_EXIT)
> > > perf_cgroup_event_disable(event, ctx);
> >
> > I'm too tired to get my head straight. I'll look tomorrow.
>
>
> Right; had a sleep. Lets do this :-)
Thanks a lot for the state machine diagram.
> So the normal states are:
>
> ACTIVE ---.
> ^ |
> | |
> sched_{in,out}() |
> | |
> v |
> ,---> INACTIVE <--+
> | |
> | {dis,en}able()
> sched_in() |
> | OFF <--+
> | |
> `---> ERROR ---'
>
> That is:
>
> sched_in: INACTIVE -> {ACTIVE,ERROR}
Strictly speaking, sched_in() can keep INACTIVE state if an event is
rotated.
> sched_out: ACTIVE -> INACTIVE
> disable: {ACTIVE,INACTIVE} -> OFF
> enable: {OFF,ERROR} -> INACTIVE
>
> Where OFF/ERROR are 'disable' and have this perf_cgroup_event_disable()
> called.
>
> Then we have {EXIT,REVOKED,DEAD} states which are various shades of
> defunct events:
>
> - EXIT means task that the even was assigned to died, but child events
> still live, and further children can still be created. But the event
> itself will never be active again. It can only transition to
> {REVOKED,DEAD};
>
> - REVOKED means the PMU the event was associated with is gone; all
> functionality is stopped but the event is still alive. Can only
> transition to DEAD;
>
> - DEAD event really is DYING tearing down state and freeing bits.
>
> And now we have the sitation that __perf_remove_from_context() can do:
>
> {ACTIVE,INACTIVE,OFF,ERROR} -> {OFF,EXIT,REVOKED,DEAD}
A detailed transition is:
Case 1: {ACTIVE} -> {INACTIVE} -> {OFF,EXIT,REVOKED,DEAD}
Case 2: {ERROR} -> {ERROR,EXIT,REVOKED,DEAD}
Case 3: {OFF} -> {OFF,EXIT,REVOKED,DEAD}
> Where the {OFF,ERROR} -> * transition already have
> perf_cgroup_event_disable(), but the {ACTIVE,INACTIVE} -> * part has
> not.
Just a minor concern.
I noticed perf_put_aux_event() sets the ERROR state for sibling events
of an AUX event. IIUC, the AUX event is the group leader, so we only
need to clean up the cgroup pointer for the AUX event, and simply set
the ERROR state for its sibling events, correct?
> The condition:
>
> if (event->state > PERF_EVENT_STATE_OFF)
>
> captures exactly that {ACTIVE,INACTIVE} that still needs the cgroup
> disable. Every other state is already a disabled state.
>
>
> Agreed?
Except above concern, otherwise, the conclusion makes sense to me.
> Also, I should probably stick most of all this in a comment somewhere.
Totally agree. The comment would be very useful!
Thanks,
Leo
next prev parent reply other threads:[~2025-06-04 10:18 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-02 18:40 [PATCH 1/1] perf/core: fix dangling cgroup pointer in cpuctx Yeoreum Yun
2025-06-03 2:01 ` David Wang
2025-06-03 4:46 ` [PATCH " Yeoreum Yun
2025-06-03 5:44 ` David Wang
2025-06-03 6:34 ` Yeoreum Yun
2025-06-03 6:39 ` Yeoreum Yun
2025-06-03 6:47 ` David Wang
2025-06-03 6:42 ` David Wang
2025-06-03 7:16 ` Yeoreum Yun
2025-06-03 7:31 ` David Wang
2025-06-03 8:15 ` David Wang
2025-06-03 6:54 ` David Wang
2025-06-03 9:20 ` Yeoreum Yun
2025-06-03 10:08 ` David Wang
2025-06-03 13:41 ` Yeoreum Yun
2025-06-03 14:02 ` David Wang
2025-06-03 14:00 ` Leo Yan
2025-06-03 14:44 ` Peter Zijlstra
2025-06-03 15:17 ` Yeoreum Yun
2025-06-04 7:06 ` Peter Zijlstra
2025-06-04 8:03 ` Peter Zijlstra
2025-06-04 10:06 ` Yeoreum Yun
2025-06-04 12:37 ` Peter Zijlstra
2025-06-04 12:54 ` Yeoreum Yun
2025-06-04 10:18 ` Leo Yan [this message]
2025-06-04 13:58 ` Peter Zijlstra
2025-06-04 15:17 ` Leo Yan
2025-06-04 14:16 ` Peter Zijlstra
2025-06-04 15:46 ` Leo Yan
2025-06-04 15:59 ` Peter Zijlstra
2025-06-05 11:29 ` Peter Zijlstra
2025-06-05 12:33 ` Peter Zijlstra
2025-06-05 17:21 ` Leo Yan
2025-06-05 11:41 ` Peter Zijlstra
2025-06-03 15:05 ` Yeoreum Yun
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250604101821.GC8020@e132581.arm.com \
--to=leo.yan@arm.com \
--cc=00107082@163.com \
--cc=acme@kernel.org \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=irogers@google.com \
--cc=jolsa@kernel.org \
--cc=kan.liang@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-perf-users@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=yeoreum.yun@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).