From nobody Mon Jun 8 21:52:13 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 F2DDB1FE44A; Tue, 26 May 2026 13:51:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779803479; cv=none; b=MwGfNt3Pyx404rYGn6mAl0mMMp3erp9WhKal9j1Mw+tJs2ip4/ZqAWVB3GnHLo5RvYAvmlO59Q/fCSdehgIdyp8YFTU1oEuyWSsGgsR7UwyoCifbZjl5iU7c8Y9vh0fdlHkITvDSxoY5lTRnuCNsGvoh974zYPoOGjoYe9U/Z5U= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779803479; c=relaxed/simple; bh=7xU5AHbuTJWg/v3VXXXgEAuoOGUJYGEqz87SG+GdURk=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=fG27o38NIRjJ9yf9hlbE5Ey2gXmleT5PGDTxOQNMWA6vjry0PGuJCYF2k3XerBvfmOYlyhPYGyK4dnGl5//4ggid5d49b8Ub1rWG6hU5HdpJ2qUlMLz7uBIDl5fdZ97zoMamWoFBqqLydKFHTvhqJBvlrS6U6UzRpJKMts9aaAI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=S+6wPiRY; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="S+6wPiRY" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=H9O+UnZSoUGr8poiTa1psKAAL62vlHP66fwIYRcsJ6g=; b=S+6wPiRYg1phu6+4R5xGk3BEym N4qiuMiGmz4kGfgjROyRvuvDnbcZpqLnqwhmLWcuy06UkMJ8C0xNSrVz81OfzalXOyxJtd909opOT yp4DEpapw/ksPmKB7N4p+T5CHzaWNWgihfFGxAG03JJTZDcqBMc8CnCf9MBDYxPqjIFhPnEVhtmsm TuozWNbQyizPTUKIfZR52d4noBd7zgN2HjdUWKRk+45HIRqf/Mve9j3rPeUYruRDS6HJxtDiAT2ER BiZ1t2e9eoES16nq+lyVZYREgkEQKQu4+xlah2neQrrztnRPR228lSCx71Ix0xPI9yIs3+bEVbYG6 ZZ4Jg6sg==; Received: from 177-136-90-227.vmaxnet.com.br ([177.136.90.227] helo=[192.168.1.54]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wRsBe-008SdX-NS; Tue, 26 May 2026 15:51:14 +0200 From: Heitor Alves de Siqueira Date: Tue, 26 May 2026 10:50:57 -0300 Subject: [PATCH v2 1/3] Bluetooth: hci_core: Rework hci_dev_do_reset() to use hci_sync functions Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260526-hci_send-v2-1-596977a9a814@igalia.com> References: <20260526-hci_send-v2-0-596977a9a814@igalia.com> In-Reply-To: <20260526-hci_send-v2-0-596977a9a814@igalia.com> To: Marcel Holtmann , Luiz Augusto von Dentz , Gustavo Padovan , Schspa Shi Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, Heitor Alves de Siqueira , Luiz Augusto von Dentz X-Mailer: b4 0.15.2 The current HCI reset function in hci_core.c duplicates most of the work done by hci_dev_close_sync(), and doesn't handle LE, advertising or discovery. Instead of porting these to hci_dev_do_reset(), directly call the close/open functions from hci_sync to reset the hdev. MGMT now notifies when a user performs a reset. Suggested-by: Luiz Augusto von Dentz Signed-off-by: Heitor Alves de Siqueira --- net/bluetooth/hci_core.c | 43 +++---------------------------------------- 1 file changed, 3 insertions(+), 40 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index c46c1236ebfa..28d7929dc593 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -539,46 +539,9 @@ static int hci_dev_do_reset(struct hci_dev *hdev) =20 hci_req_sync_lock(hdev); =20 - /* Drop queues */ - skb_queue_purge(&hdev->rx_q); - skb_queue_purge(&hdev->cmd_q); - - /* Cancel these to avoid queueing non-chained pending work */ - hci_dev_set_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); - /* Wait for - * - * if (!hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE)) - * queue_delayed_work(&hdev->{cmd,ncmd}_timer) - * - * inside RCU section to see the flag or complete scheduling. - */ - synchronize_rcu(); - /* Explicitly cancel works in case scheduled after setting the flag. */ - cancel_delayed_work(&hdev->cmd_timer); - cancel_delayed_work(&hdev->ncmd_timer); - - /* Avoid potential lockdep warnings from the *_flush() calls by - * ensuring the workqueue is empty up front. - */ - drain_workqueue(hdev->workqueue); - - hci_dev_lock(hdev); - hci_inquiry_cache_flush(hdev); - hci_conn_hash_flush(hdev); - hci_dev_unlock(hdev); - - if (hdev->flush) - hdev->flush(hdev); - - hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); - - atomic_set(&hdev->cmd_cnt, 1); - hdev->acl_cnt =3D 0; - hdev->sco_cnt =3D 0; - hdev->le_cnt =3D 0; - hdev->iso_cnt =3D 0; - - ret =3D hci_reset_sync(hdev); + ret =3D hci_dev_close_sync(hdev); + if (!ret) + ret =3D hci_dev_open_sync(hdev); =20 hci_req_sync_unlock(hdev); return ret; --=20 2.54.0 From nobody Mon Jun 8 21:52:13 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 9B7223FBB44; Tue, 26 May 2026 13:51:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779803482; cv=none; b=vDhz0QJ+m98xtYkglDhm0ICygPOavnK+ypY0hnypEr+qgPmCECrirbA18RiWJQFy1Io7hnVVVBFnIo0jFrYdqQQJXEHaAZ6oBec3DGX2uOUA94coEfI1tFaG/PBEiIMZa+6b7FxJWuCozX8+Fe036J5yJ+EPLO7GOlvoCRk2kvI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779803482; c=relaxed/simple; bh=T5cP5aWqHViHWcK7TFKx8t8Fb7G33UJku7kGcP3/o0o=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=Ma3cas6z0DyZmV+gf3Gmx8lW53tFjnBlSznDiQm+B5VhCLn0d8U7mgXEfg4q7JxT38YHCujCfLJQRZKXX6N/mgS6lYnk2gzQ4paqtr+5hXStqnuMSiXmQPoo5mHymbAhjC6+7xjbPdI23+rtwMeR20NgiZlZdkWzAahf5/WO1f4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=JnkYsEX1; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="JnkYsEX1" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=/N0WmDQkvEjoZtguvmPAossBWif/jgp5Q6q5tkvrs9U=; b=JnkYsEX1z9B8XC83raQXatwoSh y4Llh3EMAiI7jBoY0mVYKjKMlTEOvLkV6Q65FuFBB4O6uibyt9C47XHAIbU/a7wvcqkSj8oPohsjm Ww8k4LcIIKG9CXrjNCccDLLCcPA0lv+yXSGA9PwrwCRRu1PU/hgJQB9z/V5H993uEVzj1Tn7PiN5/ bNe86dzKFvxarm4GnDwJ5dN15oFilblzkD7VKMxBOkdC3G6XcOfudtCtTzzQgTl8a9yRha2vJePhn on0OgVFy6HOdv7hg/kuHpjArqWDbM1+zENFwmIohBrWcsDnAjg4s4j2SIXtf7PdwvAExHz7D9Q0P7 IDkC5SXw==; Received: from 177-136-90-227.vmaxnet.com.br ([177.136.90.227] helo=[192.168.1.54]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wRsBh-008SdX-Be; Tue, 26 May 2026 15:51:17 +0200 From: Heitor Alves de Siqueira Date: Tue, 26 May 2026 10:50:58 -0300 Subject: [PATCH v2 2/3] Bluetooth: hci_sync: Set HCI_CMD_DRAIN_WORKQUEUE during device close Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260526-hci_send-v2-2-596977a9a814@igalia.com> References: <20260526-hci_send-v2-0-596977a9a814@igalia.com> In-Reply-To: <20260526-hci_send-v2-0-596977a9a814@igalia.com> To: Marcel Holtmann , Luiz Augusto von Dentz , Gustavo Padovan , Schspa Shi Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, Heitor Alves de Siqueira , Luiz Augusto von Dentz X-Mailer: b4 0.15.2 Since hci_dev_close_sync() can now be called during the reset path, we should also set HCI_CMD_DRAIN_WORKQUEUE. This avoids queuing timeouts while the hdev workqueue is being drained. Fixes: 877afadad2dc ("Bluetooth: When HCI work queue is drained, only queue= chained work") Signed-off-by: Heitor Alves de Siqueira --- net/bluetooth/hci_sync.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index fd3aacdea512..84d8f457c799 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5298,6 +5298,12 @@ int hci_dev_close_sync(struct hci_dev *hdev) =20 bt_dev_dbg(hdev, ""); =20 + /* Set HCI_DRAIN_WORKQUEUE flag to prevent queuing work during + * reset/close. See hci_cmd_work() and handle_cmd_cnt_and_timer(). + */ + hci_dev_set_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); + synchronize_rcu(); + if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { disable_delayed_work(&hdev->power_off); disable_delayed_work(&hdev->ncmd_timer); @@ -5321,6 +5327,7 @@ int hci_dev_close_sync(struct hci_dev *hdev) =20 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { cancel_delayed_work_sync(&hdev->cmd_timer); + hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); return err; } =20 @@ -5420,6 +5427,7 @@ int hci_dev_close_sync(struct hci_dev *hdev) /* Clear flags */ hdev->flags &=3D BIT(HCI_RAW); hci_dev_clear_volatile_flags(hdev); + hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); =20 memset(hdev->eir, 0, sizeof(hdev->eir)); memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); --=20 2.54.0 From nobody Mon Jun 8 21:52:13 2026 Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) (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 334E41FE44A; Tue, 26 May 2026 13:51:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.97.179.56 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779803485; cv=none; b=JD8C/2BJnz+HzXVU1+K7u51kr577xacxyJhm+l9FMu7d4khOlR3oUQZVE5Z3UQ+s66kSpU/v4vw4hAqbSnrmUh7KF9zqHL5lUKD9N1RsLfIniPZbhP9bGnCx9ECpIgeO2nugNdMFsL5Qu8IurPYiXOnnWgVFS3FyIpFeYmHlc2E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779803485; c=relaxed/simple; bh=vQUQe1pASHSJG4MNLG7fnrfrv2VJerlu3jh/gTp9Bgg=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZCo2V4wBo0E9Qeu8ye3Il+dHl+ZfG8DsgqCDQuGQo1jUfcmnh0GP+cfPxp5SDEXjgv/FngXC73OPxxdwW9R9mY79EhwACx20k5t9uCME/Lw/yeQmKYqZjnRYfQbSFP7jhDXUYpcSQGRmWMESR41umuU7ej0B5KqfuFLPI2GTYFI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com; spf=pass smtp.mailfrom=igalia.com; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b=RmABoBwT; arc=none smtp.client-ip=213.97.179.56 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=igalia.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=igalia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=igalia.com header.i=@igalia.com header.b="RmABoBwT" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Cc:To:In-Reply-To:References:Message-Id: Content-Transfer-Encoding:Content-Type:MIME-Version:Subject:Date:From:Sender: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=Z8/rR4xEc7BEvLs78RonuVsVc+Cbme4iJ0VrA+fCQZo=; b=RmABoBwTGjbxoIRxVM7bSrTqWg oeUsXHp0CLI013OuZBS19+j8vdFmoKh3yYCy8oFtR/FZvm+jjoI88ayz7ue6sYaAGYE9sXfVJ8lC3 j/tkDcYTR3xmoTktCT6o0LNHAFoVIpHMW3L2V/IOluEHfU7oW39460O+fNmNrJuYzLFeIzdhgVH8w Tt0MfFlTgyQghZLJujcFEvBHbvZASoQHQHYlz/6B0bvylNy17hySC73GratrnF1ZnppHtz34EzQ90 r3dmrIy+Xeo02eFZR8SGzbD67TUr/ckHblqve1gvyNT+OcSyw8W0hmETo4sJ4fZ09NQJIKBsO07Pf 8ocE1odQ==; Received: from 177-136-90-227.vmaxnet.com.br ([177.136.90.227] helo=[192.168.1.54]) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1wRsBj-008SdX-W5; Tue, 26 May 2026 15:51:20 +0200 From: Heitor Alves de Siqueira Date: Tue, 26 May 2026 10:50:59 -0300 Subject: [PATCH v2 3/3] Bluetooth: hci_sync: Reset device counters in hci_dev_close_sync() Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20260526-hci_send-v2-3-596977a9a814@igalia.com> References: <20260526-hci_send-v2-0-596977a9a814@igalia.com> In-Reply-To: <20260526-hci_send-v2-0-596977a9a814@igalia.com> To: Marcel Holtmann , Luiz Augusto von Dentz , Gustavo Padovan , Schspa Shi Cc: linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-dev@igalia.com, Heitor Alves de Siqueira , Luiz Augusto von Dentz X-Mailer: b4 0.15.2 Before resetting or closing the device, protocol counters should also be zeroed. Fixes: d0b137062b2d ("Bluetooth: hci_sync: Rework init stages") Signed-off-by: Heitor Alves de Siqueira --- net/bluetooth/hci_sync.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 84d8f457c799..c11d5a1f2dba 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -5390,6 +5390,10 @@ int hci_dev_close_sync(struct hci_dev *hdev) /* Reset device */ skb_queue_purge(&hdev->cmd_q); atomic_set(&hdev->cmd_cnt, 1); + hdev->acl_cnt =3D 0; + hdev->sco_cnt =3D 0; + hdev->le_cnt =3D 0; + hdev->iso_cnt =3D 0; if (hci_test_quirk(hdev, HCI_QUIRK_RESET_ON_CLOSE) && !auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { set_bit(HCI_INIT, &hdev->flags); --=20 2.54.0