Received: by 2002:a05:7412:8d10:b0:f3:1519:9f41 with SMTP id bj16csp4647023rdb; Tue, 12 Dec 2023 05:48:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IHhbp5cEMQIwy8ZnkRz5Z6eyosl7Iw18MrJ9AA25SVvGGT67cwk+NaD26lZ5M5t1KKJA2Hw X-Received: by 2002:a05:6a20:ce93:b0:18f:97c:4f64 with SMTP id if19-20020a056a20ce9300b0018f097c4f64mr2592178pzb.112.1702388909953; Tue, 12 Dec 2023 05:48:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702388909; cv=none; d=google.com; s=arc-20160816; b=Z5cuteHUSrZnVsewhIzijB4pgy8/PwTBkcNHgpqgp9xD993dzTxoJ9cVA0SKXfKJ3K KwGsNm//Q9NpRfVpuO70D9z9xhEd6vg6X3mdwhlTigF1YA/AVewrIFLS1Fm2dUiHZu0T Cd9LMQYZcoum29zBQkqUBjC/+hKjI3utuqh59r5dGFS+V7F7UNpJIJRCT1C6hK+F5rOE OY97qMHiNbCue0VeWBtmbuGwh9FYgZqEkBIisrlhFyWxoOrYXatteYVA1irAePvaDXRS MgG7KPEj0hWyb23LAQ828IP/DpSEiXqJ1OXnaDaNW38RwmdsYRbu0pt5InpAYNXoep7e OElA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=pDy5fEP4XOh3ErCcLJFQKzQqtLqJcGuPOX+UTCs8LYY=; fh=8IgpUQ2T6XGOjA/qDosxdUSIIBz0a6nQ23NA8pgv1Tg=; b=cH6M+ZqAYT9XR3J3yTkMUYKBhMzOxyRXihpAMIx97QwvpoxN8c9Z3a9FkUBaugnWhz DhF5cV4DhuHkY1J5Q8ac4sKQb2vzAOy3MqzkSyNMbZplp+S8bhqJtNAtOZVRTeoJhVAz Bp7t37I/ilCSh6rGlvHh6D7SSx5hLbIOoftH1BTcgLO6CfLIRNkBeIX7/GHV+uBAcY1v /qbkH1uTbuRS4bz37OIj2NxY34DzTls9a8DFxis6hxfdMgIQg5EktqIxXXpPO/zRmkNj bQuj35AMG7g1CbHIy2UHN1ORmRAtPK0XgsFvNafW7HTsv+Bvv77QnszENjNCedJsP4E2 kRZg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e4-20020a17090a4a0400b0028abf878ca1si1021660pjh.46.2023.12.12.05.48.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Dec 2023 05:48:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id C2933805F09D; Tue, 12 Dec 2023 05:48:28 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1376381AbjLLNsQ (ORCPT + 99 others); Tue, 12 Dec 2023 08:48:16 -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: 8bit X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Dec 2023 05:48:28 -0800 (PST) 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_sysfs.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; ret = kstrtoint(buf, 0, &weight); @@ -968,7 +969,12 @@ ssize_t weight_store(struct device *dev, struct device_attribute *attr, return ret; instance = container_of(attr, struct thermal_instance, weight_attr); + tz = instance->tz; + + /* Don't race with governors using the 'weight' value */ + mutex_lock(&tz->lock); instance->weight = weight; + mutex_unlock(&tz->lock); return count; } -- 2.25.1