Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1602816 > unrolled thread
| Started by | Andy Lutomirski <luto@kernel.org> |
|---|---|
| First post | 2017-03-16 21:10 +0100 |
| Last post | 2017-03-17 11:50 +0100 |
| Articles | 5 — 2 participants |
Back to article view | Back to linux.kernel
[PATCH 0/2] x86/perf: A CR4.PCE bugfix and clarification Andy Lutomirski <luto@kernel.org> - 2017-03-16 21:10 +0100
[PATCH 1/2] x86/perf: Fix CR4.PCE propagation to use active_mm instead of mm Andy Lutomirski <luto@kernel.org> - 2017-03-16 21:10 +0100
[tip:perf/urgent] x86/perf: Fix CR4.PCE propagation to use active_mm instead of mm tip-bot for Andy Lutomirski <tipbot@zytor.com> - 2017-03-17 11:50 +0100
[PATCH 2/2] x86/perf: Clarify why x86_pmu_event_mapped() isn't racy Andy Lutomirski <luto@kernel.org> - 2017-03-16 21:10 +0100
[tip:perf/urgent] x86/perf: Clarify why x86_pmu_event_mapped() isn't racy tip-bot for Andy Lutomirski <tipbot@zytor.com> - 2017-03-17 11:50 +0100
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2017-03-16 21:10 +0100 |
| Subject | [PATCH 0/2] x86/perf: A CR4.PCE bugfix and clarification |
| Message-ID | <tlJSF-3pV-5@gated-at.bofh.it> |
Hi all- Vince found a bug in our CR4.PCE handling. While investigating, I found what looked like another bug but actually wasn't. Here's a fix for the bug (cc'd to stable) and a comment and lockdep annotation for why the other non-bug isn't actually a bug. Andy Lutomirski (2): x86/perf: Fix CR4.PCE propagation to use active_mm instead of mm x86/perf: Clarify why x86_pmu_event_mapped() isn't racy arch/x86/events/core.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) -- 2.9.3
[toc] | [next] | [standalone]
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2017-03-16 21:10 +0100 |
| Subject | [PATCH 1/2] x86/perf: Fix CR4.PCE propagation to use active_mm instead of mm |
| Message-ID | <tlJSG-3pV-25@gated-at.bofh.it> |
| In reply to | #1602816 |
If one thread mmaps a perf event while another thread in the same mm
is in some context where active_mm != mm (which can happen in the
scheduler, for example), refresh_pce() would write the wrong value
to CR4.PCE. This broke some PAPI tests.
Cc: stable@vger.kernel.org
Fixes: 7911d3f7af14 ("perf/x86: Only allow rdpmc if a perf_event is mapped")
Reported-and-tested-by: Vince Weaver <vincent.weaver@maine.edu>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
---
arch/x86/events/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 349d4d17aa7f..4f564df73b8f 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2101,8 +2101,8 @@ static int x86_pmu_event_init(struct perf_event *event)
static void refresh_pce(void *ignored)
{
- if (current->mm)
- load_mm_cr4(current->mm);
+ if (current->active_mm)
+ load_mm_cr4(current->active_mm);
}
static void x86_pmu_event_mapped(struct perf_event *event)
--
2.9.3
[toc] | [prev] | [next] | [standalone]
| From | tip-bot for Andy Lutomirski <tipbot@zytor.com> |
|---|---|
| Date | 2017-03-17 11:50 +0100 |
| Subject | [tip:perf/urgent] x86/perf: Fix CR4.PCE propagation to use active_mm instead of mm |
| Message-ID | <tlXCi-535-25@gated-at.bofh.it> |
| In reply to | #1602819 |
Commit-ID: 5dc855d44c2ad960a86f593c60461f1ae1566b6d
Gitweb: http://git.kernel.org/tip/5dc855d44c2ad960a86f593c60461f1ae1566b6d
Author: Andy Lutomirski <luto@kernel.org>
AuthorDate: Thu, 16 Mar 2017 12:59:39 -0700
Committer: Ingo Molnar <mingo@kernel.org>
CommitDate: Fri, 17 Mar 2017 08:28:26 +0100
x86/perf: Fix CR4.PCE propagation to use active_mm instead of mm
If one thread mmaps a perf event while another thread in the same mm
is in some context where active_mm != mm (which can happen in the
scheduler, for example), refresh_pce() would write the wrong value
to CR4.PCE. This broke some PAPI tests.
Reported-and-tested-by: Vince Weaver <vincent.weaver@maine.edu>
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Borislav Petkov <bpetkov@suse.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
Fixes: 7911d3f7af14 ("perf/x86: Only allow rdpmc if a perf_event is mapped")
Link: http://lkml.kernel.org/r/0c5b38a76ea50e405f9abe07a13dfaef87c173a1.1489694270.git.luto@kernel.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
---
arch/x86/events/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/x86/events/core.c b/arch/x86/events/core.c
index 1635c0c..e07b36c 100644
--- a/arch/x86/events/core.c
+++ b/arch/x86/events/core.c
@@ -2100,8 +2100,8 @@ static int x86_pmu_event_init(struct perf_event *event)
static void refresh_pce(void *ignored)
{
- if (current->mm)
- load_mm_cr4(current->mm);
+ if (current->active_mm)
+ load_mm_cr4(current->active_mm);
}
static void x86_pmu_event_mapped(struct perf_event *event)
[toc] | [prev] | [next] | [standalone]
| From | Andy Lutomirski <luto@kernel.org> |
|---|---|
| Date | 2017-03-16 21:10 +0100 |
| Subject | [PATCH 2/2] x86/perf: Clarify why x86_pmu_event_mapped() isn't racy |
| Message-ID | <tlJSG-3pV-13@gated-at.bofh.it> |
| In reply to | #1602816 |
Naively, it looks racy, but mmap_sem saves it. Add a comment and a lockdep assertion. Signed-off-by: Andy Lutomirski <luto@kernel.org> --- 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 4f564df73b8f..2aa1ad194db2 100644 --- a/arch/x86/events/core.c +++ b/arch/x86/events/core.c @@ -2110,6 +2110,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); } -- 2.9.3
[toc] | [prev] | [next] | [standalone]
| From | tip-bot for Andy Lutomirski <tipbot@zytor.com> |
|---|---|
| Date | 2017-03-17 11:50 +0100 |
| Subject | [tip:perf/urgent] x86/perf: Clarify why x86_pmu_event_mapped() isn't racy |
| Message-ID | <tlXCi-535-15@gated-at.bofh.it> |
| In reply to | #1602820 |
Commit-ID: 4b07372a32c0c1505a7634ad7e607d83340ef645 Gitweb: http://git.kernel.org/tip/4b07372a32c0c1505a7634ad7e607d83340ef645 Author: Andy Lutomirski <luto@kernel.org> AuthorDate: Thu, 16 Mar 2017 12:59:40 -0700 Committer: Ingo Molnar <mingo@kernel.org> 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 <luto@kernel.org> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Borislav Petkov <bpetkov@suse.de> Cc: H. Peter Anvin <hpa@zytor.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Vince Weaver <vincent.weaver@maine.edu> Link: http://lkml.kernel.org/r/03a1e629063899168dfc4707f3bb6e581e21f5c6.1489694270.git.luto@kernel.org Signed-off-by: Ingo Molnar <mingo@kernel.org> --- 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); }
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web