Skip to content

Commit

Permalink
hrtimer: Protect lockless access to timer->base
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Julien Grall authored and Thomas Gleixner committed Aug 21, 2019
1 parent 7cb9a94 commit dd2261e
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion kernel/time/hrtimer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit dd2261e

Please sign in to comment.