Skip to contentSkip to conversation

perf fixes for 4.11

GIT PULL Thomas Gleixner 1 participant 1 message Mar 17, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Linus,

please pull the latest perf-urgent-for-linus git tree from:

git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git perf-urgent-for-linus

A set of perf related fixes:

- Fix a CR4.PCE propagation issue caused by usage of mm instead of active_mm and therefore propagated the wrong value.

- Perf core fixes, which plug a use-after-free issue and make the event inheritance on fork more robust.

- A tooling fix for symbol handling

Thanks,

tglx

------------------>
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

Daniel Borkmann (1):
perf symbols: Fix symbols__fixup_end heuristic for corner cases

Peter Zijlstra (4):
perf/core: Fix use-after-free in perf_release() perf/core: Fix event inheritance on fork() perf/core: Simplify perf_event_free_task() perf/core: Better explain the inherit magic

 arch/x86/events/core.c   | 16 ++++++++++--
 kernel/events/core.c     | 64 ++++++++++++++++++++++++++++++++++++------------
 tools/perf/util/symbol.c |  2 +-
 3 files changed, 63 insertions(+), 19 deletions(-)
arch/x86/events/core.c +14 -2
index 1635c0c8df23..183a972f9210 100644
@@ -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)
@@ -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(&current->mm->mmap_sem);
+
 	if (atomic_inc_return(&current->mm->context.perf_rdpmc_allowed) == 1)
 		on_each_cpu_mask(mm_cpumask(current->mm), refresh_pce, NULL, 1);
 }
kernel/events/core.c +48 -16

128 lines not on this page · raw message

tools/perf/util/symbol.c +1 -1
index 70e389bc4af7..9b4d8ba22fed 100644
@@ -202,7 +202,7 @@ void symbols__fixup_end(struct rb_root *symbols)
 
 	/* Last entry */
 	if (curr->end == curr->start)
-		curr->end = roundup(curr->start, 4096);
+		curr->end = roundup(curr->start, 4096) + 4096;
 }
 
 void __map_groups__fixup_end(struct map_groups *mg, enum map_type type)