Re: [PATCH v2] USB: cdc-acm: Prevent data loss when filling tty buffer.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 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
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux