[LinuxPPS] [PATCHv3 03/16] pps: fix race in PPS_FETCH handler

Alexander Gordeev lasaine at lvk.cs.msu.su
Thu Aug 5 12:19:51 CEST 2010


Hi Vitezslav,

В Thu, 5 Aug 2010 07:19:29 +0200
Vitezslav Samel <vitezslav at samel.cz> пишет:

> On Thu, Aug 05, 2010 at 01:06:40AM +0400, Alexander Gordeev wrote:
> > There was a race in PPS_FETCH ioctl handler when several processes want
> > to obtain PPS data simultaneously using sleeping PPS_FETCH. They all
> > sleep most of the time in the system call.
> > With the old approach when the first process waiting on the pps queue
> > is waken up it makes new system call right away and zeroes pps->go. So
> > other processes continue to sleep. This is a clear race condition
> > because of the global 'go' variable.
> > With the new approach pps->last_ev holds some value increasing at each
> > PPS event. PPS_FETCH ioctl handler saves current value to the local
> > variable at the very beginning so it can safely check that there is a
> > new event by just comparing both variables.
> > 
> > Signed-off-by: Alexander Gordeev <lasaine at lvk.cs.msu.su>
> > ---
> >  drivers/pps/kapi.c         |    4 ++--
> >  drivers/pps/pps.c          |   10 +++++++---
> >  include/linux/pps_kernel.h |    2 +-
> >  3 files changed, 10 insertions(+), 6 deletions(-)
> > 
> > diff --git a/drivers/pps/kapi.c b/drivers/pps/kapi.c
> > index 55f3961..3f89f5e 100644
> > --- a/drivers/pps/kapi.c
> > +++ b/drivers/pps/kapi.c
> > @@ -326,8 +326,8 @@ void pps_event(int source, struct pps_ktime *ts, int event, void *data)
> >  
> >  	/* Wake up if captured something */
> >  	if (captured) {
> > -		pps->go = ~0;
> > -		wake_up_interruptible(&pps->queue);
> > +		pps->last_ev++;
> > +		wake_up_interruptible_all(&pps->queue);
> 
>   What happens if pps->last_ev overflows? Seems to me it would freeze
> pps.

Yes, it will freeze the fds (if they don't use timeouts). But in normal
circumstances, i.e. when pps_event is called twice a second, it will
overflow after ~68 years of uninterrupted work. Well, it's the same
kind of problem as an overflow of struct timespec. I thought it's not
actually a problem. Should I use u64 instead of unsigned int or add a
runtime check somewhere?

-- 
  Alexander
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
Url : http://ml.enneenne.com/pipermail/linuxpps/attachments/20100805/6c068ea0/attachment.pgp 


More information about the LinuxPPS mailing list