Skip to contentSkip to conversation

perf fixes

GIT PULL Ingo Molnar 1 participant 1 message Sep 19, 2014

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

# HEAD: 3577af70a2ce4853d58e57d832e687d739281479 perf: Fix a race condition in perf_remove_from_context()

Two kernel side fixes: a kprobes fix and a
perf_remove_from_context() fix (which does
not yet fix the migration bug which is WIP).

Thanks,

Ingo

------------------>
Cong Wang (1):
perf: Fix a race condition in perf_remove_from_context()

Wang Nan (1):
kprobes/x86: Free 'optinsn' cache when range check fails

 arch/x86/kernel/kprobes/opt.c |  4 +++-
 kernel/events/core.c          | 10 ++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
arch/x86/kernel/kprobes/opt.c +3 -1
index f304773285ae..f1314d0bcf0a 100644
@@ -338,8 +338,10 @@ int arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
 	 * a relative jump.
 	 */
 	rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
-	if (abs(rel) > 0x7fffffff)
+	if (abs(rel) > 0x7fffffff) {
+		__arch_remove_optimized_kprobe(op, 0);
 		return -ERANGE;
+	}
 
 	buf = (u8 *)op->optinsn.insn;
 
kernel/events/core.c +10 -0
index f9c1ed002dbc..d640a8b4dcbc 100644
@@ -1524,6 +1524,11 @@ static void perf_remove_from_context(struct perf_event *event, bool detach_group
 	 */
 	if (ctx->is_active) {
 		raw_spin_unlock_irq(&ctx->lock);
+		/*
+		 * Reload the task pointer, it might have been changed by
+		 * a concurrent perf_event_context_sched_out().
+		 */
+		task = ctx->task;
 		goto retry;
 	}
 
@@ -1967,6 +1972,11 @@ perf_install_in_context(struct perf_event_context *ctx,
 	 */
 	if (ctx->is_active) {
 		raw_spin_unlock_irq(&ctx->lock);
+		/*
+		 * Reload the task pointer, it might have been changed by
+		 * a concurrent perf_event_context_sched_out().
+		 */
+		task = ctx->task;
 		goto retry;
 	}