netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Is there a race between __mod_timer() and del_timer()?
@ 2017-11-08 10:15 David Howells
  2017-11-08 10:23 ` David Howells
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: David Howells @ 2017-11-08 10:15 UTC (permalink / raw)
  To: tglx; +Cc: dhowells, torvalds, netdev, linux-kernel

Is there a race between the optimisation for networking code in __mod_timer()
and del_timer() - or, at least, a race that matters?

Consider:

	CPU A				CPU B
	===============================	===============================
	[timer X is active]
	==>__mod_timer(X)
	if (timer_pending(timer))
		[Take the true path]
	-- IRQ --			==>del_timer(X)
					<==
	if (timer->expires == expires)
		[Take the true path]
	<==return 1
	[timer X is not active]

There's no locking to prevent this, but __mod_timer() returns without
restarting the timer.  I'm not sure this is a problem exactly, however, since
del_timer() *was* issued, and could've deleted the timer after __mod_timer()
returned.

A couple of possible alleviations:

 (1) Recheck timer_pending() before returning from __mod_timer().

 (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.

I think it might just be best to put a note in the comments in __mod_timer().

Thoughts?

David

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-11-08 16:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).