From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.41 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796410214; b=UhA27qwv2lSrRp4gQ4hzQTnNkij4l9FcfAwl/8ykxvoWo77QDqFYXM7PgyKdLCTYzCC3 2Syu1H6Nzu9Q6oUUKMxKlUkuus7FEA51itwYVMKZAszDNkwdnJhQcIJsEspDnzmIEsZat rUZ/oY81eMoBWYLZPqEN++ikLWJu6F5sGCaJ6GkpAEC3S3XiktTGQ8x2S7xqUvguApjQM HhAyAdxce2Uw2g4C3hhDV4wvNo2rnkYIpp8QSsh4ziMYBJcQALFLdiS/z1l4axBpBx23G 7gDqVS8u8VOIup1UyG29BO6ym/aagcokkuheKQj9/5jF8d8cviZON+NJpgVYmDYnJZw== 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=vAzLnB9AmYwqle2tH3iTXaYRRnIJTK1nWVA0IQtKACWydyvIq4yOOIB98GC2u2Xl7/ex wLCf+gCyXpoxKosfdCFgfGZ1V1ewErzNZod4OCG3Z6mENYdlcjDNywzfOkaqrwp1UPsbO ubpdsgK0Mi+NsgUgCt16T3cOZR028U8r6Hu6TRtMEPyWGBqy37ZAhFPYOO6lqf8XvydA5 q5Fjj8lo4Wvgl4GGGpJbZrPwgsnAhk2o+HYEBfWw5Okc5t8CTMQznbYTt6yLKyMVoHNBJ T68NZUjL+8oO2RrGylLr7VrP/ES/0C9o1DGQy3M4cmczYJswh4yu6eXHm/c7FybThqg== 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.41 Received: from mail-dl1-f41.google.com (mail-dl1-f41.google.com [74.125.82.41]) (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 EEEEC606A332 for ; Fri, 4 Dec 2026 18:50:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EEEEC606A332 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-f41.google.com with SMTP id a92af1059eb24-170135e43c7so2608648c88.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=nxrMmtDGEOK9SYs1AvjaUQXT/H7OfvFqDFAnKHP73/Nhpa2CZIfZ4ZbjHRus9cnmgn p1g/xMUpKBm2Rn/ETavnPTpcxkh7zpPr+mS/EPHaTRP1iTN0skZh7osrrgGBniixzIev ibYlakx95/CAlqU4u6LQF+5BIk297qJxRDUWj3BOqyLN8sZkQChH4MYS64pm2KMYpZYZ vSQutiILzW9jUMzVmt1T149tvlOd0ZY2fcp9UIS8PzHohIY8PH21UDTNVis/31y7ZJne F+/hNbtRnoOTlRgYNvnkluCXvUuzYO0atNktBnWRO0hdoxGJrZmkvukf2bRIt0xWfRHj 3kpA== X-Forwarded-Encrypted: i=1; AL+hErGfwiv3p7TjzZHQBbZI/3xxqqGmsCswq4azfiZ9/NVxERNMAlcJUZUV+aKXv7FA/oOiCPEfJPI/UlR4/RA=@vger.kernel.org X-Gm-Message-State: APuU4Z+vverqzs82BEQAgIXztjJTBaEYrEOOkenh9uOkt7uDI6x4S4pj EaawJh3GmW631Fw7fnjtgLS6VyYthPQFtCGdauxYE1xWrPhF7AlF5Wlph4RzmWJG X-Gm-Gg: AZFdTZcgxC9qB4dO8iXvTDQlp6gmIwBEFRJFgN9llBT3mxjIRunlktJSEx4lxEZ57AU 9D2zLkqFs0Ai23MwsjMTbrxiAnoCAkdC1Dybcm6ny3FyyrCCTeB/6Nw8FyvFUq7eE/UUQDe+/nH boJ/RAA4f686E9YjxgDiXmH5lT6FmbAgn8OmwAL+Jb/qHC75V2y4A96S58Bgq4TFyXoAX59q0Kl lIC1MKzqO1dlW+IflPj5JP6ERZqY7gnJMV7yFEEc3AenqC6f+tXoJRXajkC29Ijry3Ar8MCyQm7 Tza4iwG9sJSk7gqHUYy9AEOEkeby59x8crtoQXueJT0rBPvm0FQm99+QBWcq30LBEw7HtJzMoKW +1DoisdLFqkB+LSEw8iUN36i0W/xqqqhTAiYVzijsc1ynuDE3KRUdPZITc9PcY1stLeHmWRdOJt gO1C8mujim2MeeSdvXgiHF07UwRb1GjJGVBDYPiz67ru6Ubmz01q9F9QKtDXpvtiDFutixDmNLx uiyjfNSWggQofwMmjN4yqFaJtCg92muvGDvzoO/Gt/0+4nwGnOCCw8TjjmfJLdY+aAgFaH4YYD6 3/JH1FqubzuyuEKCLmhmWO+yGlSgtzeo4RIUaoXDByj5JoKoH/Yj9C83bdOss5gPFAY= 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: linux-kernel@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