From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796380109; b=TLkxZlS+zf2cFRFtH3cdBsLQaaHtkMRhjIFCVMC4NIo6ciq2iXVnxew0I/aqPm3qlgEe 9ewp5MSFI2+DVkyJlXyJBQaId0uRcdRs5XD5REfCZC1VlWEYN78iii4inK/M52zVo6nsF q8L1uJdhYXpZ8RrV8iaG9p748Zq9BYyV8HmCl2XzjaDPmtMsfwux1GWilCiDjfh1+hmSp O7UpTec2jsNUg176mLyvg+JZ9X0u9kvX+f2qXdIC+rz+QEKrHN6Y2SBMqupQqIwN32MWB 1LaObhUE0f/HJI/LQHka1Tz1+076LDRz3B7HqM0iNmDFnJkK4F7xWxuYb2anB5yCBCQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796380109; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=nedZo84wMkIOhZvkr1Sj4mpZuKIlfYtGGVzySA3JTWk=; b=OxXX28MPNMrcn1usUgySNK26vuw/Kn/d9hjol63KFSfF2BULaAp9OJ7ko2tKLPM4QX4+ wb6Xv/46XwUFH7j08A5FvItO/1NfGhCssxpfp5H4CzFyvYXkyoIVx2OZYhX2UWw861UDz Bx3CQMmLVs0cKqyX9zCOvPOnQ+gSuUXSnVeBHhnQBUQOciPVEHClSdfeZNUA0b3ZZ/97m DQs5wuHWsVMsDbJCpgukqCTrnmYoFPQV/0Sjzso/A1sG09D9qbt5fjas7G4YF470H19pm PSunxhkVYqFbdpoDxat7DWeLD//WTL75wfZO6nvP+M3Kp8iDaLU1r9Qgx1xv0cQCA0Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Eu4gV7BW; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 85409606A32C; Fri, 4 Dec 2026 10:28:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=Eu4gV7BW Received: by smtp.kernel.org (Postfix) with ESMTPSA id 002991F0092C; Fri, 4 Dec 2026 10:28:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796380109; bh=nedZo84wMkIOhZvkr1Sj4mpZuKIlfYtGGVzySA3JTWk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=Eu4gV7BWj+6UmbUo1P0jM9kS6zjNkzeVhV+IaearySrg1viuUNO8v9pYBXNifHf8F uTt2LDkdSk8hG2mVqkmSnT+U9wK3Qt14DOpEKDwgaKQHM/nY0PH4txXC5w9+UAZv2x CUKiC7w6+c6BfnX+tf7f4tLmh+6GqsvwP9ruyUjM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Cen Zhang , Luiz Augusto von Dentz , Sasha Levin Subject: [PATCH 7.3 128/742] Bluetooth: hci_sync: Use controller handles for periodic advertising Date: Fri, 4 Dec 2026 18:59:52 +0900 Message-ID: <20261204100638.522577754@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Cen Zhang [ Upstream commit a7d2c94ba2995b5fb766d5ec7086f5e6a2774745 ] Management instance numbers and controller advertising handles differ on controllers with a single set: instance 1 uses handle 0x00. Periodic advertising data already sends adv->handle, but the parameters and enable commands send the instance number. The completion handler also treats the command's handle as an instance number: Request worker Controller / completion create instance 1 on handle 0 send periodic parameters for 1 Unknown Advertising Identifier Snapshot the handle under hdev->lock for periodic parameters, enable and disable. For instance 1 using handle 0, update periodic_enabled under the mutex after the command succeeds. Its completion handler cannot distinguish that instance from global advertising by the handle alone; keep the software instance number in the request, as the existing remove-set and random-address paths do. Use the same mapping for the advertising set in periodic transfer and both BIG creation commands, which obtain the instance number from the same broadcast QoS field as hci_start_per_adv_sync(). Keep the instance number in software state, and send no HCI command with the mutex held. Fixes: eca0ae4aea66 ("Bluetooth: Add initial implementation of BIS connections") Signed-off-by: Cen Zhang Signed-off-by: Luiz Augusto von Dentz Signed-off-by: Sasha Levin --- net/bluetooth/hci_sync.c | 68 +++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 7 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index d1f2929bb8772..54ecb0a79f946 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -1782,11 +1782,15 @@ int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance) struct hci_cp_le_set_per_adv_enable cp; struct adv_info *adv; bool enabled; + u8 handle = instance; + int err; /* If periodic advertising already disabled there is nothing to do. */ hci_dev_lock(hdev); adv = hci_find_adv_instance(hdev, instance); enabled = adv && adv->periodic_enabled; + if (adv) + handle = adv->handle; hci_dev_unlock(hdev); if (!enabled) return 0; @@ -1794,10 +1798,39 @@ int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance) memset(&cp, 0, sizeof(cp)); cp.enable = 0x00; - cp.handle = instance; + cp.handle = handle; - return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, - sizeof(cp), &cp, HCI_CMD_TIMEOUT); + err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, + sizeof(cp), &cp, HCI_CMD_TIMEOUT); + if (err || handle == instance) + return err; + + /* Handle 0 is shared with global advertising, so the completion + * cannot identify the software instance from the command alone. + */ + hci_dev_lock(hdev); + adv = hci_find_adv_instance(hdev, instance); + if (adv) + adv->periodic_enabled = false; + hci_dev_unlock(hdev); + + return 0; +} + +/* Map a management instance number to its controller handle. */ +static u8 hci_adv_instance_handle(struct hci_dev *hdev, u8 instance) + __must_not_hold(&hdev->lock) +{ + struct adv_info *adv; + u8 handle = instance; + + hci_dev_lock(hdev); + adv = hci_find_adv_instance(hdev, instance); + if (adv) + handle = adv->handle; + hci_dev_unlock(hdev); + + return handle; } static int hci_set_per_adv_params_sync(struct hci_dev *hdev, u8 instance, @@ -1813,7 +1846,7 @@ static int hci_set_per_adv_params_sync(struct hci_dev *hdev, u8 instance, if (!max_interval) max_interval = DISCOV_LE_PER_ADV_INT_MAX; - cp.handle = instance; + cp.handle = hci_adv_instance_handle(hdev, instance); cp.min_interval = cpu_to_le16(min_interval); cp.max_interval = cpu_to_le16(max_interval); cp.periodic_properties = 0x0000; @@ -1859,11 +1892,15 @@ static int hci_enable_per_advertising_sync(struct hci_dev *hdev, u8 instance) struct hci_cp_le_set_per_adv_enable cp; struct adv_info *adv; bool enabled; + u8 handle = instance; + int err; /* If periodic advertising already enabled there is nothing to do. */ hci_dev_lock(hdev); adv = hci_find_adv_instance(hdev, instance); enabled = adv && adv->periodic_enabled; + if (adv) + handle = adv->handle; hci_dev_unlock(hdev); if (enabled) return 0; @@ -1871,10 +1908,23 @@ static int hci_enable_per_advertising_sync(struct hci_dev *hdev, u8 instance) memset(&cp, 0, sizeof(cp)); cp.enable = 0x01; - cp.handle = instance; + cp.handle = handle; - return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, - sizeof(cp), &cp, HCI_CMD_TIMEOUT); + err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, + sizeof(cp), &cp, HCI_CMD_TIMEOUT); + if (err || handle == instance) + return err; + + /* Handle 0 is shared with global advertising, so the completion + * cannot identify the software instance from the command alone. + */ + hci_dev_lock(hdev); + adv = hci_find_adv_instance(hdev, instance); + if (adv) + adv->periodic_enabled = true; + hci_dev_unlock(hdev); + + return 0; } /* Checks if periodic advertising data contains a Basic Announcement and if it @@ -8152,6 +8202,7 @@ static int hci_le_past_set_info_sync(struct hci_dev *hdev, void *data) { struct past_data *past = data; struct hci_cp_le_past_set_info cp; + struct adv_info *adv; hci_dev_lock(hdev); @@ -8164,6 +8215,9 @@ static int hci_le_past_set_info_sync(struct hci_dev *hdev, void *data) memset(&cp, 0, sizeof(cp)); cp.handle = cpu_to_le16(past->le->handle); cp.adv_handle = past->conn->iso_qos.bcast.bis; + adv = hci_find_adv_instance(hdev, cp.adv_handle); + if (adv) + cp.adv_handle = adv->handle; hci_dev_unlock(hdev); -- 2.53.0