aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/time/hrtimer.c
diff options
context:
space:
mode:
authorJulien Grall <julien.grall@arm.com>2019-08-21 10:24:07 +0100
committerThomas Gleixner <tglx@linutronix.de>2019-08-21 16:10:01 +0200
commitdd2261ed45aaeddeb77768f291d604179bcab096 (patch)
tree728574e052504dd97511baa14d8db39b46dd4a3e /kernel/time/hrtimer.c
parentposix-cpu-timers: Fixup stale comment (diff)
downloadlinux-dev-dd2261ed45aaeddeb77768f291d604179bcab096.tar.xz
linux-dev-dd2261ed45aaeddeb77768f291d604179bcab096.zip
hrtimer: Protect lockless access to timer->base
The update to timer->base is protected by the base->cpu_base->lock(). However, hrtimer_cancel_wait_running() does access it lockless. So the compiler is allowed to refetch timer->base which can cause havoc when the timer base is changed concurrently. Use READ_ONCE() to prevent this. [ tglx: Adapted from a RT patch ] Signed-off-by: Julien Grall <julien.grall@arm.com> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lkml.kernel.org/r/20190821092409.13225-2-julien.grall@arm.com
Diffstat (limited to 'kernel/time/hrtimer.c')
-rw-r--r--kernel/time/hrtimer.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/kernel/time/hrtimer.c b/kernel/time/hrtimer.c
index 833353732554..f48864e2ff8a 100644
--- a/kernel/time/hrtimer.c
+++ b/kernel/time/hrtimer.c
@@ -1214,7 +1214,8 @@ static void hrtimer_sync_wait_running(struct hrtimer_cpu_base *cpu_base,
*/
void hrtimer_cancel_wait_running(const struct hrtimer *timer)
{
- struct hrtimer_clock_base *base = timer->base;
+ /* Lockless read. Prevent the compiler from reloading it below */
+ struct hrtimer_clock_base *base = READ_ONCE(timer->base);
if (!timer->is_soft || !base || !base->cpu_base) {
cpu_relax();