2018-05-31 09:50:13

by Amit K Bag

[permalink] [raw]
Subject: [PATCH] Bluetooth: btusb: Avoid race condition during controller recovery

From: Chethan T N <[email protected]>

Observed race condition during controller recovery mechanism
resulting the controller not responding to the reset command.

To avoid such race condition need a delay of 2ms soon after the
USB re-enumeration and before sending the Reset command which shall
allow controller to completely recover and process the Reset command.

Change-Id: Ifbc387d4377bc79081244d444d45ba6effc95f23
Signed-off-by: Chethan T N <[email protected]>
---
drivers/bluetooth/btusb.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index f73a27ea28cc..844b4145ff76 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -1741,6 +1741,15 @@ static int btusb_setup_intel(struct hci_dev *hdev)
int disable_patch, err;
struct intel_version ver;

+ /* Observed race condition during controller recovery mechanism
+ * resulting the controller not responding to the reset command.
+ *
+ * To avoid such race condition need a delay of 2ms soon after the
+ * USB re-enumeration and before sending the Reset command which shall
+ * allow controller to completely recover and process the Reset command.
+ */
+ mdelay(2);
+
BT_DBG("%s", hdev->name);

/* The controller has a bug with the first HCI command sent to it
--
2.7.4



2018-06-06 09:57:48

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: btusb: Avoid race condition during controller recovery

Hi Amit,

On Wed, Jun 6, 2018 at 9:22 AM, Amit K Bag <[email protected]> wrote:
> From: Chethan T N <[email protected]>
>
> Observed race condition during controller recovery mechanism
> resulting the controller not responding to the reset command.
>
> To avoid such race condition need a delay of 2ms soon after the
> USB re-enumeration and before sending the Reset command which shall
> allow controller to completely recover and process the Reset command.
>
> BUG=b:64035404
> TEST=Magic tethering, P0 and P1 santiy test cases, kernel-boot log
>
> Signed-off-by: Chethan T N <[email protected]>
> Signed-off-by: Amit K Bag <[email protected]>
> ---
> drivers/bluetooth/btusb.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index f73a27ea28cc..2303ac037240 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -1743,6 +1743,15 @@ static int btusb_setup_intel(struct hci_dev *hdev)
>
> BT_DBG("%s", hdev->name);
>
> + /* Observed race condition during controller recovery mechanism
> + * resulting the controller not responding to the reset command.
> + *
> + * To avoid such race condition need a delay of 2ms soon after the
> + * USB re-enumeration and before sending the Reset command which shall
> + * allow controller to completely recover and process the Reset command.
> + */
> + mdelay(5);

Looks like the commit message and comment are not longer in sync with
the actual value here. Also perhaps this could be a parameter so any
hardware that has this problem just set how much delay it needs before
setup can be called.

> /* The controller has a bug with the first HCI command sent to it
> * returning number of completed commands as zero. This would stall the
> * command processing in the Bluetooth core.
> --
> 2.7.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html



--
Luiz Augusto von Dentz

2018-06-05 14:07:02

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: btusb: Avoid race condition during controller recovery

Hi Amit,

> Observed race condition during controller recovery mechanism
> resulting the controller not responding to the reset command.
>
> To avoid such race condition need a delay of 2ms soon after the
> USB re-enumeration and before sending the Reset command which shall
> allow controller to completely recover and process the Reset command.
>
> Change-Id: Ifbc387d4377bc79081244d444d45ba6effc95f23
> Signed-off-by: Chethan T N <[email protected]>

oh, and no Change-Id please and you also need to add your Signed-off-by here.

Regards

Marcel


2018-06-05 14:05:46

by Marcel Holtmann

[permalink] [raw]
Subject: Re: [PATCH] Bluetooth: btusb: Avoid race condition during controller recovery

Hi Amit,

> Observed race condition during controller recovery mechanism
> resulting the controller not responding to the reset command.
>
> To avoid such race condition need a delay of 2ms soon after the
> USB re-enumeration and before sending the Reset command which shall
> allow controller to completely recover and process the Reset command.
>
> Change-Id: Ifbc387d4377bc79081244d444d45ba6effc95f23
> Signed-off-by: Chethan T N <[email protected]>
> ---
> drivers/bluetooth/btusb.c | 9 +++++++++
> 1 file changed, 9 insertions(+)
>
> diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
> index f73a27ea28cc..844b4145ff76 100644
> --- a/drivers/bluetooth/btusb.c
> +++ b/drivers/bluetooth/btusb.c
> @@ -1741,6 +1741,15 @@ static int btusb_setup_intel(struct hci_dev *hdev)
> int disable_patch, err;
> struct intel_version ver;
>
> + /* Observed race condition during controller recovery mechanism
> + * resulting the controller not responding to the reset command.
> + *
> + * To avoid such race condition need a delay of 2ms soon after the
> + * USB re-enumeration and before sending the Reset command which shall
> + * allow controller to completely recover and process the Reset command.
> + */
> + mdelay(2);
> +
> BT_DBG("%s", hdev->name);

can you leave the BT_DBG() at the top and move the mdelay + comment after it.

Regards

Marcel