linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Bluetooth: hci_h5: Stop erroneously setting HCI_UART_REGISTERED
@ 2020-08-01 15:43 Samuel Holland
  2020-08-01 15:43 ` [PATCH 2/2] Bluetooth: hci_serdev: Fix crash with HCI_UART_INIT_PENDING Samuel Holland
  2020-08-01 16:24 ` [PATCH 1/2] Bluetooth: hci_h5: Stop erroneously setting HCI_UART_REGISTERED Samuel Holland
  0 siblings, 2 replies; 3+ messages in thread
From: Samuel Holland @ 2020-08-01 15:43 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg
  Cc: Hans de Goede, linux-bluetooth, linux-kernel, Samuel Holland, stable

This code attempts to set the HCI_UART_RESET_ON_INIT flag. However,
it sets the bit in the wrong flag word: HCI_UART_RESET_ON_INIT goes in
hu->hdev_flags, not hu->flags. So it is actually setting
HCI_UART_REGISTERED, which is bit 1 in hu->flags.

Since commit cba736465e5c ("Bluetooth: hci_serdev: Remove setting of
HCI_QUIRK_RESET_ON_CLOSE."), this flag is ignored for hci_serdev users,
so instead of fixing which flag is set, let's remove the flag entirely.

Cc: stable@vger.kernel.org
Fixes: ce945552fde4 ("Bluetooth: hci_h5: Add support for serdev enumerated devices")
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 drivers/bluetooth/hci_h5.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/bluetooth/hci_h5.c b/drivers/bluetooth/hci_h5.c
index e60b2e0773db..981d96cc7695 100644
--- a/drivers/bluetooth/hci_h5.c
+++ b/drivers/bluetooth/hci_h5.c
@@ -793,8 +793,6 @@ static int h5_serdev_probe(struct serdev_device *serdev)
 	if (!h5)
 		return -ENOMEM;
 
-	set_bit(HCI_UART_RESET_ON_INIT, &h5->serdev_hu.flags);
-
 	h5->hu = &h5->serdev_hu;
 	h5->serdev_hu.serdev = serdev;
 	serdev_device_set_drvdata(serdev, h5);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH 2/2] Bluetooth: hci_serdev: Fix crash with HCI_UART_INIT_PENDING
  2020-08-01 15:43 [PATCH 1/2] Bluetooth: hci_h5: Stop erroneously setting HCI_UART_REGISTERED Samuel Holland
@ 2020-08-01 15:43 ` Samuel Holland
  2020-08-01 16:24 ` [PATCH 1/2] Bluetooth: hci_h5: Stop erroneously setting HCI_UART_REGISTERED Samuel Holland
  1 sibling, 0 replies; 3+ messages in thread
From: Samuel Holland @ 2020-08-01 15:43 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg
  Cc: Hans de Goede, linux-bluetooth, linux-kernel, Samuel Holland, stable

