From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.54 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410214; b=iY2UNR0IZGbMOX6BDPQUtMTt3Yptb9qYAAen20tL0jKQ28yDWyL6grJMQsrlJ7jXUvJ+ bZIv9byRJDIeF8PosfyjmrOHZF0iuFJAAzVSPxIJ8+nRC3CoFDwox67HNE8vfenY/eqxe 4x9KZnaC0pu8CzKNaun6EutdMrSDbilLYiNIBHrXwfbzk6hOBVQ39a3ECYTH7B+2JVYWi Q/1Vo07ZzI5Gx21QNwUwut3twme1Ab6TOQBc+6o1J4n5PNNlb+sw7vINakBwDZS4y1Jo1 EY2agTnOFAMYfslBdV5E4oV7bvYbiNH9MzVN+9qGMdMakfg3XzO4KTOQh4BY902UA4Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796410214; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=vyPHiQ7cAPiiOLkFkxaEwM4NKC2d7VCOnb3h/HFuAF8=; b=5GEydU4CyiSoM9gm9uRuNO08iFlJNp7e80TQSdyWGF0+rfL6H9KNZHddEFUOL22CxiiD ViqPcQMoSHKmxgAujF3Ewan+/3cSfVwlfF1dPOEz6ins1MfAZ7Fxmg5IOsWdYlAmlbUtU I70w14dh+Q/5ikcJerJXz9CHw5rx1p1fKBnzLUfjRZ2J8H3fugwkaZQX1Vk0e5V7O+W0+ +3xG+99l6ZIyPuGK86Ktae7cjxvocdu7chEqrjQ/6zQEr9x2WvWdYGYGoOjtycrcS6rWs TyLyM0xDK7I3ND17qqiBoNf/WaxQKe7by/JghrlTRdpX+hmauR724nvQIqV4ZgsYwNw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0M38+OyW; arc=none smtp.remote-ip=74.125.82.54 Received: from mail-dl1-f54.google.com (mail-dl1-f54.google.com [74.125.82.54]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06906606A333 for ; Fri, 4 Dec 2026 18:50:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 06906606A333 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=0M38+OyW Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-170135e43c7so2608646c88.0 for ; Fri, 04 Dec 2026 10:50:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796410213; x=1797015013; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=vyPHiQ7cAPiiOLkFkxaEwM4NKC2d7VCOnb3h/HFuAF8=; b=0M38+OyW6YWyYhdf8G34F50eKyyBFkO1RftPYS0UbZEgG2PSbt3Uqk8yyxtoh+upvq yiGjsI/XagH8h8FGPqYxyWTRAcnwDzmNVpVOrjAttRhl7JIjiia+NeZfW3JfqgBuVpC8 vn9QRf16vkG8rr3NPzx6UGbF8QD9h1jovDq65P48cuL57S9aU/RgXiN6M6SAjCBZYfUy 04Iy02Y6fo/DDk08mVZgyi3KtPS73yCDEUHIPU59awPddBZsQev+CQ4OWYaiSa6zOG+6 sdmYQFSwRz8QlairvuqBApa7JwHPmo3l8MIfwAgNr1Bl6NGr13+VjgRejGfuQCmRkpGE hkvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796410213; x=1797015013; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=vyPHiQ7cAPiiOLkFkxaEwM4NKC2d7VCOnb3h/HFuAF8=; b=lAo9dlOq93wqLDwCprZhuh7aGDhWDrf/wdXMCRTB9kv0hjMDvfPCBhq/Ou92/cp0WQ flvp7UTBfPwFeeyl4eex+rkkLJkUyfBAcbpYBsv7nMhiAzCSx2S4kULWZRACkq6z4aB2 HSL5ysVecNmAQ31lb//YfsY/IqhZBbqDsFQHycbpTxhJsroDFFlkO8Ud6lW/lq0ooIh7 jeyVsLwpMTwP2idWP8Em0CWFT+5pgXhcgVRcdq9AdhNmjOfG2dLssFlzyr824kGXIDGI h3Uo7BwMtSwYKj2wJuXOy+3NtrR057yFSWhhir04jO/kelvOqNyT8GDr0g8capccUEz8 m0ww== X-Forwarded-Encrypted: i=1; AL+hErFS477ksSruvWNlt/hKvtvQoUt6GtODSlYZ/pUKPeXLrXBuEIFADa1/GjlM/KSrhVr0mLCiubE=@vger.kernel.org X-Gm-Message-State: APuU4Z/buG2aakrAPjj3NYrpJPrm289rQxcTyOqe7Q5KblSosof5ZYTN m9y32SOwtCpMWqdHF2ybTP7S3bjnVSx4Tf9MSNQdf7Qc4sQvkcN9SmHU X-Gm-Gg: AZFdTZdg8s4XH4ETXjuOBuq3JMgXuaVhic0l6MRjBAcadyh1JwHUnaeWjhSL7ZsTS5E HfqtKq5nzvzWEvRoA2ja89KgRlLlVR4ZuNaN3QaAnM+hxUaUOF5WqvYkWT52b21CPLsOkpBmhUn 8JQ7SV3FGLfzc5PTK+nL5V/2JLWdykF5oblLtTCBsluM+0kDCEeYiXBXNspSTGmma78ifbfxvZ9 72YrLe2pHRis+hOtbGW2Jga3VHR0E5Srp3y/CS0f6bhybmUsTpOKnZ85f7t6Z/kGDKVqaAraqUL J5l5jiwxkmLTRKJX7gLnfhZjVeZxI8Xw3DvyshV9lMPwm0CBUDpwXJjN15jOEEFO8FMQwrjFIPX WF8fGz7mhzsW0nCVCpQaX+jYcIFBSpW24RuVQ+mq/NebSRP/iN+L3DtOqKvyfrDKYp1bjlcbdOX sglvQghyObfjNKXLY82X7a+CceGotalNyzIw3YoR4AuyKeIEJMjQUS7dr6sDT+CRW6p2wkXEoAh mwciEK2Tj7VmOCQTmD9aaIhVeqYXzStjUQZ4RcncssJawkaNPvMLwZJOnofgBqieFoKA4Z0RIEN dOcP9wyYvroX0rgraKwnT9UxgSZ+vgAWApxVgmKw+p+lyR8OGnX7X0LWYi2KwydxBFA= X-Received: by 2002:a05:701a:c9db:20b0:1b5:c305:2f6d with SMTP id a92af1059eb24-1b5d70cc875mr2728947c88.7.1796410213069; Fri, 04 Dec 2026 10:50:13 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d642e254sm9316253c88.4.2026.12.04.10.50.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 10:50:12 -0800 (PST) From: Praneeth Balasubramanian To: Marcel Holtmann , Luiz Augusto von Dentz Cc: Hans de Goede , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, Praneeth Balasubramanian , stable@vger.kernel.org Subject: [RFC PATCH] Bluetooth: btusb: Try the device lock when the CSR quirk re-enables autosuspend Date: Fri, 4 Dec 2026 10:50:10 -0800 Message-Id: <20261204185010.1687331-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 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 btusb_setup_csr() ends its workaround for fake CSR controllers by calling usb_enable_autosuspend() when btusb was loaded with enable_autosuspend. usb_enable_autosuspend() changes the policy that user space sets through power/control, and its kernel-doc says that the caller must hold the udev device lock, which serializes it with writes to power/control. btusb_setup_csr() runs from the HCI power-on work without that lock. A plain usb_lock_device() would deadlock: USB interface drivers are unbound with the parent device locked, and btusb_disconnect() -> hci_unregister_dev() waits for the power-on work with disable_work_sync(). So take the lock with usb_trylock_device(). If it is busy, which mostly means that the device is going away, leave autosuspend off and warn; it can still be enabled through power/control. pm_runtime_allow() and pm_runtime_forbid(), which the workaround calls before, have no such requirement and are left as they are. The missing lock was found by a static check that turns the locking rule in a function's comment into a Clang context-analysis requirement on its callers. Fixes: 0671c0662383 ("Bluetooth: btusb: Add workaround for remote-wakeup issues with Barrot 8041a02 fake CSR controllers") Cc: stable@vger.kernel.org Signed-off-by: Praneeth Balasubramanian --- Notes: This was found by a compiler-based check, part of research at UCSB SecLab. The locking rule stated in the kernel-doc comment of the called function was turned into a Clang context-analysis requirement (__must_hold) on that function, and Clang 23 with CONFIG_WARN_CONTEXT_ANALYSIS then checked every caller. An LLM was used only to turn the comment into a machine-readable rule; the report itself comes from the compiler. The patch and changelog were drafted with Claude Opus 5.5. I reviewed the patch and take responsibility for it. Testing: builds without new warnings with W=1 (x86_64, clang 23, allmodconfig). Not runtime-tested; I do not have this hardware, and I have not observed the race myself. drivers/bluetooth/btusb_main.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c index 95398e2ca098..d1d4b9a70606 100644 --- a/drivers/bluetooth/btusb_main.c +++ b/drivers/bluetooth/btusb_main.c @@ -2838,9 +2838,19 @@ static int btusb_setup_csr(struct hci_dev *hdev) device_set_wakeup_capable(&data->udev->dev, false); - /* Re-enable autosuspend if this was requested */ - if (enable_autosuspend) - usb_enable_autosuspend(data->udev); + /* + * Re-enable autosuspend if this was requested. This needs the + * device lock, but btusb_disconnect() holds it while it waits + * for the power-on work that runs this setup, so only try it. + */ + if (enable_autosuspend) { + if (usb_trylock_device(data->udev)) { + usb_enable_autosuspend(data->udev); + usb_unlock_device(data->udev); + } else { + bt_dev_warn(hdev, "CSR: Couldn't re-enable autosuspend"); + } + } } kfree_skb(skb); -- 2.25.1