public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Paul Fulghum <paulkf@microgate.com>
To: Ryan Reading <rreading@msm.umr.edu>
Cc: linux-kernel@vger.kernel.org
Subject: Re: 2.4.27 Potential race in n_tty.c:write_chan()
Date: Sun, 05 Dec 2004 16:40:20 -0600	[thread overview]
Message-ID: <1102286420.3386.20.camel@at2.pipehead.org> (raw)
In-Reply-To: <1102280061.10493.19.camel@localhost>

On Sun, 2004-12-05 at 15:54 -0500, Ryan Reading wrote:
> So when write_chan() calls usb_driver::write(), typically the driver
> calls usb_submit_urb().  The write() call then returns immediately
> indicating that all of the data has been written (assuming it is less
> than the USB packets size).  The driver however is still waiting for an
> interrupt to complete the write and wakeup the current kernel path.  If
> write_chan() is called again and the interrupt is received within the
> window I outlined above, the current_state will be reset to TASK_RUNNING
> before the next usb_driver::write() is ever called!  If this happens, it
> seems that we would lose synchronisity and potentially lock the kernel
> path.

The line discipline write routine is serialized
on a per tty basis in do_tty_write() of tty_io.c
using tty->atomic_write semaphore, so you will not
reenter write_chan() for a particular tty instance.

Even if this were not the case, if the task state
changes to TASK_RUNNING inside the window
you describe, the only thing that happens is the loop
executes again. The driver must decide if it can accept
more data or not and return the appropriate value.

There is no potential for deadlock.

> It is also my understanding that the usb interrupt is generated from the
> ACK/NAK of the original usb_submit_urb().  If the driver is returning
> immediately without waiting on the interrupt and schedule() is never
> being called, there is no guarantee that the write() happened
> successfully (although we return that it has).  It seems if a driver
> wanted to guarantee this, it would have to artificially wait of the
> interrupt before returning.

True, but this is a matter of layering.

The line discipline knows nothing about the driver's concept
of write completion apart from the driver's write method
return value. If it is critical for the write not to complete
until the URB is sent, it is up to the driver to block
and return the appropriate return value.
 
--
Paul Fulghum
paulkf@microgate.com


  reply	other threads:[~2004-12-05 22:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-05 20:54 2.4.27 Potential race in n_tty.c:write_chan() Ryan Reading
2004-12-05 22:40 ` Paul Fulghum [this message]
2004-12-06  4:42   ` Ryan Reading
     [not found]   ` <1102307945.1876.27.camel@localhost>
2004-12-06 14:15     ` Paul Fulghum

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=1102286420.3386.20.camel@at2.pipehead.org \
    --to=paulkf@microgate.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rreading@msm.umr.edu \
    /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