When using HCI_UART_INIT_PENDING, hci_register_dev is not called from
hci_uart_register_device. Instead, it is called by hci_uart_init_work,
which is enqueued by hci_uart_init_ready (as hu->init_ready). In the
case of the hci_h5 proto, hci_uart_init_ready is called only after
handshaking with the hardware. If that handshake never completes,
hci_register_dev is never called. When later unregistering the device,
the kernel crashes:

  Unable to handle kernel write to read-only memory at virtual address 0000000000000008
  Internal error: Oops: 96000045 [#1] PREEMPT SMP
  Modules linked in: hci_uart(-) btrtl bnep bluetooth 8723cs(C) [...]
  CPU: 3 PID: 516 Comm: rmmod Tainted: G         C        5.8.0-rc7-00277-gd87641cb644c-dirty #1
  Hardware name: Pine64 PinePhone Braveheart (1.1) (DT)
  pstate: 80400005 (Nzcv daif +PAN -UAO BTYPE=--)
  pc : hci_unregister_dev+0x58/0x4b0 [bluetooth]
  lr : hci_unregister_dev+0x54/0x4b0 [bluetooth]
  sp : ffffffc011b5bc60
  x29: ffffffc011b5bc60 x28: ffffff8075d23800
  x27: 0000000000000000 x26: 0000000000000000
  x25: 0000000000000000 x24: 0000000000000000
  x23: 0000000000000000 x22: ffffffc008d86000
  x21: ffffff8079dd2000 x20: ffffff8078026000
  x19: ffffffc008f4f6d0 x18: 0000000000000000
  x17: 0000000000000000 x16: 0000000000000000
  x15: 0000000000000004 x14: ffffff807b15c110
  x13: 0000000000000000 x12: ffffff80778e6720
  x11: ffffff80778e66c8 x10: ffffff807ac6ada2
  x9 : ffffffc010c95864 x8 : 0000000000210d00
  x7 : 0000000000000000 x6 : 0000000000000001
  x5 : 0000000000000001 x4 : 0000000000000001
  x3 : 0000000000000000 x2 : 0000000000000000
  x1 : 0000000000000000 x0 : 0000000000000000
  Call trace:
   hci_unregister_dev+0x58/0x4b0 [bluetooth]
   hci_uart_unregister_device+0x40/0x74 [hci_uart]
   h5_serdev_remove+0x18/0x20 [hci_uart]
   serdev_drv_remove+0x28/0x4c
   __device_release_driver+0x174/0x210
   driver_detach+0xc4/0x100
   bus_remove_driver+0x5c/0xb0
   driver_unregister+0x34/0x60
   h5_deinit+0x14/0xd10 [hci_uart]
   hci_uart_exit+0xc/0x30 [hci_uart]
   __arm64_sys_delete_module+0x1b0/0x260
   el0_svc_common.constprop.0+0x60/0x100
   do_el0_svc+0x20/0x30
   el0_sync_handler+0x88/0x1b4
   el0_sync+0x138/0x140
  Code: aa1303e0 79408297 95f69770 a9400682 (f9000441)
  ---[ end trace b68f9044c8f92379 ]---

Fix the crash by flushing the hu->init_ready work to ensure
hci_register_dev is not being called concurrently, and then only
calling hci_unregister_dev if the HCI was previously registered.

Cc: stable@vger.kernel.org
Fixes: fdee6d8fc630 ("Bluetooth: hci_serdev: Fix HCI_UART_INIT_PENDING not working")
Signed-off-by: Samuel Holland <samuel@sholland.org>
---
 drivers/bluetooth/hci_serdev.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/bluetooth/hci_serdev.c b/drivers/bluetooth/hci_serdev.c
index 599855e4c57c..3977bba485c2 100644
--- a/drivers/bluetooth/hci_serdev.c
+++ b/drivers/bluetooth/hci_serdev.c
@@ -355,7 +355,10 @@ void hci_uart_unregister_device(struct hci_uart *hu)
 	struct hci_dev *hdev = hu->hdev;
 
 	clear_bit(HCI_UART_PROTO_READY, &hu->flags);
-	hci_unregister_dev(hdev);
+
+	cancel_work_sync(&hu->init_ready);
+	if (test_bit(HCI_UART_REGISTERED, &hu->flags))
+		hci_unregister_dev(hdev);
 	hci_free_dev(hdev);
 
 	cancel_work_sync(&hu->write_work);
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/2] Bluetooth: hci_h5: Stop erroneously setting HCI_UART_REGISTERED
  2020-08-01 15:43 [PATCH 1/2] Bluetooth: hci_h5: Stop erroneously setting HCI_UART_REGISTERED Samuel Holland
  2020-08-01 15:43 ` [PATCH 2/2] Bluetooth: hci_serdev: Fix crash with HCI_UART_INIT_PENDING Samuel Holland
@ 2020-08-01 16:24 ` Samuel Holland
  1 sibling, 0 replies; 3+ messages in thread
From: Samuel Holland @ 2020-08-01 16:24 UTC (permalink / raw)
  To: Marcel Holtmann, Johan Hedberg
  Cc: Hans de Goede, linux-bluetooth, linux-kernel, stable

On 8/1/20 10:43 AM, Samuel Holland wrote:
> This code attempts to set the HCI_UART_RESET_ON_INIT flag. However,
> it sets the bit in the wrong flag word: HCI_UART_RESET_ON_INIT goes in
> hu->hdev_flags, not hu->flags. So it is actually setting
> HCI_UART_REGISTERED, which is bit 1 in hu->flags.
> 
> Since commit cba736465e5c ("Bluetooth: hci_serdev: Remove setting of
> HCI_QUIRK_RESET_ON_CLOSE."), this flag is ignored for hci_serdev users,
> so instead of fixing which flag is set, let's remove the flag entirely.
> 
> Cc: stable@vger.kernel.org
> Fixes: ce945552fde4 ("Bluetooth: hci_h5: Add support for serdev enumerated devices")
> Signed-off-by: Samuel Holland <samuel@sholland.org>
> ---
>  drivers/bluetooth/hci_h5.c | 2 --
>  1 file changed, 2 deletions(-)

Sorry, I didn't see the other patches that were just added to -next.
I'll rebase my additional changes on top of them and resend.

Regards,
Samuel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-08-01 16:24 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-01 15:43 [PATCH 1/2] Bluetooth: hci_h5: Stop erroneously setting HCI_UART_REGISTERED Samuel Holland
2020-08-01 15:43 ` [PATCH 2/2] Bluetooth: hci_serdev: Fix crash with HCI_UART_INIT_PENDING Samuel Holland
2020-08-01 16:24 ` [PATCH 1/2] Bluetooth: hci_h5: Stop erroneously setting HCI_UART_REGISTERED Samuel Holland

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).