04 Aug, 2015

1 commit


24 Sep, 2014

1 commit

  • Without serialization, the flow control state can become inverted
    wrt. the actual hardware state. For example,

    CPU 0 | CPU 1
    stop_tty() |
    lock ctrl_lock |
    tty->stopped = 1 |
    unlock ctrl_lock |
    | start_tty()
    | lock ctrl_lock
    | tty->stopped = 0
    | unlock ctrl_lock
    | driver->start()
    driver->stop() |

    In this case, the flow control state now indicates the tty has
    been started, but the actual hardware state has actually been stopped.

    Introduce tty->flow_lock spinlock to serialize tty flow control changes.
    Split out unlocked __start_tty()/__stop_tty() flavors for use by
    ioctl(TCXONC) in follow-on patch.

    Signed-off-by: Peter Hurley
    Signed-off-by: Greg Kroah-Hartman

    Peter Hurley
     

11 Jul, 2014

1 commit


05 Feb, 2013

1 commit


14 Aug, 2012

3 commits

  • We need the /dev/ node not to be available before we call
    tty_register_device. Otherwise we might race with open and
    tty_struct->port might not be available at that time.

    This is not an issue now, but would be a problem after "TTY: use
    tty_port_register_device" is applied.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     
  • This allows drivers like ttyprintk to avoid hacks to create an
    unnumbered node in /dev. It used to set TTY_DRIVER_DYNAMIC_DEV in
    flags and call device_create on its own. That is incorrect, because
    TTY_DRIVER_DYNAMIC_DEV may be set only if tty_register_device is
    called explicitly.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     
  • Switch to the new driver allocation interface, as this is one of the
    special call-sites. Here, we need TTY_DRIVER_DYNAMIC_ALLOC to not
    allocate tty_driver->ports, cdevs and potentially other structures
    because we reserve too many lines in pty. Instead, it provides the
    tty_porttty_struct link in tty->ops->install already.

    Signed-off-by: Jiri Slaby
    Acked-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     

11 Aug, 2012

1 commit

  • We need to allow drivers that use neither tty_port_install nor
    tty_port_register_device to link a tty_port to a tty somehow. To
    avoid a race with open, this has to be performed before
    tty_register_device. But currently tty_driver->ports is allocated even
    in tty_register_device because we do not know whether this is the PTY
    driver. The PTY driver is special here due to an excessive count of
    lines it declares to handle. We cannot handle tty_ports there this
    way.

    To circumvent this, we start passing tty_driver flags to
    alloc_tty_driver already and we create tty_alloc_driver for this
    purpose. There we can allocate tty_driver->ports and do all the magic
    between tty_alloc_driver and tty_register_device. Later we will
    introduce tty_port_link_device function for that purpose.

    All drivers should eventually switch to this new tty driver allocation
    interface.

    Signed-off-by: Jiri Slaby
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     

18 Jul, 2012

1 commit

  • Now that we don't have tty->termios tied to drivers->tty we can untangle
    the logic here. In addition we can push the removal logic out of the
    destructor path.

    At that point we can think about sorting out tty_port and console and all
    the other ugly hangovers.

    Signed-off-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Alan Cox
     

14 Jun, 2012

1 commit

  • It will hold tty_port structures for all drivers which do not want to
    define tty->ops->install hook.

    We ignore PTY here because it wants 1 million lines and it installs
    tty_port in ->install anyway.

    Signed-off-by: Jiri Slaby
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     

09 Mar, 2012

3 commits

  • Note that tty->ops->shutdown is called from whatever context the user
    drops the last tty reference from. E.g. if one takes a reference in
    an ISR, tty close happens on other CPU and the final tty put is from
    the ISR, tty->ops->shutdown will be called from that hard irq context.

    We would have a problem in vt if we start using tty refcounting from
    other contexts than user there. It is because vt's shutdown uses
    mutexes. This is yet to be fixed.

    Signed-off-by: Jiri Slaby
    Reported-by: Al Viro
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     
  • It was added back in 2004 and never used for anything real. Remove the
    only assignment in the tree as well.

    Signed-off-by: Jiri Slaby
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     
  • Like the rest of the kernel, make a stub from alloc_tty_driver which
    calls __alloc_tty_driver with proper owner. This will save us one more
    assignment on the driver side.

    Also this fixes some drivers which didn't set the owner. This allowed
    user to remove the module from the system even though a tty from the
    driver is still open.

    Signed-off-by: Jiri Slaby
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     

