From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796264400; b=n1HfiVwPHlZzoihiixtnBYZCeJbVI4PNHmIGXkas/NkwRbJgjtqXpCFl1EpJ467DdQPH RejvSfi6jNsWIpxTrA+iSFXcvJQ64bD9ItiMWe50V60VYddTIN1d96m4ZciQnUl5Yuv4J e34EdkTCdBDYlH679fwKWe5ziiQ5iBQwHy14cvYSmINfW0c45bv6WbuKu1/F4AWWf6JJd mx2kxJ1wX+kfi3d5uYQzMrrNMSkhRPiyCebgqQ6jMZTXRDefRaD7LS0WAm+5XtAw1iTFL 8PMt7mozQAMgpFMFLujaltR8PMnexGFGJ/CWB2FRqtEF1XXCq3GInqgvKx3kKq5TWNQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796264400; h=Received:DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-Id: MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=y+TIcRvGJvu3Xj319lLSkAZqaqM/B6nZPJ3K7PsysMQ=; b=QBTUUdXuZ7cLnwcw0p5evBZM30jFp8LaC8nEJLNmoSoe0tr4LrRO5dA5njDdVwgpNG7u 6khDfEkUYs2wolTyTzuf3/cbSVj1LEfRDCKqdkl3jfUtvLPuyEhgZubzii2udFKFENNYo AuYr8zeO/sLNdn94/8wpRc3esHZdTpnBJ1trSev+Mc6i77Gug2Tv2fqdQAKGAoz3iAhhb 1m4DYjYE82fwjZQeUaBGVFyqkO4sJCJwXNsqd9XR1TuGy1AevsSa6bcEj8NgI2x9lvgIZ i9/4vbleGuYP8bMaVTmJvZQPj5jJzjcfRQH5vXJgicEBtnPrJ/meibKOm+2+wb1gWMg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jV2vtEBE; arc=pass header.oldest-pass=0 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 44CD8606A692; Thu, 3 Dec 2026 02:20:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=jV2vtEBE Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796264400; b=i8Cmf097brnzfJ+iZx7cIJsrHgtUa+bJK1a/cwYPEFV8BGlak4sY+Xs6XHmIwbq4R/kR skxL4KmelT+n8Kd50TAieYY/j/ilCLSYlBGAiDDv0WW9Ose5KJuXjMV9isYDykBZ7wLwV 68bYhxx7X+PjxcsWCjXA1gJt4tdROSC1nHLYxJiukmGkXIJW4DSY3XQpcHFM3LSRRQ9AP 9FAG7CC3qmBE0SSsTo93AfHJwb7xvBT/Eqney9+UQZCrBkSK5X6zBT51pksENqfqOe2T3 QUaBlbj0NHVTmHTuc2tvcgDTxE6TnR7RA4vs8jw+BdxmSoZrV7SjGDDl/iCrcVK03RQ== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796264400; h=DKIM-Signature:Received:From:To:Cc:Subject:Date:Message-Id: MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To; bh=y+TIcRvGJvu3Xj319lLSkAZqaqM/B6nZPJ3K7PsysMQ=; b=08oAeYRb7B8JmBdNSB1bXUuVafHyjIYad4xCtSYdsaUSqtcF6lfr6gFh02nXX93m4s3o S52kFRn2qs/P88KfTk+wHQeIYa3GKTb6aWeI9nYu0e775zYU6QhPKBAvqAocz3VRAtTo9 GsUfLPko5I9MdisHbhs50KaO6RFiPW7c6yR0MKi/J9I2eqCUsoc4wkYzVmU7M7NfSPU05 uHg54YUEnY///bzgI57ipgLp9jVohsoNuyASnvaqIu3xqENwUmwLh+zTeq6XAJtZZ6rxo P7jJEtcPgoGnJ1lG4Lk+YY89+tGGgN0asnhaUBYW9uNcgLW+ctmp8i5ALanl6Vqt4Qw== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id 1DE951F000C1; Thu, 3 Dec 2026 02:19:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796264399; bh=y+TIcRvGJvu3Xj319lLSkAZqaqM/B6nZPJ3K7PsysMQ=; h=From:To:Cc:Subject:Date:Reply-To; b=jV2vtEBE9Bd0ZYyJ4382NNfWQzuj6t42N8bjtetgiigEiK5wXiyldU+x6Vpz8g6Q/ G+ooIzDsinKfZloppcfxtPoMH3t1hml9rHvVJPR1kgO5L/DetrkxsClfNL8tlgRejy chWiiK0ujOobegpxkyKFiCZcUABKc8xxNjuY9jNH1ZTMyw/PWBvqEV0lTbvmPose4f gEbD42UYCnhb3TaMiL8rFmNj48klJRKr7Ry/QHarroqG+UQ5sfzg8crkEjwCNQvVpz LbSuM8NjWb0Q1dJXe67oRPMhzFQodjwNZWeosWD8j4JG6oAH3FOdcYG5g1Lk1rVCe4 Xte/Nk7Z1NPeQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 705294F74C; Thu, 3 Dec 2026 02:19:57 +0000 (UTC) From: Ilia Snezhkov via B4 Relay To: daniel.lezcano@kernel.org, rafael@kernel.org, rui.zhang@intel.com, lukasz.luba@arm.com Cc: matthias.bgg@gmail.com, angelogioacchino.delregno@collabora.com, bchihi@baylibre.com, nfraprado@collabora.com, linux-pm@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, phone-devel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 0/5] thermal/drivers/mediatek/lvts: CALSCALE, overflow, trip, and IRQ fixes Date: Thu, 03 Dec 2026 02:19:56 +0000 Message-Id: <20261203021956.43607-1-iasnezhkov@gmail.com> 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-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 8bit X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1796264396; l=2832; i=iasnezhkov@gmail.com; s=mindone2026; h=from:subject:message-id; bh=OVJcWg25z3eiKMOip7EnCvyQ6Y6em+67cFDcvaADXTI=; b=Itx1W7ZgFjYvPpYzX1Dbu5tm08KB1m/bD2i4BpBzQF24d4HiQEe3qelnIgUbNulSwSuroFb9f 02RvYx+GQ33Bue2LehVLyT2DgqA+9dByVh1K88QtQItfRruSwhDsdJj X-Developer-Key: i=iasnezhkov@gmail.com; a=ed25519; pk=hQgXfiWi4ukk2jh4BHu1vRVhg9BUivo//AFp50AKMag= X-Endpoint-Received: by B4 Relay for iasnezhkov@gmail.com/mindone2026 with auth_id=1643 X-Original-From: Ilia Snezhkov Reply-To: iasnezhkov@gmail.com This five-patch series fixes bugs in drivers/thermal/mediatek/lvts_thermal.c: 1. Write LVTS_CALSCALE_CONF (0x300) to LVTS_CALSCALE instead of overwriting a local variable and discarding it. 2. Avoid 32-bit overflow, negative left shift, and unsigned wraparound in lvts_temp_to_raw_mt7988(). 3. Serialize lvts_set_trips() with a per-controller spinlock_t so concurrent updates across sibling thermal zones cannot race on shared thresholds or LVTS_MONINT. 4. Recompute shared controller thresholds safely across sibling sensors (excluding INT_MAX from winning high_thresh, falling back to the next highest finite sibling on cooldown, matching low/high IRQ masks independently, skipping lvts_temp_to_raw(INT_MAX), and masking offset IRQs before writing LVTS_OFFSETL/LVTS_OFFSETH). 5. Check lvts_ctrl->sensors[i].tz before calling thermal_zone_device_update() in lvts_ctrl_irq_handler(). --- v1: https://lore.kernel.org/r/20261126005321.71799-1-iasnezhkov@gmail.com Changes in v2: - Split the INT_MAX trip handling out of patch 2/5 so patch 2/5 only fixes lvts_temp_to_raw_mt7988() (now returning 0 early when golden_temp_offset - temperature <= 0 to avoid shifting a negative s64) and corrected the golden_temp boundary example in its commit message (LVTS_GOLDEN_TEMP_MAX is 62, not 64). - Added patch 4/5 combining the INT_MAX trip handling with full sibling threshold recomputation (lvts_recompute_thresh()), independent low/high IRQ mask matching, leaving LVTS_OFFSETH untouched when new_high == INT_MAX, and masking offset IRQs before writing LVTS_OFFSETL/LVTS_OFFSETH. - Shortened patch subjects and normalized prefix to "thermal/drivers/mediatek/lvts:". Testing note: - Patches 1, 2, 3, and 5 were regression-tested on MT6789 hardware (iKKO MindOne, factory golden_temp = 60) in an out-of-tree port of lvts_thermal.c on ACK 6.18 (the unpopulated-tz IRQ path in patch 5 was not directly triggered on this hardware). - The exact lvts_temp_to_raw_mt7988() boundary cases and the patch 4/5 lvts_recompute_thresh() / MMIO write-ordering state machine were verified in a host userspace test harness under ASan and UBSan, not directly on mainline hardware. Found and drafted with an AI coding assistant. Ilia Snezhkov (5): thermal/drivers/mediatek/lvts: write LVTS_CALSCALE in configure thermal/drivers/mediatek/lvts: fix 32-bit overflow in temp_to_raw thermal/drivers/mediatek/lvts: serialize lvts_set_trips() per ctrl thermal/drivers/mediatek/lvts: recompute shared trips and mask first thermal/drivers/mediatek/lvts: skip sensors without tz in IRQ drivers/thermal/mediatek/lvts_thermal.c | 220 +++++++++++++++--------- 1 file changed, 142 insertions(+), 78 deletions(-) -- 2.54.0 (Apple Git-157)