]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/2.6.25.1/hrtimer-raise-softirq-unlocked-to-avoid-circular-lock-dependency.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 2.6.25.1 / hrtimer-raise-softirq-unlocked-to-avoid-circular-lock-dependency.patch
1 From jejb@kernel.org Tue Apr 29 09:51:24 2008
2 From: Thomas Gleixner <tglx@linutronix.de>
3 Date: Tue, 29 Apr 2008 01:15:10 GMT
4 Subject: hrtimer: raise softirq unlocked to avoid circular lock dependency
5 To: jejb@kernel.org, stable@kernel.org
6 Message-ID: <200804290115.m3T1FAaX028758@hera.kernel.org>
7
8 From: Thomas Gleixner <tglx@linutronix.de>
9
10 commit 0c96c5979a522c3323c30a078a70120e29b5bdbc upstream
11
12 The scheduler hrtimer bits in 2.6.25 introduced a circular lock
13 dependency in a rare code path:
14
15 =======================================================
16 [ INFO: possible circular locking dependency detected ]
17 2.6.25-sched-devel.git-x86-latest.git #19
18 -------------------------------------------------------
19 X/2980 is trying to acquire lock:
20 (&rq->rq_lock_key#2){++..}, at: [<ffffffff80230146>] task_rq_lock+0x56/0xa0
21
22 but task is already holding lock:
23 (&cpu_base->lock){++..}, at: [<ffffffff80257ae1>] lock_hrtimer_base+0x31/0x60
24
25 which lock already depends on the new lock.
26
27 The scenario which leads to this is:
28
29 posix-timer signal is delivered
30 -> posix-timer is rearmed
31 timer is already expired in hrtimer_enqueue()
32 -> softirq is raised
33
34 To prevent this we need to move the raise of the softirq out of the
35 base->lock protected code path.
36
37 Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
38 Acked-by: Peter Zijlstra <a.p.zijlstra@chello.nl>
39 Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
40
41 ---
42 kernel/hrtimer.c | 19 +++++++++++++++++--
43 1 file changed, 17 insertions(+), 2 deletions(-)
44
45 --- a/kernel/hrtimer.c
46 +++ b/kernel/hrtimer.c
47 @@ -590,7 +590,6 @@ static inline int hrtimer_enqueue_reprog
48 list_add_tail(&timer->cb_entry,
49 &base->cpu_base->cb_pending);
50 timer->state = HRTIMER_STATE_PENDING;
51 - raise_softirq(HRTIMER_SOFTIRQ);
52 return 1;
53 default:
54 BUG();
55 @@ -633,6 +632,11 @@ static int hrtimer_switch_to_hres(void)
56 return 1;
57 }
58
59 +static inline void hrtimer_raise_softirq(void)
60 +{
61 + raise_softirq(HRTIMER_SOFTIRQ);
62 +}
63 +
64 #else
65
66 static inline int hrtimer_hres_active(void) { return 0; }
67 @@ -651,6 +655,7 @@ static inline int hrtimer_reprogram(stru
68 {
69 return 0;
70 }
71 +static inline void hrtimer_raise_softirq(void) { }
72
73 #endif /* CONFIG_HIGH_RES_TIMERS */
74
75 @@ -850,7 +855,7 @@ hrtimer_start(struct hrtimer *timer, kti
76 {
77 struct hrtimer_clock_base *base, *new_base;
78 unsigned long flags;
79 - int ret;
80 + int ret, raise;
81
82 base = lock_hrtimer_base(timer, &flags);
83
84 @@ -884,8 +889,18 @@ hrtimer_start(struct hrtimer *timer, kti
85 enqueue_hrtimer(timer, new_base,
86 new_base->cpu_base == &__get_cpu_var(hrtimer_bases));
87
88 + /*
89 + * The timer may be expired and moved to the cb_pending
90 + * list. We can not raise the softirq with base lock held due
91 + * to a possible deadlock with runqueue lock.
92 + */
93 + raise = timer->state == HRTIMER_STATE_PENDING;
94 +
95 unlock_hrtimer_base(timer, &flags);
96
97 + if (raise)
98 + hrtimer_raise_softirq();
99 +
100 return ret;
101 }
102 EXPORT_SYMBOL_GPL(hrtimer_start);