18 Jan, 2012

1 commit


24 Aug, 2011

1 commit

  • tty_operations->remove is normally called like:
    queue_release_one_tty
    ->tty_shutdown
    ->tty_driver_remove_tty
    ->tty_operations->remove

    However tty_shutdown() is called from queue_release_one_tty() only if
    tty_operations->shutdown is NULL. But for pty, it is not.
    pty_unix98_shutdown() is used there as ->shutdown.

    So tty_operations->remove of pty (i.e. pty_unix98_remove()) is never
    called. This results in invalid pty_count. I.e. what can be seen in
    /proc/sys/kernel/pty/nr.

    I see this was already reported at:
    https://lkml.org/lkml/2009/11/5/370
    But it was not fixed since then.

    This patch is kind of a hackish way. The problem lies in ->install. We
    allocate there another tty (so-called tty->link). So ->install is
    called once, but ->remove twice, for both tty and tty->link. The fix
    here is to count both tty and tty->link and divide the count by 2 for
    user.

    And to have ->remove called, let's make tty_driver_remove_tty() global
    and call that from pty_unix98_shutdown() (tty_operations->shutdown).

    While at it, let's document that when ->shutdown is defined,
    tty_shutdown() is not called.

    Signed-off-by: Jiri Slaby
    Cc: Alan Cox
    Cc: "H. Peter Anvin"
    Cc: stable
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     

18 Feb, 2011

3 commits


17 Dec, 2010

1 commit


17 Nov, 2010

1 commit

  • We reference termios and termiox in tty_driver.h, but we do not include
    linux/termios.h where these are defined. Add the #include properly.

    Otherwise when we include tty_driver.h, we get compile errors.

    Signed-off-by: Jiri Slaby
    Cc: Alan Cox
    Cc: Greg KH
    Signed-off-by: Greg Kroah-Hartman

    Jiri Slaby
     

23 Oct, 2010

1 commit

  • Dan Rosenberg noted that various drivers return the struct with uncleared
    fields. Instead of spending forever trying to stomp all the drivers that
    get it wrong (and every new driver) do the job in one place.

    This first patch adds the needed operations and hooks them up, including
    the needed USB midlayer and serial core plumbing.

    Signed-off-by: Alan Cox
    Signed-off-by: Greg Kroah-Hartman

    Alan Cox
     

28 Sep, 2009

1 commit

  • The following commit made console open fails while booting:

    commit b50989dc444599c8b21edc23536fc305f4e9b7d5
    Author: Alan Cox
    Date: Sat Sep 19 13:13:22 2009 -0700

    tty: make the kref destructor occur asynchronously

    Due to tty release routines run in a workqueue now, error like the
    following will be reported while booting:

    INIT open /dev/console Input/output error

    It also causes hibernation regression to appear as reported at
    http://bugzilla.kernel.org/show_bug.cgi?id=14229

    The reason is that now there's latency issue with closing, but when
    we open a "closing not finished" tty, -EIO will be returned.

    Fix it as per the following Alan's suggestion:

    Fun but it's actually not a bug and the fix is wrong in itself as
    the port may be closing but not yet being destructed, in which case
    it seems to do the wrong thing. Opening a tty that is closing (and
    could be closing for long periods) is supposed to return -EIO.

    I suspect a better way to deal with this and keep the old console
    timing is to split tty->shutdown into two functions.

    tty->shutdown() - called synchronously just before we dump the tty
    onto the waitqueue for destruction

    tty->cleanup() - called when the destructor runs.

    We would then do the shutdown part which can occur in IRQ context
    fine, before queueing the rest of the release (from tty->magic = 0
    ... the end) to occur asynchronously

    The USB update in -next would then need a call like

    if (tty->cleanup)
    tty->cleanup(tty);

    at the top of the async function and the USB shutdown to be split
    between shutdown and cleanup as the USB resource cleanup and final
    tidy cannot occur synchronously as it needs to sleep.

    In other words the logic becomes

    final kref put
    make object unfindable

    async
    clean it up

    Signed-off-by: Dave Young
    [ rjw: Rebased on top of 2.6.31-git, reworked the changelog. ]
    Signed-off-by: "Rafael J. Wysocki"
    [ Changed serial naming to match new rules, dropped tty_shutdown as per
    comments from Alan Stern - Linus ]
    Signed-off-by: Linus Torvalds

    Dave Young
     

