Received: by 2002:a05:7412:a9a8:b0:f9:92ae:e617 with SMTP id o40csp38955rdh; Wed, 20 Dec 2023 15:18:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNHqwQzciefSR98RQtnsZak22DyWgRKoMWbxyObqd80Ua27KkfyRdhh6mQZsE+rZtTcihm X-Received: by 2002:a17:906:36d5:b0:a23:dffc:9ff4 with SMTP id b21-20020a17090636d500b00a23dffc9ff4mr3731472ejc.27.1703114333577; Wed, 20 Dec 2023 15:18:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703114333; cv=none; d=google.com; s=arc-20160816; b=wGbm0bFkkYXBSUxgR3guKT/PWoels+15cm26CfbqG9Z9uSAIP2GLAfPQkypOQa7BwV LHjTrQhX1VugsQm2RLjnqoZIxcImvuOZAEhUHI47q0/0+9Defn/6S9yAeOa/SRiCRFHe PdQLf7CBOJR4B7q08vfsHr0nPl+5Qmee9vXPkHzq/JxQXRgndkq2EOpzq6AvPiTsJv/b sZKepCtRm76OhnxnOeJBh/D2sFASooqECS44uQIckVdDF5EC7VISqX8Y+rOQoBu3NDc7 1YZjaV2Uo7rBJJXqoKHmQO+9F88qbL6kzPRF/nOBhSFaTpY2iI+yJDTaXXdR3zfWvTu2 k5VA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=zn1sy36H8FEmmSfbilQBVnkwdcCw5fuD350ICT8tkh8=; fh=BLXDRFxX5XTO46cEytehPgkEKhEpfPIIZAXbZsHkuJk=; b=jrN5aJGZyclrC3Ap5pCH1t5aZwj1sFt3Joe6+9Ax19sJUWSWudpp1FclF61kYd1FDi 2nZkdVVob9MrN7twuRiHCZTA5hukoEJODnc6lR96PRvyKKU/rIEXG08MRk33oM0thgk9 yAVH3yQhDYesHq1MtHSxXIAYvz4zObMMjabSpaiEbLWHfkMVABImEyt17hC0+aqon3o/ GSHAqOLcz//PUyw+txU7zLjuFEjSTxNcArxddbW+DyWhS27YarycY+zvSFMprRFqD1nb Cdj3Usd1dZo5I1MSiOTJkMGr/SFiLjxctdylvShXkvSJzalajCHAkJkfo+qWen4Tpx2N FXJA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-7629-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7629-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id dm16-20020a170907949000b00a1dfe5894aasi244397ejc.332.2023.12.20.15.18.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Dec 2023 15:18:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-7629-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-7629-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-7629-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 5ACB51F24118 for ; Wed, 20 Dec 2023 23:18:53 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E7BCA4CDF0; Wed, 20 Dec 2023 23:17:05 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3ED0F4CB2C; Wed, 20 Dec 2023 23:17:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=arm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=arm.com 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 1D1922F4; Wed, 20 Dec 2023 15:17:49 -0800 (PST) Received: from e129166.arm.com (unknown [10.57.82.217]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id D87BB3F64C; Wed, 20 Dec 2023 15:17:02 -0800 (PST) From: Lukasz Luba To: linux-kernel@vger.kernel.org, rafael@kernel.org Cc: linux-pm@vger.kernel.org, daniel.lezcano@linaro.org, rui.zhang@intel.com, lukasz.luba@arm.com Subject: [PATCH v3 7/9] thermal/sysfs: Update instance->weight under tz lock Date: Wed, 20 Dec 2023 23:17:51 +0000 Message-Id: <20231220231753.1824364-8-lukasz.luba@arm.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20231220231753.1824364-1-lukasz.luba@arm.com> References: <20231220231753.1824364-1-lukasz.luba@arm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit User space can change the weight of a thermal instance via sysfs while the .throttle() callback is running for a governor, because weight_store() does not use the zone lock. The IPA governor uses instance weight values for power calculations and caches the sum of them as total_weight, so it gets confused when one of them changes while its .throttle() callback is running. To prevent that from happening, use thermal zone locking in weight_store(). Signed-off-by: Lukasz Luba --- drivers/thermal/thermal_sysfs.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/thermal/thermal_sysfs.c b/drivers/thermal/thermal_sysfs.c index d8ff74a4338a..299c0fb16593 100644 --- a/drivers/thermal/thermal_sysfs.c +++ b/drivers/thermal/thermal_sysfs.c @@ -936,7 +936,11 @@ ssize_t weight_store(struct device *dev, struct device_attribute *attr, return ret; instance = container_of(attr, struct thermal_instance, weight_attr); + + /* Don't race with governors using the 'weight' value */ + mutex_lock(&instance->tz->lock); instance->weight = weight; + mutex_unlock(&instance->tz->lock); return count; } -- 2.25.1