From nobody Sun Dec 28 06:57:24 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1D421C4332F for ; Tue, 12 Dec 2023 13:48:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376439AbjLLNsR (ORCPT ); Tue, 12 Dec 2023 08:48:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376341AbjLLNsD (ORCPT ); Tue, 12 Dec 2023 08:48:03 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DED3D10A; Tue, 12 Dec 2023 05:48:05 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E5D211474; Tue, 12 Dec 2023 05:48:51 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.82.227]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 62F0E3F738; Tue, 12 Dec 2023 05:48:04 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, daniel.lezcano@linaro.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, rui.zhang@intel.com, lukasz.luba@arm.com Subject: [PATCH v2 6/8] thermal/sysfs: Update instance->weight under tz lock Date: Tue, 12 Dec 2023 13:48:42 +0000 Message-Id: <20231212134844.1213381-7-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231212134844.1213381-1-lukasz.luba@arm.com> References: <20231212134844.1213381-1-lukasz.luba@arm.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The user-space can change thermal instance weight value while the throtte() callback is running for a governor. The IPA governor uses the 'weight' value for power calculation and also keeps it in 'total_weight'. Therefore, the 'weight' value must not change during the throttle() callback. Use 'tz->lock' mutex which also guards the throttle() to make the update value safe. Signed-off-by: Lukasz Luba --- drivers/thermal/thermal_sysfs.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysf= s.c index eef40d4f3063..df85df7d4a88 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -961,6 +961,7 @@ ssize_t weight_store(struct device *dev, struct device_= attribute *attr, const char *buf, size_t count) { struct thermal_instance *instance; + struct thermal_zone_device *tz; int ret, weight; =20 ret =3D kstrtoint(buf, 0, &weight); @@ -968,7 +969,12 @@ ssize_t weight_store(struct device *dev, struct device= _attribute *attr, return ret; =20 instance =3D container_of(attr, struct thermal_instance, weight_attr); + tz =3D instance->tz; + + /* Don't race with governors using the 'weight' value */ + mutex_lock(&tz->lock); instance->weight =3D weight; + mutex_unlock(&tz->lock); =20 return count; } --=20 2.25.1