364-v5.2-brcmfmac-convert-dev_init_lock-mutex-to-completion.patch 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. From a9fd0953fa4a62887306be28641b4b0809f3b2fd Mon Sep 17 00:00:00 2001
  2. From: Piotr Figiel <[email protected]>
  3. Date: Wed, 13 Mar 2019 09:52:42 +0000
  4. Subject: [PATCH] brcmfmac: convert dev_init_lock mutex to completion
  5. Leaving dev_init_lock mutex locked in probe causes BUG and a WARNING when
  6. kernel is compiled with CONFIG_PROVE_LOCKING. Convert mutex to completion
  7. which silences those warnings and improves code readability.
  8. Fix below errors when connecting the USB WiFi dongle:
  9. brcmfmac: brcmf_fw_alloc_request: using brcm/brcmfmac43143 for chip BCM43143/2
  10. BUG: workqueue leaked lock or atomic: kworker/0:2/0x00000000/434
  11. last function: hub_event
  12. 1 lock held by kworker/0:2/434:
  13. #0: 18d5dcdf (&devinfo->dev_init_lock){+.+.}, at: brcmf_usb_probe+0x78/0x550 [brcmfmac]
  14. CPU: 0 PID: 434 Comm: kworker/0:2 Not tainted 4.19.23-00084-g454a789-dirty #123
  15. Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
  16. Workqueue: usb_hub_wq hub_event
  17. [<8011237c>] (unwind_backtrace) from [<8010d74c>] (show_stack+0x10/0x14)
  18. [<8010d74c>] (show_stack) from [<809c4324>] (dump_stack+0xa8/0xd4)
  19. [<809c4324>] (dump_stack) from [<8014195c>] (process_one_work+0x710/0x808)
  20. [<8014195c>] (process_one_work) from [<80141a80>] (worker_thread+0x2c/0x564)
  21. [<80141a80>] (worker_thread) from [<80147bcc>] (kthread+0x13c/0x16c)
  22. [<80147bcc>] (kthread) from [<801010b4>] (ret_from_fork+0x14/0x20)
  23. Exception stack(0xed1d9fb0 to 0xed1d9ff8)
  24. 9fa0: 00000000 00000000 00000000 00000000
  25. 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  26. 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000
  27. ======================================================
  28. WARNING: possible circular locking dependency detected
  29. 4.19.23-00084-g454a789-dirty #123 Not tainted
  30. ------------------------------------------------------
  31. kworker/0:2/434 is trying to acquire lock:
  32. e29cf799 ((wq_completion)"events"){+.+.}, at: process_one_work+0x174/0x808
  33. but task is already holding lock:
  34. 18d5dcdf (&devinfo->dev_init_lock){+.+.}, at: brcmf_usb_probe+0x78/0x550 [brcmfmac]
  35. which lock already depends on the new lock.
  36. the existing dependency chain (in reverse order) is:
  37. -> #2 (&devinfo->dev_init_lock){+.+.}:
  38. mutex_lock_nested+0x1c/0x24
  39. brcmf_usb_probe+0x78/0x550 [brcmfmac]
  40. usb_probe_interface+0xc0/0x1bc
  41. really_probe+0x228/0x2c0
  42. __driver_attach+0xe4/0xe8
  43. bus_for_each_dev+0x68/0xb4
  44. bus_add_driver+0x19c/0x214
  45. driver_register+0x78/0x110
  46. usb_register_driver+0x84/0x148
  47. process_one_work+0x228/0x808
  48. worker_thread+0x2c/0x564
  49. kthread+0x13c/0x16c
  50. ret_from_fork+0x14/0x20
  51. (null)
  52. -> #1 (brcmf_driver_work){+.+.}:
  53. worker_thread+0x2c/0x564
  54. kthread+0x13c/0x16c
  55. ret_from_fork+0x14/0x20
  56. (null)
  57. -> #0 ((wq_completion)"events"){+.+.}:
  58. process_one_work+0x1b8/0x808
  59. worker_thread+0x2c/0x564
  60. kthread+0x13c/0x16c
  61. ret_from_fork+0x14/0x20
  62. (null)
  63. other info that might help us debug this:
  64. Chain exists of:
  65. (wq_completion)"events" --> brcmf_driver_work --> &devinfo->dev_init_lock
  66. Possible unsafe locking scenario:
  67. CPU0 CPU1
  68. ---- ----
  69. lock(&devinfo->dev_init_lock);
  70. lock(brcmf_driver_work);
  71. lock(&devinfo->dev_init_lock);
  72. lock((wq_completion)"events");
  73. *** DEADLOCK ***
  74. 1 lock held by kworker/0:2/434:
  75. #0: 18d5dcdf (&devinfo->dev_init_lock){+.+.}, at: brcmf_usb_probe+0x78/0x550 [brcmfmac]
  76. stack backtrace:
  77. CPU: 0 PID: 434 Comm: kworker/0:2 Not tainted 4.19.23-00084-g454a789-dirty #123
  78. Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
  79. Workqueue: events request_firmware_work_func
  80. [<8011237c>] (unwind_backtrace) from [<8010d74c>] (show_stack+0x10/0x14)
  81. [<8010d74c>] (show_stack) from [<809c4324>] (dump_stack+0xa8/0xd4)
  82. [<809c4324>] (dump_stack) from [<80172838>] (print_circular_bug+0x210/0x330)
  83. [<80172838>] (print_circular_bug) from [<80175940>] (__lock_acquire+0x160c/0x1a30)
  84. [<80175940>] (__lock_acquire) from [<8017671c>] (lock_acquire+0xe0/0x268)
  85. [<8017671c>] (lock_acquire) from [<80141404>] (process_one_work+0x1b8/0x808)
  86. [<80141404>] (process_one_work) from [<80141a80>] (worker_thread+0x2c/0x564)
  87. [<80141a80>] (worker_thread) from [<80147bcc>] (kthread+0x13c/0x16c)
  88. [<80147bcc>] (kthread) from [<801010b4>] (ret_from_fork+0x14/0x20)
  89. Exception stack(0xed1d9fb0 to 0xed1d9ff8)
  90. 9fa0: 00000000 00000000 00000000 00000000
  91. 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
  92. 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000
  93. Signed-off-by: Piotr Figiel <[email protected]>
  94. Signed-off-by: Kalle Valo <[email protected]>
  95. ---
  96. .../wireless/broadcom/brcm80211/brcmfmac/usb.c | 17 ++++++++---------
  97. 1 file changed, 8 insertions(+), 9 deletions(-)
  98. --- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/usb.c
  99. +++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/usb.c
  100. @@ -160,7 +160,7 @@ struct brcmf_usbdev_info {
  101. struct usb_device *usbdev;
  102. struct device *dev;
  103. - struct mutex dev_init_lock;
  104. + struct completion dev_init_done;
  105. int ctl_in_pipe, ctl_out_pipe;
  106. struct urb *ctl_urb; /* URB for control endpoint */
  107. @@ -1194,11 +1194,11 @@ static void brcmf_usb_probe_phase2(struc
  108. if (ret)
  109. goto error;
  110. - mutex_unlock(&devinfo->dev_init_lock);
  111. + complete(&devinfo->dev_init_done);
  112. return;
  113. error:
  114. brcmf_dbg(TRACE, "failed: dev=%s, err=%d\n", dev_name(dev), ret);
  115. - mutex_unlock(&devinfo->dev_init_lock);
  116. + complete(&devinfo->dev_init_done);
  117. device_release_driver(dev);
  118. }
  119. @@ -1266,7 +1266,7 @@ static int brcmf_usb_probe_cb(struct brc
  120. if (ret)
  121. goto fail;
  122. /* we are done */
  123. - mutex_unlock(&devinfo->dev_init_lock);
  124. + complete(&devinfo->dev_init_done);
  125. return 0;
  126. }
  127. bus->chip = bus_pub->devid;
  128. @@ -1326,11 +1326,10 @@ brcmf_usb_probe(struct usb_interface *in
  129. devinfo->usbdev = usb;
  130. devinfo->dev = &usb->dev;
  131. - /* Take an init lock, to protect for disconnect while still loading.
  132. + /* Init completion, to protect for disconnect while still loading.
  133. * Necessary because of the asynchronous firmware load construction
  134. */
  135. - mutex_init(&devinfo->dev_init_lock);
  136. - mutex_lock(&devinfo->dev_init_lock);
  137. + init_completion(&devinfo->dev_init_done);
  138. usb_set_intfdata(intf, devinfo);
  139. @@ -1408,7 +1407,7 @@ brcmf_usb_probe(struct usb_interface *in
  140. return 0;
  141. fail:
  142. - mutex_unlock(&devinfo->dev_init_lock);
  143. + complete(&devinfo->dev_init_done);
  144. kfree(devinfo);
  145. usb_set_intfdata(intf, NULL);
  146. return ret;
  147. @@ -1423,7 +1422,7 @@ brcmf_usb_disconnect(struct usb_interfac
  148. devinfo = (struct brcmf_usbdev_info *)usb_get_intfdata(intf);
  149. if (devinfo) {
  150. - mutex_lock(&devinfo->dev_init_lock);
  151. + wait_for_completion(&devinfo->dev_init_done);
  152. /* Make sure that devinfo still exists. Firmware probe routines
  153. * may have released the device and cleared the intfdata.
  154. */