mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Song Liu <songliubraving@fb.com>
To: Peter Zijlstra <peterz@infradead.org>
Cc: linux-kernel <linux-kernel@vger.kernel.org>,
	Kernel Team <Kernel-team@fb.com>,
	Andi Kleen <andi@firstfloor.org>,
	Alexander Shishkin <alexander.shishkin@linux.intel.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>
Subject: Re: [PATCH] perf/core: Install cgroup event via IPI
Date: Tue, 21 Jan 2020 18:38:40 +0000	[thread overview]
Message-ID: <C754CC54-2BFE-4363-BB05-6382DF984165@fb.com> (raw)
In-Reply-To: <20200120085022.GJ14879@hirez.programming.kicks-ass.net>



> On Jan 20, 2020, at 12:50 AM, Peter Zijlstra <peterz@infradead.org> wrote:
> 
> On Thu, Jan 16, 2020 at 09:25:55AM -0800, Song Liu wrote:
>> cgroup events in OFF state cannot be installed without IPI, otherwise, it
>> may trigger the following calltrace with CONFIG_DEBUG_LIST:
>> 
>> [   31.776974] ------------[ cut here ]------------
>> [   31.777570] list_add double add: new=ffff888ff7cf0db0, prev=ffff888ff7ce82f0, next=ffff888ff7cf0db0.
>> [   31.778737] WARNING: CPU: 3 PID: 1186 at lib/list_debug.c:31 __list_add_valid+0x67/0x70
>> [   31.779745] Modules linked in:
>> [   31.780138] CPU: 3 PID: 1186 Comm: perf Tainted: G        W         5.5.0-rc6+ #3962
>> [   31.781125] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.11.0-2.el7 04/01/2014
>> [   31.782199] RIP: 0010:__list_add_valid+0x67/0x70
> 
>> diff --git a/kernel/events/core.c b/kernel/events/core.c
>> index a1f8bde19b56..36e8fe27e2a1 100644
>> --- a/kernel/events/core.c
>> +++ b/kernel/events/core.c
>> @@ -2682,14 +2682,18 @@ perf_install_in_context(struct perf_event_context *ctx,
>> 	smp_store_release(&event->ctx, ctx);
>> 
>> 	/*
>> -	 * perf_event_attr::disabled events will not run and can be initialized
>> -	 * without IPI. Except when this is the first event for the context, in
>> -	 * that case we need the magic of the IPI to set ctx->is_active.
>> +	 * perf_event_attr::disabled events will not run and can be
>> +	 * initialized without IPI. Except:
>> +	 *   1. when this is the first event for the context, in that case
>> +	 *      we need the magic of the IPI to set ctx->is_active;
>> +	 *   2. cgroup event in OFF state, because it is installed in the
>> +	 *      cpuctx.
>> 	 *
>> 	 * The IOC_ENABLE that is sure to follow the creation of a disabled
>> 	 * event will issue the IPI and reprogram the hardware.
>> 	 */
>> -	if (__perf_effective_state(event) == PERF_EVENT_STATE_OFF && ctx->nr_events) {
>> +	if (__perf_effective_state(event) == PERF_EVENT_STATE_OFF &&
>> +	    !is_cgroup_event(event) && ctx->nr_events) {
>> 		raw_spin_lock_irq(&ctx->lock);
>> 		if (ctx->task == TASK_TOMBSTONE) {
>> 			raw_spin_unlock_irq(&ctx->lock);
> 
> I don't think this is right. Because cgroup events are always per-cpu
> events, ctx == &cpuctx->ctx, so the locking should work out just fine.
> 
> What does appear to be the problem is that:
> 
>  add_event_to_ctx()
>    list_update_cgroup_event()
>      cpuctx = __get_cpu_context(ctx)
> 
> uses this_cpu_ptr() and we're now calling it from the 'wrong' CPU.

Yes, this is because add_event_to_ctx() is called from wrong CPU. 

> 
> But I'm thinking the below should also work just fine, hmm?

And yes, this also fixes it. Thanks!

Would you send official PATCH?

Song


      reply	other threads:[~2020-01-21 18:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-16 17:25 Song Liu
2020-01-20  8:50 ` Peter Zijlstra
2020-01-21 18:38   ` Song Liu [this message]

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=C754CC54-2BFE-4363-BB05-6382DF984165@fb.com \
    --to=songliubraving@fb.com \
    --cc=Kernel-team@fb.com \
    --cc=acme@redhat.com \
    --cc=alexander.shishkin@linux.intel.com \
    --cc=andi@firstfloor.org \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=namhyung@kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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

all inboxes | Powered by JetHome®