1. 23 10月, 2012 18 次提交
    • J
      TTY: move ldisc data from tty_struct: locks · bddc7152
      Jiri Slaby 提交于
      atomic_write_lock is not n_tty specific, so move it up in the
      tty_struct.
      
      And since these are the last ones to move, remove also the comment
      saying there are some ldisc' members. There are none now.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bddc7152
    • J
      ba2e68ac
    • J
      TTY: move ldisc data from tty_struct: bitmaps · 3fe780b3
      Jiri Slaby 提交于
      Here we move bitmaps and use DECLARE_BITMAP to declare them in the new
      structure. And instead of memset, we use bitmap_zero as it is more
      appropriate.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3fe780b3
    • J
      TTY: move ldisc data from tty_struct: simple members · 53c5ee2c
      Jiri Slaby 提交于
      Here we start moving all the n_tty related bits from tty_struct to
      the newly defined n_tty_data struct in n_tty proper.
      
      In this patch primitive members and bits are moved. The rest will be
      done per-partes in the next patches.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      53c5ee2c
    • J
      TTY: n_tty, add ldisc data to n_tty · 70ece7a7
      Jiri Slaby 提交于
      All n_tty related members from tty_struct will be moved here.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      70ece7a7
    • J
      TTY: audit, stop accessing tty->icount · 6c633f27
      Jiri Slaby 提交于
      This is a private member of n_tty. Stop accessing it. Instead, take is
      as an argument.
      
      This is needed to allow clean switch of the private members to a
      separate private structure of n_tty.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6c633f27
    • J
      TTY: n_tty, remove bogus checks · 3383427a
      Jiri Slaby 提交于
      * BUG_ON(!tty) in n_tty_set_termios -- it cannot be called with tty ==
        NULL. It is called from two call sites. First, from n_tty_open where
        we have a valid tty. Second, as ld->ops->set_termios from
        tty_set_termios. But there we have a valid tty too.
      * if (!tty) in n_tty_open -- why would the TTY layer call ldisc's
        open with an invalid TTY? No it indeed does not. All call sites have
        a tty and dereference that.
      * BUG_ON(!tty->read_buf) in n_tty_read -- this used to be a valid
        check. The ldisc handling was broken some time ago when I added the
        check to ensure everything is OK. It still can catch the case, but
        no later than we move the buffer to ldisc data. Then there will be
        no read_buf in tty_struct, i.e. nothing to check for.
      * if (!tty->read_buf) in n_tty_receive_buf -- this should never
        happen. All callers of ldisc->ops->receive_ops should hold a
        reference to an ldisc and close (which frees read_buf) cannot be
        called until the reference is dropped.
      * if (WARN_ON(!tty->read_buf)) in n_tty_read -- the same as in the
        previous case.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      3383427a
    • J
      TTY: n_tty, simplify read_buf+echo_buf allocation · b91939f5
      Jiri Slaby 提交于
      ldisc->open and close are called only once and cannot cross. So the
      tests in open and close are superfluous. Remove them. (But leave sets
      to NULL to ensure there is not a bug somewhere.)
      
      And when the tests are gone, handle properly failures in open. We
      leaked read_buf if allocation of echo_buf failed before. Now this is
      not the case anymore.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      b91939f5
    • J
      TTY: hci_ldisc, remove invalid check in open · f327b340
      Jiri Slaby 提交于
      hci_ldisc's open checks if tty_struct->disc_data is set. And if so it
      returns with an error. But nothing ensures disc_data to be NULL. And
      since ld->ops->open shall be called only once, we do not need the
      check at all. So remove it.
      
      Note that this is not an issue now, but n_tty will start using the
      disc_data pointer and this invalid 'if' would trigger then rendering
      TTYs over BT unusable.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NMarcel Holtmann <marcel@holtmann.org>
      Cc: Gustavo Padovan <gustavo@padovan.org>
      Cc: Johan Hedberg <johan.hedberg@gmail.com>
      Cc: linux-bluetooth@vger.kernel.org
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f327b340
    • J
      TTY: ldisc, wait for idle ldisc in release · 31e12128
      Jiri Slaby 提交于
      We reintroduced tty_ldisc_wait_idle in 100eeae2 (TTY: restore
      tty_ldisc_wait_idle) and used in set_ldisc. Then we added it also to
      the hangup path in 92f6fa09 (TTY: ldisc, do not close until there
      are readers). And we noted that there is one more path:
      ~   Before 65b77046 tty_ldisc_wait_idle was called also from
      ~   tty_ldisc_release. It is called from tty_release, so I don't think
      ~   we need to restore that one.
      
      Well, I was wrong. There might still be holders of an ldisc
      reference. Not from userspace, but drivers. If they take a reference
      and a user closes the device immediately after that, we have a
      problem. ldisc is halted and closed by TTY, but the driver still may
      call some ldisc's operation and cause a crash.
      
      So restore the tty_ldisc_wait_idle call also to the third location
      where it was before 65b77046 (tty-ldisc: turn ldisc user count
      into a proper refcount). Now we should be safe with respect to the
      ldisc reference counting as all* tty_ldisc_close paths are safely
      called with reference count of one.
      
      * Not the one in tty_ldisc_setup's fail path. But that is called
        before the first open finishes. So userspace does not see it yet.
        Even thought the driver is given the TTY already via ->install, it
        should not take a reference to the ldisc yet. If some driver is to
        do this, we should put one tty_ldisc_wait_idle also in the setup.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      31e12128
    • J
      TTY: vt, fix paste_selection ldisc handling · 7ee00fdb
      Jiri Slaby 提交于
      There used to be a single tty_ldisc_ref_wait. But then, when a
      big-tty-mutex (BTM) was introduced, it has to be tty_ldisc_ref +
      tty_unlock + tty_ldisc_ref_wait + tty_lock. Later, BTM was removed
      from that path and tty_ldisc_ref + tty_ldisc_ref_wait remained there.
      But it makes no sense now. So leave there only tty_ldisc_ref_wait.
      
      And when we have a reference to an ldisc, actually use it in the loop.
      Otherwise it may be racy.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      7ee00fdb
    • J
      TTY: move devpts kill to pty · fa2ecfc5
      Jiri Slaby 提交于
      Now that we have control over tty->driver_data in pty, we can just
      kill the /dev/pts/ in pty code too. Namely, in ->shutdown hook of
      tty. For pty, this is called only once, for whichever end is closed
      last. But we don't care, both driver_data are the inode as it used to
      be till now.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      fa2ecfc5
    • J
      TTY: devpts, document devpts inode operations · 1dcb8e6d
      Jiri Slaby 提交于
      Add kernel-doc texts for some devpts functions, i.e. document them.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      1dcb8e6d
    • J
      TTY: devpts, do not set driver_data · f11afb61
      Jiri Slaby 提交于
      The goal is to stop setting and using tty->driver_data in devpts code.
      It should be used solely by the driver's code, pty in this case.
      
      Now driver_data are managed only in the pty driver. devpts_pty_new is
      switched to accept what we used to dig out of tty_struct, i.e. device
      node number and index.
      
      This also removes a note about driver_data being set outside of the
      driver.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f11afb61
    • J
      TTY: devpts, return created inode from devpts_pty_new · 162b97cf
      Jiri Slaby 提交于
      The goal is to stop setting and using tty->driver_data in devpts code.
      It should be used solely by the driver's code, pty in this case.
      
      For the cleanup of layering, we will need the inode created in
      devpts_pty_new to be stored into slave's driver_data. So we convert
      devpts_pty_new to return the inode or an ERR_PTR-encoded error in case
      of failure.
      
      The move of 'inode = new_inode(sb);' from declarators to the code is
      only cosmetical, but it makes the code easier to read.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      162b97cf
    • J
      TTY: devpts, don't care about TTY in devpts_get_tty · 8fcbaa2b
      Jiri Slaby 提交于
      The goal is to stop setting and using tty->driver_data in devpts code.
      It should be used solely by the driver's code, pty in this case.
      
      First, here we remove TTY from devpts_get_tty and rename it to
      devpts_get_priv. Note we do not remove type safety, we just shift the
      [implicit] (void *) cast one layer up.
      
      index was unused in devpts_get_tty, so remove that from the prototype
      too.
      Signed-off-by: NJiri Slaby <jslaby@suse.cz>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      8fcbaa2b
    • I
      tty: prevent unnecessary work queue lock checking on flip buffer copy · cee4ad1e
      Ivo Sieben 提交于
      When low_latency flag is set the TTY receive flip buffer is copied to the
      line discipline directly instead of using a work queue in the background.
      Therefor only in case a workqueue is actually used for copying data to the
      line discipline we'll have to flush the workqueue.
      
      This prevents unnecessary spin lock/unlock on the workqueue spin lock that
      can cause additional scheduling overhead on a PREEMPT_RT system. On a 200
      MHz AT91SAM9261 processor setup this fixes about 100us of scheduling
      overhead on the TTY read call.
      Signed-off-by: NIvo Sieben <meltedpianoman@gmail.com>
      Acked-by: NAlan Cox <alan@linux.intel.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      cee4ad1e
    • D
      console: implement lockdep support for console_lock · daee7797
      Daniel Vetter 提交于
      Dave Airlie recently discovered a locking bug in the fbcon layer,
      where a timer_del_sync (for the blinking cursor) deadlocks with the
      timer itself, since both (want to) hold the console_lock:
      
      https://lkml.org/lkml/2012/8/21/36
      
      Unfortunately the console_lock isn't a plain mutex and hence has no
      lockdep support. Which resulted in a few days wasted of tracking down
      this bug (complicated by the fact that printk doesn't show anything
      when the console is locked) instead of noticing the bug much earlier
      with the lockdep splat.
      
      Hence I've figured I need to fix that for the next deadlock involving
      console_lock - and with kms/drm growing ever more complex locking
      that'll eventually happen.
      
      Now the console_lock has rather funky semantics, so after a quick irc
      discussion with Thomas Gleixner and Dave Airlie I've quickly ditched
      the original idead of switching to a real mutex (since it won't work)
      and instead opted to annotate the console_lock with lockdep
      information manually.
      
      There are a few special cases:
      - The console_lock state is protected by the console_sem, and usually
        grabbed/dropped at _lock/_unlock time. But the suspend/resume code
        drops the semaphore without dropping the console_lock (see
        suspend_console/resume_console). But since the same thread that did
        the suspend will do the resume, we don't need to fix up anything.
      
      - In the printk code there's a special trylock, only used to kick off
        the logbuffer printk'ing in console_unlock. But all that happens
        while lockdep is disable (since printk does a few other evil
        tricks). So no issue there, either.
      
      - The console_lock can also be acquired form irq context (but only
        with a trylock). lockdep already handles that.
      
      This all leaves us with annotating the normal console_lock, _unlock
      and _trylock functions.
      
      And yes, it works - simply unloading a drm kms driver resulted in
      lockdep complaining about the deadlock in fbcon_deinit:
      
      ======================================================
      [ INFO: possible circular locking dependency detected ]
      3.6.0-rc2+ #552 Not tainted
      -------------------------------------------------------
      kms-reload/3577 is trying to acquire lock:
       ((&info->queue)){+.+...}, at: [<ffffffff81058c70>] wait_on_work+0x0/0xa7
      
      but task is already holding lock:
       (console_lock){+.+.+.}, at: [<ffffffff81264686>] bind_con_driver+0x38/0x263
      
      which lock already depends on the new lock.
      
      the existing dependency chain (in reverse order) is:
      
      -> #1 (console_lock){+.+.+.}:
             [<ffffffff81087440>] lock_acquire+0x95/0x105
             [<ffffffff81040190>] console_lock+0x59/0x5b
             [<ffffffff81209cb6>] fb_flashcursor+0x2e/0x12c
             [<ffffffff81057c3e>] process_one_work+0x1d9/0x3b4
             [<ffffffff810584a2>] worker_thread+0x1a7/0x24b
             [<ffffffff8105ca29>] kthread+0x7f/0x87
             [<ffffffff813b1204>] kernel_thread_helper+0x4/0x10
      
      -> #0 ((&info->queue)){+.+...}:
             [<ffffffff81086cb3>] __lock_acquire+0x999/0xcf6
             [<ffffffff81087440>] lock_acquire+0x95/0x105
             [<ffffffff81058cab>] wait_on_work+0x3b/0xa7
             [<ffffffff81058dd6>] __cancel_work_timer+0xbf/0x102
             [<ffffffff81058e33>] cancel_work_sync+0xb/0xd
             [<ffffffff8120a3b3>] fbcon_deinit+0x11c/0x1dc
             [<ffffffff81264793>] bind_con_driver+0x145/0x263
             [<ffffffff81264a45>] unbind_con_driver+0x14f/0x195
             [<ffffffff8126540c>] store_bind+0x1ad/0x1c1
             [<ffffffff8127cbb7>] dev_attr_store+0x13/0x1f
             [<ffffffff8116d884>] sysfs_write_file+0xe9/0x121
             [<ffffffff811145b2>] vfs_write+0x9b/0xfd
             [<ffffffff811147b7>] sys_write+0x3e/0x6b
             [<ffffffff813b0039>] system_call_fastpath+0x16/0x1b
      
      other info that might help us debug this:
      
       Possible unsafe locking scenario:
      
             CPU0                    CPU1
             ----                    ----
        lock(console_lock);
                                     lock((&info->queue));
                                     lock(console_lock);
        lock((&info->queue));
      
       *** DEADLOCK ***
      
      v2: Mark the lockdep_map static, noticed by Jani Nikula.
      
      Cc: Dave Airlie <airlied@gmail.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Alan Cox <alan@lxorguk.ukuu.org.uk>
      Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
      Signed-off-by: NDaniel Vetter <daniel.vetter@ffwll.ch>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      daee7797
  2. 21 10月, 2012 2 次提交
  3. 20 10月, 2012 20 次提交