All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Bluetooth: Move shutdown callback before flushing tx and rx queue
@ 2021-08-09 17:43 Kai-Heng Feng
  2021-08-09 18:14 ` bluez.test.bot
  2021-08-10  4:10 ` [PATCH] " Hsin-Yi Wang
  0 siblings, 2 replies; 4+ messages in thread
From: Kai-Heng Feng @ 2021-08-09 17:43 UTC (permalink / raw)
  To: marcel, johan.hedberg, luiz.dentz
  Cc: Kai-Heng Feng, Mattijs Korpershoek, Hsin-Yi Wang, Guenter Roeck,
	David S. Miller, Jakub Kicinski, open list:BLUETOOTH SUBSYSTEM,
	open list:NETWORKING [GENERAL],
	open list

Commit 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues
are flushed or cancelled") introduced a regression that makes mtkbtsdio
driver stops working:
[   36.593956] Bluetooth: hci0: Firmware already downloaded
[   46.814613] Bluetooth: hci0: Execution of wmt command timed out
[   46.814619] Bluetooth: hci0: Failed to send wmt func ctrl (-110)

The shutdown callback depends on the result of hdev->rx_work, so we
should call it before flushing rx_work:
-> btmtksdio_shutdown()
 -> mtk_hci_wmt_sync()
  -> __hci_cmd_send()
   -> wait for BTMTKSDIO_TX_WAIT_VND_EVT gets cleared

-> btmtksdio_recv_event()
 -> hci_recv_frame()
  -> queue_work(hdev->workqueue, &hdev->rx_work)
   -> clears BTMTKSDIO_TX_WAIT_VND_EVT

So move the shutdown callback before flushing TX/RX queue to resolve the
issue.

Reported-and-tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
Tested-by: Hsin-Yi Wang <hsinyi@chromium.org>
Cc: Guenter Roeck <linux@roeck-us.net>
Fixes: 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues are flushed or cancelled")
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
 net/bluetooth/hci_core.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index cb2e9e513907..8da04c899197 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -1735,6 +1735,14 @@ int hci_dev_do_close(struct hci_dev *hdev)
 
 	hci_leds_update_powered(hdev, false);
 
+	if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&
+	    !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
+	    test_bit(HCI_UP, &hdev->flags)) {
+		/* Execute vendor specific shutdown routine */
+		if (hdev->shutdown)
+			hdev->shutdown(hdev);
+	}
+
 	/* Flush RX and TX works */
 	flush_work(&hdev->tx_work);
 	flush_work(&hdev->rx_work);
@@ -1798,14 +1806,6 @@ int hci_dev_do_close(struct hci_dev *hdev)
 		clear_bit(HCI_INIT, &hdev->flags);
 	}
 
-	if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&
-	    !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
-	    test_bit(HCI_UP, &hdev->flags)) {
-		/* Execute vendor specific shutdown routine */
-		if (hdev->shutdown)
-			hdev->shutdown(hdev);
-	}
-
 	/* flush cmd  work */
 	flush_work(&hdev->cmd_work);
 
-- 
2.31.1


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

* RE: Bluetooth: Move shutdown callback before flushing tx and rx queue
  2021-08-09 17:43 [PATCH] Bluetooth: Move shutdown callback before flushing tx and rx queue Kai-Heng Feng
@ 2021-08-09 18:14 ` bluez.test.bot
  2021-08-10  4:10 ` [PATCH] " Hsin-Yi Wang
  1 sibling, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2021-08-09 18:14 UTC (permalink / raw)
  To: linux-bluetooth, kai.heng.feng

