Re: [PATCH v2] perf/core: install cgroup events to correct cpuctx

From: Peter Zijlstra
Date: Wed Mar 18 2020 - 14:05:53 EST


On Wed, Mar 18, 2020 at 07:07:29AM +0000, Song Liu wrote:
> Hi Peter,
>
> > On Mar 5, 2020, at 11:48 PM, Song Liu <songliubraving@xxxxxx> wrote:
> >
> >
> >
> >> On Jan 24, 2020, at 1:15 AM, Peter Zijlstra <peterz@xxxxxxxxxxxxx> wrote:
> >>
> >> On Wed, Jan 22, 2020 at 11:50:27AM -0800, Song Liu wrote:
> >>> cgroup events are always installed in the cpuctx. However, when it is not
> >>> installed via IPI, list_update_cgroup_event() adds it to cpuctx of current
> >>> CPU, which triggers the following with CONFIG_DEBUG_LIST:
> >>>
> >>
> >>> [ 31.777570] list_add double add: new=ffff888ff7cf0db0, prev=ffff888ff7ce82f0, next=ffff888ff7cf0db0.
> >>
> >>> To reproduce this, we can simply run:
> >>> perf stat -e cs -a &
> >>> perf stat -e cs -G anycgroup
> >>>
> >>> Fix this by installing it to cpuctx that contains event->ctx, and the
> >>> proper cgrp_cpuctx_list.
> >>>
> >>> Fixes: db0503e4f675 ("perf/core: Optimize perf_install_in_event()")
> >>> Suggested-by: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> >>> Cc: Andi Kleen <andi@xxxxxxxxxxxxxx>
> >>> Cc: Peter Zijlstra (Intel) <peterz@xxxxxxxxxxxxx>
> >>> Cc: Alexander Shishkin <alexander.shishkin@xxxxxxxxxxxxxxx>
> >>> Cc: Arnaldo Carvalho de Melo <acme@xxxxxxxxxx>
> >>> Cc: Jiri Olsa <jolsa@xxxxxxxxxx>
> >>> Cc: Namhyung Kim <namhyung@xxxxxxxxxx>
> >>> Cc: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> >>> Signed-off-by: Song Liu <songliubraving@xxxxxx>
> >>
> >> Thanks!
> >
> > I just realized this won't fully fix the problem, because later in
> > list_update_cgroup_event() we use "current":
> >
> > struct perf_cgroup *cgrp = perf_cgroup_from_task(current, ctx);
>
> Could you please share your thoughts on this? I think we cannot use current
> in list_update_cgroup_event(), unless we call it on the target CPU.

Bah, that cgroup crap is 'wrong'. It's pointless to track the
cpuctx->cgrp state for disabled events.

Let me see if I can unravel that crud.