hrtimer possible issue
Quoted 11 lines · Izik Eidus
Hi,
it seems like
hrtimer_enqueue_reprogramcontain a race which could result in timer.base switch during unlock/lock sequence.See the code at
__hrtimer_start_range_nswhere it callshrtimer_enqueue_reprogram. The later is releasing lock protecting the timer base for a short time and timer base switch can occur from a different CPU thread. Later when__hrtimer_start_range_nscallsunlock_hrtimer_base, a base switch could have happened and this causes the bug
Quoted 7 lines
Try to start the same hrtimer from two different threads in kernel running each one on a different CPU. Eventually one of the calls will cause timer base switch while another thread is not expecting it.
This can happen in virtualized environment where one thread can be delayed by lower hypervisor, and due to time delay a different CPU is taking care of missed timer start and runs the timer start logic on its own.
Nice analysis.
Quoted 5 lines
This simple patch (just to give example of a fix) refactor this function to get rid of unneeded lock which immediately was followed by the unlock (with possible undesired base switch).
(Both the bug and the fixed were found/patched by Leonid Shatz)
The patch got mangled by your mail client and it is missing the proper Signed-off-by annotation in the patch description. See Documentation/SubmittingPatches.
Can you please resend ?
Thanks,
tglx
I assume the race can also happen between hrtimer cancel and start. In both cases timer base switch can happen.
Izik, please check if you can arrange the patch in the standard format (do we need to do it against latest kernel version?)
Leonid Shatz
Quoted 7 lines
-----Original Message-----
From: Thomas Gleixner [mailto:[email protected]]
Sent: Monday, February 04, 2013 12:13 PM
To: Izik Eidus
Cc: [email protected]; Andrea Arcangeli; Leonid Shatz
Subject: Re: hrtimer possible issue
Quoted 21 lines
Quoted 19 lines · Izik Eidus
Hi,
it seems like
hrtimer_enqueue_reprogramcontain a race which could result in timer.base switch during unlock/lock sequence.See the code at
__hrtimer_start_range_nswhere it callshrtimer_enqueue_reprogram. The later is releasing lock protecting the timer base for a short time and timer base switch can occur from a different CPU thread. Later when__hrtimer_start_range_nscallsunlock_hrtimer_base, a base switch could have happened and this causes the bugTry to start the same hrtimer from two different threads in kernel running each one on a different CPU. Eventually one of the calls will cause timer base switch while another thread is not expecting it.
This can happen in virtualized environment where one thread can be delayed by lower hypervisor, and due to time delay a different CPU is taking care of missed timer start and runs the timer start logic on its
own.
Quoted 10 lines
Nice analysis.
Quoted 5 lines
This simple patch (just to give example of a fix) refactor this function to get rid of unneeded lock which immediately was followed by the unlock (with possible undesired base switch).
(Both the bug and the fixed were found/patched by Leonid Shatz)
The patch got mangled by your mail client and it is missing the proper
Signed-
Quoted 9 lines
off-by annotation in the patch description. See
Documentation/SubmittingPatches.Can you please resend ?
Thanks,
tglx
Quoted 5 lines · Leonid Shatz
I assume the race can also happen between hrtimer cancel and start. In both cases timer base switch can happen.
Izik, please check if you can arrange the patch in the standard format (do we need to do it against latest kernel version?)
Yes please.
Thanks,
tglx
Quoted 8 lines · Thomas Gleixner
Quoted 5 lines · Leonid Shatz
I assume the race can also happen between hrtimer cancel and start. In both cases timer base switch can happen.
Izik, please check if you can arrange the patch in the standard format (do we need to do it against latest kernel version?)
Yes please.
But I sent it already yasterday with git-send-email and checkpatch.pl :-)
Quoted 3 lines
Thanks,
tglx
Thomas,
Quoted 9 lines · Thomas Gleixner
Quoted 5 lines · Leonid Shatz
I assume the race can also happen between hrtimer cancel and start. In both cases timer base switch can happen.
Izik, please check if you can arrange the patch in the standard format (do we need to do it against latest kernel version?)
Yes please.
The patch is here: https://patchwork.kernel.org/patch/2091501/
Quoted 3 lines
Thanks,
tglx
Signature · 2 lines
Sincerely yours, Mike.