[-- Attachment #1: Type: text/plain, Size: 3753 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=528639

---Test result---

Test Summary:
CheckPatch                    FAIL      0.56 seconds
GitLint                       FAIL      0.13 seconds
BuildKernel                   PASS      630.13 seconds
TestRunner: Setup             PASS      401.12 seconds
TestRunner: l2cap-tester      PASS      2.88 seconds
TestRunner: bnep-tester       PASS      2.08 seconds
TestRunner: mgmt-tester       PASS      32.17 seconds
TestRunner: rfcomm-tester     PASS      2.44 seconds
TestRunner: sco-tester        PASS      2.28 seconds
TestRunner: smp-tester        FAIL      2.40 seconds
TestRunner: userchan-tester   PASS      2.21 seconds

Details
##############################
Test: CheckPatch - FAIL - 0.56 seconds
Run checkpatch.pl script with rule in .checkpatch.conf
Bluetooth: Move shutdown callback before flushing tx and rx queue
WARNING: Unknown commit id '0ea9fd001a14', maybe rebased or not pulled?
#7: 
Commit 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues

WARNING: Unknown commit id '0ea9fd001a14', maybe rebased or not pulled?
#32: 
Fixes: 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues are flushed or cancelled")

total: 0 errors, 2 warnings, 0 checks, 28 lines checked

NOTE: For some of the reported defects, checkpatch may be able to
      mechanically convert to the typical style using --fix or --fix-inplace.

"[PATCH] Bluetooth: Move shutdown callback before flushing tx and rx" has style problems, please review.

NOTE: If any of the errors are false positives, please report
      them to the maintainer, see CHECKPATCH in MAINTAINERS.


##############################
Test: GitLint - FAIL - 0.13 seconds
Run gitlint with rule in .gitlint
Bluetooth: Move shutdown callback before flushing tx and rx queue
28: B1 Line exceeds max length (96>80): "Fixes: 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues are flushed or cancelled")"


##############################
Test: BuildKernel - PASS - 630.13 seconds
Build Kernel with minimal configuration supports Bluetooth


##############################
Test: TestRunner: Setup - PASS - 401.12 seconds
Setup environment for running Test Runner


##############################
Test: TestRunner: l2cap-tester - PASS - 2.88 seconds
Run test-runner with l2cap-tester
Total: 40, Passed: 40 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: bnep-tester - PASS - 2.08 seconds
Run test-runner with bnep-tester
Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: mgmt-tester - PASS - 32.17 seconds
Run test-runner with mgmt-tester
Total: 448, Passed: 445 (99.3%), Failed: 0, Not Run: 3

##############################
Test: TestRunner: rfcomm-tester - PASS - 2.44 seconds
Run test-runner with rfcomm-tester
Total: 9, Passed: 9 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: sco-tester - PASS - 2.28 seconds
Run test-runner with sco-tester
Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0

##############################
Test: TestRunner: smp-tester - FAIL - 2.40 seconds
Run test-runner with smp-tester
Total: 8, Passed: 7 (87.5%), Failed: 1, Not Run: 0

Failed Test Cases
SMP Client - SC Request 2                            Failed       0.024 seconds

##############################
Test: TestRunner: userchan-tester - PASS - 2.21 seconds
Run test-runner with userchan-tester
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0



---
Regards,
Linux Bluetooth


