2024-02-07 20:39:51

by Luiz Augusto von Dentz

[permalink] [raw]
Subject: [PATCH v1] Bluetooth: hci_conn: Always use sk_timeo as conn_timeout

From: Luiz Augusto von Dentz <[email protected]>

This aligns the use socket sk_timeo as conn_timeout when initiating a
connection and then use it when scheduling the resulting HCI command,
that way the command is actually aborted synchronously thus not
blocking commands generated by hci_abort_conn_sync to inform the
controller the connection is to be aborted.

Signed-off-by: Luiz Augusto von Dentz <[email protected]>
---
include/net/bluetooth/hci_core.h | 5 +++--
include/net/bluetooth/l2cap.h | 2 +-
net/bluetooth/hci_conn.c | 8 +++++---
net/bluetooth/hci_sync.c | 2 +-
net/bluetooth/l2cap_core.c | 10 ++++------
net/bluetooth/l2cap_sock.c | 3 ++-
net/bluetooth/mgmt.c | 3 ++-
net/bluetooth/sco.c | 3 ++-
8 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 34aa9d0290fe..2bdea85b7c44 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1495,9 +1495,10 @@ struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst,
u16 conn_timeout, u8 role);
struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
u8 sec_level, u8 auth_type,
- enum conn_reasons conn_reason);
+ enum conn_reasons conn_reason, u16 timeout);
struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
- __u16 setting, struct bt_codec *codec);
+ __u16 setting, struct bt_codec *codec,
+ u16 timeout);
struct hci_conn *hci_bind_cis(struct hci_dev *hdev, bdaddr_t *dst,
__u8 dst_type, struct bt_iso_qos *qos);
struct hci_conn *hci_bind_bis(struct hci_dev *hdev, bdaddr_t *dst,
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 92d7197f9a56..a4278aa618ab 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -939,7 +939,7 @@ int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid);
struct l2cap_chan *l2cap_chan_create(void);
void l2cap_chan_close(struct l2cap_chan *chan, int reason);
int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
- bdaddr_t *dst, u8 dst_type);
+ bdaddr_t *dst, u8 dst_type, u16 timeout);
int l2cap_chan_reconfigure(struct l2cap_chan *chan, __u16 mtu);
int l2cap_chan_send(struct l2cap_chan *chan, struct msghdr *msg, size_t len);
void l2cap_chan_busy(struct l2cap_chan *chan, int busy);
diff --git a/net/bluetooth/hci_conn.c b/net/bluetooth/hci_conn.c
index a4beed8587eb..8164502234c5 100644
--- a/net/bluetooth/hci_conn.c
+++ b/net/bluetooth/hci_conn.c
@@ -1607,7 +1607,7 @@ struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst,

struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
u8 sec_level, u8 auth_type,
- enum conn_reasons conn_reason)
+ enum conn_reasons conn_reason, u16 timeout)
{
struct hci_conn *acl;

@@ -1643,6 +1643,7 @@ struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst,
acl->sec_level = BT_SECURITY_LOW;
acl->pending_sec_level = sec_level;
acl->auth_type = auth_type;
+ acl->conn_timeout = timeout;

err = hci_acl_create_connection_sync(hdev, acl);
if (err) {
@@ -1683,14 +1684,15 @@ static struct hci_link *hci_conn_link(struct hci_conn *parent,
}

struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst,
- __u16 setting, struct bt_codec *codec)
+ __u16 setting, struct bt_codec *codec,
+ u16 timeout)
{
struct hci_conn *acl;
struct hci_conn *sco;
struct hci_link *link;

acl = hci_connect_acl(hdev, dst, BT_SECURITY_LOW, HCI_AT_NO_BONDING,
- CONN_REASON_SCO_CONNECT);
+ CONN_REASON_SCO_CONNECT, timeout);
if (IS_ERR(acl))
return acl;

diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c
index 617407b81ffe..788a889210d8 100644
--- a/net/bluetooth/hci_sync.c
+++ b/net/bluetooth/hci_sync.c
@@ -6548,7 +6548,7 @@ static int __hci_acl_create_connection_sync(struct hci_dev *hdev, void *data)
err = __hci_cmd_sync_status_sk(hdev, HCI_OP_CREATE_CONN,
sizeof(cp), &cp,
HCI_EV_CONN_COMPLETE,
- HCI_ACL_CONN_TIMEOUT, NULL);
+ conn->conn_timeout, NULL);

