From: Peter Zijlstra <peterz@infradead.org>
To: Andy Lutomirski <luto@kernel.org>
Cc: Vince Weaver <vincent.weaver@maine.edu>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Ingo Molnar <mingo@redhat.com>,
Arnaldo Carvalho de Melo <acme@kernel.org>
Subject: Re: perf: race with automatic rdpmc() disabling
Date: Mon, 13 Mar 2017 17:55:07 +0100 [thread overview]
Message-ID: <20170313165507.GJ3312@twins.programming.kicks-ass.net> (raw)
In-Reply-To: <CALCETrWoB9UNThOdbMjquA0uBhU74DqF2RB9ERX1Xi_ujyOwEA@mail.gmail.com>
On Mon, Mar 13, 2017 at 09:44:02AM -0700, Andy Lutomirski wrote:
> static void x86_pmu_event_mapped(struct perf_event *event)
> {
> if (!(event->hw.flags & PERF_X86_EVENT_RDPMC_ALLOWED))
> return;
>
> if (atomic_inc_return(¤t->mm->context.perf_rdpmc_allowed) == 1)
>
> <-- thread 1 stalls here
>
> on_each_cpu_mask(mm_cpumask(current->mm), refresh_pce, NULL, 1);
> }
>
> Suppose you start with perf_rdpmc_allowed == 0. Thread 1 runs
> x86_pmu_event_mapped and gets preempted (or just runs slowly) where I
> marked. Then thread 2 runs the whole function, does *not* update CR4,
> returns to userspace, and GPFs.
>
> The big hammer solution is to stick a per-mm mutex around it. Let me
> ponder whether a smaller hammer is available.
Reminds me a bit of what we ended up with in kernel/jump_label.c:static_key_slow_inc().
next prev parent reply other threads:[~2017-03-13 16:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-13 13:58 Vince Weaver
2017-03-13 16:44 ` Andy Lutomirski
2017-03-13 16:55 ` Peter Zijlstra [this message]
2017-03-13 21:05 ` Andy Lutomirski
2017-03-14 15:58 ` Andy Lutomirski
2017-03-14 16:45 ` Vince Weaver
2017-03-15 20:16 ` Andy Lutomirski
2017-03-16 5:35 ` Vince Weaver
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=20170313165507.GJ3312@twins.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=acme@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@kernel.org \
--cc=mingo@redhat.com \
--cc=vincent.weaver@maine.edu \
/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
Powered by JetHome