From: Alan Cox <alan@lxorguk.ukuu.org.uk>
To: Toby Gray <toby.gray@realvnc.com>
Cc: Johan Hovold <jhovold@gmail.com>,
Oliver Neukum <oliver@neukum.name>,
Greg Kroah-Hartman <gregkh@suse.de>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] USB: cdc-acm: Prevent data loss when filling tty buffer.
Date: Tue, 22 Mar 2011 18:05:45 +0000 [thread overview]
Message-ID: <20110322180545.54df2fa0@lxorguk.ukuu.org.uk> (raw)
In-Reply-To: <4D88ADFB.10206@realvnc.com>
> 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
next prev parent reply other threads:[~2011-03-22 18:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-21 15:52 [PATCH] " Toby Gray
2011-03-21 16:56 ` Alan Cox
2011-03-21 17:58 ` Toby Gray
2011-03-22 8:07 ` Oliver Neukum
2011-03-22 11:07 ` Alan Cox
2011-03-21 18:04 ` [PATCH v2] " Toby Gray
2011-03-22 10:05 ` Johan Hovold
2011-03-22 10:35 ` Alan Cox
2011-03-22 11:34 ` Johan Hovold
2011-03-22 14:11 ` Toby Gray
2011-03-22 18:05 ` Alan Cox [this message]
2011-03-22 7:43 ` [PATCH] " Oliver Neukum
2011-03-23 12:15 ` Toby Gray
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20110322180545.54df2fa0@lxorguk.ukuu.org.uk \
--to=alan@lxorguk.ukuu.org.uk \
--cc=gregkh@suse.de \
--cc=jhovold@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=oliver@neukum.name \
--cc=toby.gray@realvnc.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®