From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751180AbdCQKnA (ORCPT ); Fri, 17 Mar 2017 06:43:00 -0400 Received: from terminus.zytor.com ([65.50.211.136]:37358 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751111AbdCQKm6 (ORCPT ); Fri, 17 Mar 2017 06:42:58 -0400 Date: Fri, 17 Mar 2017 03:17:17 -0700 From: tip-bot for Andy Lutomirski Message-ID: Cc: torvalds@linux-foundation.org, alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org, bpetkov@suse.de, luto@kernel.org, tglx@linutronix.de, vincent.weaver@maine.edu, eranian@google.com, jolsa@redhat.com, hpa@zytor.com, mingo@kernel.org, peterz@infradead.org, acme@redhat.com Reply-To: alexander.shishkin@linux.intel.com, linux-kernel@vger.kernel.org, torvalds@linux-foundation.org, eranian@google.com, tglx@linutronix.de, vincent.weaver@maine.edu, luto@kernel.org, bpetkov@suse.de, mingo@kernel.org, hpa@zytor.com, peterz@infradead.org, jolsa@redhat.com, acme@redhat.com In-Reply-To: <03a1e629063899168dfc4707f3bb6e581e21f5c6.1489694270.git.luto@kernel.org> References: <03a1e629063899168dfc4707f3bb6e581e21f5c6.1489694270.git.luto@kernel.org> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/urgent] x86/perf: Clarify why x86_pmu_event_mapped() isn't racy Git-Commit-ID: 4b07372a32c0c1505a7634ad7e607d83340ef645 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 4b07372a32c0c1505a7634ad7e607d83340ef645 Gitweb: http://git.kernel.org/tip/4b07372a32c0c1505a7634ad7e607d83340ef645 Author: Andy Lutomirski AuthorDate: Thu, 16 Mar 2017 12:59:40 -0700 Committer: Ingo Molnar CommitDate: Fri, 17 Mar 2017 08:28:26 +0100 x86/perf: Clarify why x86_pmu_event_mapped() isn't racy Naively, it looks racy, but ->mmap_sem saves it. Add a comment and a lockdep assertion. Signed-off-by: Andy Lutomirski Cc: Alexander Shishkin Cc: Arnaldo Carvalho de Melo Cc: Borislav Petkov Cc: H. Peter Anvin Cc: Jiri Olsa Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Stephane Eranian Cc: Thomas Gleixner Cc: Vince Weaver Link: http://lkml.kernel.org/r/03a1e629063899168dfc4707f3bb6e581e21f5c6.1489694270.git.luto@kernel.org Signed-off-by: Ingo Molnar --- arch/x86/events/core.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c index e07b36c..183a972 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2109,6 +2109,18 @@ static void x86_pmu_event_mapped(struct perf_event *event) if (!(event->hw.flags & PERF_X86_EVENT_RDPMC_ALLOWED)) return; + /* + * This function relies on not being called concurrently in two + * tasks in the same mm. Otherwise one task could observe + * perf_rdpmc_allowed > 1 and return all the way back to + * userspace with CR4.PCE clear while another task is still + * doing on_each_cpu_mask() to propagate CR4.PCE. + * + * For now, this can't happen because all callers hold mmap_sem + * for write. If this changes, we'll need a different solution. + */ + lockdep_assert_held_exclusive(¤t->mm->mmap_sem); + if (atomic_inc_return(¤t->mm->context.perf_rdpmc_allowed) == 1) on_each_cpu_mask(mm_cpumask(current->mm), refresh_pce, NULL, 1); }