From: Ryan Arnold <rsa@us.ibm.com>
To: "Theodore Ts'o" <tytso@mit.edu>
Cc: Kernel Mailing List <linux-kernel@vger.kernel.org>,
alan@lxorguk.ukuu.org.uk
Subject: ldisc writes during tty release_dev() causing problems.
Date: Thu, 23 Sep 2004 20:15:40 -0500 [thread overview]
Message-ID: <1095988521.3372.240.camel@localhost.localdomain> (raw)
In-Reply-To: <20040915204107.GA26776@thunk.org>
On Wed, 2004-09-15 at 15:41, Theodore Ts'o wrote:
> The current (I can't speak to what Alan Cox is going to change) rules
> with tty drivers is that tty drivers are supposed to close the line
> discpline in their close routines. That's the much safer and cleaner
> way of fixing this problem, and it is in line with what most of the
> other tty drivers are doing.
> - Ted
Ted,
I greped through the drivers directory and it appears that the only tty
drivers that actually invoke ldisc.close() are those drivers that don't
use the N_TTY line discipline (serial drivers).
Many of the drivers actually call ldisc.flush_buffers() which
effectively does the same as a ldisc.close(), cleaning up the
tty->read_buf and tasks waiting on tty->read_wait.
The story is different with writes. The tty layer dipatches a write via
the line discpline's write_chan() function. The line discipline is then
responsible for delivering this data to the driver's write() function.
If driver->write() returns 0 [device is blocking] (which it can do often
in the case of hvc_console) the ldisc write_chan() function will
schedule() and get put on the tty->write_wait queue with the expectation
that it will be awoken by the driver when the device is available for
further writes.
If tty release_dev() is called when write_chan() is blocked awaiting I/O
with the driver and tty->count == 1 the final call to driver->close()
will clean up the driver without the ldisc knowing that the driver has
closed the device.
Following this release_dev() actually awakens the tty->write_wait, which
basically tells the ldisc to continue trying to send data to the driver
for the device it has just told the driver to close!
Ideally I would want hvc_close() to be able to tell the ldisc to wake up
the thread blocking on tty->write_wait and discard any unsent data.
Unless I'm mistaken there is currrently no way to do this.
I suppose I could make hvc_write() return -EIO if hvc_struct->count ==
0. I can't think of any races with this but it doesn't seem correct.
Additionally, there doesn't seem to be anything to prevent hangup being
called on a tty during the final close operation (this actually happened
in hvc_console).
Do you have any wisdom or advice? Am I missing something obvious?
Ryan S. Arnold
IBM Linux Technology Center
next prev parent reply other threads:[~2004-09-24 1:06 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-09-15 18:43 [PATCH] hvc_console fix to protect hvc_write against ldisc write after hvc_close Ryan Arnold
2004-09-15 19:20 ` Alan Cox
2004-09-15 21:23 ` Ryan Arnold
2004-09-15 20:41 ` Theodore Ts'o
2004-09-15 21:36 ` Alan Cox
2004-09-15 22:35 ` Ryan Arnold
2004-09-24 1:15 ` Ryan Arnold [this message]
2004-09-24 12:40 ` ldisc writes during tty release_dev() causing problems Alan Cox
2004-09-24 16:18 ` Ryan Arnold
2004-09-24 15:30 ` Alan Cox
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=1095988521.3372.240.camel@localhost.localdomain \
--to=rsa@us.ibm.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=linux-kernel@vger.kernel.org \
--cc=tytso@mit.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