1. 22 1月, 2018 6 次提交
  2. 10 1月, 2018 1 次提交
  3. 09 1月, 2018 11 次提交
  4. 21 12月, 2017 1 次提交
    • L
      n_tty: fix EXTPROC vs ICANON interaction with TIOCINQ (aka FIONREAD) · 966031f3
      Linus Torvalds 提交于
      We added support for EXTPROC back in 2010 in commit 26df6d13 ("tty:
      Add EXTPROC support for LINEMODE") and the intent was to allow it to
      override some (all?) ICANON behavior.  Quoting from that original commit
      message:
      
               There is a new bit in the termios local flag word, EXTPROC.
               When this bit is set, several aspects of the terminal driver
               are disabled.  Input line editing, character echo, and mapping
               of signals are all disabled.  This allows the telnetd to turn
               off these functions when in linemode, but still keep track of
               what state the user wants the terminal to be in.
      
      but the problem turns out that "several aspects of the terminal driver
      are disabled" is a bit ambiguous, and you can really confuse the n_tty
      layer by setting EXTPROC and then causing some of the ICANON invariants
      to no longer be maintained.
      
      This fixes at least one such case (TIOCINQ) becoming unhappy because of
      the confusion over whether ICANON really means ICANON when EXTPROC is set.
      
      This basically makes TIOCINQ match the case of read: if EXTPROC is set,
      we ignore ICANON.  Also, make sure to reset the ICANON state ie EXTPROC
      changes, not just if ICANON changes.
      
      Fixes: 26df6d13 ("tty: Add EXTPROC support for LINEMODE")
      Reported-by: NTetsuo Handa <penguin-kernel@i-love.sakura.ne.jp>
      Reported-by: Nsyzkaller <syzkaller@googlegroups.com>
      Cc: Jiri Slaby <jslaby@suse.com>
      Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      966031f3
  5. 19 12月, 2017 6 次提交
    • S
      pty: cancel pty slave port buf's work in tty_release · 2b022ab7
      Sahara 提交于
      In case that CONFIG_SLUB_DEBUG is on and pty is used, races between
      release_one_tty and flush_to_ldisc work threads may happen and lead
      to use-after-free condition on tty->link->port. Because SLUB_DEBUG
      is turned on, freed tty->link->port is filled with POISON_FREE value.
      So far without SLUB_DEBUG, port was filled with zero and flush_to_ldisc
      could return without a problem by checking if tty is NULL.
      
      CPU 0                                 CPU 1
      -----                                 -----
      release_tty                           pty_write
         cancel_work_sync(tty)                 to = tty->link
         tty_kref_put(tty->link)               tty_schedule_flip(to->port)
            << workqueue >>                 ...
            release_one_tty                 ...
               pty_cleanup                  ...
                  kfree(tty->link->port)       << workqueue >>
                                               flush_to_ldisc
                                                  tty = READ_ONCE(port->itty)
                                                  tty is 0x6b6b6b6b6b6b6b6b
                                                  !!PANIC!! access tty->ldisc
      
       Unable to handle kernel paging request at virtual address 6b6b6b6b6b6b6b93
       pgd = ffffffc0eb1c3000
       [6b6b6b6b6b6b6b93] *pgd=0000000000000000, *pud=0000000000000000
       ------------[ cut here ]------------
       Kernel BUG at ffffff800851154c [verbose debug info unavailable]
       Internal error: Oops - BUG: 96000004 [#1] PREEMPT SMP
       CPU: 3 PID: 265 Comm: kworker/u8:9 Tainted: G        W 3.18.31-g0a58eeb #1
       Hardware name: Qualcomm Technologies, Inc. MSM 8996pro v1.1 + PMI8996 Carbide (DT)
       Workqueue: events_unbound flush_to_ldisc
       task: ffffffc0ed610ec0 ti: ffffffc0ed624000 task.ti: ffffffc0ed624000
       PC is at ldsem_down_read_trylock+0x0/0x4c
       LR is at tty_ldisc_ref+0x24/0x4c
       pc : [<ffffff800851154c>] lr : [<ffffff800850f6c0>] pstate: 80400145
       sp : ffffffc0ed627cd0
       x29: ffffffc0ed627cd0 x28: 0000000000000000
       x27: ffffff8009e05000 x26: ffffffc0d382cfa0
       x25: 0000000000000000 x24: ffffff800a012f08
       x23: 0000000000000000 x22: ffffffc0703fbc88
       x21: 6b6b6b6b6b6b6b6b x20: 6b6b6b6b6b6b6b93
       x19: 0000000000000000 x18: 0000000000000001
       x17: 00e80000f80d6f53 x16: 0000000000000001
       x15: 0000007f7d826fff x14: 00000000000000a0
       x13: 0000000000000000 x12: 0000000000000109
       x11: 0000000000000000 x10: 0000000000000000
       x9 : ffffffc0ed624000 x8 : ffffffc0ed611580
       x7 : 0000000000000000 x6 : ffffff800a42e000
       x5 : 00000000000003fc x4 : 0000000003bd1201
       x3 : 0000000000000001 x2 : 0000000000000001
       x1 : ffffff800851004c x0 : 6b6b6b6b6b6b6b93
      Signed-off-by: NSahara <keun-o.park@darkmatter.ae>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2b022ab7
    • J
      serial: max310x: Reduce RX work starvation · 22587612
      Jan Kundrát 提交于
      Prior to this patch, the code would happily trigger TX on some ports
      before having a chance of reading the RX buffer from the rest of them.
      When no flow control was used, this led to RX buffer overruns and
      therefore lost data under certain circumstances.
      
      I was able to reproduce this with MAX14830 (that's a quad channel one)
      and a simple daisy-chain of RX and TX ports on the eval board:
      
      - TX0 -> RX1
      - TX1 -> RX2
      - TX2 -> RX3
      - TX3 -> RX0
      
      I was testing this by transferring 2MB of data at 115200 baud via each
      port. I used a Solidrun Clearfog Base (Armada 388) which was talking to
      the UART over an SPI bus clocked at 26MHz (the chip's maximum). Without
      this patch, I would always get a "Possible RX FIFO overrun" in dmesg,
      and fewer-than-expected amount of bytes received over ttyMAX0. Results
      on ttyMAX{1,2,3} tended to be correct all the time, even without the
      previous patches in this series and with PIO SPI transfers ("indirect
      mode" as the Marvell datasheet calls it), so I assume that heavy
      congestion is needed in order to reproduce this.
      
      A drawback of this patch is that the throughput gets reduced "a bit".
      Previously, a 115200 baud resulted in about 11.2kBps throughput as
      reported by a simple `pv`. With this patch, the throughput of four
      parallel streams is roughly 7kBps each, and 9kBps for three streams.
      There is no slowdown for one or two parallel streams.
      
      Situation is worse if bytes are being read one-by-one (such as if the
      userspace wants to perform parity/framing/break checking) and therefore
      without the batched reads.
      
      With just this patch and no other modifications on top of 4.14, I was
      only getting roughly 3.6kBps with four parallel streams. The
      single-stream performance was the same, and I was seeing about 7.2kBps
      with two parallel streams. `perf top` said that a substantial amount of
      time was spent in `finish_task_switch`, `_raw_spin_unlock_irqrestore`
      and `__timer_delay`.
      Signed-off-by: NJan Kundrát <jan.kundrat@cesnet.cz>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      22587612
    • J
      serial: max310x: Use batched reads when reasonably safe · 2b4bac48
      Jan Kundrát 提交于
      The hardware has a 128 byte RX FIFO buffer for each independent UART.
      Previously, the code was always reading that byte-by-byte via
      independent SPI transactions and the associated overhead. In practice,
      this led to up to eight bytes over SPI for just one byte in the UART's
      RX FIFO:
      
      - reading the global IRQ register (two bytes, one for command, the other
      for data)
      - reading one UART's ISR (again two bytes)
      - reading the byte count (two bytes yet again)
      - finally, reading one byte of the FIFO via another two-byte transaction
      
      We cannot always use a batched read. If the TTY is set to intercept
      break conditions or report framing or parity errors, then it is required
      to check the Line Status Register (LSR) for each byte which is read from
      the RX FIFO. The documentation does not show a way of doing that in a
      single SPI transaction; registers 0x00 and 0x04 are separate.
      
      In my testing, this is no silver bullet. I was feeding 2MB of random
      data over four daisy-chaned UARTs of MAX14830, and this is the
      distribution that I was getting:
      
      - R <= 1: 7437322
      - R <= 2: 162093
      - R <= 4: 4093
      - R <= 8: 4196
      - R <= 16: 645
      - R <= 32: 165
      - R <= 64: 58
      - R <= 128: 0
      
      For a reference, batching the write operations works much better:
      
      - W <= 1: 2664
      - W <= 2: 1305
      - W <= 4: 627
      - W <= 8: 371
      - W <= 16: 121
      - W <= 32: 68
      - W <= 64: 33
      - W <= 128: 63139
      
      That's probably because this HW/SW combination (Clearfog Base, Armada
      388) is probably "good enough" to react to the chip's IRQ "fast enough"
      most of the time. Still, I was getting RX overruns every now and then.
      In future, I plan to improve this by letting the RX FIFO be filled a
      little more (the chip has support for that and also for a "stale
      timeout" to prevent additional starvation).
      Signed-off-by: NJan Kundrát <jan.kundrat@cesnet.cz>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      2b4bac48
    • J
      serial: max310x: use a batch write op for UART transmit · d584b65c
      Jan Kundrát 提交于
      The transmit register supports batched writes. The key is simply to keep
      sending additional bytes up to the FIFO size in the same SPI
      transaction with the CS pin still being held low.
      
      This duplicates the regmap infrastructure to a certain extent. There are
      some provisions for multiple writes in there, but there does not appear
      to be any support for those writes which are destined to the *same*
      register (and also no standard for SPI bus transfers of these, anyway).
      
      This patch does not solve every case (if the UART xmit circular buffer
      wraps around, we're still doing two SPI transactions), but at least
      it's not one-byte-per-transaction anymore.
      
      This change does not touch the receive path at this time. Doing that in
      the generic case appears to be impossible in the general case, because
      the chips' status register contains data about the *current* byte in the
      HW's Rx FIFO. We cannot read these two registers in one go,
      unfortunately.
      Signed-off-by: NJan Kundrát <jan.kundrat@cesnet.cz>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      d584b65c
    • J
      serial: max310x: Support IRQ sharing with other devices · 78be70c8
      Jan Kundrát 提交于
      According to my chip's datasheet [1], the IRQ output is an open
      collector pin which is suitable for sharing with other chips. The chip
      also has a register which indicates which UART performed a change and
      the driver checks that register already, so we have everything what is
      needed to effectively share the IRQ GPIO.
      
      [1] https://datasheets.maximintegrated.com/en/ds/MAX14830.pdfSigned-off-by: NJan Kundrát <jan.kundrat@cesnet.cz>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      78be70c8
    • J
      serial: max310x: Do not hard-code the IRQ type · bceb4839
      Jan Kundrát 提交于
      As suggested by Russell King, a driver should not really care about bits
      such as the interrupt polarity or whether it is edge- or level-
      triggered. The reasons for that include:
      
      - an upstream IRQ controller which cannot support edge- or
      level-triggered interrupts,
      - board design with a built-in inverter
      
      The interrupt type is being already specified by the Device Tree,
      anyway. Other drivers (gpio/gpio-tc3589x.c for example) already work in
      this way, delegating the proper IRQ line setup to the DT and not
      specifying anything by hand.
      
      Also, there's no reason to have the IRQ flags split between two places.
      The SPI probing is the only entry point anyway.
      Signed-off-by: NJan Kundrát <jan.kundrat@cesnet.cz>
      Signed-off-by: NGreg Kroah-Hartman <gregkh@linuxfoundation.org>
      bceb4839
  6. 18 12月, 2017 2 次提交
  7. 16 12月, 2017 12 次提交
  8. 28 11月, 2017 1 次提交