11 Jun, 2009

1 commit

  • The tty throttling code can race due to the lock drops. It takes very high
    loads but this has been observed and verified by Rob Duncan.

    The basic problem is that on an SMP box we can go

    CPU #1 CPU #2
    need to throttle ?
    suppose we should buffer space cleared
    are we throttled
    yes ? - unthrottle
    call throttle method

    This changeet take the termios lock to protect against this. The termios
    lock isn't the initial obvious candidate but many implementations of throttle
    methods already need to poke around their own termios structures (and nobody
    really locks them against a racing change of flow control).

    This does mean that anyone who is setting tty->low_latency = 1 and then
    calling tty_flip_buffer_push from their unthrottle method is going to end up
    collapsing in a pile of locks. However we've removed all the known bogus
    users of low_latency = 1 and such use isn't safe anyway for other reasons so
    catching it would be an improvement.

    Signed-off-by: Alan Cox
    Signed-off-by: Linus Torvalds

    Alan Cox
     

07 Apr, 2009

1 commit


01 Apr, 2009

2 commits

  • struct tty_operations::proc_fops took it's place and there is one less
    create_proc_read_entry() user now!

    Signed-off-by: Alexey Dobriyan
    Cc: Alan Cox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     
  • Used for gradual switch of TTY drivers from using ->read_proc which helps
    with gradual switch from ->read_proc for the whole tree.

    As side effect, fix possible race condition when ->data initialized after
    PDE is hooked into proc tree.

    ->proc_fops takes precedence over ->read_proc.

    Signed-off-by: Alexey Dobriyan
    Cc: Alan Cox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alexey Dobriyan
     

03 Jan, 2009

1 commit

  • We have special case logic for resizing pty/tty pairs. We also have a per
    driver resize method so for the pty case we should use it.

    Signed-off-by: Alan Cox
    Signed-off-by: Linus Torvalds

    Alan Cox
     

14 Oct, 2008

6 commits

  • Pass-in 'inode' or 'tty' parameter to devpts interfaces. With multiple
    devpts instances, these parameters will be used in subsequent patches
    to identify the instance of devpts mounted. The parameters also help
    simplify devpts implementation.

    Changelog[v3]:
    - minor changes due to merge with ttydev updates
    - rename parameters to emphasize they are ptmx or pts inodes
    - pass-in tty_struct * to devpts_pty_kill() (this will help
    cleanup the get_node() call in a subsequent patch)

    Signed-off-by: Sukadev Bhattiprolu
    Signed-off-by: Alan Cox
    Signed-off-by: Linus Torvalds

    Sukadev Bhattiprolu
     
  • We have the lookup operation abstracted which is nice for pty cleanup but
    we really want to abstract the add/remove entries as well so that we can
    pull the pty code out of the tty core and create a clear defined interface
    for the tty driver table.

    Signed-off-by: Alan Cox
    Signed-off-by: Linus Torvalds

    Alan Cox
     
  • Signed-off-by: Alan Cox
    Signed-off-by: Linus Torvalds

    Alan Cox
     
  • Fix up the naming, style and extract some bits of code into the driver
    specific code

    Signed-off-by: Alan Cox
    Signed-off-by: Linus Torvalds

    Alan Cox
     
  • Right now there are various drivers that try to use tty->count to know when
    they get the final close. Aristeau Rozanski showed while debugging the vt
    sysfs race that this isn't entirely safe.

    Instead of driver side tricks to work around this introduce a shutdown which
    is called when the tty is being destructed. This also means that the shutdown
    method is tied into the refcounting.

    Use this to rework the console close/sysfs logic.

    Remove lots of special case code from the tty core code. The pty code can now
    have a shutdown() method that replaces the special case hackery in the tree
    free up paths.

    Signed-off-by: Alan Cox
    Signed-off-by: Linus Torvalds

    Alan Cox
     
  • We need a way to describe the various additional modes and flow control
    features that random weird hardware shows up and software such as wine
    wants to emulate as Windows supports them.

    TCGETX/TCSETX and the termiox ioctl are a SYS5 extension that we might as
    well adopt. This patches adds the structures and the basic ioctl interfaces
    when the TCGETX etc defines are added for an architecture. Drivers wishing
    to use this stuff need to add new methods.

    Signed-off-by: Alan Cox
    Signed-off-by: Linus Torvalds

    Alan Cox
     