if (err == -ETIMEDOUT)
hci_abort_conn_sync(hdev, conn, HCI_ERROR_LOCAL_HOST_TERM);
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index ab5a9d42fae7..467b242d8be0 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -6925,7 +6925,7 @@ static void l2cap_chan_by_pid(struct l2cap_chan *chan, void *data)
}

int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
- bdaddr_t *dst, u8 dst_type)
+ bdaddr_t *dst, u8 dst_type, u16 timeout)
{
struct l2cap_conn *conn;
struct hci_conn *hcon;
@@ -7018,19 +7018,17 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,

if (hci_dev_test_flag(hdev, HCI_ADVERTISING))
hcon = hci_connect_le(hdev, dst, dst_type, false,
- chan->sec_level,
- HCI_LE_CONN_TIMEOUT,
+ chan->sec_level, timeout,
HCI_ROLE_SLAVE);
else
hcon = hci_connect_le_scan(hdev, dst, dst_type,
- chan->sec_level,
- HCI_LE_CONN_TIMEOUT,
+ chan->sec_level, timeout,
CONN_REASON_L2CAP_CHAN);

} else {
u8 auth_type = l2cap_get_auth_type(chan);
hcon = hci_connect_acl(hdev, dst, chan->sec_level, auth_type,
- CONN_REASON_L2CAP_CHAN);
+ CONN_REASON_L2CAP_CHAN, timeout);
}

