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=1796410248; b=kpOgz3Bqesmftmkwd4EZflwO2CGDilekvywqT43sfDKpm2Zc68adhjleLSjhySxIosGc Yn/m7FqToA+uERU5ySKqLCbAqcaug9a+UpT7iNuPQrIy6FxmZotjthiioSS0H/oqlRoYe J3oXXgaHa3T+j2ygC0/KIs2Dr+oepdGRJZbrQI5vhqAM//liWsQ4yj6+vdF0T/nCATet5 pz6iroHPVQ5aAMZpFqhj2RNjsfM/QsDMNavbZbwRJJQsnHgVpEOmzeCDPNuYgt4e9R55W Iccge6PLobeIx0iUsxvhQycRd1OvZWabRjUXK729pWbZuoFfz7OqM6uxsAUhs2yXeBg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796410248; 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:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=mgHi6BxutEWZ+vXRKNTDwnv2Rgn3qIXZvhYqRTFbqD0=; b=rglp7wlWmhHnOEoTya2g+f8XrW/IWBZfcnINblGjL00ua3rma5FYdnrlmLogPhoc08np MyPaDIDphAAdaMp3ozJ++tU3jC8kLc+f4dBTb6FhvObGX+j3Ao9+PTd5mmk5gc7xajhtj hOGzQ8AVWQeAoOSyvnpb+bSMOeqaHOA7pICtoSo61oOP54I6mnf8bvwNoAtimKaI3Ek5U noENj4sVzvgZfiYjNNZZVDvbbRzHwj4tMQw+OC3Mr6nQF81eqLhCy5YpiMHdnjOWXV1vb 6e5msWZXN4GBvUUnZLDs7FVpeoAstZb8A4AjPR1wwPG4ipHyK5MTZkCoCQd3ZIlrNtg== 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=q3IUGMji; 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 157AE606A322 for ; Fri, 4 Dec 2026 18:50:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 157AE606A322 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=q3IUGMji Received: by mail-dl1-f54.google.com with SMTP id a92af1059eb24-170135e43c7so2610458c88.0 for ; Fri, 04 Dec 2026 10:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796410247; x=1797015047; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=mgHi6BxutEWZ+vXRKNTDwnv2Rgn3qIXZvhYqRTFbqD0=; b=q3IUGMji/JU4w6W05dc5N+JdQhpJZMjGFp4m2t4o768eDHHoNta1NWI7vFxmwXO2Du IgVw1XGXQRisC9w06ypTEMoyXc05zjL7ZQugn7sC9l8F4B6aPIXCFoE6TUatYYKeEn+X bTOx9+Rdc956C+GKBvmtqfgca0SH88DD45EuSpsj/xydOR8Vrbc/ThW5DSwxOEtBEwO4 unrDXWaZmKbL1u4RjPKGS0k0jZwDyMJgG141sVzEwuBV4PbRVSmLH2UZ0gYT3luCPkxR bNjOU3boD6cMhj2/7XqyXZv8LyKw4NKpOUbFzY2Wad0HxLjOJhHHURnHFlYOUfVqogZx gB9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796410247; x=1797015047; h=content-transfer-encoding:mime-version:references:in-reply-to :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=mgHi6BxutEWZ+vXRKNTDwnv2Rgn3qIXZvhYqRTFbqD0=; b=FKx7GCOsYHEEIRcNXq/phl4WqZ1ZfVLOfUP71EouPb5mOtk1DXWmNVJlSDDyoIRUn1 L/+k1BBtQ1t4ps753UInHA3oEINu/o+/uiOqEGV0amyDeFJ8cnYF07CUepU8q6ls9xSQ gUi5jxv/KBtB8YYdgoZOz4QFPYOTk2Wy7GGCJzo9nJKApMPuvR0o548xfOoOAx6aenHL hdYw1jyBI5GVzphclG7oycKsoAUDTdNDM+cnrqVIOn/EDz85wsoCMezfhrpBdiz+P82e 8U28aw92rv1WbgFomRZST5XZXLtT2PS7QIK3l9HF7b4KRJHZBXO8lEJudgeg1WXQfVQs Qyqw== X-Forwarded-Encrypted: i=1; AL+hErE6XWhXvS9NdwXSGNuRPfIQQyBvoTqy/r4jQz1uvh783QLbeZIK5BVm/6BCSq3VpS6CXy5tUabuLyMfS/Bsh6E=@vger.kernel.org X-Gm-Message-State: APuU4Z/hpRkCUDC2ZIisybOARHIvIwEzSaT/Frb/hJ6oRwfeY6yCVpAU VAu2Qh2umoW1rnmH8uAbb/6Afdc0enEoFa1V9J99H4ddjxNChHlnKeNpppVVGb45 X-Gm-Gg: AZFdTZcxD6gw8S1KQmlamyUjqRrPYa5EjUOYo1zKxmGSb3JtmYXUgLw6DahtXcBO5Mf aL15LUBhcQsIGX1wiKfzVC3uuBRWiWGs8aNte8+IK49Z0RfXsggmdQGY74ivKXRAoi9e4vyyTnD QsCMrfw50kQeN9l3jDqap6QUBFMHglN1LMWldIeU/d37xMsHAfiYqI918ooCuUW7ouysc7LOTlH MPf7+w0Pbl6wAP8F3AXbGRSAufOUKQ3RXfPCtXM7tmx6fl15OPFT+2xcMGk+Nr8xXhP3oQfbTFd kIe1xHcB02u83gQ++HZ4duYF44DtDeoq7DsmgDzmjkBab4FwiaJfD55Xjn77FbyvnhmiBjPpNU/ ULP72T/Pv7WHvQoM2M9YwJ6vbvf7WHAiZzT2Ro+zOPftCfkRPbguxbhKx0qsvHDUyJ9gAnaE8Fl ipPAi/jIaomLBfnjxV16VqhM/MZX3ucV5/DxU3+WZcUjY16LxTDqbaFTYjVfZ9v0kanT47BanC9 8hFVlgiEP83f1ZkTYjtFOW8dqJ/k1dZnLV0odL0PObtVTG96yYK74nI/AJ7kfe7YDU+TlBgeaej 87YzvFvEsoRnQQ+6B/JMWgmHLxRNsBwd7Z/Uu+nq+ZQBQqZE1QIEcs/NCNYGxxBjiJYZLOyxxwk rl2BjTLj0EA2k+A== X-Received: by 2002:a05:701a:ccdc:20b0:1b5:b1a2:9873 with SMTP id a92af1059eb24-1b5d7103e17mr2493863c88.25.1796410247220; Fri, 04 Dec 2026 10:50:47 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5d644109esm9944981c88.8.2026.12.04.10.50.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 10:50:46 -0800 (PST) From: Praneeth Balasubramanian To: Marcel Holtmann , Luiz Augusto von Dentz Cc: Matthias Brugger , AngeloGioacchino Del Regno , linux-bluetooth@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, Praneeth Balasubramanian , stable@vger.kernel.org Subject: [PATCH 2/2] Bluetooth: btusb: mediatek: Use a PM reference when the firmware dumps Date: Fri, 4 Dec 2026 10:50:17 -0800 Message-Id: <20261204185017.1687516-2-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20261204185017.1687516-1-praneethb2002@gmail.com> References: <20261204185017.1687516-1-praneethb2002@gmail.com> X-Mailing-List: linux-bluetooth@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 btmtk_usb_recv_acl() calls usb_disable_autosuspend() for every firmware dump packet (handle 0xfc6f), because a hung firmware can no longer suspend. usb_disable_autosuspend() changes the autosuspend policy that user space sets through power/control, and its kernel-doc says that the caller must hold the udev device lock. btmtk_usb_recv_acl() runs in the receive path, from URB completion, where that lock cannot be taken. Keep the device awake with a runtime PM reference on the interface instead, using the BTUSB_DUMP_AWAKE flag from the previous patch. btusb now takes the reference on the first dump packet, in a small wrapper around btmtk_usb_recv_acl(), and btusb_disconnect() drops it when the device is unbound, for example after a USB reset. As before, the device stays awake until then, but the user's autosuspend setting is left alone. btusb is the only user of btmtk_usb_recv_acl(). 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: 0b10c8c84c0c ("Bluetooth: btusb: Record debug log for Mediatek Chip.") 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/btmtk.c | 6 +----- drivers/bluetooth/btusb_main.c | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/drivers/bluetooth/btmtk.c b/drivers/bluetooth/btmtk.c index 1b3dab0d10bb..d868e7ba4745 100644 --- a/drivers/bluetooth/btmtk.c +++ b/drivers/bluetooth/btmtk.c @@ -1439,7 +1439,6 @@ EXPORT_SYMBOL_GPL(btmtk_usb_subsys_reset); int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb) { - struct btmtk_data *data = hci_get_priv(hdev); u16 handle = le16_to_cpu(hci_acl_hdr(skb)->handle); /* The handles below are vendor-reserved values MTK firmware uses to @@ -1451,10 +1450,7 @@ int btmtk_usb_recv_acl(struct hci_dev *hdev, struct sk_buff *skb) */ switch (handle) { case 0xfc6f: /* Firmware dump from device */ - /* When the firmware hangs, the device can no longer - * suspend and thus disable auto-suspend. - */ - usb_disable_autosuspend(data->udev); + /* btusb keeps the device awake, see btusb_recv_acl_mtk() */ /* We need to forward the diagnostic packet to userspace daemon * for backward compatibility, so we have to clone the packet diff --git a/drivers/bluetooth/btusb_main.c b/drivers/bluetooth/btusb_main.c index 468415530e3e..088bea4bb594 100644 --- a/drivers/bluetooth/btusb_main.c +++ b/drivers/bluetooth/btusb_main.c @@ -3063,6 +3063,23 @@ static void btusb_mtk_release_iso_intf(struct hci_dev *hdev) clear_bit(BTMTK_ISOPKT_OVER_INTR, &btmtk_data->flags); } +static int btusb_recv_acl_mtk(struct hci_dev *hdev, struct sk_buff *skb) +{ + struct btusb_data *data = hci_get_drvdata(hdev); + + /* When the firmware hangs, it sends a dump on handle 0xfc6f and the + * device can no longer suspend. Keep it awake until it is reset and + * rebound; btusb_disconnect() drops the reference. This runs in URB + * completion context, so hold a PM reference rather than change the + * autosuspend policy, which needs the device lock. + */ + if (le16_to_cpu(hci_acl_hdr(skb)->handle) == 0xfc6f && + !test_and_set_bit(BTUSB_DUMP_AWAKE, &data->flags)) + usb_autopm_get_interface_no_resume(data->intf); + + return btmtk_usb_recv_acl(hdev, skb); +} + static int btusb_mtk_disconnect(struct hci_dev *hdev) { /* This function describes the specific additional steps taken by MediaTek @@ -4628,7 +4645,7 @@ static int btusb_probe(struct usb_interface *intf, hdev->send = btusb_send_frame_mtk; hci_set_quirk(hdev, HCI_QUIRK_BROKEN_ENHANCED_SETUP_SYNC_CONN); hci_set_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_SETUP); - data->recv_acl = btmtk_usb_recv_acl; + data->recv_acl = btusb_recv_acl_mtk; data->recv_event = btmtk_recv_event; data->suspend = btmtk_usb_suspend; data->resume = btmtk_usb_resume; -- 2.25.1