netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Linus Torvalds <torvalds@linux-foundation.org>
To: David Howells <dhowells@redhat.com>
Cc: Thomas Gleixner <tglx@linutronix.de>,
	Network Development <netdev@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Subject: Re: Is there a race between __mod_timer() and del_timer()?
Date: Wed, 8 Nov 2017 08:26:51 -0800	[thread overview]
Message-ID: <CA+55aFwz2U4hY30YNqvHeFQqaZfVVwGXcM73BnJfxL1gkd2cGg@mail.gmail.com> (raw)
In-Reply-To: <20750.1510136141@warthog.procyon.org.uk>

On Wed, Nov 8, 2017 at 2:15 AM, David Howells <dhowells@redhat.com> wrote:
>
>  (2) Set timer->expires to jiffies in del_timer() - but since there's nothing
>      preventing the optimisation in __mod_timer() from occurring concurrently
>      with del_timer(), this probably won't help.

Right. The "race" is fundamental, and not in the timer code, but in the user.

If somebody does "del_timer()" at the same time somebody else modifies
the timer, it's not clear which one will win. The timer going away is
basically just "somebody modified it, but then immediately afterwards
another user deleted it".

So the modification was successful, but the end result is that the
timer is deleted, so it obviously isn't started.

I'm not even sure it merits a comment in the timer code, because the
timer code seems to do the right thing. The problem is in whoever
modifies and deletes a timer at the same time. It's fundamentally not
well-defined: either operation might happen "last", so you may end up
with a timer active or not, based purely on timing and luck.

              Linus

      parent reply	other threads:[~2017-11-08 16:26 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-08 10:15 Is there a race between __mod_timer() and del_timer()? David Howells
2017-11-08 10:23 ` David Howells
2017-11-08 10:40 ` Thomas Gleixner
2017-11-08 16:26 ` Linus Torvalds [this message]

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=CA+55aFwz2U4hY30YNqvHeFQqaZfVVwGXcM73BnJfxL1gkd2cGg@mail.gmail.com \
    --to=torvalds@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).