LKML Archive on
help / color / mirror / Atom feed
From: Frederic Weisbecker <>
To: Thomas Gleixner <>
Cc: LKML <>,
	Marco Elver <>,
	kasan-dev <>,
	Peter Zijlstra <>,
	"Paul E. McKenney" <>,
	Anna-Maria Behnsen <>,
	Sebastian Andrzej Siewior <>
Subject: Re: timers: Move clearing of base::timer_running under base::lock
Date: Mon, 7 Dec 2020 02:10:13 +0100	[thread overview]
Message-ID: <20201207011013.GB113660@lothringen> (raw)
In-Reply-To: <>

On Sun, Dec 06, 2020 at 10:40:07PM +0100, Thomas Gleixner wrote:
> syzbot reported KCSAN data races vs. timer_base::timer_running being set to
> NULL without holding base::lock in expire_timers().
> This looks innocent and most reads are clearly not problematic but for a
> non-RT kernel it's completely irrelevant whether the store happens before
> or after taking the lock. For an RT kernel moving the store under the lock
> requires an extra unlock/lock pair in the case that there is a waiter for
> the timer. But that's not the end of the world and definitely not worth the
> trouble of adding boatloads of comments and annotations to the code. Famous
> last words...

There is another thing I noticed lately wrt. del_timer_sync() VS timer execution:

    int data = 0;

    void timer_func(struct timer_list *t)
        data = 1;

                 CPU 0                                           CPU 1
    ------------------------------                             --------------------------
    base = lock_timer_base(timer, &flags);                     raw_spin_unlock(&base->lock);
    if (base->running_timer != timer)                          call_timer_fn(timer, fn, baseclk);
        ret = detach_if_pending(timer, base, true);            base->running_timer = NULL;
    raw_spin_unlock_irqrestore(&base->lock, flags);            raw_spin_lock(&base->lock);

    x = data;

Here if the timer has previously executed on CPU 1 and then CPU 0 sees base->running_timer == NULL,
it will return, assuming the timer has completed. But there is nothing to enforce the fact that x
will be equal to 1. Enforcing that is a behaviour I would expect in this case since this is a kind
of "wait for completion" function. But perhaps it doesn't apply here, in fact I have no idea...

But if we recognize that as an issue, we would need a mirroring load_acquire()/store_release() on

  reply	other threads:[~2020-12-07  1:11 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-06 21:40 Thomas Gleixner
2020-12-07  1:10 ` Frederic Weisbecker [this message]
2020-12-07 12:25   ` Peter Zijlstra
2020-12-07 12:49     ` Frederic Weisbecker
2020-12-07 13:07 ` Sebastian Andrzej Siewior
2020-12-07 14:29   ` Thomas Gleixner
2020-12-07 15:25     ` Sebastian Andrzej Siewior
2020-12-07 16:06       ` Paul E. McKenney
2020-12-08  8:50         ` Sebastian Andrzej Siewior
2020-12-08 15:04           ` Paul E. McKenney
2020-12-11 14:36           ` Thomas Gleixner
2020-12-11 15:04             ` Sebastian Andrzej Siewior
2021-07-27 19:00 ` [tip: timers/urgent] timers: Move clearing of base::timer_running under base:: Lock tip-bot2 for Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201207011013.GB113660@lothringen \ \ \ \ \ \ \ \ \ \
    --subject='Re: timers: Move clearing of base::timer_running under base::lock' \

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).