Message ID | 20240102185933.64179-4-verdre@v0yd.nl |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel+bounces-14753-ouuuleilei=gmail.com@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4630323dyb; Tue, 2 Jan 2024 11:01:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IGgqLAE0mlzU3Gv/nFzEBt6L6CfuG5fiKysKhcjKbp/fPlzTvNQuL6SA4b3ujCDwp3iR4tZ X-Received: by 2002:a17:902:d5cd:b0:1d3:485a:833d with SMTP id g13-20020a170902d5cd00b001d3485a833dmr19442295plh.39.1704222095352; Tue, 02 Jan 2024 11:01:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704222095; cv=none; d=google.com; s=arc-20160816; b=RSnpBs88h3KoyXPO3EuDrF6Y31jejr2irRfMDbbCrR9xbcH8XlubqxGvqA4tm9zU1n a1bxs13i5M6VW029FNgg7nweOicBZ4X2J1qiO68+0IdOKD2JiSQDfQlu23o5RovvGCZi mgpuclkzEc3UWItL+HCZGlLc6CDo4RVs/53X/yftAD/2zLOZT1ZNUhkf6sauT7mifVh3 2SRK0gflDpbYFPMMI5kQtop5X+zqP3NJ78x3H22+tx/Vul5AM+aCBtPLAzUzKa5o1SGT 6i3tl/LTU/NcD9BETNT9dY6kyfx7qBUZ+uHvZcz38wVe6UF3RTpIeXMqQKXyPQxkOyo9 ywPA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=gooZhh7JPQWGYYCXVr4EkSSJBp4Ez14i+QXmjsCifbA=; fh=3AqDzvZy8BuFcn015+g5AB3sGQnZc/edyFwniXfpO+U=; b=aEBuqaGFxQDJoHM4ro3QO+f1Q1LBuIDSrn0yIyWFY7XrodaT/M5ilsS3v8qG8JXtNO d1XkhHeub8kJp7MCxgiA8LQt+DI8/kixuB44Y6TamAH7EQ+jEqOf/03PbAf+dIkQ8dgE Y9Ah9dhqcrLJ19VM6ff/4jm0EF4vnzxuKLPBR6WzA8FirXGI4hGgXFILcYWm1dQKqNUw Z8El6cZB3w29japrdq+KBz5cTDOLrgfSra/dtNeVPmmUbqzzxQhKrTQBBkHA+h/2eQgR rm23cV6z14Hsce6C4te5LsqhyaTqmhwiQ4KA2FE1pdeelFm/ZA8Fhw0nFUAYIvPDuQzQ UgOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14753-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14753-ouuuleilei=gmail.com@vger.kernel.org" Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id q10-20020a170902daca00b001d3c4df5004si16753413plx.151.2024.01.02.11.01.34 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 11:01:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14753-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-14753-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14753-ouuuleilei=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id AA3B0B22862 for <ouuuleilei@gmail.com>; Tue, 2 Jan 2024 19:01:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 78ABE171B6; Tue, 2 Jan 2024 18:59:47 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5A3F516415; Tue, 2 Jan 2024 18:59:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp1.mailbox.org (smtp1.mailbox.org [IPv6:2001:67c:2050:b231:465::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4T4Mbc4QNnz9sQb; Tue, 2 Jan 2024 19:59:40 +0100 (CET) From: =?utf-8?q?Jonas_Dre=C3=9Fler?= <verdre@v0yd.nl> To: Marcel Holtmann <marcel@holtmann.org>, Johan Hedberg <johan.hedberg@gmail.com>, Luiz Augusto von Dentz <luiz.dentz@gmail.com> Cc: =?utf-8?q?Jonas_Dre=C3=9Fler?= <verdre@v0yd.nl>, linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, netdev@vger.kernel.org Subject: [PATCH 3/5] Bluetooth: hci_event: Remove limit of 2 reconnection attempts Date: Tue, 2 Jan 2024 19:59:30 +0100 Message-ID: <20240102185933.64179-4-verdre@v0yd.nl> In-Reply-To: <20240102185933.64179-1-verdre@v0yd.nl> References: <20240102185933.64179-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: <linux-kernel.vger.kernel.org> List-Subscribe: <mailto:linux-kernel+subscribe@vger.kernel.org> List-Unsubscribe: <mailto:linux-kernel+unsubscribe@vger.kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4T4Mbc4QNnz9sQb X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787006387843018230 X-GMAIL-MSGID: 1787006387843018230 |
Series |
Bluetooth: Improve retrying of connection attempts
|
|
Commit Message
Jonas Dreßler
Jan. 2, 2024, 6:59 p.m. UTC
Since commit 4c67bc74f016b0d360b8573e18969c0ff7926974, we retry connecting
later when we get a "Command Disallowed" error returned by "Create
Connection".
In this commit the intention was to retry only once, and give up if we see
"Command Disallowed" again on the second try.
This made sense back then when the retry was initiated *only* from the
"Connect Complete" event. If we received that event, we knew that now the
card now must have a "free slot" for a new connection request again. These
days we call hci_conn_check_pending() from a few more places though, and
in these places we can't really be sure that there's a "free slot" on the
card, so the second try to "Create Connection" might fail again.
Deal with this by being less strict about these retries and try again
every time we get "Command Disallowed" errors, removing the limitation to
only two attempts.
Since this can potentially cause us to enter an endless cycle of
reconnection attempts, we'll add some guarding against that with the next
commit.
Signed-off-by: Jonas Dreßler <verdre@v0yd.nl>
---
net/bluetooth/hci_event.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
Comments
Hi Jonas, On Tue, Jan 2, 2024 at 1:59 PM Jonas Dreßler <verdre@v0yd.nl> wrote: > > Since commit 4c67bc74f016b0d360b8573e18969c0ff7926974, we retry connecting > later when we get a "Command Disallowed" error returned by "Create > Connection". > > In this commit the intention was to retry only once, and give up if we see > "Command Disallowed" again on the second try. > > This made sense back then when the retry was initiated *only* from the > "Connect Complete" event. If we received that event, we knew that now the > card now must have a "free slot" for a new connection request again. These > days we call hci_conn_check_pending() from a few more places though, and > in these places we can't really be sure that there's a "free slot" on the > card, so the second try to "Create Connection" might fail again. > > Deal with this by being less strict about these retries and try again > every time we get "Command Disallowed" errors, removing the limitation to > only two attempts. > > Since this can potentially cause us to enter an endless cycle of > reconnection attempts, we'll add some guarding against that with the next > commit. Don't see where you are doing such guarding, besides you seem to assume HCI_ERROR_COMMAND_DISALLOWED would always means the controller is busy, or something like that, but it could perform the connection later, but that may not always be the case, thus why I think reconnecting just a few number of times is better, if you really need to keep retrying then this needs to be controlled by a policy in userspace not hardcoded in the kernel, well I can even argument that perhaps the initial number of reconnection shall be configurable so one don't have to recompile the kernel if that needs changing. > Signed-off-by: Jonas Dreßler <verdre@v0yd.nl> > --- > net/bluetooth/hci_event.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > index e8b4a0126..e1f5b6f90 100644 > --- a/net/bluetooth/hci_event.c > +++ b/net/bluetooth/hci_event.c > @@ -2323,12 +2323,13 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) > > if (status) { > if (conn && conn->state == BT_CONNECT) { > - if (status != HCI_ERROR_COMMAND_DISALLOWED || conn->attempt > 2) { > + if (status == HCI_ERROR_COMMAND_DISALLOWED) { > + conn->state = BT_CONNECT2; > + } else { > conn->state = BT_CLOSED; > hci_connect_cfm(conn, status); > hci_conn_del(conn); > - } else > - conn->state = BT_CONNECT2; > + } > } > } else { > if (!conn) { > -- > 2.43.0 >
Hi Luiz, On 1/3/24 17:05, Luiz Augusto von Dentz wrote: > Hi Jonas, > > On Tue, Jan 2, 2024 at 1:59 PM Jonas Dreßler <verdre@v0yd.nl> wrote: >> >> Since commit 4c67bc74f016b0d360b8573e18969c0ff7926974, we retry connecting >> later when we get a "Command Disallowed" error returned by "Create >> Connection". >> >> In this commit the intention was to retry only once, and give up if we see >> "Command Disallowed" again on the second try. >> >> This made sense back then when the retry was initiated *only* from the >> "Connect Complete" event. If we received that event, we knew that now the >> card now must have a "free slot" for a new connection request again. These >> days we call hci_conn_check_pending() from a few more places though, and >> in these places we can't really be sure that there's a "free slot" on the >> card, so the second try to "Create Connection" might fail again. >> >> Deal with this by being less strict about these retries and try again >> every time we get "Command Disallowed" errors, removing the limitation to >> only two attempts. >> >> Since this can potentially cause us to enter an endless cycle of >> reconnection attempts, we'll add some guarding against that with the next >> commit. > > Don't see where you are doing such guarding, besides you seem to > assume HCI_ERROR_COMMAND_DISALLOWED would always means the controller > is busy, or something like that, but it could perform the connection > later, but that may not always be the case, thus why I think > reconnecting just a few number of times is better, if you really need > to keep retrying then this needs to be controlled by a policy in > userspace not hardcoded in the kernel, well I can even argument that > perhaps the initial number of reconnection shall be configurable so > one don't have to recompile the kernel if that needs changing. Yes, fair enough, the next commit assumes that COMMAND_DISALLOWED always means busy. The guarding is that we stop retrying as soon as there's no (competing) ongoing connection attempt nor an active inquiry, which should eventually be the case no matter what, no? I agree it's probably still better to not rely on this fairly complex sanity check and keep the checking of attempts nonetheless. I think we could keep doing that if we check for !hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT) && !test_bit(HCI_INQUIRY, &hdev->flags) in hci_conn_check_pending() before we actually retry, to make sure the retry counter doesn't get incremented wrongly. I'll give that a try. > >> Signed-off-by: Jonas Dreßler <verdre@v0yd.nl> >> --- >> net/bluetooth/hci_event.c | 7 ++++--- >> 1 file changed, 4 insertions(+), 3 deletions(-) >> >> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c >> index e8b4a0126..e1f5b6f90 100644 >> --- a/net/bluetooth/hci_event.c >> +++ b/net/bluetooth/hci_event.c >> @@ -2323,12 +2323,13 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) >> >> if (status) { >> if (conn && conn->state == BT_CONNECT) { >> - if (status != HCI_ERROR_COMMAND_DISALLOWED || conn->attempt > 2) { >> + if (status == HCI_ERROR_COMMAND_DISALLOWED) { >> + conn->state = BT_CONNECT2; >> + } else { >> conn->state = BT_CLOSED; >> hci_connect_cfm(conn, status); >> hci_conn_del(conn); >> - } else >> - conn->state = BT_CONNECT2; >> + } >> } >> } else { >> if (!conn) { >> -- >> 2.43.0 >> > > Cheers, Jonas
Hi Jonas, On Fri, Jan 5, 2024 at 10:54 AM Jonas Dreßler <verdre@v0yd.nl> wrote: > > Hi Luiz, > > On 1/3/24 17:05, Luiz Augusto von Dentz wrote: > > Hi Jonas, > > > > On Tue, Jan 2, 2024 at 1:59 PM Jonas Dreßler <verdre@v0yd.nl> wrote: > >> > >> Since commit 4c67bc74f016b0d360b8573e18969c0ff7926974, we retry connecting > >> later when we get a "Command Disallowed" error returned by "Create > >> Connection". > >> > >> In this commit the intention was to retry only once, and give up if we see > >> "Command Disallowed" again on the second try. > >> > >> This made sense back then when the retry was initiated *only* from the > >> "Connect Complete" event. If we received that event, we knew that now the > >> card now must have a "free slot" for a new connection request again. These > >> days we call hci_conn_check_pending() from a few more places though, and > >> in these places we can't really be sure that there's a "free slot" on the > >> card, so the second try to "Create Connection" might fail again. > >> > >> Deal with this by being less strict about these retries and try again > >> every time we get "Command Disallowed" errors, removing the limitation to > >> only two attempts. > >> > >> Since this can potentially cause us to enter an endless cycle of > >> reconnection attempts, we'll add some guarding against that with the next > >> commit. > > > > Don't see where you are doing such guarding, besides you seem to > > assume HCI_ERROR_COMMAND_DISALLOWED would always means the controller > > is busy, or something like that, but it could perform the connection > > later, but that may not always be the case, thus why I think > > reconnecting just a few number of times is better, if you really need > > to keep retrying then this needs to be controlled by a policy in > > userspace not hardcoded in the kernel, well I can even argument that > > perhaps the initial number of reconnection shall be configurable so > > one don't have to recompile the kernel if that needs changing. > > Yes, fair enough, the next commit assumes that COMMAND_DISALLOWED always > means busy. The guarding is that we stop retrying as soon as there's no > (competing) ongoing connection attempt nor an active inquiry, which > should eventually be the case no matter what, no? > > I agree it's probably still better to not rely on this fairly complex > sanity check and keep the checking of attempts nonetheless. > > I think we could keep doing that if we check for > !hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT) && > !test_bit(HCI_INQUIRY, &hdev->flags) in hci_conn_check_pending() before > we actually retry, to make sure the retry counter doesn't get > incremented wrongly. I'll give that a try. Perhaps I'm missing something, but it should be possible to block concurrent access to HCI while a command is pending with use of hci_cmd_sync, at least on LE we do that by waiting the connection complete event so connection attempts are serialized but we don't seem to be doing the same for BR/EDR. > > > >> Signed-off-by: Jonas Dreßler <verdre@v0yd.nl> > >> --- > >> net/bluetooth/hci_event.c | 7 ++++--- > >> 1 file changed, 4 insertions(+), 3 deletions(-) > >> > >> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > >> index e8b4a0126..e1f5b6f90 100644 > >> --- a/net/bluetooth/hci_event.c > >> +++ b/net/bluetooth/hci_event.c > >> @@ -2323,12 +2323,13 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) > >> > >> if (status) { > >> if (conn && conn->state == BT_CONNECT) { > >> - if (status != HCI_ERROR_COMMAND_DISALLOWED || conn->attempt > 2) { > >> + if (status == HCI_ERROR_COMMAND_DISALLOWED) { > >> + conn->state = BT_CONNECT2; > >> + } else { > >> conn->state = BT_CLOSED; > >> hci_connect_cfm(conn, status); > >> hci_conn_del(conn); > >> - } else > >> - conn->state = BT_CONNECT2; > >> + } > >> } > >> } else { > >> if (!conn) { > >> -- > >> 2.43.0 > >> > > > > > > Cheers, > Jonas -- Luiz Augusto von Dentz
Hi Luiz, On 1/5/24 17:05, Luiz Augusto von Dentz wrote: > Hi Jonas, > > On Fri, Jan 5, 2024 at 10:54 AM Jonas Dreßler <verdre@v0yd.nl> wrote: >> >> Hi Luiz, >> >> On 1/3/24 17:05, Luiz Augusto von Dentz wrote: >>> Hi Jonas, >>> >>> On Tue, Jan 2, 2024 at 1:59 PM Jonas Dreßler <verdre@v0yd.nl> wrote: >>>> >>>> Since commit 4c67bc74f016b0d360b8573e18969c0ff7926974, we retry connecting >>>> later when we get a "Command Disallowed" error returned by "Create >>>> Connection". >>>> >>>> In this commit the intention was to retry only once, and give up if we see >>>> "Command Disallowed" again on the second try. >>>> >>>> This made sense back then when the retry was initiated *only* from the >>>> "Connect Complete" event. If we received that event, we knew that now the >>>> card now must have a "free slot" for a new connection request again. These >>>> days we call hci_conn_check_pending() from a few more places though, and >>>> in these places we can't really be sure that there's a "free slot" on the >>>> card, so the second try to "Create Connection" might fail again. >>>> >>>> Deal with this by being less strict about these retries and try again >>>> every time we get "Command Disallowed" errors, removing the limitation to >>>> only two attempts. >>>> >>>> Since this can potentially cause us to enter an endless cycle of >>>> reconnection attempts, we'll add some guarding against that with the next >>>> commit. >>> >>> Don't see where you are doing such guarding, besides you seem to >>> assume HCI_ERROR_COMMAND_DISALLOWED would always means the controller >>> is busy, or something like that, but it could perform the connection >>> later, but that may not always be the case, thus why I think >>> reconnecting just a few number of times is better, if you really need >>> to keep retrying then this needs to be controlled by a policy in >>> userspace not hardcoded in the kernel, well I can even argument that >>> perhaps the initial number of reconnection shall be configurable so >>> one don't have to recompile the kernel if that needs changing. >> >> Yes, fair enough, the next commit assumes that COMMAND_DISALLOWED always >> means busy. The guarding is that we stop retrying as soon as there's no >> (competing) ongoing connection attempt nor an active inquiry, which >> should eventually be the case no matter what, no? >> >> I agree it's probably still better to not rely on this fairly complex >> sanity check and keep the checking of attempts nonetheless. >> >> I think we could keep doing that if we check for >> !hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT) && >> !test_bit(HCI_INQUIRY, &hdev->flags) in hci_conn_check_pending() before >> we actually retry, to make sure the retry counter doesn't get >> incremented wrongly. I'll give that a try. > > Perhaps I'm missing something, but it should be possible to block > concurrent access to HCI while a command is pending with use of > hci_cmd_sync, at least on LE we do that by waiting the connection > complete event so connection attempts are serialized but we don't seem > to be doing the same for BR/EDR. > That's a good point, it might even allow for a nice little cleanup because we can then cancel inquiries in hci_acl_create_connection() synchronously, too. Question is just whether there's any devices out there that actually do support paging with more than a single device at a time and if we want to support that? > >>> >>>> Signed-off-by: Jonas Dreßler <verdre@v0yd.nl> >>>> --- >>>> net/bluetooth/hci_event.c | 7 ++++--- >>>> 1 file changed, 4 insertions(+), 3 deletions(-) >>>> >>>> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c >>>> index e8b4a0126..e1f5b6f90 100644 >>>> --- a/net/bluetooth/hci_event.c >>>> +++ b/net/bluetooth/hci_event.c >>>> @@ -2323,12 +2323,13 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) >>>> >>>> if (status) { >>>> if (conn && conn->state == BT_CONNECT) { >>>> - if (status != HCI_ERROR_COMMAND_DISALLOWED || conn->attempt > 2) { >>>> + if (status == HCI_ERROR_COMMAND_DISALLOWED) { >>>> + conn->state = BT_CONNECT2; >>>> + } else { >>>> conn->state = BT_CLOSED; >>>> hci_connect_cfm(conn, status); >>>> hci_conn_del(conn); >>>> - } else >>>> - conn->state = BT_CONNECT2; >>>> + } >>>> } >>>> } else { >>>> if (!conn) { >>>> -- >>>> 2.43.0 >>>> >>> >>> >> >> Cheers, >> Jonas > > > > -- > Luiz Augusto von Dentz
Hi Jonas, On Sun, Jan 7, 2024 at 5:20 PM Jonas Dreßler <verdre@v0yd.nl> wrote: > > Hi Luiz, > > On 1/5/24 17:05, Luiz Augusto von Dentz wrote: > > Hi Jonas, > > > > On Fri, Jan 5, 2024 at 10:54 AM Jonas Dreßler <verdre@v0yd.nl> wrote: > >> > >> Hi Luiz, > >> > >> On 1/3/24 17:05, Luiz Augusto von Dentz wrote: > >>> Hi Jonas, > >>> > >>> On Tue, Jan 2, 2024 at 1:59 PM Jonas Dreßler <verdre@v0yd.nl> wrote: > >>>> > >>>> Since commit 4c67bc74f016b0d360b8573e18969c0ff7926974, we retry connecting > >>>> later when we get a "Command Disallowed" error returned by "Create > >>>> Connection". > >>>> > >>>> In this commit the intention was to retry only once, and give up if we see > >>>> "Command Disallowed" again on the second try. > >>>> > >>>> This made sense back then when the retry was initiated *only* from the > >>>> "Connect Complete" event. If we received that event, we knew that now the > >>>> card now must have a "free slot" for a new connection request again. These > >>>> days we call hci_conn_check_pending() from a few more places though, and > >>>> in these places we can't really be sure that there's a "free slot" on the > >>>> card, so the second try to "Create Connection" might fail again. > >>>> > >>>> Deal with this by being less strict about these retries and try again > >>>> every time we get "Command Disallowed" errors, removing the limitation to > >>>> only two attempts. > >>>> > >>>> Since this can potentially cause us to enter an endless cycle of > >>>> reconnection attempts, we'll add some guarding against that with the next > >>>> commit. > >>> > >>> Don't see where you are doing such guarding, besides you seem to > >>> assume HCI_ERROR_COMMAND_DISALLOWED would always means the controller > >>> is busy, or something like that, but it could perform the connection > >>> later, but that may not always be the case, thus why I think > >>> reconnecting just a few number of times is better, if you really need > >>> to keep retrying then this needs to be controlled by a policy in > >>> userspace not hardcoded in the kernel, well I can even argument that > >>> perhaps the initial number of reconnection shall be configurable so > >>> one don't have to recompile the kernel if that needs changing. > >> > >> Yes, fair enough, the next commit assumes that COMMAND_DISALLOWED always > >> means busy. The guarding is that we stop retrying as soon as there's no > >> (competing) ongoing connection attempt nor an active inquiry, which > >> should eventually be the case no matter what, no? > >> > >> I agree it's probably still better to not rely on this fairly complex > >> sanity check and keep the checking of attempts nonetheless. > >> > >> I think we could keep doing that if we check for > >> !hci_conn_hash_lookup_state(hdev, ACL_LINK, BT_CONNECT) && > >> !test_bit(HCI_INQUIRY, &hdev->flags) in hci_conn_check_pending() before > >> we actually retry, to make sure the retry counter doesn't get > >> incremented wrongly. I'll give that a try. > > > > Perhaps I'm missing something, but it should be possible to block > > concurrent access to HCI while a command is pending with use of > > hci_cmd_sync, at least on LE we do that by waiting the connection > > complete event so connection attempts are serialized but we don't seem > > to be doing the same for BR/EDR. > > > > That's a good point, it might even allow for a nice little cleanup > because we can then cancel inquiries in hci_acl_create_connection() > synchronously, too. > > Question is just whether there's any devices out there that actually do > support paging with more than a single device at a time and if we want > to support that? I think the controller would serialize the paging anyway, so the fact that we would serialize it on the host side might actually means that we have a common behavior across controllers rather than having to handle errors when the controller is not capable of serializing connections by themselves. > > > >>> > >>>> Signed-off-by: Jonas Dreßler <verdre@v0yd.nl> > >>>> --- > >>>> net/bluetooth/hci_event.c | 7 ++++--- > >>>> 1 file changed, 4 insertions(+), 3 deletions(-) > >>>> > >>>> diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > >>>> index e8b4a0126..e1f5b6f90 100644 > >>>> --- a/net/bluetooth/hci_event.c > >>>> +++ b/net/bluetooth/hci_event.c > >>>> @@ -2323,12 +2323,13 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) > >>>> > >>>> if (status) { > >>>> if (conn && conn->state == BT_CONNECT) { > >>>> - if (status != HCI_ERROR_COMMAND_DISALLOWED || conn->attempt > 2) { > >>>> + if (status == HCI_ERROR_COMMAND_DISALLOWED) { > >>>> + conn->state = BT_CONNECT2; > >>>> + } else { > >>>> conn->state = BT_CLOSED; > >>>> hci_connect_cfm(conn, status); > >>>> hci_conn_del(conn); > >>>> - } else > >>>> - conn->state = BT_CONNECT2; > >>>> + } > >>>> } > >>>> } else { > >>>> if (!conn) { > >>>> -- > >>>> 2.43.0 > >>>> > >>> > >>> > >> > >> Cheers, > >> Jonas > > > > > > > > -- > > Luiz Augusto von Dentz
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index e8b4a0126..e1f5b6f90 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -2323,12 +2323,13 @@ static void hci_cs_create_conn(struct hci_dev *hdev, __u8 status) if (status) { if (conn && conn->state == BT_CONNECT) { - if (status != HCI_ERROR_COMMAND_DISALLOWED || conn->attempt > 2) { + if (status == HCI_ERROR_COMMAND_DISALLOWED) { + conn->state = BT_CONNECT2; + } else { conn->state = BT_CLOSED; hci_connect_cfm(conn, status); hci_conn_del(conn); - } else - conn->state = BT_CONNECT2; + } } } else { if (!conn) {