android_kernel_samsung_msm8976/kernel/time
John Stultz 63946e8616 timekeeping: Fix HRTICK related deadlock from ntp lock changes
commit 7bd36014460f793c19e7d6c94dab67b0afcfcb7f upstream.

Gerlando Falauto reported that when HRTICK is enabled, it is
possible to trigger system deadlocks. These were hard to
reproduce, as HRTICK has been broken in the past, but seemed
to be connected to the timekeeping_seq lock.

Since seqlock/seqcount's aren't supported w/ lockdep, I added
some extra spinlock based locking and triggered the following
lockdep output:

[   15.849182] ntpd/4062 is trying to acquire lock:
[   15.849765]  (&(&pool->lock)->rlock){..-...}, at: [<ffffffff810aa9b5>] __queue_work+0x145/0x480
[   15.850051]
[   15.850051] but task is already holding lock:
[   15.850051]  (timekeeper_lock){-.-.-.}, at: [<ffffffff810df6df>] do_adjtimex+0x7f/0x100

<snip>

[   15.850051] Chain exists of: &(&pool->lock)->rlock --> &p->pi_lock --> timekeeper_lock
[   15.850051]  Possible unsafe locking scenario:
[   15.850051]
[   15.850051]        CPU0                    CPU1
[   15.850051]        ----                    ----
[   15.850051]   lock(timekeeper_lock);
[   15.850051]                                lock(&p->pi_lock);
[   15.850051] lock(timekeeper_lock);
[   15.850051] lock(&(&pool->lock)->rlock);
[   15.850051]
[   15.850051]  *** DEADLOCK ***

The deadlock was introduced by 06c017fdd4 ("timekeeping:
Hold timekeepering locks in do_adjtimex and hardpps") in 3.10

This patch avoids this deadlock, by moving the call to
schedule_delayed_work() outside of the timekeeper lock
critical section.

Reported-by: Gerlando Falauto <gerlando.falauto@keymile.com>
Tested-by: Lin Ming <minggr@gmail.com>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Link: http://lkml.kernel.org/r/1378943457-27314-1-git-send-email-john.stultz@linaro.org
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2013-10-01 09:17:45 -07:00
..
Kconfig Merge branch 'timers-urgent-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2013-05-15 14:05:17 -07:00
Makefile time: remove the timecompare code. 2012-11-01 11:41:35 -04:00
alarmtimer.c alarmtimer: Rename alarmtimer_remove to alarmtimer_dequeue 2012-09-24 12:38:03 -04:00
clockevents.c clockevents: export clockevents_config_and_register for module use 2013-01-14 10:12:37 -08:00
clocksource.c
jiffies.c time: Kill xtime_lock, replacing it with jiffies_lock 2012-11-13 14:08:23 -05:00
ntp.c timekeeping: Fix HRTICK related deadlock from ntp lock changes 2013-10-01 09:17:45 -07:00
ntp_internal.h ntp: Rework do_adjtimex to take timespec and tai arguments 2013-04-04 13:18:15 -07:00
posix-clock.c
tick-broadcast.c tick: Prevent uncontrolled switch to oneshot mode 2013-07-25 14:07:29 -07:00
tick-common.c tick: Sanitize broadcast control logic 2013-07-25 14:07:29 -07:00
tick-internal.h Merge branch 'fortglx/3.10/time' of git://git.linaro.org/people/jstultz/linux into timers/core 2013-04-03 12:27:29 +02:00
tick-oneshot.c
tick-sched.c Revert "cpuidle: Quickly notice prediction failure for repeat mode" 2013-08-11 18:35:24 -07:00
timeconv.c
timekeeping.c timekeeping: Fix HRTICK related deadlock from ntp lock changes 2013-10-01 09:17:45 -07:00
timer_list.c timer_list: correct the iterator for timer_list 2013-09-07 22:09:58 -07:00
timer_stats.c