1. 04 8月, 2019 1 次提交
  2. 27 3月, 2019 2 次提交
  3. 11 9月, 2018 1 次提交
    • H
      Bluetooth: hci_ldisc: Free rw_semaphore on close · e6a57d22
      Hermes Zhang 提交于
      The percpu_rw_semaphore is not currently freed, and this leads to
      a crash when the stale rcu callback is invoked.  DEBUG_OBJECTS
      detects this.
      
       ODEBUG: free active (active state 1) object type: rcu_head hint: (null)
       ------------[ cut here ]------------
       WARNING: CPU: 1 PID: 2024 at debug_print_object+0xac/0xc8
       PC is at debug_print_object+0xac/0xc8
       LR is at debug_print_object+0xac/0xc8
       Call trace:
       [<ffffff80082e2c2c>] debug_print_object+0xac/0xc8
       [<ffffff80082e40b0>] debug_check_no_obj_freed+0x1e8/0x228
       [<ffffff8008191254>] kfree+0x1cc/0x250
       [<ffffff80083cc03c>] hci_uart_tty_close+0x54/0x108
       [<ffffff800832e118>] tty_ldisc_close.isra.1+0x40/0x58
       [<ffffff800832e14c>] tty_ldisc_kill+0x1c/0x40
       [<ffffff800832e3dc>] tty_ldisc_release+0x94/0x170
       [<ffffff8008325554>] tty_release_struct+0x1c/0x58
       [<ffffff8008326400>] tty_release+0x3b0/0x490
       [<ffffff80081a3fe8>] __fput+0x88/0x1d0
       [<ffffff80081a418c>] ____fput+0xc/0x18
       [<ffffff80080c0624>] task_work_run+0x9c/0xc0
       [<ffffff80080a9e24>] do_exit+0x24c/0x8a0
       [<ffffff80080aa4e0>] do_group_exit+0x38/0xa0
       [<ffffff80080aa558>] __wake_up_parent+0x0/0x28
       [<ffffff8008082c00>] el0_svc_naked+0x34/0x38
       ---[ end trace bfe08cbd89098cdf ]---
      Signed-off-by: NHermes Zhang <chenhuiz@axis.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      e6a57d22
  4. 30 5月, 2018 2 次提交
  5. 18 5月, 2018 1 次提交
  6. 29 11月, 2017 1 次提交
  7. 30 10月, 2017 1 次提交
  8. 29 10月, 2017 1 次提交
    • R
      Bluetooth: hci_ldisc: Allow sleeping while proto locks are held. · 67d2f878
      Ronald Tschalär 提交于
      Commit dec2c928 ("Bluetooth: hci_ldisc:
      Use rwlocking to avoid closing proto races") introduced locks in
      hci_ldisc that are held while calling the proto functions. These locks
      are rwlock's, and hence do not allow sleeping while they are held.
      However, the proto functions that hci_bcm registers use mutexes and
      hence need to be able to sleep.
      
      In more detail: hci_uart_tty_receive() and hci_uart_dequeue() both
      acquire the rwlock, after which they call proto->recv() and
      proto->dequeue(), respectively. In the case of hci_bcm these point to
      bcm_recv() and bcm_dequeue(). The latter both acquire the
      bcm_device_lock, which is a mutex, so doing so results in a call to
      might_sleep(). But since we're holding a rwlock in hci_ldisc, that
      results in the following BUG (this for the dequeue case - a similar
      one for the receive case is omitted for brevity):
      
        BUG: sleeping function called from invalid context at kernel/locking/mutex.c
        in_atomic(): 1, irqs_disabled(): 0, pid: 7303, name: kworker/7:3
        INFO: lockdep is turned off.
        CPU: 7 PID: 7303 Comm: kworker/7:3 Tainted: G        W  OE   4.13.2+ #17
        Hardware name: Apple Inc. MacBookPro13,3/Mac-A5C67F76ED83108C, BIOS MBP133.8
        Workqueue: events hci_uart_write_work [hci_uart]
        Call Trace:
         dump_stack+0x8e/0xd6
         ___might_sleep+0x164/0x250
         __might_sleep+0x4a/0x80
         __mutex_lock+0x59/0xa00
         ? lock_acquire+0xa3/0x1f0
         ? lock_acquire+0xa3/0x1f0
         ? hci_uart_write_work+0xd3/0x160 [hci_uart]
         mutex_lock_nested+0x1b/0x20
         ? mutex_lock_nested+0x1b/0x20
         bcm_dequeue+0x21/0xc0 [hci_uart]
         hci_uart_write_work+0xe6/0x160 [hci_uart]
         process_one_work+0x253/0x6a0
         worker_thread+0x4d/0x3b0
         kthread+0x133/0x150
      
      We can't replace the mutex in hci_bcm, because there are other calls
      there that might sleep. Therefore this replaces the rwlock's in
      hci_ldisc with rw_semaphore's (which allow sleeping). This is a safer
      approach anyway as it reduces the restrictions on the proto callbacks.
      Also, because acquiring write-lock is very rare compared to acquiring
      the read-lock, the percpu variant of rw_semaphore is used.
      
      Lastly, because hci_uart_tx_wakeup() may be called from an IRQ context,
      we can't block (sleep) while trying acquire the read lock there, so we
      use the trylock variant.
      Signed-off-by: NRonald Tschalär <ronald@innovation.ch>
      Reviewed-by: NLukas Wunner <lukas@wunner.de>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      67d2f878
  9. 07 10月, 2017 1 次提交
  10. 22 7月, 2017 1 次提交
  11. 18 5月, 2017 1 次提交
    • D
      Bluetooth: hci_ldisc: Use rwlocking to avoid closing proto races · dec2c928
      Dean Jenkins 提交于
      When HCI_UART_PROTO_READY is in the set state, the Data Link protocol
      layer (proto) is bound to the HCI UART driver. This state allows the
      registered proto function pointers to be used by the HCI UART driver.
      
      When unbinding (closing) the Data Link protocol layer, the proto
      function pointers much be prevented from being used immediately before
      running the proto close function pointer. Otherwise, there is a risk
      that a proto non-close function pointer is used during or after the
      proto close function pointer is used. The consequences are likely to
      be a kernel crash because the proto close function pointer will free
      resources used in the Data Link protocol layer.
      
      Therefore, add a reader writer lock (rwlock) solution to prevent the
      close proto function pointer from running by using write_lock_irqsave()
      whilst the other proto function pointers are protected using
      read_lock(). This means HCI_UART_PROTO_READY can safely be cleared
      in the knowledge that no proto function pointers are running.
      
      When flag HCI_UART_PROTO_READY is put into the clear state,
      proto close function pointer can safely be run. Note
      flag HCI_UART_PROTO_SET being in the set state prevents the proto
      open function pointer from being run so there is no race condition
      between proto open and close function pointers.
      Signed-off-by: NDean Jenkins <Dean_Jenkins@mentor.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      dec2c928
  12. 30 4月, 2017 3 次提交
    • D
      Bluetooth: hci_ldisc: Add protocol check to hci_uart_tx_wakeup() · 2d6f1da1
      Dean Jenkins 提交于
      Before attempting to schedule a work-item onto hu->write_work in
      hci_uart_tx_wakeup(), check that the Data Link protocol layer is
      still bound to the HCI UART driver.
      
      Failure to perform this protocol check causes a race condition between
      the work queue hu->write_work running hci_uart_write_work() and the
      Data Link protocol layer being unbound (closed) in hci_uart_tty_close().
      
      Note hci_uart_tty_close() does have a "cancel_work_sync(&hu->write_work)"
      but it is ineffective because it cannot prevent work-items being added
      to hu->write_work after cancel_work_sync() has run.
      
      Therefore, add a check for HCI_UART_PROTO_READY into hci_uart_tx_wakeup()
      which prevents scheduling of the work queue when HCI_UART_PROTO_READY
      is in the clear state. However, note a small race condition remains
      because the hci_uart_tx_wakeup() thread can run in parallel with the
      hci_uart_tty_close() thread so it is possible that a schedule of
      hu->write_work can occur when HCI_UART_PROTO_READY is cleared. A complete
      solution needs locking of the threads which is implemented in a future
      commit.
      Signed-off-by: NDean Jenkins <Dean_Jenkins@mentor.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      2d6f1da1
    • D
      Bluetooth: hci_ldisc: Add protocol check to hci_uart_dequeue() · 048e1bd3
      Dean Jenkins 提交于
      Before attempting to dequeue a Data Link protocol encapsulated message,
      check that the Data Link protocol is still bound to the HCI UART driver.
      This makes the code consistent with the usage of the other proto
      function pointers.
      
      Therefore, add a check for HCI_UART_PROTO_READY into hci_uart_dequeue()
      and return NULL if the Data Link protocol is not bound.
      
      This is needed for robustness as there is a scheduling race condition.
      hci_uart_write_work() is scheduled to run via work queue hu->write_work
      from hci_uart_tx_wakeup(). Therefore, there is a delay between
      scheduling hci_uart_write_work() to run and hci_uart_dequeue() running
      whereby the Data Link protocol layer could become unbound during the
      scheduling delay. In this case, without the check, the call to the
      unbound Data Link protocol layer dequeue function can crash.
      
      It is noted that hci_uart_tty_close() has a
      "cancel_work_sync(&hu->write_work)" statement but this only reduces
      the window of the race condition because it is possible for a new
      work-item to be added to work queue hu->write_work after the call to
      cancel_work_sync(). For example, Data Link layer retransmissions can
      be added to the work queue after the cancel_work_sync() has finished.
      Signed-off-by: NDean Jenkins <Dean_Jenkins@mentor.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      048e1bd3
    • D
      Bluetooth: hci_ldisc: Add protocol check to hci_uart_send_frame() · ab00f89f
      Dean Jenkins 提交于
      Before attempting to send a HCI message, check that the Data Link
      protocol is still bound to the HCI UART driver. This makes the code
      consistent with the usage of the other proto function pointers.
      
      Therefore, add a check for HCI_UART_PROTO_READY into hci_uart_send_frame()
      and return -EUNATCH if the Data Link protocol is not bound.
      
      This also allows hci_send_frame() to report the error of an unbound
      Data Link protocol layer. Therefore, it assists with diagnostics into
      why HCI messages are being sent when the Data Link protocol is not
      bound and avoids potential crashes.
      Signed-off-by: NDean Jenkins <Dean_Jenkins@mentor.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      ab00f89f
  13. 22 4月, 2017 3 次提交
  14. 14 4月, 2017 1 次提交
  15. 13 4月, 2017 2 次提交
  16. 24 9月, 2016 1 次提交
  17. 20 9月, 2016 1 次提交
  18. 10 7月, 2016 1 次提交
    • M
      Bluetooth: Rename HCI_BREDR into HCI_PRIMARY · ca8bee5d
      Marcel Holtmann 提交于
      The HCI_BREDR naming is confusing since it actually stands for Primary
      Bluetooth Controller. Which is a term that has been used in the latest
      standard. However from a legacy point of view there only really have
      been Basic Rate (BR) and Enhanced Data Rate (EDR). Recent versions of
      Bluetooth introduced Low Energy (LE) and made this terminology a little
      bit confused since Dual Mode Controllers include BR/EDR and LE. To
      simplify this the name HCI_PRIMARY stands for the Primary Controller
      which can be a single mode or dual mode controller.
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      Signed-off-by: NJohan Hedberg <johan.hedberg@intel.com>
      ca8bee5d
  19. 09 4月, 2016 1 次提交
  20. 24 2月, 2016 1 次提交
  21. 10 12月, 2015 1 次提交
  22. 20 11月, 2015 1 次提交
  23. 21 10月, 2015 1 次提交
  24. 05 10月, 2015 2 次提交
  25. 24 9月, 2015 1 次提交
    • F
      Bluetooth: Remove useless rx_lock spinlock · 7649faff
      Frederic Danis 提交于
      rx_lock spinlock is only used in hci_uart_tty_receive() which is the
      receive_buf ldisc callback.
      
      hci_uart_tty_receive() is protected from re-entrance by its only
      caller (flush_to_ldisc() in drivers/tty/tty_buffer.c) which held a
      mutex (buf->lock) for this section.
      This lock allows "safe use of the line discipline's receive_buf()
      method by excluding the buffer work and any pending flush from using
      the flip buffer." (comments from tty_buffer_lock_exclusive() in
      drivers/tty/tty_buffer.c)
      
      So, no need to double protect this resource with rx_lock.
      Signed-off-by: NFrederic Danis <frederic.danis@linux.intel.com>
      Signed-off-by: NMarcel Holtmann <marcel@holtmann.org>
      7649faff
  26. 11 8月, 2015 1 次提交
  27. 27 7月, 2015 1 次提交
  28. 23 7月, 2015 1 次提交
  29. 18 6月, 2015 2 次提交
  30. 06 6月, 2015 2 次提交