if (IS_ERR(hcon)) {
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index ee7a41d6994f..4287aa6cc988 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -254,7 +254,8 @@ static int l2cap_sock_connect(struct socket *sock, struct sockaddr *addr,
chan->mode = L2CAP_MODE_LE_FLOWCTL;

err = l2cap_chan_connect(chan, la.l2_psm, __le16_to_cpu(la.l2_cid),
- &la.l2_bdaddr, la.l2_bdaddr_type);
+ &la.l2_bdaddr, la.l2_bdaddr_type,
+ sk->sk_sndtimeo);
if (err)
return err;

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index 064a67157d43..78ab562807d0 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3444,7 +3444,8 @@ static int pair_device(struct sock *sk, struct hci_dev *hdev, void *data,

if (cp->addr.type == BDADDR_BREDR) {
conn = hci_connect_acl(hdev, &cp->addr.bdaddr, sec_level,
- auth_type, CONN_REASON_PAIR_DEVICE);
+ auth_type, CONN_REASON_PAIR_DEVICE,
+ HCI_ACL_CONN_TIMEOUT);
} else {
u8 addr_type = le_addr_type(cp->addr.type);
struct hci_conn_params *p;
diff --git a/net/bluetooth/sco.c b/net/bluetooth/sco.c
index c736186aba26..43daf965a01e 100644
--- a/net/bluetooth/sco.c
+++ b/net/bluetooth/sco.c
@@ -264,7 +264,8 @@ static int sco_connect(struct sock *sk)
}

hcon = hci_connect_sco(hdev, type, &sco_pi(sk)->dst,
- sco_pi(sk)->setting, &sco_pi(sk)->codec);
+ sco_pi(sk)->setting, &sco_pi(sk)->codec,
+ sk->sk_sndtimeo);
if (IS_ERR(hcon)) {
err = PTR_ERR(hcon);
goto unlock;
--
2.43.0



2024-02-07 22:09:14

by bluez.test.bot

[permalink] [raw]
Subject: RE: [v1] Bluetooth: hci_conn: Always use sk_timeo as conn_timeout

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=824105

---Test result---

Test Summary:
CheckPatch PASS 1.95 seconds
GitLint PASS 0.34 seconds
SubjectPrefix PASS 0.13 seconds
BuildKernel FAIL 28.25 seconds
CheckAllWarning FAIL 31.16 seconds
CheckSparse FAIL 36.41 seconds
CheckSmatch FAIL 97.95 seconds
BuildKernel32 FAIL 27.67 seconds
TestRunnerSetup PASS 508.73 seconds
TestRunner_l2cap-tester FAIL 12.37 seconds
TestRunner_iso-tester PASS 33.24 seconds
TestRunner_bnep-tester PASS 4.90 seconds
TestRunner_mgmt-tester FAIL 174.90 seconds
TestRunner_rfcomm-tester PASS 7.51 seconds
TestRunner_sco-tester PASS 18.24 seconds
TestRunner_ioctl-tester PASS 8.06 seconds
TestRunner_mesh-tester PASS 6.06 seconds
TestRunner_smp-tester PASS 7.06 seconds
TestRunner_userchan-tester PASS 5.15 seconds
IncrementalBuild FAIL 26.92 seconds

Details
##############################
Test: BuildKernel - FAIL
Desc: Build Kernel for Bluetooth
Output:

net/bluetooth/6lowpan.c: In function ‘bt_6lowpan_connect’:
net/bluetooth/6lowpan.c:894:8: error: too few arguments to function ‘l2cap_chan_connect’
894 | err = l2cap_chan_connect(chan, cpu_to_le16(L2CAP_PSM_IPSP), 0,
| ^~~~~~~~~~~~~~~~~~
In file included from net/bluetooth/6lowpan.c:20:
./include/net/bluetooth/l2cap.h:941:5: note: declared here
941 | int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
| ^~~~~~~~~~~~~~~~~~
make[4]: *** [scripts/Makefile.build:243: net/bluetooth/6lowpan.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:481: net/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:481: net] Error 2
make[1]: *** [/github/workspace/src/src/Makefile:1921: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2
##############################
Test: CheckAllWarning - FAIL
Desc: Run linux kernel with all warning enabled
Output:

net/bluetooth/6lowpan.c: In function ‘bt_6lowpan_connect’:
net/bluetooth/6lowpan.c:894:8: error: too few arguments to function ‘l2cap_chan_connect’
894 | err = l2cap_chan_connect(chan, cpu_to_le16(L2CAP_PSM_IPSP), 0,
| ^~~~~~~~~~~~~~~~~~
In file included from net/bluetooth/6lowpan.c:20:
./include/net/bluetooth/l2cap.h:941:5: note: declared here
941 | int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
| ^~~~~~~~~~~~~~~~~~
make[4]: *** [scripts/Makefile.build:243: net/bluetooth/6lowpan.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:481: net/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:481: net] Error 2
make[1]: *** [/github/workspace/src/src/Makefile:1921: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2
##############################
Test: CheckSparse - FAIL
Desc: Run sparse tool with linux kernel
Output:

net/bluetooth/af_bluetooth.c:223:25: warning: context imbalance in 'bt_accept_enqueue' - different lock contexts for basic block
drivers/bluetooth/hci_ag6xx.c:257:24: warning: restricted __le32 degrades to integer
drivers/bluetooth/hci_mrvl.c:170:23: warning: restricted __le16 degrades to integer
drivers/bluetooth/hci_mrvl.c:203:23: warning: restricted __le16 degrades to integer
net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
./include/net/bluetooth/hci.h:2673:47: warning: array of flexible structures
./include/net/bluetooth/hci.h:2759:43: warning: array of flexible structures
drivers/bluetooth/hci_nokia.c:284:23: warning: incorrect type in assignment (different base types)
drivers/bluetooth/hci_nokia.c:284:23: expected unsigned short [usertype] baud
drivers/bluetooth/hci_nokia.c:284:23: got restricted __le16 [usertype]
drivers/bluetooth/hci_nokia.c:287:26: warning: incorrect type in assignment (different base types)
drivers/bluetooth/hci_nokia.c:287:26: expected unsigned short [usertype] sys_clk
drivers/bluetooth/hci_nokia.c:287:26: got restricted __le16 [usertype]
net/bluetooth/hci_codec.c: note: in included file:
./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures
net/bluetooth/sco.c: note: in included file:
./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures
net/bluetooth/6lowpan.c: In function ‘bt_6lowpan_connect’:
net/bluetooth/6lowpan.c:894:8: error: too few arguments to function ‘l2cap_chan_connect’
894 | err = l2cap_chan_connect(chan, cpu_to_le16(L2CAP_PSM_IPSP), 0,
| ^~~~~~~~~~~~~~~~~~
In file included from net/bluetooth/6lowpan.c:20:
./include/net/bluetooth/l2cap.h:941:5: note: declared here
941 | int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
| ^~~~~~~~~~~~~~~~~~
make[4]: *** [scripts/Makefile.build:243: net/bluetooth/6lowpan.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:481: net/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:481: net] Error 2
make[1]: *** [/github/workspace/src/src/Makefile:1921: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2
##############################
Test: CheckSmatch - FAIL
Desc: Run smatch tool with source
Output:

net/bluetooth/hci_event.c: note: in included file (through include/net/bluetooth/hci_core.h):
./include/net/bluetooth/hci.h:2673:47: warning: array of flexible structures
./include/net/bluetooth/hci.h:2759:43: warning: array of flexible structures
net/bluetooth/hci_codec.c: note: in included file:
./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures
net/bluetooth/sco.c: note: in included file:
./include/net/bluetooth/hci_core.h:150:35: warning: array of flexible structures
net/bluetooth/6lowpan.c: In function ‘bt_6lowpan_connect’:
net/bluetooth/6lowpan.c:894:8: error: too few arguments to function ‘l2cap_chan_connect’
894 | err = l2cap_chan_connect(chan, cpu_to_le16(L2CAP_PSM_IPSP), 0,
| ^~~~~~~~~~~~~~~~~~
In file included from net/bluetooth/6lowpan.c:20:
./include/net/bluetooth/l2cap.h:941:5: note: declared here
941 | int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
| ^~~~~~~~~~~~~~~~~~
make[4]: *** [scripts/Makefile.build:243: net/bluetooth/6lowpan.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:481: net/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:481: net] Error 2
make[1]: *** [/github/workspace/src/src/Makefile:1921: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2
##############################
Test: BuildKernel32 - FAIL
Desc: Build 32bit Kernel for Bluetooth
Output:

net/bluetooth/6lowpan.c: In function ‘bt_6lowpan_connect’:
net/bluetooth/6lowpan.c:894:8: error: too few arguments to function ‘l2cap_chan_connect’
894 | err = l2cap_chan_connect(chan, cpu_to_le16(L2CAP_PSM_IPSP), 0,
| ^~~~~~~~~~~~~~~~~~
In file included from net/bluetooth/6lowpan.c:20:
./include/net/bluetooth/l2cap.h:941:5: note: declared here
941 | int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
| ^~~~~~~~~~~~~~~~~~
make[4]: *** [scripts/Makefile.build:243: net/bluetooth/6lowpan.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:481: net/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:481: net] Error 2
make[1]: *** [/github/workspace/src/src/Makefile:1921: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2
##############################
Test: TestRunner_l2cap-tester - FAIL
Desc: Run l2cap-tester with test-runner
Output:
No test result found
##############################
Test: TestRunner_mgmt-tester - FAIL
Desc: Run mgmt-tester with test-runner
Output:
Total: 497, Passed: 490 (98.6%), Failed: 1, Not Run: 6

Failed Test Cases
LL Privacy - Remove Device 2 (Remove from RL) Timed out 2.422 seconds
##############################
Test: IncrementalBuild - FAIL
Desc: Incremental build with the patches in the series
Output:
[v1] Bluetooth: hci_conn: Always use sk_timeo as conn_timeout

net/bluetooth/6lowpan.c: In function ‘bt_6lowpan_connect’:
net/bluetooth/6lowpan.c:894:8: error: too few arguments to function ‘l2cap_chan_connect’
894 | err = l2cap_chan_connect(chan, cpu_to_le16(L2CAP_PSM_IPSP), 0,
| ^~~~~~~~~~~~~~~~~~
In file included from net/bluetooth/6lowpan.c:20:
./include/net/bluetooth/l2cap.h:941:5: note: declared here
941 | int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
| ^~~~~~~~~~~~~~~~~~
make[4]: *** [scripts/Makefile.build:243: net/bluetooth/6lowpan.o] Error 1
make[4]: *** Waiting for unfinished jobs....
make[3]: *** [scripts/Makefile.build:481: net/bluetooth] Error 2
make[2]: *** [scripts/Makefile.build:481: net] Error 2
make[1]: *** [/github/workspace/src/src/Makefile:1921: .] Error 2
make: *** [Makefile:240: __sub-make] Error 2


---
Regards,
Linux Bluetooth