16 Aug, 2008

1 commit

  • This moves it to being a tty operation. That removes special cases and now
    also means that resize can be picked up by um and other non vt consoles
    which may have a resize operation.

    Signed-off-by: Alan Cox
    Signed-off-by: Linus Torvalds

    Alan Cox
     

23 Jul, 2008

1 commit

  • Some hardware needs to do break handling itself and may have partial
    support only. Make break_ctl return an error code. Add a tty driver flag
    so you can indicate driver hardware side break support.

    Signed-off-by: Alan Cox
    Signed-off-by: Linus Torvalds

    Alan Cox
     

24 Jun, 2008

1 commit


30 Apr, 2008

2 commits

  • Something Arjan suggested which allows us to clean up the code nicely

    Signed-off-by: Alan Cox
    Cc: Arjan van de Ven
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alan Cox
     
  • - Operations are now a shared const function block as with most other Linux
    objects

    - Introduce wrappers for some optional functions to get consistent behaviour

    - Wrap put_char which used to be patched by the tty layer

    - Document which functions are needed/optional

    - Make put_char report success/fail

    - Cache the driver->ops pointer in the tty as tty->ops

    - Remove various surplus lock calls we no longer need

    - Remove proc_write method as noted by Alexey Dobriyan

    - Introduce some missing sanity checks where certain driver/ldisc
    combinations would oops as they didn't check needed methods were present

    [akpm@linux-foundation.org: fix fs/compat_ioctl.c build]
    [akpm@linux-foundation.org: fix isicom]
    [akpm@linux-foundation.org: fix arch/ia64/hp/sim/simserial.c build]
    [akpm@linux-foundation.org: fix kgdb]
    Signed-off-by: Alan Cox
    Acked-by: Greg Kroah-Hartman
    Cc: Jason Wessel
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Alan Cox
     

18 Apr, 2008

1 commit

  • polled console handling support, to access a console in an irq-less
    way while in debug or irq context.

    absolutely zero impact as long as CONFIG_CONSOLE_POLL is disabled.
    (which is the default)

    [ jan.kiszka@siemens.com: lots of cleanups ]
    [ mingo@elte.hu: redesign, splitups, cleanups. ]

    Signed-off-by: Jason Wessel
    Signed-off-by: Ingo Molnar
    Signed-off-by: Jan Kiszka
    Reviewed-by: Thomas Gleixner

    Jason Wessel
     

11 May, 2007

1 commit

  • Add compat_ioctl method for tty code to allow processing of 32 bit ioctl
    calls on 64 bit systems by tty core, tty drivers, and line disciplines.

    Based on patch by Arnd Bergmann:
    http://www.uwsg.iu.edu/hypermail/linux/kernel/0511.0/1732.html

    [akpm@linux-foundation.org: make things static]
    Signed-off-by: Paul Fulghum
    Acked-by: Arnd Bergmann
    Cc: Alan Cox
    Signed-off-by: Andrew Morton
    Signed-off-by: Linus Torvalds

    Paul Fulghum