Thread (4 messages) flat view 4 messages, 3 authors, 2017-11-08

Re: Is there a race between __mod_timer() and del_timer()?

From: David Howells <dhowells@redhat.com>
Date: 2017-11-08 10:23:42
Also in: lkml
Subsystem: high-resolution timers, timer wheel, clockevents, the rest · Maintainers: Anna-Maria Behnsen, Frederic Weisbecker, Thomas Gleixner, Linus Torvalds

David Howells [off-list ref] 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 [off-list ref]
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 [off-list ref]
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;
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help