From: Grant Edwards <grant.b.edwards@gmail.com>
To: linux-serial@vger.kernel.org
Subject: Re: Are calls to open()/close() serialized by tty layer?
Date: Wed, 16 Jan 2013 23:07:18 +0000 (UTC) [thread overview]
Message-ID: <kd7br6$fom$1@ger.gmane.org> (raw)
In-Reply-To: 20130116224400.67169491@pyramind.ukuu.org.uk
On 2013-01-16, Alan Cox <alan@lxorguk.ukuu.org.uk> wrote:
> Grant Edwards <grant.b.edwards@gmail.com> wrote:
>
>> Are calls to a tty driver's open()/close() methods serialized by the
>> tty layer? If so, has this always been the case?
>
> They are not fully serialized - never have been. A lot of the drivers
> were always racy, some that have not been fully converted to the port
> helpers still are.
That's what it looked like it to me, but I wasn't sure.
>> [...]
>> The old driver I'm working on had its own internal locking to protect
>> race conditiions when incrementing and decrementing of a port's open
>> count. That counter is being replaced by tty->port->count, and in
>> existing in-kernel tty drivers it doesn't look like there is any
>> locking when that count is incremented during an open().
>
> Use the tty_port helpers.
That was the plan...
> They will also handle all the other detail you need. The helpers
> themselves provide serialized activate/shutdown callbacks on the port
> which are serialized against each other and hangups.
Ah! None of the examples I looked at so far were using tty_port_open()
and the port activate method, and I had somehow missed noticing their
existence when I was looking through tty_port sources.
> The port helpers will also ensure your refcounting is right, you
> don't have open/close/hangup races and that you get the required
> POSIX semantics.
>
> The port helpers are designed so you can propogate your own error
> codes either by wrapping them or by returning your own error code
> from port->activate() which will be duly propogated to user space.
Cool, thanks!
Which of the tty drivers is the best example to follow when it comes
to use of the tty_port_ helpers?
It looks like the tty_port_ helpers only go back to 2.6.33, so
supporting kernels older than that will require some sort of private,
backported versions of the helpers. Maybe I can talk management and
tech support into dropping support for kernels older than 2.6.33...
--
Grant Edwards grant.b.edwards Yow! I threw up on my
at window!
gmail.com
prev parent reply other threads:[~2013-01-16 23:07 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-16 20:07 Are calls to open()/close() serialized by tty layer? Grant Edwards
2013-01-16 22:44 ` Alan Cox
2013-01-16 23:07 ` Grant Edwards [this message]
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='kd7br6$fom$1@ger.gmane.org' \
--to=grant.b.edwards@gmail.com \
--cc=linux-serial@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).