[-- Attachment #2: l2cap-tester.log --]
[-- Type: application/octet-stream, Size: 44385 bytes --]

[-- Attachment #3: bnep-tester.log --]
[-- Type: application/octet-stream, Size: 3592 bytes --]

[-- Attachment #4: mgmt-tester.log --]
[-- Type: application/octet-stream, Size: 616862 bytes --]

[-- Attachment #5: rfcomm-tester.log --]
[-- Type: application/octet-stream, Size: 11712 bytes --]

[-- Attachment #6: sco-tester.log --]
[-- Type: application/octet-stream, Size: 9947 bytes --]

[-- Attachment #7: smp-tester.log --]
[-- Type: application/octet-stream, Size: 11740 bytes --]

[-- Attachment #8: userchan-tester.log --]
[-- Type: application/octet-stream, Size: 5486 bytes --]

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

* Re: [PATCH] Bluetooth: Move shutdown callback before flushing tx and rx queue
  2021-08-09 17:43 [PATCH] Bluetooth: Move shutdown callback before flushing tx and rx queue Kai-Heng Feng
  2021-08-09 18:14 ` bluez.test.bot
@ 2021-08-10  4:10 ` Hsin-Yi Wang
  2021-08-10  4:37   ` Kai-Heng Feng
  1 sibling, 1 reply; 4+ messages in thread
From: Hsin-Yi Wang @ 2021-08-10  4:10 UTC (permalink / raw)
  To: Kai-Heng Feng
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	Mattijs Korpershoek, Guenter Roeck, David S. Miller,
	Jakub Kicinski, open list:BLUETOOTH SUBSYSTEM,
	open list:NETWORKING [GENERAL],
	open list

On Tue, Aug 10, 2021 at 1:44 AM Kai-Heng Feng
<kai.heng.feng@canonical.com> wrote:
>
> Commit 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues
> are flushed or cancelled") introduced a regression that makes mtkbtsdio
> driver stops working:
> [   36.593956] Bluetooth: hci0: Firmware already downloaded
> [   46.814613] Bluetooth: hci0: Execution of wmt command timed out
> [   46.814619] Bluetooth: hci0: Failed to send wmt func ctrl (-110)
>
> The shutdown callback depends on the result of hdev->rx_work, so we
> should call it before flushing rx_work:
> -> btmtksdio_shutdown()
>  -> mtk_hci_wmt_sync()
>   -> __hci_cmd_send()
>    -> wait for BTMTKSDIO_TX_WAIT_VND_EVT gets cleared
>
> -> btmtksdio_recv_event()
>  -> hci_recv_frame()
>   -> queue_work(hdev->workqueue, &hdev->rx_work)
>    -> clears BTMTKSDIO_TX_WAIT_VND_EVT
>
> So move the shutdown callback before flushing TX/RX queue to resolve the
> issue.
>
> Reported-and-tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
> Tested-by: Hsin-Yi Wang <hsinyi@chromium.org>

Hello,

Sorry for confusion, but the version I tested is this one:
https://lkml.org/lkml/2021/8/4/486 (shutdown is prior to the
test_and_clear HCI_UP)
I tested this version and still see the error I've seen before.




> Cc: Guenter Roeck <linux@roeck-us.net>
> Fixes: 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues are flushed or cancelled")
> Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> ---
>  net/bluetooth/hci_core.c | 16 ++++++++--------
>  1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> index cb2e9e513907..8da04c899197 100644
> --- a/net/bluetooth/hci_core.c
> +++ b/net/bluetooth/hci_core.c
> @@ -1735,6 +1735,14 @@ int hci_dev_do_close(struct hci_dev *hdev)
>
>         hci_leds_update_powered(hdev, false);
>
> +       if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&
> +           !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
> +           test_bit(HCI_UP, &hdev->flags)) {
> +               /* Execute vendor specific shutdown routine */
> +               if (hdev->shutdown)
> +                       hdev->shutdown(hdev);
> +       }
> +
>         /* Flush RX and TX works */
>         flush_work(&hdev->tx_work);
>         flush_work(&hdev->rx_work);
> @@ -1798,14 +1806,6 @@ int hci_dev_do_close(struct hci_dev *hdev)
>                 clear_bit(HCI_INIT, &hdev->flags);
>         }
>
> -       if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&
> -           !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
> -           test_bit(HCI_UP, &hdev->flags)) {
> -               /* Execute vendor specific shutdown routine */
> -               if (hdev->shutdown)
> -                       hdev->shutdown(hdev);
> -       }
> -
>         /* flush cmd  work */
>         flush_work(&hdev->cmd_work);
>
> --
> 2.31.1
>

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

* Re: [PATCH] Bluetooth: Move shutdown callback before flushing tx and rx queue
  2021-08-10  4:10 ` [PATCH] " Hsin-Yi Wang
@ 2021-08-10  4:37   ` Kai-Heng Feng
  0 siblings, 0 replies; 4+ messages in thread
From: Kai-Heng Feng @ 2021-08-10  4:37 UTC (permalink / raw)
  To: Hsin-Yi Wang
  Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
	Mattijs Korpershoek, Guenter Roeck, David S. Miller,
	Jakub Kicinski, open list:BLUETOOTH SUBSYSTEM,
	open list:NETWORKING [GENERAL],
	open list

On Tue, Aug 10, 2021 at 12:10 PM Hsin-Yi Wang <hsinyi@chromium.org> wrote:
>
> On Tue, Aug 10, 2021 at 1:44 AM Kai-Heng Feng
> <kai.heng.feng@canonical.com> wrote:
> >
> > Commit 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues
> > are flushed or cancelled") introduced a regression that makes mtkbtsdio
> > driver stops working:
> > [   36.593956] Bluetooth: hci0: Firmware already downloaded
> > [   46.814613] Bluetooth: hci0: Execution of wmt command timed out
> > [   46.814619] Bluetooth: hci0: Failed to send wmt func ctrl (-110)
> >
> > The shutdown callback depends on the result of hdev->rx_work, so we
> > should call it before flushing rx_work:
> > -> btmtksdio_shutdown()
> >  -> mtk_hci_wmt_sync()
> >   -> __hci_cmd_send()
> >    -> wait for BTMTKSDIO_TX_WAIT_VND_EVT gets cleared
> >
> > -> btmtksdio_recv_event()
> >  -> hci_recv_frame()
> >   -> queue_work(hdev->workqueue, &hdev->rx_work)
> >    -> clears BTMTKSDIO_TX_WAIT_VND_EVT
> >
> > So move the shutdown callback before flushing TX/RX queue to resolve the
> > issue.
> >
> > Reported-and-tested-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
> > Tested-by: Hsin-Yi Wang <hsinyi@chromium.org>
>
> Hello,
>
> Sorry for confusion, but the version I tested is this one:
> https://lkml.org/lkml/2021/8/4/486 (shutdown is prior to the
> test_and_clear HCI_UP)
> I tested this version and still see the error I've seen before.

Ah, sorry for causing your trouble, I am the one who got confused :(
HCI_UP is obviously required for hci_req_sync() to work.

Let me resend one, and sorry again!

Kai-Heng

>
>
>
>
> > Cc: Guenter Roeck <linux@roeck-us.net>
> > Fixes: 0ea9fd001a14 ("Bluetooth: Shutdown controller after workqueues are flushed or cancelled")
> > Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
> > ---
> >  net/bluetooth/hci_core.c | 16 ++++++++--------
> >  1 file changed, 8 insertions(+), 8 deletions(-)
> >
> > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
> > index cb2e9e513907..8da04c899197 100644
> > --- a/net/bluetooth/hci_core.c
> > +++ b/net/bluetooth/hci_core.c
> > @@ -1735,6 +1735,14 @@ int hci_dev_do_close(struct hci_dev *hdev)
> >
> >         hci_leds_update_powered(hdev, false);
> >
> > +       if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&
> > +           !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
> > +           test_bit(HCI_UP, &hdev->flags)) {
> > +               /* Execute vendor specific shutdown routine */
> > +               if (hdev->shutdown)
> > +                       hdev->shutdown(hdev);
> > +       }
> > +
> >         /* Flush RX and TX works */
> >         flush_work(&hdev->tx_work);
> >         flush_work(&hdev->rx_work);
> > @@ -1798,14 +1806,6 @@ int hci_dev_do_close(struct hci_dev *hdev)
> >                 clear_bit(HCI_INIT, &hdev->flags);
> >         }
> >
> > -       if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) &&
> > -           !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
> > -           test_bit(HCI_UP, &hdev->flags)) {
> > -               /* Execute vendor specific shutdown routine */
> > -               if (hdev->shutdown)
> > -                       hdev->shutdown(hdev);
> > -       }
> > -
> >         /* flush cmd  work */
> >         flush_work(&hdev->cmd_work);
> >
> > --
> > 2.31.1
> >

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

end of thread, other threads:[~2021-08-10  4:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-09 17:43 [PATCH] Bluetooth: Move shutdown callback before flushing tx and rx queue Kai-Heng Feng
2021-08-09 18:14 ` bluez.test.bot
2021-08-10  4:10 ` [PATCH] " Hsin-Yi Wang
2021-08-10  4:37   ` Kai-Heng Feng

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.