* [RFC PATCH] Bluetooth: core: Allow bind HCI socket user channel when HCI is UP.
@ 2022-04-12 12:09 Vasyl Vavrychuk
2022-04-22 9:20 ` Marcel Holtmann
0 siblings, 1 reply; 3+ messages in thread
From: Vasyl Vavrychuk @ 2022-04-12 12:09 UTC (permalink / raw)
To: linux-kernel, netdev, linux-bluetooth
Cc: Marcel Holtmann, Johan Hedberg, Luiz Augusto von Dentz,
David S. Miller, Jakub Kicinski, Paolo Abeni, Vasyl Vavrychuk
This is needed for user-space to ensure that HCI init scheduled from
hci_register_dev is completed.
Function hci_register_dev queues power_on workqueue which will run
hci_power_on > hci_dev_do_open. Function hci_dev_do_open sets HCI_INIT
for some time.
It is not allowed to bind to HCI socket user channel when HCI_INIT is
set. As result, bind might fail when user-space program is run early
enough during boot.
Now, user-space program can first issue HCIDEVUP ioctl to ensure HCI
init scheduled at hci_register_dev was completed.
Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
---
net/bluetooth/hci_sock.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
index 33b3c0ffc339..c98de809f856 100644
--- a/net/bluetooth/hci_sock.c
+++ b/net/bluetooth/hci_sock.c
@@ -1194,9 +1194,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
if (test_bit(HCI_INIT, &hdev->flags) ||
hci_dev_test_flag(hdev, HCI_SETUP) ||
- hci_dev_test_flag(hdev, HCI_CONFIG) ||
- (!hci_dev_test_flag(hdev, HCI_AUTO_OFF) &&
- test_bit(HCI_UP, &hdev->flags))) {
+ hci_dev_test_flag(hdev, HCI_CONFIG)) {
err = -EBUSY;
hci_dev_put(hdev);
goto done;
--
2.30.2
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [RFC PATCH] Bluetooth: core: Allow bind HCI socket user channel when HCI is UP.
2022-04-12 12:09 [RFC PATCH] Bluetooth: core: Allow bind HCI socket user channel when HCI is UP Vasyl Vavrychuk
@ 2022-04-22 9:20 ` Marcel Holtmann
2022-04-26 9:24 ` Vasyl Vavrychuk
0 siblings, 1 reply; 3+ messages in thread
From: Marcel Holtmann @ 2022-04-22 9:20 UTC (permalink / raw)
To: Vasyl Vavrychuk
Cc: LKML, open list:NETWORKING [GENERAL], BlueZ, Johan Hedberg,
Luiz Augusto von Dentz, David S. Miller, Jakub Kicinski,
Paolo Abeni, Vasyl Vavrychuk
Hi Vasyl,
> This is needed for user-space to ensure that HCI init scheduled from
> hci_register_dev is completed.
>
> Function hci_register_dev queues power_on workqueue which will run
> hci_power_on > hci_dev_do_open. Function hci_dev_do_open sets HCI_INIT
> for some time.
>
> It is not allowed to bind to HCI socket user channel when HCI_INIT is
> set. As result, bind might fail when user-space program is run early
> enough during boot.
>
> Now, user-space program can first issue HCIDEVUP ioctl to ensure HCI
> init scheduled at hci_register_dev was completed.
>
> Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
> ---
> net/bluetooth/hci_sock.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
> index 33b3c0ffc339..c98de809f856 100644
> --- a/net/bluetooth/hci_sock.c
> +++ b/net/bluetooth/hci_sock.c
> @@ -1194,9 +1194,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
>
> if (test_bit(HCI_INIT, &hdev->flags) ||
> hci_dev_test_flag(hdev, HCI_SETUP) ||
> - hci_dev_test_flag(hdev, HCI_CONFIG) ||
> - (!hci_dev_test_flag(hdev, HCI_AUTO_OFF) &&
> - test_bit(HCI_UP, &hdev->flags))) {
> + hci_dev_test_flag(hdev, HCI_CONFIG)) {
> err = -EBUSY;
> hci_dev_put(hdev);
> goto done;
I am not following the reasoning here. It is true that the device has to run init before you can do something with it. From mgmt interface your device will only be announced when it is really ready.
Regards
Marcel
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [RFC PATCH] Bluetooth: core: Allow bind HCI socket user channel when HCI is UP.
2022-04-22 9:20 ` Marcel Holtmann
@ 2022-04-26 9:24 ` Vasyl Vavrychuk
0 siblings, 0 replies; 3+ messages in thread
From: Vasyl Vavrychuk @ 2022-04-26 9:24 UTC (permalink / raw)
To: Marcel Holtmann, Vasyl Vavrychuk
Cc: LKML, open list:NETWORKING [GENERAL], BlueZ, Johan Hedberg,
Luiz Augusto von Dentz, David S. Miller, Jakub Kicinski,
Paolo Abeni
Hi, Marcel,
On 4/22/2022 12:20 PM, Marcel Holtmann wrote:
> Hi Vasyl,
>
>> This is needed for user-space to ensure that HCI init scheduled from
>> hci_register_dev is completed.
>>
>> Function hci_register_dev queues power_on workqueue which will run
>> hci_power_on > hci_dev_do_open. Function hci_dev_do_open sets HCI_INIT
>> for some time.
>>
>> It is not allowed to bind to HCI socket user channel when HCI_INIT is
>> set. As result, bind might fail when user-space program is run early
>> enough during boot.
>>
>> Now, user-space program can first issue HCIDEVUP ioctl to ensure HCI
>> init scheduled at hci_register_dev was completed.
>>
>> Signed-off-by: Vasyl Vavrychuk <vasyl.vavrychuk@opensynergy.com>
>> ---
>> net/bluetooth/hci_sock.c | 4 +---
>> 1 file changed, 1 insertion(+), 3 deletions(-)
>>
>> diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
>> index 33b3c0ffc339..c98de809f856 100644
>> --- a/net/bluetooth/hci_sock.c
>> +++ b/net/bluetooth/hci_sock.c
>> @@ -1194,9 +1194,7 @@ static int hci_sock_bind(struct socket *sock, struct sockaddr *addr,
>>
>> if (test_bit(HCI_INIT, &hdev->flags) ||
>> hci_dev_test_flag(hdev, HCI_SETUP) ||
>> - hci_dev_test_flag(hdev, HCI_CONFIG) ||
>> - (!hci_dev_test_flag(hdev, HCI_AUTO_OFF) &&
>> - test_bit(HCI_UP, &hdev->flags))) {
>> + hci_dev_test_flag(hdev, HCI_CONFIG)) {
>> err = -EBUSY;
>> hci_dev_put(hdev);
>> goto done;
>
> I am not following the reasoning here. It is true that the device has to run init before you can do something with it. From mgmt interface your device will only be announced when it is really ready.
Sorry, I am not familiar with mgmt interface. I obtain device using
HCIGETDEVLIST.
BTW. I have pushed related patch [1]. Comparing to this patch, [1] is
less intrusive since it does not effect user-space semantics.
Patch [1] allows to ensure that device is not in HCI_INIT state by running
hciconfig hci0 down
This will either wait for HCI_INIT complete and then powers HCI down, or
cancels pending power_on.
If we apply [1], we can still consider an optimization to allow binding
during HCI_INIT since this optimization will allow me to ommit extra
hciconfig hci0 down
[1]:
https://lore.kernel.org/linux-bluetooth/20220426081823.21557-1-vasyl.vavrychuk@opensynergy.com/T/#u
Kind regards,
Vasyl
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-26 10:01 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-12 12:09 [RFC PATCH] Bluetooth: core: Allow bind HCI socket user channel when HCI is UP Vasyl Vavrychuk
2022-04-22 9:20 ` Marcel Holtmann
2022-04-26 9:24 ` Vasyl Vavrychuk
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox