Received: by 2002:ac8:678b:0:b0:405:464a:c27a with SMTP id b11csp17430qtp; Tue, 1 Aug 2023 12:20:28 -0700 (PDT) X-Google-Smtp-Source: APBJJlH5+YA/2lLahMcC+PZHlURnjmI+utvZbQt84ly/nHDRcXPHTfYX2Mp+IbI4PsUOTS0/8grT X-Received: by 2002:a05:6a00:b4e:b0:67f:48a2:5d9f with SMTP id p14-20020a056a000b4e00b0067f48a25d9fmr18449365pfo.11.1690917627934; Tue, 01 Aug 2023 12:20:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690917627; cv=none; d=google.com; s=arc-20160816; b=VwMGEqlmMGZzvedFMqy+mxpf6jheelng+TWc1gyw6wgWhJPqtIy/1ak7TryVoAabUq Uv8AFv4GhJSztKxk8REaHfeI/1GyjrtsI0ZHNJNURRcm5WpTGKGtY6bvk+xNNw9hKk5Q CD5S5ME1SWOaahPqO2Mk+WEfTYvWpDFSS5gibcGG+tHAR9Hpjm00CGxtq0DDFGMiN6Vz fGGi3+IloQXj8LZOffPJ6O7HAOdBnQuiygoGTG37b7FmSgOdwqEBXD/ifGses0pb2spb Mn07yr3KwYfbRQhhAUk7uQAT2B43yVbB3P36hZ+7EtsZtMfAHxMWfZC4J6WP6wML+Njg vd+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version; bh=hkmGfRsWcb6AIjog6HI5LeNRfcqucYrB/xABjqbeyWo=; fh=FQ/w6k7Qz6bMR8FOPJiFU9M7OR2iCyejlVLyqUye3Pc=; b=BaXUxBI2EOsQe8SQfINF4PHHJuiHwCBKY8S3/vc8UKS+ZbjRkrDetifT6mt9UCwiW0 oc8zzLzD1kVooOMhhYXfDLqF62uJTntlOT9yIr1WxEXnYsSs+tArM2HECYpCpMbWfZgC PNvQ4qahD/vF+rGI1+ianSJ1/SqHVUJU325queAu+HJewhAXimE+95VRSjGiwNsAwMQC RUh9kRc9XhLuGikNzKTn1AN0gEbR9eosr5iYTSyzLdi3NvlzjV8hdE3+VI8MU3IJilI6 sVsqL3h+AHbKl1BIcxfAv/0SB1fo7nzwhbVgslE9FZ3PGIc3E1CiG1bFPdkjWwgWSnVo le9w== 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y128-20020a636486000000b00543c84bf588si8278113pgb.473.2023.08.01.12.20.14; Tue, 01 Aug 2023 12:20:27 -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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230484AbjHASwT convert rfc822-to-8bit (ORCPT + 99 others); Tue, 1 Aug 2023 14:52:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230274AbjHASwS (ORCPT ); Tue, 1 Aug 2023 14:52:18 -0400 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2A64126A1; Tue, 1 Aug 2023 11:52:11 -0700 (PDT) Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-56d0deeca09so32945eaf.0; Tue, 01 Aug 2023 11:52:11 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690915930; x=1691520730; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oDF+MyCYxqY1Suy31l3VNJ8qreWErHQzhBqOCnxacPo=; b=GnRNdVeGxggrfPV1lIMsZoJd+xTxbj1fYGN6uugm7cDw+PMnBEIjwqQgiVB/SHh4U6 uTZ0SrRrGGgeuxUGnceFSMRe7ZI1AoRkD/Hv89j4Sh9+eO99Msx8796dm9t1cv/1jvlk 4qBzsq821urpo4tQqHigyv+xfk9S9uAiERiXT7VSI5LrV4YUAeXFGMUi25hCdNqmIjY6 /b/213kJ//7EA0UvXj2aEnEmpqVquzhKecBWMClUscwCf7CIn1bYzxzD5dELl3G64RPo W5RwZTmaJVOxY/PzyEAAsdaHUoaSNhDYL2/adNKv/gzN0tEkzWonOKEt5OQl2xUlJxyv UfDg== X-Gm-Message-State: ABy/qLZ1valhqZUNmf3NN4Wa1BJcYDm7c+Hwu5huO5J2CgA/Qt0cbI1C HjpkuYdpkyE9TYXKOQfCqUtytCUYk+5slRbdItdfjS8bI3o= X-Received: by 2002:a4a:cf14:0:b0:569:a08a:d9c5 with SMTP id l20-20020a4acf14000000b00569a08ad9c5mr7986887oos.0.1690915930146; Tue, 01 Aug 2023 11:52:10 -0700 (PDT) MIME-Version: 1.0 References: <13318886.uLZWGnKmhe@kreacher> <12254967.O9o76ZdvQC@kreacher> <7552439.EvYhyI6sBW@kreacher> In-Reply-To: From: "Rafael J. Wysocki" Date: Tue, 1 Aug 2023 20:51:58 +0200 Message-ID: Subject: Re: [PATCH v3 5/8] ACPI: thermal: Hold thermal zone lock around trip updates To: Daniel Lezcano Cc: "Rafael J. Wysocki" , Linux ACPI , LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_BLOCKED,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=no 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 On Tue, Aug 1, 2023 at 8:39 PM Daniel Lezcano wrote: > > > Hi Rafael, > > On 25/07/2023 14:16, Rafael J. Wysocki wrote: > > 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 the thermal zone > > lock across the entire update of trip points. > > As commented in patch 3/8, having a driver locking a thermal core > structure is not right and goes to the opposite direction of the recent > cleanups. It already happens though, because thermal_zone_device_update() locks the zone and it is called by the driver. > Don't we have 2 race conditions: > > acpi_thermal_trips_update() + thermal_zone_device_check() > > acpi_thermal_trips_update() + acpi_thermal_trips_update() I'm not sure what you mean. First off, acpi_thermal_check_fn() needs to be locked against anything using the trips in the zone's trips[] table, in particular thermal_get_trend(). However, thermal_get_trend() also uses the driver's private trips information, so it needs to be locked against acpi_thermal_trips_update(). And obviously the latter needs to be locked against acpi_thermal_check_fn(). > For the former, we can disable the thermal zone, update and then enable Disabling the thermal zone is an idea, but it would be necessary to do that in both acpi_thermal_check_fn() and acpi_thermal_trips_update(). Also I'm not sure how different that would be from holding the zone lock across the updates. Moreover, acpi_thermal_trips_update() would then need to hold the local lock around the thermal zone disable/enable which would be way uglier than just using the zone lock directly in it.