From patchwork Tue Jul 18 18:06:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 122202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c923:0:b0:3e4:2afc:c1 with SMTP id j3csp1945245vqt; Tue, 18 Jul 2023 11:57:56 -0700 (PDT) X-Google-Smtp-Source: APBJJlF+oKyixfjriDlrINDxVFwpumJbtHeuLAyv+4e3R32hQJsC+Czw9WGLoL7Kp9gwTrnpEYEo X-Received: by 2002:a05:6a20:7f85:b0:132:ef90:1d1d with SMTP id d5-20020a056a207f8500b00132ef901d1dmr387992pzj.0.1689706675866; Tue, 18 Jul 2023 11:57:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689706675; cv=none; d=google.com; s=arc-20160816; b=vyUHSLd+I4Oi7eY1czuRydTdv3004ByfizYHu5Q3jESNbGhhnwA0QjHrnBq/UAWmrE rggalamaZjnnTQA7sdkA/wddlQt3Pw4PXlrW45hPV79oWo/0lRBmTXTofKP5vPCTSEVz Ff5G7cSG4ZQ3pyWOSPe/oeGrhOnRSrGpaGJd+5BJIuFwyinJKy3sDO/MR+SweloJGR1L 10f9+AXP/zYAUKca47wbLCpB/YRvStETH7/z31hhAS6BQYR55vvBX5lyL8g8pcxKJxIA f7JftB4w2scWgSqRMLcf4NH9lQi0gzsIQbhTVjwxNvv3lPsEWlEDSq+wolQ57CZEuIps 4BXQ== 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=RqsLgAHG1ElqV+YrLiaoxgDR9kem7XP2SXh6iE4duBw=; fh=WAm0nkxw3rD71A4QzwJS1JiPPKRsyn91IiWMPsOrzoY=; b=B1a4nOaZT3lsXboFE34g9Hwc6q0M7UGggRNBFMlO/hN8ox30WIU7qjrHA+rTm7fLgF dP557mAq9U8O5gUu7M75C2O3cUBkKNk8IeuAEdnNQzgQXoxxMuGzTOEhVGSaFo3D613u V8Ca9PlBDfMZbbPkd7lqztl75ELmUxsVYVoDvZCMoMMz9AFqHXT4nKuTW/3Jk5pZYBdq /9R1EHQBpWxuZN3ANm3NIQhi7qtXZZOinBMoyHhuLBT7ypAd+6/RJZf11Y1/qYyYvEmC uTmWMd4+FENv7AvAq/Tn4vqHQzrmFmRqPHJZjH5kbTeRZ/gnVBVXSjnKYxSuDB1KYcL3 QGbA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f3-20020a637543000000b0056337aa2f06si1645546pgn.527.2023.07.18.11.57.41; Tue, 18 Jul 2023 11:57:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229796AbjGRSVm (ORCPT + 99 others); Tue, 18 Jul 2023 14:21:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229536AbjGRSVe (ORCPT ); Tue, 18 Jul 2023 14:21:34 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 81D7BFD; Tue, 18 Jul 2023 11:21:27 -0700 (PDT) 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 5.2.0) id 1abb4fa41606034e; Tue, 18 Jul 2023 20:21:26 +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 v370.home.net.pl (Postfix) with ESMTPSA id 86FC26614F7; Tue, 18 Jul 2023 20:21:25 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v1 4/7] ACPI: thermal: Hold thermal_check_lock around trip updates Date: Tue, 18 Jul 2023 20:06:02 +0200 Message-ID: <21958338.EfDdHjke4D@kreacher> In-Reply-To: <13318886.uLZWGnKmhe@kreacher> References: <13318886.uLZWGnKmhe@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrgeeggdduudelucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhkvghrnhgvlhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehmihgthhgrlhdrfihilhgtiiihnhhskhhisehinhhtvghlrdgtohhmpdhr tghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehsrhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhm X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1771785867653956328 X-GMAIL-MSGID: 1771785867653956328 From: Rafael J. Wysocki There is a race condition between acpi_thermal_trips_update() and acpi_thermal_check_fn(), because the trip points may get updated while the latter is running which in theory may lead to inconsistent results. For example, if two trips are updated together, using the temperature value of one of them from before the update and the temperature value of the other one from after the update may not lead to the expected outcome. To address this, make acpi_thermal_trips_update() hold thermal_check_lock across the entire update of trip points. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/thermal.c | 4 ++++ 1 file changed, 4 insertions(+) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -193,6 +193,8 @@ static int acpi_thermal_trips_update(str struct acpi_handle_list devices; bool valid = false; int i; + + mutex_lock(&tz->thermal_check_lock); /* Critical Shutdown */ if (flag & ACPI_TRIPS_CRITICAL) { @@ -395,6 +397,8 @@ static int acpi_thermal_trips_update(str } } + mutex_unlock(&tz->thermal_check_lock); + return 0; }