From: Arseniy Krasnov <avkrasnov@salutedevices.com>
To: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Marcel Holtmann <marcel@holtmann.org>, <oxffffaa@gmail.com>,
<linux-bluetooth@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
<kernel@salutedevices.com>
Subject: Re: [PATCH v2] Bluetooth: hci_uart: fix race during initialization
Date: Thu, 30 Jan 2025 21:34:43 +0300 [thread overview]
Message-ID: <64dafad8-c4f1-d8bb-368a-239caa09a32c@salutedevices.com> (raw)
In-Reply-To: <a2a239f1-5697-cb09-5e4f-83c024fd5ea6@salutedevices.com>
Hi, sorry ping
Thanks
On 08.01.2025 15:39, Arseniy Krasnov wrote:
>
>
> On 19.12.2024 23:07, Arseniy Krasnov wrote:
>>
>>
>> On 19.12.2024 22:18, Luiz Augusto von Dentz wrote:
>>> Hi Arseniy,
>>>
>>> On Tue, Dec 17, 2024 at 3:12 AM Arseniy Krasnov
>>> <avkrasnov@salutedevices.com> wrote:
>>>>
>>>> 'hci_register_dev()' calls power up function, which is executed by
>>>> kworker - 'hci_power_on()'. This function does access to bluetooth chip
>>>> using callbacks from 'hci_ldisc.c', for example 'hci_uart_send_frame()'.
>>>> Now 'hci_uart_send_frame()' checks 'HCI_UART_PROTO_READY' bit set, and
>>>> if not - it fails. Problem is that 'HCI_UART_PROTO_READY' is set after
>>>> 'hci_register_dev()', and there is tiny chance that 'hci_power_on()' will
>>>> be executed before setting this bit. In that case HCI init logic fails.
>>>>
>>>> Patch moves setting of 'HCI_UART_PROTO_READY' before calling function
>>>> 'hci_uart_register_dev()'.
>>>>
>>>> Signed-off-by: Arseniy Krasnov <avkrasnov@salutedevices.com>
>>>> ---
>>>> Changelog v1->v2:
>>>> * Move 'set_bit()' before 'hci_uart_register_dev()' instead of
>>>> adding new bit 'HCI_UART_PROTO_INIT'.
>>>
>>> What drivers/controllers this was tested with? I want to make sure
>>> this doesn't cause regressions to other drivers if there are perhaps
>>> some drivers assuming HCI_UART_PROTO_READY was set in a certain order.
>>
>> Hi,
>>
>> I tested this on:
>>
>> CONFIG_BT=y
>> CONFIG_BT_HCIUART=y
>> CONFIG_BT_HCIUART_H4=y
>
> Hi, sorry, but is this enough info about my test env ?
>
> Thanks
>
>>
>> Yes, my v1 patchset with extra INIT bit was targeted to keep
>> original behaviour - e.g. PROTO_READY bit usage still the same,
>> just adding extra bit to handle this specific case.
>>
>> Thanks
>>
>>>
>>>> drivers/bluetooth/hci_ldisc.c | 3 ++-
>>>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/bluetooth/hci_ldisc.c b/drivers/bluetooth/hci_ldisc.c
>>>> index 30192bb083549..07b9aa09bbe2e 100644
>>>> --- a/drivers/bluetooth/hci_ldisc.c
>>>> +++ b/drivers/bluetooth/hci_ldisc.c
>>>> @@ -704,12 +704,13 @@ static int hci_uart_set_proto(struct hci_uart *hu, int id)
>>>>
>>>> hu->proto = p;
>>>>
>>>> + set_bit(HCI_UART_PROTO_READY, &hu->flags);
>>>> +
>>>> err = hci_uart_register_dev(hu);
>>>> if (err) {
>>>> return err;
>>>> }
>>>>
>>>> - set_bit(HCI_UART_PROTO_READY, &hu->flags);
>>>> return 0;
>>>> }
>>>>
>>>> --
>>>> 2.30.1
>>>
>>>
>>>
next prev parent reply other threads:[~2025-01-30 18:34 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-17 8:12 [PATCH v2] Bluetooth: hci_uart: fix race during initialization Arseniy Krasnov
2024-12-17 8:37 ` [v2] " bluez.test.bot
2024-12-19 18:42 ` [PATCH v2] " Arseniy Krasnov
2024-12-19 19:01 ` Luiz Augusto von Dentz
2024-12-19 20:07 ` Arseniy Krasnov
2024-12-19 19:18 ` Luiz Augusto von Dentz
2024-12-19 20:07 ` Arseniy Krasnov
2025-01-08 12:39 ` Arseniy Krasnov
2025-01-30 18:34 ` Arseniy Krasnov
2025-01-30 18:37 ` Luiz Augusto von Dentz
2025-01-30 18:34 ` Arseniy Krasnov [this message]
2025-01-30 18:43 ` [RESEND PATCH " Arseniy Krasnov
2025-01-30 19:01 ` [RESEND,v2] " bluez.test.bot
2025-02-03 21:40 ` [RESEND PATCH v2] " patchwork-bot+bluetooth
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=64dafad8-c4f1-d8bb-368a-239caa09a32c@salutedevices.com \
--to=avkrasnov@salutedevices.com \
--cc=kernel@salutedevices.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
--cc=oxffffaa@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox