From: Peter Zijlstra <peterz@infradead.org>
To: Paul Mackerras <paulus@samba.org>
Cc: Ingo Molnar <mingo@elte.hu>, Anton Blanchard <anton@samba.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] perf_event: Fix oops triggered by cpu offline/online
Date: Fri, 05 Mar 2010 10:41:23 +0100 [thread overview]
Message-ID: <1267782083.16716.56.camel@laptop> (raw)
In-Reply-To: <20100305060654.GE27606@brick.ozlabs.ibm.com>
On Fri, 2010-03-05 at 17:06 +1100, Paul Mackerras wrote:
> Anton Blanchard found that he could reliably make the kernel hit a
> BUG_ON in the slab allocator by taking a cpu offline and then online
> while a system-wide perf record session was running.
>
> The reason is that when the cpu comes up, we completely reinitialize
> the ctx field of the struct perf_cpu_context for the cpu. If there is
> a system-wide perf record session running, then there will be a struct
> perf_event that has a reference to the context, so its refcount will
> be 2. (The perf_event has been removed from the context's group_entry
> and event_entry lists by perf_event_exit_cpu(), but that doesn't
> remove the perf_event's reference to the context and doesn't decrement
> the context's refcount.)
>
> When the cpu comes up, perf_event_init_cpu() gets called, and it calls
> __perf_event_init_context() on the cpu's context. That resets the
> refcount to 1. Then when the perf record session finishes and the
> perf_event is closed, the refcount gets decremented to 0 and the
> context gets kfreed after an RCU grace period. Since the context
> wasn't kmalloced -- it's part of a per-cpu variable -- bad things
> happen.
>
> In fact we don't need to completely reinitialize the context when the
> cpu comes up. It's sufficient to initialize the context once at boot,
> but we need to do it for all possible cpus.
>
> This moves the context initialization to happen at boot time. With
> this, we don't trash the refcount and the context never gets kfreed,
> and we don't hit the BUG_ON.
>
> Reported-by: Anton Blanchard <anton@samba.org>
> Signed-off-by: Paul Mackerras <paulus@samba.org>
> Tested-by: Anton Blanchard <anton@samba.org>
Very nice catch!
Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
prev parent reply other threads:[~2010-03-05 9:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-05 6:06 [PATCH] perf_event: Fix oops triggered by cpu offline/online Paul Mackerras
2010-03-05 9:41 ` Peter Zijlstra [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=1267782083.16716.56.camel@laptop \
--to=peterz@infradead.org \
--cc=anton@samba.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
/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