lkml.org 
[lkml]   [2011]   [Mar]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH v2] USB: cdc-acm: Prevent data loss when filling tty buffer.
> Is there a mechanism preventing a different thread from running 
> n_tty_read between n_tty_receive_buf finding receive_room to be below
> the threshold and tty_throttle being called? If not then isn't there a
> race condition when the following happens:

n_tty_receive is single threaded and is going to get run in preference to
user threads.

> 1. n_tty_receive_buf fills up the buffer so that the free space
> is below TTY_THRESHOLD_THROTTLE
> 2. n_tty_receive_buf comes to the check at the end and decide
> that it needs to call tty_throttle
> 3. Thread rescheduling happens and a different thread runs
> n_tty_read which empties the buffer
> 4. After emptying the buffer n_tty_read calls tty_unthrottle,
> which does nothing as the throttling bit isn't set
> 5. The n_tty_receive_buf thread is executed again, calling
> tty_throttle, causing throttling, but with an empty buffer.
>
> Or have I not understood a complexity in the interactions within n_tty.c?

Looks possible - historically it would have been safe but not any more.
The scenario I think would have to be two thread of execution in parallel
on two processors at the same moment and with near perfect timing but I
don't see why it can't happen.

Alan


\
 
 \ /
  Last update: 2011-03-22 19:07    [W:0.054 / U:1.056 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site