linux-stable/kernel/time
Anna-Maria Gleixner f61eff83ce hrtimer: Prepare support for PREEMPT_RT
When PREEMPT_RT is enabled, the soft interrupt thread can be preempted.  If
the soft interrupt thread is preempted in the middle of a timer callback,
then calling hrtimer_cancel() can lead to two issues:

  - If the caller is on a remote CPU then it has to spin wait for the timer
    handler to complete. This can result in unbound priority inversion.

  - If the caller originates from the task which preempted the timer
    handler on the same CPU, then spin waiting for the timer handler to
    complete is never going to end.

To avoid these issues, add a new lock to the timer base which is held
around the execution of the timer callbacks. If hrtimer_cancel() detects
that the timer callback is currently running, it blocks on the expiry
lock. When the callback is finished, the expiry lock is dropped by the
softirq thread which wakes up the waiter and the system makes progress.

This addresses both the priority inversion and the life lock issues.

The same issue can happen in virtual machines when the vCPU which runs a
timer callback is scheduled out. If a second vCPU of the same guest calls
hrtimer_cancel() it will spin wait for the other vCPU to be scheduled back
in. The expiry lock mechanism would avoid that. It'd be trivial to enable
this when paravirt spinlocks are enabled in a guest, but it's not clear
whether this is an actual problem in the wild, so for now it's an RT only
mechanism.

[ tglx: Refactored it for mainline ]

Signed-off-by: Anna-Maria Gleixner <anna-maria@linutronix.de>
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lkml.kernel.org/r/20190726185753.737767218@linutronix.de
2019-08-01 20:51:22 +02:00
..
alarmtimer.c alarmtimer: Fix kerneldoc comment for alarmtimer_suspend() 2019-06-14 17:04:04 +02:00
clockevents.c tick: Remove outgoing CPU from broadcast masks 2019-03-23 18:26:43 +01:00
clocksource.c clocksource: Move inline keyword to the beginning of function declarations 2019-06-14 17:04:03 +02:00
hrtimer.c hrtimer: Prepare support for PREEMPT_RT 2019-08-01 20:51:22 +02:00
itimer.c time: Remove useless filenames in top level comments 2018-11-23 11:51:20 +01:00
jiffies.c Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-05-06 14:50:46 -07:00
Kconfig treewide: Add SPDX license identifier - Makefile/Kconfig 2019-05-21 10:50:46 +02:00
Makefile timekeeping: Provide a generic update_vsyscall() implementation 2019-06-22 21:21:06 +02:00
ntp.c ntp: Limit TAI-UTC offset 2019-06-22 11:28:53 +02:00
ntp_internal.h ntp: Audit NTP parameters adjustment 2019-04-15 18:14:01 -04:00
posix-clock.c timex: use __kernel_timex internally 2019-02-07 00:13:27 +01:00
posix-cpu-timers.c posix-cpu-timers: Remove private interval storage 2019-01-15 16:36:13 +01:00
posix-stubs.c y2038: syscalls: rename y2038 compat syscalls 2019-02-07 00:13:27 +01:00
posix-timers.c posix-timers: Use spin_lock_irq() in itimer_delete() 2019-06-22 12:14:22 +02:00
posix-timers.h timex: use __kernel_timex internally 2019-02-07 00:13:27 +01:00
sched_clock.c Printk changes for 5.2 2019-05-07 09:18:12 -07:00
test_udelay.c time/debug: Remove license boilerplate 2018-11-23 11:51:21 +01:00
tick-broadcast-hrtimer.c tick: Mark tick related hrtimers to expiry in hard interrupt context 2019-08-01 20:51:21 +02:00
tick-broadcast.c tick: Fix typos in comments 2019-04-19 19:17:04 +02:00
tick-common.c Merge branch 'timers-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip 2019-05-06 14:50:46 -07:00
tick-internal.h tick: Remove outgoing CPU from broadcast masks 2019-03-23 18:26:43 +01:00
tick-oneshot.c hrtimers/tick/clockevents: Remove sloppy license references 2018-11-23 11:51:21 +01:00
tick-sched.c tick: Mark tick related hrtimers to expiry in hard interrupt context 2019-08-01 20:51:21 +02:00
tick-sched.h tick/sched: Update tick_sched struct documentation 2019-03-24 20:29:32 +01:00
time.c time: Validate user input in compat_settimeofday() 2019-07-07 12:05:40 +02:00
timeconst.bc time: Add SPDX license identifiers 2018-11-23 11:51:20 +01:00
timeconv.c time: Add SPDX license identifiers 2018-11-23 11:51:20 +01:00
timecounter.c time: Remove license boilerplate 2018-11-23 11:51:21 +01:00
timekeeping.c timekeeping: Use proper ktime_add when adding nsecs in coarse offset 2019-06-22 12:11:27 +02:00
timekeeping.h timers/sched_clock: Prevent generic sched_clock wrap caused by tick_freeze() 2019-04-18 14:34:53 +02:00
timekeeping_debug.c timekeeping/debug: No need to check return value of debugfs_create functions 2019-01-29 20:08:41 +01:00
timekeeping_internal.h timekeeping/ntp: Constify some function arguments 2018-07-19 17:08:05 -07:00
timer.c Printk changes for 5.2 2019-05-07 09:18:12 -07:00
timer_list.c timer_list: Guard procfs specific code 2019-06-23 00:08:52 +02:00
vsyscall.c timekeeping/vsyscall: Use __iter_div_u64_rem() 2019-07-10 20:37:49 +02:00