Peter Zijlstra
c127449944
perf: Fix race in perf_event_exec()
...
I managed to tickle this warning:
[ 2338.884942] ------------[ cut here ]------------
[ 2338.890112] WARNING: CPU: 13 PID: 35162 at ../kernel/events/core.c:2702 task_ctx_sched_out+0x6b/0x80()
[ 2338.900504] Modules linked in:
[ 2338.903933] CPU: 13 PID: 35162 Comm: bash Not tainted 4.4.0-rc4-dirty #244
[ 2338.911610] Hardware name: Intel Corporation S2600GZ/S2600GZ, BIOS SE5C600.86B.02.02.0002.122320131210 12/23/2013
[ 2338.923071] ffffffff81f1468e ffff8807c6457cb8 ffffffff815c680c 0000000000000000
[ 2338.931382] ffff8807c6457cf0 ffffffff810c8a56 ffffe8ffff8c1bd0 ffff8808132ed400
[ 2338.939678] 0000000000000286 ffff880813170380 ffff8808132ed400 ffff8807c6457d00
[ 2338.947987] Call Trace:
[ 2338.950726] [<ffffffff815c680c>] dump_stack+0x4e/0x82
[ 2338.956474] [<ffffffff810c8a56>] warn_slowpath_common+0x86/0xc0
[ 2338.963195] [<ffffffff810c8b4a>] warn_slowpath_null+0x1a/0x20
[ 2338.969720] [<ffffffff811a49cb>] task_ctx_sched_out+0x6b/0x80
[ 2338.976244] [<ffffffff811a62d2>] perf_event_exec+0xe2/0x180
[ 2338.982575] [<ffffffff8121fb6f>] setup_new_exec+0x6f/0x1b0
[ 2338.988810] [<ffffffff8126de83>] load_elf_binary+0x393/0x1660
[ 2338.995339] [<ffffffff811dc772>] ? get_user_pages+0x52/0x60
[ 2339.001669] [<ffffffff8121e297>] search_binary_handler+0x97/0x200
[ 2339.008581] [<ffffffff8121f8b3>] do_execveat_common.isra.33+0x543/0x6e0
[ 2339.016072] [<ffffffff8121fcea>] SyS_execve+0x3a/0x50
[ 2339.021819] [<ffffffff819fc165>] stub_execve+0x5/0x5
[ 2339.027469] [<ffffffff819fbeb2>] ? entry_SYSCALL_64_fastpath+0x12/0x71
[ 2339.034860] ---[ end trace ee1337c59a0ddeac ]---
Which is a WARN_ON_ONCE() indicating that cpuctx->task_ctx is not
what we expected it to be.
This is because context switches can swap the task_struct::perf_event_ctxp[]
pointer around. Therefore you have to either disable preemption when looking
at current, or hold ctx->lock.
Fix perf_event_enable_on_exec(), it loads current->perf_event_ctxp[]
before disabling interrupts, therefore a preemption in the right place
can swap contexts around and we're using the wrong one.
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Cc: Alexander Potapenko <glider@google.com>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Dmitry Vyukov <dvyukov@google.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Kostya Serebryany <kcc@google.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Sasha Levin <sasha.levin@oracle.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Vince Weaver <vincent.weaver@maine.edu>
Cc: syzkaller <syzkaller@googlegroups.com>
Link: http://lkml.kernel.org/r/20151210195740.GG6357@twins.programming.kicks-ass.net
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-01-06 10:52:38 +01:00
..
2015-11-03 11:29:56 -05:00
2015-06-16 11:04:29 +01:00
2015-02-19 12:39:03 -06:00
2016-01-06 10:52:38 +01:00
2015-06-30 19:44:57 -07:00
2015-11-15 09:30:48 -08:00
2015-11-11 17:36:04 +01:00
2015-11-23 09:44:58 +01:00
2015-11-06 17:50:42 -08:00
2015-11-06 17:50:42 -08:00
2015-10-07 16:06:25 -07:00
2015-11-23 09:44:58 +01:00
2015-11-15 09:30:48 -08:00
2015-11-23 09:44:58 +01:00
2015-10-21 15:18:35 +01:00
2015-04-11 22:27:55 -04:00
2015-08-06 16:14:53 -04:00
2015-11-04 08:23:51 -05:00
2015-09-08 13:34:59 -07:00
2015-11-06 17:50:42 -08:00
2015-11-04 08:23:51 -05:00
2015-11-04 08:23:51 -05:00
2015-09-08 13:34:59 -07:00
2015-04-15 16:35:22 -07:00
2015-07-14 17:29:23 -04:00
2015-10-15 16:41:53 -04:00
2015-11-06 17:50:42 -08:00
2015-06-04 23:57:18 +02:00
2015-11-10 12:06:23 +01:00
2015-09-03 02:42:20 +02:00
2015-11-03 18:03:50 -08:00
2015-11-05 23:10:54 -08:00
2015-09-10 13:29:01 -07:00
2015-04-12 21:03:31 +02:00
2015-11-03 18:03:50 -08:00
2015-09-10 13:29:01 -07:00
2015-11-05 23:10:54 -08:00
2014-10-21 23:44:20 +02:00
2015-11-04 21:50:37 -08:00
2015-04-15 16:35:22 -07:00
2015-04-15 16:35:22 -07:00
2015-11-23 09:44:58 +01:00
2015-11-23 09:44:58 +01:00
2014-10-14 02:18:16 +02:00
2015-05-12 09:46:00 +02:00
2015-11-06 17:50:42 -08:00
2015-11-06 17:50:42 -08:00
2015-09-10 13:29:01 -07:00
2015-11-06 17:50:42 -08:00
2015-10-23 17:55:10 +09:00
2015-08-04 10:16:54 +02:00
2015-09-10 13:29:01 -07:00
2015-09-04 16:54:41 -07:00
2015-09-11 15:21:34 -07:00
2015-09-11 15:21:34 -07:00
2015-11-10 12:07:22 -08:00
2015-10-21 15:18:36 +01:00
2015-08-24 10:37:01 +09:30
2015-09-01 08:40:25 -07:00
2014-12-04 14:34:54 -05:00
2015-02-13 21:21:38 -08:00
2015-11-20 16:17:32 -08:00
2015-11-09 15:53:39 -08:00
2014-12-16 15:53:03 -08:00
2015-07-22 15:27:32 -07:00
2015-09-08 15:35:28 -07:00
2015-10-27 19:55:13 -07:00
2015-01-17 10:02:23 +13:00
2015-09-10 13:29:01 -07:00
2015-06-30 19:44:59 -07:00
2015-08-10 23:07:05 -04:00
2015-10-27 19:55:13 -07:00
2015-11-20 16:17:32 -08:00
2015-11-06 17:50:42 -08:00
2015-10-20 10:23:55 +02:00
2015-02-09 15:24:03 -08:00
2014-12-13 12:42:48 -08:00
2015-10-20 10:25:56 +02:00
2015-11-05 19:34:48 -08:00
2015-11-06 17:50:42 -08:00
2014-12-10 17:41:10 -08:00
2015-11-05 19:34:48 -08:00
2015-09-05 13:46:58 -07:00
2015-01-18 01:03:45 -05:00
2015-10-06 11:25:01 -07:00
2015-10-25 21:33:54 -04:00
2014-12-05 17:19:27 -06:00
2015-09-04 16:54:41 -07:00
2014-12-17 12:31:40 -08:00
2014-12-04 14:34:47 -05:00
2015-11-05 19:34:48 -08:00
2015-11-05 14:16:27 -08:00