* [PATCH] Bluetooth: L2CAP: Increase default socket buffer to hold large SDUs
@ 2026-11-10 21:42 Amir Abudubai
2026-11-10 23:56 ` bluez.test.bot
0 siblings, 1 reply; 2+ messages in thread
From: Amir Abudubai @ 2026-11-10 21:42 UTC (permalink / raw)
To: linux-bluetooth; +Cc: marcel, luiz.dentz, linux-kernel, Amir Abudubai
The L2CAP send path requires a full SDU to be assembled in the socket
buffer before transmission can begin. Therefore, the socket buffer must
be large enough to hold a worst-case SDU.
Derive the required buffer space from the worst-case parameters:
Maximum SDU plus length field: 65535 + 2 = 65537 bytes
At MPS 24: 2730 full PDUs + 17-byte tail
With 4-byte L2CAP headers: 28-byte full PDUs, 21-byte tail
At HCI MTU 27: 2730 * 2 + 1 = 5461 fragments
MPS 24 and MTU 27 are chosen because they produce the most fragmentation.
Apply a 4x safety factor because SKB_TRUESIZE can underestimate actual
usage because of class-size rounding and minimum allocations.
Signed-off-by: Amir Abudubai <amirabudubai@gmail.com>
---
The L2CAP send path deadlocks waiting for buffer space if it cannot fit
a full SDU in the send buffer. Using the system default typically causes
that to happen before the max allowed SDU. I didn't address the deadlock.
I just scaled the buffer so it is unlikely to happen unless the socket
gets resized after initialization.
include/net/bluetooth/l2cap.h | 4 ++++
net/bluetooth/l2cap_sock.c | 1 +
2 files changed, 5 insertions(+)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index 54eddcdd341f..0cf1ca4ec3cd 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -26,6 +26,7 @@
#include <linux/unaligned.h>
#include <linux/atomic.h>
+#include <linux/skbuff.h>
/* L2CAP defaults */
#define L2CAP_DEFAULT_MTU 672
@@ -41,6 +42,9 @@
#define L2CAP_DEFAULT_MAX_PDU_SIZE 1492 /* Sized for AMP packet */
#define L2CAP_DEFAULT_ACK_TO 200
#define L2CAP_DEFAULT_MAX_SDU_SIZE 0xFFFF
+#define L2CAP_MAX_SDU_FRAGS 5461 /* Sized for worst-case CoC fragmentation */
+#define L2CAP_DEFAULT_SNDBUF \
+ (4 * L2CAP_MAX_SDU_FRAGS * SKB_TRUESIZE(SKB_DATA_ALIGN(HCI_MIN_LE_MTU + BT_SKB_RESERVE)))
#define L2CAP_DEFAULT_SDU_ITIME 0xFFFFFFFF
#define L2CAP_DEFAULT_ACC_LAT 0xFFFFFFFF
#define L2CAP_BREDR_MAX_PAYLOAD 1019 /* 3-DH5 packet */
diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
index 7a2551ef7f50..5f4fde8b4a6d 100644
--- a/net/bluetooth/l2cap_sock.c
+++ b/net/bluetooth/l2cap_sock.c
@@ -2046,6 +2046,7 @@ static struct sock *l2cap_sock_alloc(struct net *net, struct socket *sock,
sk->sk_destruct = l2cap_sock_destruct;
sk->sk_sndtimeo = L2CAP_CONN_TIMEOUT;
+ sk->sk_sndbuf = L2CAP_DEFAULT_SNDBUF;
INIT_LIST_HEAD(&l2cap_pi(sk)->rx_busy);
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* RE: Bluetooth: L2CAP: Increase default socket buffer to hold large SDUs
2026-11-10 21:42 [PATCH] Bluetooth: L2CAP: Increase default socket buffer to hold large SDUs Amir Abudubai
@ 2026-11-10 23:56 ` bluez.test.bot
0 siblings, 0 replies; 2+ messages in thread
From: bluez.test.bot @ 2026-11-10 23:56 UTC (permalink / raw)
To: linux-bluetooth, amirabudubai
[-- Attachment #1: Type: text/plain, Size: 1074 bytes --]
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/series/1207660/
---Test result---
Test Summary:
CheckPatch PASS 0.67 seconds
VerifyFixes PASS 0.07 seconds
VerifySignedoff PASS 0.06 seconds
GitLint PASS 0.21 seconds
SubjectPrefix PASS 0.06 seconds
BuildKernel PASS 23.46 seconds
CheckAllWarning PASS 28.77 seconds
CheckSparse PASS 31.59 seconds
BuildKernel32 PASS 24.75 seconds
CheckKernelLLVM PASS 26.53 seconds
TestRunnerSetup PASS 574.85 seconds
TestRunner_l2cap-tester PASS 13.55 seconds
IncrementalBuild PASS 24.59 seconds
https://github.com/bluez/bluetooth-next/pull/1106
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-10 23:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-10 21:42 [PATCH] Bluetooth: L2CAP: Increase default socket buffer to hold large SDUs Amir Abudubai
2026-11-10 23:56 ` bluez.test.bot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox