1. 08 11月, 2017 1 次提交
    • G
      tty: add SPDX identifiers to all remaining files in drivers/tty/ · e3b3d0f5
      Greg Kroah-Hartman 提交于
      It's good to have SPDX identifiers in all files to make it easier to
      audit the kernel tree for correct licenses.
      
      Update the drivers/tty files files with the correct SPDX license
      identifier based on the license text in the file itself.  The SPDX
      identifier is a legally binding shorthand, which can be used instead of
      the full boiler plate text.
      
      This work is based on a script and data from Thomas Gleixner, Philippe
      Ombredanne, and Kate Stewart.
      
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
      Cc: Paul Mackerras <paulus@samba.org>
      Cc: Michael Ellerman <mpe@ellerman.id.au>
      Cc: Chris Metcalf <cmetcalf@mellanox.com>
      Cc: Jiri Kosina <jikos@kernel.org>
      Cc: David Sterba <dsterba@suse.com>
      Cc: James Hogan <jhogan@kernel.org>
      Cc: Rob Herring <robh@kernel.org>
      Cc: Eric Anholt <eric@anholt.net>
      Cc: Stefan Wahren <stefan.wahren@i2se.com>
      Cc: Florian Fainelli <f.fainelli@gmail.com>
      Cc: Ray Jui <rjui@broadcom.com>
      Cc: Scott Branden <sbranden@broadcom.com>
      Cc: bcm-kernel-feedback-list@broadcom.com
      Cc: "James E.J. Bottomley" <jejb@parisc-linux.org>
      Cc: Helge Deller <deller@gmx.de>
      Cc: Joachim Eastwood <manabian@gmail.com>
      Cc: Matthias Brugger <matthias.bgg@gmail.com>
      Cc: Masahiro Yamada <yamada.masahiro@socionext.com>
      Cc: Tobias Klauser <tklauser@distanz.ch>
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Vineet Gupta <vgupta@synopsys.com>
      Cc: Richard Genoud <richard.genoud@gmail.com>
      Cc: Alexander Shiyan <shc_work@mail.ru>
      Cc: Baruch Siach <baruch@tkos.co.il>
      Cc: "Maciej W. Rozycki" <macro@linux-mips.org>
      Cc: "Uwe Kleine-König" <kernel@pengutronix.de>
      Cc: Pat Gefre <pfg@sgi.com>
      Cc: "Guilherme G. Piccoli" <gpiccoli@linux.vnet.ibm.com>
      Cc: Jason Wessel <jason.wessel@windriver.com>
      Cc: Vladimir Zapolskiy <vz@mleia.com>
      Cc: Sylvain Lemieux <slemieux.tyco@gmail.com>
      Cc: Carlo Caione <carlo@caione.org>
      Cc: Kevin Hilman <khilman@baylibre.com>
      Cc: Liviu Dudau <liviu.dudau@arm.com>
      Cc: Sudeep Holla <sudeep.holla@arm.com>
      Cc: Lorenzo Pieralisi <lorenzo.pieralisi@arm.com>
      Cc: Andy Gross <andy.gross@linaro.org>
      Cc: David Brown <david.brown@linaro.org>
      Cc: "Andreas Färber" <afaerber@suse.de>
      Cc: Kevin Cernekee <cernekee@gmail.com>
      Cc: Laxman Dewangan <ldewangan@nvidia.com>
      Cc: Thierry Reding <thierry.reding@gmail.com>
      Cc: Jonathan Hunter <jonathanh@nvidia.com>
      Cc: Barry Song <baohua@kernel.org>
      Cc: Patrice Chotard <patrice.chotard@st.com>
      Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
      Cc: Alexandre Torgue <alexandre.torgue@st.com>
      Cc: "David S. Miller" <davem@davemloft.net>
      Cc: Peter Korsgaard <jacmet@sunsite.dk>
      Cc: Timur Tabi <timur@tabi.org>
      Cc: Tony Prisk <linux@prisktech.co.nz>
      Cc: Michal Simek <michal.simek@xilinx.com>
      Cc: "Sören Brinkmann" <soren.brinkmann@xilinx.com>
      Cc: Thomas Gleixner <tglx@linutronix.de>
      Cc: Kate Stewart <kstewart@linuxfoundation.org>
      Cc: Philippe Ombredanne <pombredanne@nexb.com>
      Cc: Jiri Slaby <jslaby@suse.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      e3b3d0f5
  2. 29 8月, 2017 1 次提交
    • M
      pty: show associative slave of ptmx in fdinfo · d01c3289
      Masatake YAMATO 提交于
      This patch adds "tty-index" field to /proc/PID/fdinfo/N if N
      specifies /dev/ptmx. The field shows the index of associative
      slave pts.
      
      Though a minor number is given for each pts instance, ptmx is not.
      It means there is no way in user-space to know the association between
      file descriptors for pts/n and ptmx. (n = 0, 1, ...)
      
      This is different from pipe. About pipe such association can be solved
      by inode of pipefs.
      
      Providing the way to know the association between pts/n and ptmx helps
      users understand the status of running system. lsof can utilize this field.
      Signed-off-by: NMasatake YAMATO <yamato@redhat.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d01c3289
  3. 28 8月, 2017 2 次提交
    • O
      tty: undo export of tty_open_by_driver · a033c3b1
      Okash Khawaja 提交于
      Since we have tty_kopen, we no longer need to export tty_open_by_driver.
      This patch makes this function static.
      Signed-off-by: NOkash Khawaja <okash.khawaja@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a033c3b1
    • O
      tty: resolve tty contention between kernel and user space · a09ac397
      Okash Khawaja 提交于
      The commit 12e84c71 ("tty: export tty_open_by_driver") exports
      tty_open_by_device to allow tty to be opened from inside kernel which
      works fine except that it doesn't handle contention with user space or
      another kernel-space open of the same tty. For example, opening a tty
      from user space while it is kernel opened results in failure and a
      kernel log message about mismatch between tty->count and tty's file
      open count.
      
      This patch makes kernel access to tty exclusive, so that if a user
      process or kernel opens a kernel opened tty, it gets -EBUSY. It does
      this by adding TTY_KOPENED flag to tty->flags. When this flag is set,
      tty_open_by_driver returns -EBUSY. Instead of overloading
      tty_open_by_driver for both kernel and user space, this
      patch creates a separate function tty_kopen which closely follows
      tty_open_by_driver. tty_kclose closes the tty opened by tty_kopen.
      
      To address the mismatch between tty->count and #fd's, this patch adds
      #kopen's to the count before comparing it with tty->count. That way
      check_tty_count reflects correct usage count.
      
      Returning -EBUSY on tty open is a change in the interface. I have
      tested this with minicom, picocom and commands like "echo foo >
      /dev/ttyS0". They all correctly report "Device or resource busy" when
      the tty is already kernel opened.
      Signed-off-by: NOkash Khawaja <okash.khawaja@gmail.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a09ac397
  4. 25 8月, 2017 1 次提交
    • E
      pty: Repair TIOCGPTPEER · 311fc65c
      Eric W. Biederman 提交于
      The implementation of TIOCGPTPEER has two issues.
      
      When /dev/ptmx (as opposed to /dev/pts/ptmx) is opened the wrong
      vfsmount is passed to dentry_open.  Which results in the kernel displaying
      the wrong pathname for the peer.
      
      The second is simply by caching the vfsmount and dentry of the peer it leaves
      them open, in a way they were not previously Which because of the inreased
      reference counts can cause unnecessary behaviour differences resulting in
      regressions.
      
      To fix these move the ioctl into tty_io.c at a generic level allowing
      the ioctl to have access to the struct file on which the ioctl is
      being called.  This allows the path of the slave to be derived when
      opening the slave through TIOCGPTPEER instead of requiring the path to
      the slave be cached.  Thus removing the need for caching the path.
      
      A new function devpts_ptmx_path is factored out of devpts_acquire and
      used to implement a function devpts_mntget.   The new function devpts_mntget
      takes a filp to perform the lookup on and fsi so that it can confirm
      that the superblock that is found by devpts_ptmx_path is the proper superblock.
      
      v2: Lots of fixes to make the code actually work
      v3: Suggestions by Linus
          - Removed the unnecessary initialization of filp in ptm_open_peer
          - Simplified devpts_ptmx_path as gotos are no longer required
      
      [ This is the fix for the issue that was reverted in commit
        143c97cc, but this time without breaking 'pbuilder' due to
        increased reference counts   - Linus ]
      
      Fixes: 54ebbfb1 ("tty: add TIOCGPTPEER ioctl")
      Reported-by: NChristian Brauner <christian.brauner@canonical.com>
      Reported-and-tested-by: NStefan Lippers-Hollmann <s.l-h@gmx.de>
      Signed-off-by: N"Eric W. Biederman" <ebiederm@xmission.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      311fc65c
  5. 27 6月, 2017 1 次提交
  6. 16 5月, 2017 1 次提交
    • O
      tty: export tty_open_by_driver · 12e84c71
      Okash Khawaja 提交于
      This exports tty_open_by_driver so that it can be called from other
      places inside the kernel. The checks for null file pointer are based on
      Alan Cox's patch here:
      http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg1215095.html.
      Description below is quoted from it:
      
      "[RFC] tty_port: allow a port to be opened with a tty that has no file handle
      
          Let us create tty objects entirely in kernel space. Untested proposal to
          show why all the ideas around rewriting half the uart stack are not needed.
      
          With this a kernel created non file backed tty object could be used to handle
          data, and set terminal modes. Not all ldiscs can cope with this as N_TTY in
          particular has to work back to the fs/tty layer.
      
          The tty_port code is however otherwise clean of file handles as far as I can
          tell as is the low level tty port write path used by the ldisc, the
          configuration low level interfaces and most of the ldiscs.
      
          Currently you don't have any exposure to see tty hangups because those are
          built around the file layer. However a) it's a fixed port so you probably
          don't care about that b) if you do we can add a callback and c) you almost
          certainly don't want the userspace tear down/rebuild behaviour anyway.
      
          This should however be sufficient if we wanted for example to enumerate all
          the bluetooth bound fixed ports via ACPI and make them directly available.
      
          It doesn't deal with the case of a user opening a port that's also kernel
          opened and that would need some locking out (so it returned EBUSY if bound
          to a kernel device of some kind). That needs resolving along with how you
          "up" or "down" your new bluetooth device, or enumerate it while providing
          the existing tty API to avoid regressions (and to debug)."
      
      The exported funtion is used later in this patch set to gain access to tty_struct.
      
      [changed export symbol level - gkh]
      Signed-off-by: NOkash Khawaja <okash.khawaja@gmail.com>
      Reviewed-by: NSamuel Thibault <samuel.thibault@ens-lyon.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      12e84c71
  7. 24 4月, 2017 1 次提交
  8. 19 4月, 2017 2 次提交
  9. 09 4月, 2017 1 次提交
  10. 31 3月, 2017 3 次提交
    • J
      tty: reset termios state on device registration · 93857edd
      Johan Hovold 提交于
      Free any saved termios data when registering a tty device so that the
      termios state is reset when reusing a minor number.
      
      This is useful for hot-pluggable buses such as USB where it does not
      make much sense to reuse saved termios data from an unrelated device
      when a new device is later plugged in.
      
      This specifically avoids a situation where the new device does not have
      the carrier-detect signal wired, but the saved termios state has CLOCAL
      cleared, effectively preventing the port from being opened in blocking
      mode as noted by Jan Kundrát <jan.kundrat@cesnet.cz>.
      
      Note that clearing the saved data at deregistration would not work as
      the device could still be open.
      
      Also note that the termios data is not reset for drivers with
      TTY_DRIVER_DYNAMIC_ALLOC set (e.g. legacy pty) as their character device
      is registered at driver registration and could theoretically already
      have been opened (and pty termios state is never saved anyway).
      Reported-by: NJan Kundrát <jan.kundrat@cesnet.cz>
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      93857edd
    • J
      tty: drop obsolete termios_locked comments · 16b00ae8
      Johan Hovold 提交于
      Drop comments about tty-driver termios_locked structures, which have
      been outdated since commit fe6e29fd ("tty: simplify ktermios
      allocation").
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      16b00ae8
    • J
      tty: close race between device register and open · 6a7e6f78
      Johan Hovold 提交于
      The tty class device is currently not registered until after the
      character device has been registered thereby leaving a small window
      were a racing open could end up with a NULL tty->dev pointer due to the
      class-device lookup failing in alloc_tty_struct.
      
      Close this race by registering the class device before the character
      device while making sure to defer the user-space uevent notification
      until after the character device has been registered.
      
      Note that some tty drivers expect a valid tty->dev and would misbehave
      or crash otherwise. Some line disciplines also currently dereference the
      class device unconditionally despite the fact that not every tty is
      guaranteed to have one (Unix98 pty), but this is being fixed separately.
      Signed-off-by: NJohan Hovold <johan@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      6a7e6f78
  11. 17 3月, 2017 1 次提交
  12. 02 3月, 2017 2 次提交
  13. 20 1月, 2017 1 次提交
    • A
      tty_port: allow a port to be opened with a tty that has no file handle · ed3f0af8
      Alan Cox 提交于
      Let us create tty objects entirely in kernel space. Untested proposal to
      show why all the ideas around rewriting half the uart stack are not needed.
      
      With this a kernel created non file backed tty object could be used to handle
      data, and set terminal modes. Not all ldiscs can cope with this as N_TTY in
      particular has to work back to the fs/tty layer.
      
      The tty_port code is however otherwise clean of file handles as far as I can
      tell as is the low level tty port write path used by the ldisc, the
      configuration low level interfaces and most of the ldiscs.
      
      Currently you don't have any exposure to see tty hangups because those are
      built around the file layer. However a) it's a fixed port so you probably
      don't care about that b) if you do we can add a callback and c) you almost
      certainly don't want the userspace tear down/rebuild behaviour anyway.
      
      This should however be sufficient if we wanted for example to enumerate all
      the bluetooth bound fixed ports via ACPI and make them directly available.
      It doesn't deal with the case of a user opening a port that's also kernel
      opened and that would need some locking out (so it returned EBUSY if bound
      to a kernel device of some kind). That needs resolving along with how you
      "up" or "down" your new bluetooth device, or enumerate it while providing
      the existing tty API to avoid regressions (and to debug).
      Signed-off-by: NAlan Cox <alan@linux.intel.com>
      Reviewed-by: NAndy Shevchenko <andriy.shevchenko@linux.intel.com>
      Reviewed-By: NSebastian Reichel <sre@kernel.org>
      Signed-off-by: NRob Herring <robh@kernel.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      ed3f0af8
  14. 19 1月, 2017 1 次提交
  15. 01 5月, 2016 3 次提交
  16. 27 4月, 2016 1 次提交
    • L
      devpts: more pty driver interface cleanups · 8ead9dd5
      Linus Torvalds 提交于
      This is more prep-work for the upcoming pty changes.  Still just code
      cleanup with no actual semantic changes.
      
      This removes a bunch pointless complexity by just having the slave pty
      side remember the dentry associated with the devpts slave rather than
      the inode.  That allows us to remove all the "look up the dentry" code
      for when we want to remove it again.
      
      Together with moving the tty pointer from "inode->i_private" to
      "dentry->d_fsdata" and getting rid of pointless inode locking, this
      removes about 30 lines of code.  Not only is the end result smaller,
      it's simpler and easier to understand.
      
      The old code, for example, depended on the d_find_alias() to not just
      find the dentry, but also to check that it is still hashed, which in
      turn validated the tty pointer in the inode.
      
      That is a _very_ roundabout way to say "invalidate the cached tty
      pointer when the dentry is removed".
      
      The new code just does
      
      	dentry->d_fsdata = NULL;
      
      in devpts_pty_kill() instead, invalidating the tty pointer rather more
      directly and obviously.  Don't do something complex and subtle when the
      obvious straightforward approach will do.
      
      The rest of the patch (ie apart from code deletion and the above tty
      pointer clearing) is just switching the calling convention to pass the
      dentry or file pointer around instead of the inode.
      
      Cc: Eric Biederman <ebiederm@xmission.com>
      Cc: Peter Anvin <hpa@zytor.com>
      Cc: Andy Lutomirski <luto@amacapital.net>
      Cc: Al Viro <viro@zeniv.linux.org.uk>
      Cc: Peter Hurley <peter@hurleysoftware.com>
      Cc: Serge Hallyn <serge.hallyn@ubuntu.com>
      Cc: Willy Tarreau <w@1wt.eu>
      Cc: Aurelien Jarno <aurelien@aurel32.net>
      Cc: Alan Cox <gnomes@lxorguk.ukuu.org.uk>
      Cc: Jann Horn <jann@thejh.net>
      Cc: Greg KH <greg@kroah.com>
      Cc: Jiri Slaby <jslaby@suse.com>
      Cc: Florian Weimer <fw@deneb.enyo.de>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      8ead9dd5
  17. 01 4月, 2016 2 次提交
  18. 07 2月, 2016 1 次提交
  19. 29 1月, 2016 3 次提交
    • P
      tty: Fix ioctl(FIOASYNC) on hungup file · a8f3a297
      Peter Hurley 提交于
      A small race window exists which allows signal-driven async i/o to be
      enabled for the tty when the file ptr has already been hungup and
      signal-driven i/o has been disabled:
      
      CPU 0                                CPU 1
      -----                                ------
      ioctl_fioasync(on)
        filp->f_op->fasync(on)             __tty_hangup()
          tty_fasync(on)                     tty_lock()
            tty_lock()                       ...
              .                              filp->f_op = &hung_up_tty_fops;
            (waiting)                       __tty_fasync(off)
              .                              tty_unlock()
            /* gets tty lock  */
            /* enables FASYNC */
      
      Check the tty has not been hungup while holding tty_lock.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      a8f3a297
    • P
      tty: Add fasync() hung up file operation · f557474c
      Peter Hurley 提交于
      VFS uses a two-stage check-and-call method for invoking file_operations
      methods, without explicitly snapshotting either the file_operations ptr
      or the function ptr. Since the tty core is one of the few VFS users that
      changes the f_op file_operations ptr of the file descriptor (when the
      tty has been hung up), and since the likelihood of the compiler generating
      a reload of either f_op or the function ptr is basically nil, just define
      a hung up fasync() file operation that returns an error.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      f557474c
    • P
      tty, n_tty: Remove fasync() ldisc notification · bee6741c
      Peter Hurley 提交于
      Only the N_TTY line discipline implements the signal-driven i/o
      notification enabled/disabled by fcntl(F_SETFL, O_ASYNC). The ldisc
      fasync() notification is sent to the ldisc when the enable state has
      changed (the tty core is notified via the fasync() VFS file operation).
      
      The N_TTY line discipline used the enable state to change the wakeup
      condition (minimum_to_wake = 1) for notifying the signal handler i/o is
      available. However, just the presence of data is sufficient and necessary
      to signal i/o is available, so changing minimum_to_wake is unnecessary
      (and creates a race condition with read() and poll() which may be
      concurrently updating minimum_to_wake).
      
      Furthermore, since the kill_fasync() VFS helper performs no action if
      the fasync list is empty, calling unconditionally is preferred; if
      signal driven i/o just has been disabled, no signal will be sent by
      kill_fasync() anyway so notification of the change via the ldisc
      fasync() method is superfluous.
      Signed-off-by: NPeter Hurley <peter@hurleysoftware.com>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bee6741c
  20. 28 1月, 2016 11 次提交