mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: Eric Dumazet <edumazet@google.com>
Cc: Will Deacon <will@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	"Paul E. McKenney" <paulmck@kernel.org>,
	the arch/x86 maintainers <x86@kernel.org>,
	LKML <linux-kernel@vger.kernel.org>,
	Marco Elver <elver@google.com>
Subject: Re: Confused about hlist_unhashed_lockless()
Date: Fri, 31 Jan 2020 19:43:22 +0100	[thread overview]
Message-ID: <20200131184322.GA11457@worktop.programming.kicks-ass.net> (raw)
In-Reply-To: <CANn89i+CnezK81gZSLOy0w7MaZy0uT=xyxoKSTyZU3aMpzifOA@mail.gmail.com>

On Fri, Jan 31, 2020 at 08:48:05AM -0800, Eric Dumazet wrote:
>     BUG: KCSAN: data-race in del_timer / detach_if_pending

> diff --git a/include/linux/timer.h b/include/linux/timer.h
> index 1e6650ed066d5d28251b0bd385fc37ef94c96532..0dc19a8c39c9e49a7cde3d34bfa4be8871cbc1c2
> 100644
> --- a/include/linux/timer.h
> +++ b/include/linux/timer.h
> @@ -164,7 +164,7 @@ static inline void destroy_timer_on_stack(struct
> timer_list *timer) { }
>   */
>  static inline int timer_pending(const struct timer_list * timer)
>  {
> - return timer->entry.pprev != NULL;
> + return !hlist_unhashed_lockless(&timer->entry);
>  }

That's just completely wrong.

Aside from any memory barrier issues that might or might not be there
(I'm waaaay to tired atm to tell), the above code is perfectly fine.

In fact, this is a KCSAN compiler infrastructure 'bug'.

Any load that is only compared to zero is immune to load-tearing issues.

The correct thing to do here is something like:

static inline int timer_pending(const struct timer_list *timer)
{
	/*
	 * KCSAN compiler infrastructure is insuffiently clever to
	 * realize that a 'load compared to zero' is immune to
	 * load-tearing.
	 */
	return data_race(timer->entry.pprev != NULL);
}

  parent reply	other threads:[~2020-01-31 18:43 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-01-31 16:43 Will Deacon
2020-01-31 16:48 ` Eric Dumazet
2020-01-31 16:57   ` Will Deacon
2020-01-31 17:06     ` Eric Dumazet
2020-01-31 17:20       ` Will Deacon
2020-01-31 17:33         ` Eric Dumazet
2020-01-31 18:32           ` Will Deacon
2020-01-31 19:47           ` Thomas Gleixner
2020-01-31 20:52             ` Paul E. McKenney
2020-01-31 18:43   ` Peter Zijlstra [this message]
2020-01-31 18:48     ` Eric Dumazet
2020-01-31 18:52       ` Eric Dumazet
2020-01-31 20:53         ` Paul E. McKenney
2020-01-31 21:04           ` Eric Dumazet
2020-01-31 21:19             ` Paul E. McKenney
2020-02-03 15:45         ` David Laight
2020-02-03 15:54           ` Marco Elver
2020-02-03 16:05             ` David Laight
2020-02-03 17:25               ` Paul E. McKenney
2020-02-03 15:58           ` Paul E. McKenney
2020-02-03 16:02             ` Will Deacon
2020-02-03 17:29               ` Paul E. McKenney
2020-02-03 18:27                 ` Will Deacon
2020-02-03 21:16                   ` Paul E. McKenney
2020-01-31 19:20       ` Marco Elver
2020-01-31 18:52   ` Paul E. McKenney
2020-01-31 18:55     ` Eric Dumazet

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:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

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

  git send-email \
    --in-reply-to=20200131184322.GA11457@worktop.programming.kicks-ass.net \
    --to=peterz@infradead.org \
    --cc=edumazet@google.com \
    --cc=elver@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=paulmck@kernel.org \
    --cc=tglx@linutronix.de \
    --cc=will@kernel.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®