Received: by 2002:ab2:6a05:0:b0:1f8:1780:a4ed with SMTP id w5csp535799lqo; Fri, 10 May 2024 07:23:51 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVEH4v6Uc3XjaY4kWehz/qTloz6wxerBol4YWce9Sc9+xYcdRm707lPX6M5WoNvwMrV3b5A7gJQ7vzR1UCQzgKkdVWw1jsNdCLkDjVAEA== X-Google-Smtp-Source: AGHT+IGcGLniNfDydjBaA6UXpL2jQkaSDQeTzHWfaSsRjVXpkBJ2DW7QyDRWGJrGJzNFtFYf3z+I X-Received: by 2002:a05:6a20:5643:b0:1a9:8b4a:b84 with SMTP id adf61e73a8af0-1afde0e6adamr2666004637.18.1715351031574; Fri, 10 May 2024 07:23:51 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1715351031; cv=pass; d=google.com; s=arc-20160816; b=zsjmrLrBfYtugsyDUseYFgVH57OpuXm9x5UH0U2btj/yOUuiEkfcMtvbJEocsxnolY XOTH/DhRbTIrJBKsF4BK8NEv3Pygv7nho0dkWFKLFh+qqZeIXtOx0S79BFfV3WVYdyDA YnPIfdp650x1tZ1tw2dfJwvQodL412vT06cRnVP9ZifsRPwoILD0Sht6P4eRWRcpakxt mcZmjFcFtSjyyHuJ4226ympb/X2wPlEBdgNKeYo2GvwQqoK9F87b9Gzn3NWDr8VhASLy 9pj33bQuJJDRH533bmZ0UiB5jOYA4ttMaG3Nq1c0uHn/RrQVWXkE0kU9hi3P645VJ8BP O4UA== 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=ybuwZrAnX5zh/eVDEKXTmwOoM2s2ZvNhDwN/jWaspbQ=; fh=GzCkp9dboMjnsRASvUnR8RkBPyyMxU6lLzxcgnbmqi0=; b=NmTty6rSQQnzTI2x7Hjv6pS9vKBB4TAAKqE/7kh5J7GdKcZISMyUqg65f+ikawC9OP zo9dSNh9pYjPI6WwfxlQYYgLULo4W0/dvY4U21kKa75kSYfJOL2xDh3K6JrId1qcxMuy wCUoVRRXvZoGjPYI1mM/zud3A4OhEPdmmEE4n25CPqbDqHduM4c+HyysnN8AWoMrVR97 DcF6WxoF2IFo76gN8nUw1hxx5RBXYkLeDPb1F8z+PnC47q0V7MHr3hcBE2ScHYNk3c0S gy4qqukQxC8mbKFXRArU8JTXiEzldi+j0P8WRYSqIub26fB2zmPcVIenOP3ytcUnluV1 wFUg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b="eh/ONn3v"; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-175885-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175885-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id 98e67ed59e1d1-2b6288695d0si6222203a91.4.2024.05.10.07.23.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 May 2024 07:23:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-175885-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=fail header.i=@rjwysocki.net header.s=dkim header.b="eh/ONn3v"; arc=pass (i=1 spf=pass spfdomain=rjwysocki.net); spf=pass (google.com: domain of linux-kernel+bounces-175885-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-175885-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 44BDFB2121E for ; Fri, 10 May 2024 14:21:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1CCEA17088A; Fri, 10 May 2024 14:20:45 +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="eh/ONn3v" 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 49B5412CDBE; Fri, 10 May 2024 14:20:41 +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=1715350844; cv=none; b=AVhZj2ZQkCZO5tKIZK8cWcL0UV3icjocVmOyJYoqYCfhh8xKdt4+67YuANL5aLwlrjU69wJY6WQAAx/t/wMioC5RkPoiIA4ZxuFngpNfcjet+PAMqUWV0DKk6ewjhxFoMq5m2dORraq9IAdrhOOfjHguWfnNVo9KH7lAleE52FA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1715350844; c=relaxed/simple; bh=IwYvx7AdtUSAnjVTaqdebSTKuEJtx9fGzXya37uUCEE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DF644H840KQVeF9SxYOTKYxJFEFrq7S08UlothPSAfXK3jAYjgzPXyVjdaPtZ79rWU2KMDJ19bxCTioMZcBppHwzERhIwwknEgf6bHyWS/yeZJPHTKgCn7acK8RaUwvr7Cq/EvejX8vO5Db3JCvHrjhLdHmY7Gah8PIUoqFQf4w= 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=eh/ONn3v 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.0.0) id b7e5f4da9462ce13; Fri, 10 May 2024 16:20:40 +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 A52BF2102F3F; Fri, 10 May 2024 16:20:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rjwysocki.net; s=dkim; t=1715350840; bh=IwYvx7AdtUSAnjVTaqdebSTKuEJtx9fGzXya37uUCEE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=eh/ONn3vkXsWfE2na/k8K7j4khJ5TlszDyqNR7FP09lDV1dr15b9ZINflAt3jo1mt 5HNjnPBeZHAo57+5eDuKrU7dPdhpew1uPusMAlCS/arockxsZSdwTQ4Xz8UB7j6eCe JCc/6srfOMkAqfh/KdpyeYrLcKGVXD3k5s6vMDnqkUWceYrv4GJ6U5GZz+KS44f9Sz DKqSzjpFJXTD2sjZSRreeduXUdJUD3psAyUPlhtw0VI0GGsAvVvnOSS80B16wgO6oK 81WUbGLOmIJttvw2srUIhTBiR8Ihwug21gJoSmcstloKtt36CJDloPRWyJdWdpIYKP WmMtpOR+DfERw== From: "Rafael J. Wysocki" To: Linux PM Cc: LKML , "Rafael J. Wysocki" , Lukasz Luba , Daniel Lezcano , Srinivas Pandruvada , Zhang Rui Subject: [PATCH v1 4/6] thermal: trip: Use READ_ONCE() for lockless access to trip properties Date: Fri, 10 May 2024 16:18:19 +0200 Message-ID: <7669508.EvYhyI6sBW@kreacher> In-Reply-To: <13518388.uLZWGnKmhe@kreacher> References: <13518388.uLZWGnKmhe@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: gggruggvucftvghtrhhoucdtuddrgedvledrvdefkedgjeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhukhgrshiirdhluhgsrgesrghrmhdrtghomhdprhgtphhtthhopegurghnihgvlhdrlhgviigt 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 --- 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 @@ -141,7 +141,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 @@ -165,7 +165,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); } @@ -185,7 +185,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); } EXPORT_SYMBOL_GPL(thermal_zone_set_trip_temp);