Re: [PATCH] tty: add lockdep annotations

From: Linus Torvalds
Date: Sat Jun 02 2012 - 15:59:22 EST


On Sat, Jun 2, 2012 at 11:38 AM, Linus Torvalds
<torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:
>
> I'm pretty sure this is the bug. And there's no way we can make
> 'tty_mutex' protect every tty_kref_put(). So I think we have two
> options:
>
>  - revert all the tty locking changes
>
>  - make a new global lock that protects just driver->ops->lookup(),
> driver->ttys[idx], and driver->ops->remove()
>
> Hmm?

Ok, here's the second option. THIS PATCH IS TOTALLY UNTESTED!

Basic concepts:

- the tty driver lookup is protected with "tty_lookup_mutex",
similarly to how the "current task mutex" is protected by the signal
lock.

- At lookup, we now always increment the kref (which in the case of
tty_open_current_tty() means that we do *not* drop the kref), and in
the case of a tty driver lookup, we use "atomic_inc_not_zero()" to
make sure that we get a tty that is not on its way out.

I *think* this makes sense. But it has has had absolutely zero
testing. It compiles in my config, and the locking is at least
sensible and well-localized, but maybe I'm missing something.

Comments?

Linus

Attachment: tty-lookup-locking.patch
Description: Binary data