From: Cen Zhang <zzzccc427@gmail.com>
To: marcel@holtmann.org, luiz.dentz@gmail.com
Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org,
baijiaju1990@gmail.com, jjzuming@gmail.com, zzzccc427@gmail.com
Subject: [PATCH v5 1/4] Bluetooth: SMP: Publish root channels after initialization
Date: Thu, 19 Nov 2026 08:33:40 +0800 [thread overview]
Message-ID: <pm-bluetooth-objects-candidate-0184-v12-e80229724d6ad14ca88c-1@gmail.com> (raw)
In-Reply-To: <pm-bluetooth-objects-candidate-0184-v12-e80229724d6ad14ca88c-0@gmail.com>
smp_add_cid() marks a channel as fixed before setting its operations,
address and parent nesting level. Once it also sets BT_LISTEN, a global
fixed-channel lookup can select it before the remaining stores finish:
Controller A Controller B with the same address
smp_add_cid()
l2cap_add_scid()
chan->state = BT_LISTEN
l2cap_global_fixed_chan()
select A's root
l2cap_new_connection()
call chan->ops->new_connection
chan->ops = &smp_root_chan_ops
A per-controller mutex cannot exclude the second controller. Finish
initializing the listener before setting BT_LISTEN, and serialize that
state change with global lookups through chan_list_lock. Keep the fixed
channel type assigned before publishing BT_LISTEN so connection-oriented
PSM lookups cannot select an untyped channel in between.
Fixes: 70db83c4bcdc ("Bluetooth: Add SMP L2CAP channel skeleton")
Signed-off-by: Cen Zhang <zzzccc427@gmail.com>
---
include/net/bluetooth/l2cap.h | 1 +
net/bluetooth/l2cap_core.c | 8 ++++++++
net/bluetooth/smp.c | 3 ++-
3 files changed, 11 insertions(+), 1 deletion(-)
diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
index cf5c2df68af8c..e3d826772db66 100644
--- a/include/net/bluetooth/l2cap.h
+++ b/include/net/bluetooth/l2cap.h
@@ -982,6 +982,7 @@ int l2cap_add_psm(struct l2cap_chan *chan, bdaddr_t *src, __le16 psm);
int l2cap_add_scid(struct l2cap_chan *chan, __u16 scid);
struct l2cap_chan *l2cap_chan_create(void);
+void l2cap_chan_listen(struct l2cap_chan *chan);
void l2cap_chan_close_unlocked(struct l2cap_chan *chan, int reason)
__must_not_hold(&chan->lock);
int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid,
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index 0d4f3341bd47f..319016eff9689 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -456,6 +456,14 @@ static void l2cap_chan_timeout(struct work_struct *work)
l2cap_chan_put(chan);
}
+/* Publish a fully initialized listener to global channel lookups. */
+void l2cap_chan_listen(struct l2cap_chan *chan)
+{
+ write_lock(&chan_list_lock);
+ chan->state = BT_LISTEN;
+ write_unlock(&chan_list_lock);
+}
+
struct l2cap_chan *l2cap_chan_create(void)
{
struct l2cap_chan *chan;
diff --git a/net/bluetooth/smp.c b/net/bluetooth/smp.c
index f8f86b8f73f05..948a847c0dc23 100644
--- a/net/bluetooth/smp.c
+++ b/net/bluetooth/smp.c
@@ -3400,7 +3400,6 @@ static struct l2cap_chan *smp_add_cid(struct hci_dev *hdev, u16 cid)
chan->src_type = BDADDR_BREDR;
}
- chan->state = BT_LISTEN;
chan->mode = L2CAP_MODE_BASIC;
chan->imtu = L2CAP_DEFAULT_MTU;
chan->ops = &smp_root_chan_ops;
@@ -3408,6 +3407,8 @@ static struct l2cap_chan *smp_add_cid(struct hci_dev *hdev, u16 cid)
/* Set correct nesting level for a parent/listening channel */
atomic_set(&chan->nesting, L2CAP_NESTING_PARENT);
+ l2cap_chan_listen(chan);
+
return chan;
}
next prev parent reply other threads:[~2026-11-19 0:33 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 0:33 [PATCH v5 0/4] Bluetooth: SMP: Serialize root channel updates Cen Zhang
2026-11-19 0:33 ` Cen Zhang [this message]
2026-11-19 0:33 ` [PATCH v5 2/4] Bluetooth: SMP: Serialize forced BR/EDR channel changes Cen Zhang
2026-11-19 0:33 ` [PATCH v5 3/4] Bluetooth: hci_core: Hold the request lock for the power-on update Cen Zhang
2026-11-19 0:33 ` [PATCH v5 4/4] Bluetooth: SMP: Serialize root channel replacement Cen Zhang
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=pm-bluetooth-objects-candidate-0184-v12-e80229724d6ad14ca88c-1@gmail.com \
--to=zzzccc427@gmail.com \
--cc=baijiaju1990@gmail.com \
--cc=jjzuming@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.