]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/2.6.38.4/perf-fix-task-context-scheduling.patch
Linux 4.14.124
[thirdparty/kernel/stable-queue.git] / releases / 2.6.38.4 / perf-fix-task-context-scheduling.patch
1 From ab711fe08297de1485fff0a366e6db8828cafd6a Mon Sep 17 00:00:00 2001
2 From: Peter Zijlstra <a.p.zijlstra@chello.nl>
3 Date: Thu, 31 Mar 2011 10:29:26 +0200
4 Subject: perf: Fix task context scheduling
5
6 From: Peter Zijlstra <a.p.zijlstra@chello.nl>
7
8 commit ab711fe08297de1485fff0a366e6db8828cafd6a upstream.
9
10 Jiri reported:
11
12 |
13 | - once an event is created by sys_perf_event_open, task context
14 | is created and it stays even if the event is closed, until the
15 | task is finished ... thats what I see in code and I assume it's
16 | correct
17 |
18 | - when the task opens event, perf_sched_events jump label is
19 | incremented and following callbacks are started from scheduler
20 |
21 | __perf_event_task_sched_in
22 | __perf_event_task_sched_out
23 |
24 | These callback *in/out set/unset cpuctx->task_ctx value to the
25 | task context.
26 |
27 | - close is called on event on CPU 0:
28 | - the task is scheduled on CPU 0
29 | - __perf_event_task_sched_in is called
30 | - cpuctx->task_ctx is set
31 | - perf_sched_events jump label is decremented and == 0
32 | - __perf_event_task_sched_out is not called
33 | - cpuctx->task_ctx on CPU 0 stays set
34 |
35 | - exit is called on CPU 1:
36 | - the task is scheduled on CPU 1
37 | - perf_event_exit_task is called
38 | - task_ctx_sched_out unsets cpuctx->task_ctx on CPU 1
39 | - put_ctx destroys the context
40 |
41 | - another call of perf_rotate_context on CPU 0 will use invalid
42 | task_ctx pointer, and eventualy panic.
43 |
44
45 Cure this the simplest possibly way by partially reverting the
46 jump_label optimization for the sched_out case.
47
48 Reported-and-tested-by: Jiri Olsa <jolsa@redhat.com>
49 Signed-off-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
50 Cc: Oleg Nesterov <oleg@redhat.com>
51 LKML-Reference: <1301520405.4859.213.camel@twins>
52 Signed-off-by: Ingo Molnar <mingo@elte.hu>
53 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
54
55 ---
56 include/linux/perf_event.h | 2 +-
57 1 file changed, 1 insertion(+), 1 deletion(-)
58
59 --- a/include/linux/perf_event.h
60 +++ b/include/linux/perf_event.h
61 @@ -1052,7 +1052,7 @@ void perf_event_task_sched_out(struct ta
62 {
63 perf_sw_event(PERF_COUNT_SW_CONTEXT_SWITCHES, 1, 1, NULL, 0);
64
65 - COND_STMT(&perf_task_events, __perf_event_task_sched_out(task, next));
66 + __perf_event_task_sched_out(task, next);
67 }
68
69 extern void perf_event_mmap(struct vm_area_struct *vma);