From: David Howells Subject: Re: Is there a race between __mod_timer() and del_timer()? Date: Wed, 08 Nov 2017 10:23:36 +0000 Message-ID: <21200.1510136616@warthog.procyon.org.uk> References: <20750.1510136141@warthog.procyon.org.uk> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT Cc: dhowells@redhat.com, torvalds@linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org To: tglx@linutronix.de Return-path: In-Reply-To: <20750.1510136141@warthog.procyon.org.uk> Content-ID: <21199.1510136616.1@warthog.procyon.org.uk> Sender: linux-kernel-owner@vger.kernel.org List-Id: netdev.vger.kernel.org David Howells wrote: > I think it might just be best to put a note in the comments in __mod_timer(). How about the attached? David --- commit d538c734f9bf885292b88a81a06c5efee528d70d Author: David Howells Date: Wed Nov 8 10:20:27 2017 +0000 Add a comment into __mod_timer() noting a possible race with del_timer() Add a comment into __mod_timer() noting a possible race with del_timer() in which the 'common optimization' case could leave the timer unstarted if del_timer() happens between the timer_pending() check and the timer expiration check. Signed-off-by: David Howells diff --git a/kernel/time/timer.c b/kernel/time/timer.c index f2674a056c26..e0ac4486529c 100644 --- a/kernel/time/timer.c +++ b/kernel/time/timer.c @@ -949,6 +949,9 @@ __mod_timer(struct timer_list *timer, unsigned long expires, bool pending_only) * The downside of this optimization is that it can result in * larger granularity than you would get from adding a new * timer with this expiry. + * + * Note that if del_timer() happens whilst we're just here, we + * will return with the timer unstarted. */ if (timer->expires == expires) return 1;