Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp101384lqb; Tue, 28 May 2024 09:54:52 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWwK5aAu0WI2RurPqs0RzxB0ZnnQ0zawiLhvjS0cys+UPmHNbxaWa+fFbvywhKKQKslVrUCU9nEGwskXZaZAsDJxB4YVOmJLTlLUZ/7zw== X-Google-Smtp-Source: AGHT+IEEIAU09ZNIG1fWTGfcitExwkm2MELHh5wWzMkfmYaaM3tDTIuJdG4ISAFuAFMRZ6GwBrNX X-Received: by 2002:a17:906:902:b0:a61:8e0d:a773 with SMTP id a640c23a62f3a-a6264f0eec4mr862988366b.47.1716915292328; Tue, 28 May 2024 09:54:52 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1716915292; cv=pass; d=google.com; s=arc-20160816; b=ASV6HBR6q2Vu8H02PZNSHmGppuHBKuWtP9nhdaL2HKKD+k3ZmcpyS8q+iYGqxftXfH UuhO7xGM3yJJRG+qWu4WW0eXMPo6VKJsZ5atbFlLjJ1jJmjKbacKQk3p/AwtbuoEqSZS WhwnYUE5xDNV6My20twQBG/7zJCnc2fiTpUyvDs8VDKdsCvgwqQOK7gXj2oKmZnN96wy fLj0ANZ8mujs1muRP0shXa4n67vRoyRAKLPJwnUkTPZKpxekH2XgqUUeD/SJhXEOIEem 1JZGPNPj0/+JW0WVEDB6i3kB5jV/DIGTDo5Ye/g4OUB8sC9tflmwbFIQ3MECz10fwVeO /CdQ== ARC-Message-Signature: i=2; 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:dkim-signature; bh=UR1aS0MLaJr2mQsA7T5C/qfJE/DdMozb3Owb9QAkDLk=; fh=GzCkp9dboMjnsRASvUnR8RkBPyyMxU6lLzxcgnbmqi0=; b=wasJIIvMxc6mpHKwjnKra8tVB9GBOno/VBD7F84m0EOG6vjm4Rjw0Q92PugQdZiuia s0nAEFarWFhBgVIU81l8KgzZUlTPnUrqYeVyP5Kvg59iwEJKxp2/a51F4Qdukk8qJxMY qJiup6CaoSoW5TPfMfrtJI6zE7MjTlvo9kl0hKu6HrjeI8z+Hm3CuhEE6tFgDqioB+uQ F6AHzyV1BTehY4T/4tdLoXKQcUC6zE/6YAThEetO6pqK4jLqLC11tvYwg2LDaY/bXrgr fMqcUjGqeuscGvhy2wLHGFror+R7CSwWDxqG3IvAmuCmbFcwR7cGeU5xh7YFmOU3W/We otvA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=FC+N34PE; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-192781-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192781-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a63570e5ce9si41445466b.316.2024.05.28.09.54.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 28 May 2024 09:54:52 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-192781-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; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b=FC+N34PE; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-192781-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-192781-linux.lists.archive=gmail.com@vger.kernel.org" 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 1677D1F23A2C for ; Tue, 28 May 2024 16:54:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C842A174EE2; Tue, 28 May 2024 16:54:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b="FC+N34PE" Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 06D9A172BD5; Tue, 28 May 2024 16:54:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=79.96.170.134 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716915266; cv=none; b=iFL8PJvU4iKlkE1HizyKel7zFGYOthmlQwaGgUebYoaeiYtk6tIIbh9NzedXTKlUniIUDeNonOPYhtVHJMAsDVtH5qR8GqcBmWiWrVt+9yNaTkrA0XyfFEoR94erqx+yyJQSrwCE4yxDay8PWCa5vEcXQvHeqo50XhXbW1t0rCU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1716915266; c=relaxed/simple; bh=8XIYogP3QOocTXaYFjvA1ITRN9o8M4WWA9w3jjM1ifQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=isixggLuW7IOUck4MYt80p5HGPUJV9rYWMC8TY4itXerBmEl5h2XRvLp+q6I844M1zEhL6yDkfEH6oW7Q6jP2H/OgXOnaiPQ1W7R1BpVuJ8oYKr6ir/KuSafsJAz8m7ruesEhNop2qkNJUnGgGGnDe61qj0emHSWbtodLWVvjI4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net; spf=pass smtp.mailfrom=rjwysocki.net; dkim=fail (2048-bit key) header.d=rjwysocki.net header.i=@rjwysocki.net header.b=FC+N34PE reason="signature verification failed"; arc=none smtp.client-ip=79.96.170.134 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=rjwysocki.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=rjwysocki.net Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 6.1.0) id 5c2a131d28357f4b; Tue, 28 May 2024 18:54:22 +0200 Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by cloudserver094114.home.pl (Postfix) with ESMTPSA id 5C7E66A5036; Tue, 28 May 2024 18:54:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1716915261; bh=8XIYogP3QOocTXaYFjvA1ITRN9o8M4WWA9w3jjM1ifQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=FC+N34PEHvn0DUdSE9pceaXChjVgRnrzzFHpKNiuWrNjoQS8VDUnUAZ2AvV/lbFO4 c20/SUjPmxj/jFGmqgKdDQ1OOJrk/olhC2lrLAFzRbmg+64NKHHUgCCi3URM9XR760 OFrMW2WnEIce8NbaJjEMJ8rp80Ezyi6uaTTcJeA9d1z69DE7FkzbjxqiMiFbpuRfdY V0iZuUiXvsim/B0YzItGd7eNFb5nkdyKAE+P9GlP8Nbe58iUQq+i6eec+LDf8sjkf6 blcXcHxMAr3Wl+ywMLFDERyXIFDwWuG56VSQ10a7R94u6ktu25aJYgprdYDKY/khJP MXxbnHBpZbPuA== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , "Rafael J. Wysocki" , Lukasz Luba , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui Subject: [PATCH v2 3/5] thermal: trip: Use READ_ONCE() for lockless access to trip properties Date: Tue, 28 May 2024 18:52:13 +0200 Message-ID: <1902136.tdWV9SEqCh@kreacher> In-Reply-To: <12458899.O9o76ZdvQC@kreacher> References: <12458899.O9o76ZdvQC@kreacher> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvledrvdejkedgjeekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopegurghnihgvlhdrlhgviigt rghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 From: Rafael J. Wysocki When accessing trip temperature and hysteresis without locking, it is better to use READ_ONCE() to prevent compiler optimizations possibly affecting the read from being applied. Of course, for the READ_ONCE() to be effective, WRITE_ONCE() needs to be used when updating their values. Signed-off-by: Rafael J. Wysocki --- v1 -> v2: Rebase. --- drivers/thermal/thermal_sysfs.c | 6 +++--- drivers/thermal/thermal_trip.c | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) Index: linux-pm/drivers/thermal/thermal_sysfs.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_sysfs.c +++ linux-pm/drivers/thermal/thermal_sysfs.c @@ -139,7 +139,7 @@ trip_point_temp_show(struct device *dev, if (sscanf(attr->attr.name, "trip_point_%d_temp", &trip_id) != 1) return -EINVAL; - return sprintf(buf, "%d\n", tz->trips[trip_id].trip.temperature); + return sprintf(buf, "%d\n", READ_ONCE(tz->trips[trip_id].trip.temperature)); } static ssize_t @@ -163,7 +163,7 @@ trip_point_hyst_store(struct device *dev trip = &tz->trips[trip_id].trip; if (hyst != trip->hysteresis) { - trip->hysteresis = hyst; + WRITE_ONCE(trip->hysteresis, hyst); thermal_zone_trip_updated(tz, trip); } @@ -183,7 +183,7 @@ trip_point_hyst_show(struct device *dev, if (sscanf(attr->attr.name, "trip_point_%d_hyst", &trip_id) != 1) return -EINVAL; - return sprintf(buf, "%d\n", tz->trips[trip_id].trip.hysteresis); + return sprintf(buf, "%d\n", READ_ONCE(tz->trips[trip_id].trip.hysteresis)); } static ssize_t Index: linux-pm/drivers/thermal/thermal_trip.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_trip.c +++ linux-pm/drivers/thermal/thermal_trip.c @@ -161,7 +161,7 @@ void thermal_zone_set_trip_temp(struct t if (trip->temperature == temp) return; - trip->temperature = temp; + WRITE_ONCE(trip->temperature, temp); thermal_notify_tz_trip_change(tz, trip); if (temp == THERMAL_TEMP_INVALID) {