Re: [PATCH 4/4] TTY: call tty_driver_lookup_tty unconditionally

From: Jiri Slaby
Date: Sun Oct 16 2011 - 15:37:54 EST


Fixing Alan's address. Somehow I put there a RH (defunct) one.

On 10/16/2011 09:20 PM, Sukadev Bhattiprolu wrote:
> Jiri Slaby [jirislaby@xxxxxxxxx] wrote:
> | On 10/12/2011 11:32 AM, Jiri Slaby wrote:
> | > Commit 4a2b5fddd5 (Move tty lookup/reopen to caller) made the call to
> | > tty_driver_lookup_tty conditional in tty_open. It doesn't look like it
> | > was an intention. Or if it was, it was not documented in the changelog
> | > and the code now looks weird. For example there would be no need to
> | > remember the tty driver and tty index. Further the condition depends
> | > on a tty which we drop a reference of already.
> | >
> | > If I'm looking correctly, this should not matter thanks to the locking
> | > currently done there. Thus, tty_driver->ttys[idx] cannot change under
> | > our hands. But anyway, it makes sense to change that to the old
> | > behaviour.
> |
> | Well, this doesn't work for ptys. devpts lookup code expects an inode to
> | be one of devpts filesystem (/dev/pts/*), not something on tmpfs like
> | /dev/tty. So it looks like the change was intentional, but very
> | undocumented and leaving there some unused code.
>
> Yes this was intentional - even though the tty_driver_lookup() was
> unconditional in tty_init_dev() I believe it did not do anything useful
> when called from ptmx_open(). ptmx_open() would be setting up a new pty and
> the lookup would not find a tty.

Yes, I'm not arguing against moving the code from tty_init_dev to
tty_open change. That is perfectly OK.

What I mind is that now we do:
=====
tty = get_current_tty();
if (!tty)
return -ENXIO;
driver = tty_driver_kref_get(tty->driver); /* ZZZ */
index = tty->index; /* ZZZ */
...
tty_kref_put(tty); /* XXX */
goto got_driver;
...
got_driver:
if (!tty) { /* YYY */
}
=====

But at the point of YYY, the tty may be invalid due to reference drop at
XXX. I *hope* it is not the case thanks to the current locking there
(namely BTM) but I'm really *not sure*. And if it is the case, there
should definitely be a note. (Or better the reference should be held
while necessary.)

> Would the following change to tty_open() help ?

No, it doesn't matter now. I would prefer a description of the change to
be a part of the commit log. And it missed such a notice.

> I am not sure about the unused code you refer to above. Can you please
> clarify ?

It is index and driver assigned in the branch above (see ZZZ). When we
have a live tty (which I'm not sure we have -- see above), it is
guaranteed that the driver is reff'ed. And we need neither driver nor
index when we have such a tty.

thanks,
--
js
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/