Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp395625rdg; Thu, 12 Oct 2023 08:39:29 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpTMptVb1Y1JVuIcwyw7bQOLuQwKwSNK9lGCVZ7fFYGxQa5jMIJOBY3lrW5e0MPT8QmzbP X-Received: by 2002:a05:6a20:4323:b0:16b:b4a0:e06b with SMTP id h35-20020a056a20432300b0016bb4a0e06bmr18856376pzk.43.1697125168777; Thu, 12 Oct 2023 08:39:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697125168; cv=none; d=google.com; s=arc-20160816; b=DtNqxoYssUrnejcgHEz/FhDFD/0uuFAYNLpRcx9wCR8pWdTdalrnq4IjZOMt4RLYKD VJWEQ64yMBoL6Ox6YAXcJbxIrFg4nyYvRy3q/jTyQn9KvZBVSEUR2v4GLUcPvyjCfTeX KfDyG177l5lBDeCQaYtvn47dPho1UZjvvMZwuBoVHSFpRz8zY/ND9I9BHbeDY//LtnK6 Q5HvTCC507Mkig/szckP9MNGrc4Ok20jYvog+a53wNGHwdFehfXjGev15hIVeixb5Won 1T5hoR9DtJaQKP8yqsORlf9oMMGlNPMfx3V4vNXotVXhYl13F6xst5lQmTXzljPGf90J RTuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=5Wg3EaV0LyOJdSGTmlTY0VxnIGoAeFlp+VouKoS5lNQ=; fh=qJcDSiWYQaFZQGhmjIGwyPt3r80QkLWppqT8dBtny8o=; b=Q2jods0UtAY7Xp6lQvYDHTAqDDyORKyKPA9emEVYHWjVV6mcjHN4/4lzjNK6ZUJtTz MfRNN5woGU3pvFfw2/kkGP0IAmT2SFXG/pISX2vunD9tdP/fUp2kTler82yDLwECjhIX vCOpwxYB5S/WjYGk8rVEFOo3P9QvCeBdFqKAzztaqVRNBuHpqum4Z8aAbWE/pdwYsGXp mx/9rO71EadiJPlLd4F5Q7mRL+T+IvgwkvVW8dp5zzWuUeZVPA119C6Pjt95AxFzpqa0 j0JlVljoWwhO7pxHrhE334yjADK0XEK8z4bkrK7Y5yJW7/5xLxLrcBGDpI0wyvEOf/Vb xxwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qam4t52z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id q2-20020a170902788200b001c9c566b847si2281828pll.84.2023.10.12.08.39.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 Oct 2023 08:39:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qam4t52z; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 4363B83EDDB7; Thu, 12 Oct 2023 08:39:25 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379274AbjJLPjN (ORCPT + 99 others); Thu, 12 Oct 2023 11:39:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347155AbjJLPjN (ORCPT ); Thu, 12 Oct 2023 11:39:13 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0877EC9 for ; Thu, 12 Oct 2023 08:39:11 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-4064867903cso13603945e9.2 for ; Thu, 12 Oct 2023 08:39:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1697125149; x=1697729949; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=5Wg3EaV0LyOJdSGTmlTY0VxnIGoAeFlp+VouKoS5lNQ=; b=qam4t52zhOlQYvHEQkXqZfHl4olMDg4/jI68jmOciD/tv32vxvVoxCeP34yi+dGqS8 xn4Eh8UKujgMLRqU/HM2arJnh6LvEdmxxyp4roKRHUQtzWbSQXBM4zQoIrRA6lEhDlcT mznqKrnQA4zsgkQ/7dqsOmDJBrDkUHc1XFDUtz8HRWl1g2A5EXhpL15igk+sYDg4lqop KiED5Hi820TZ9ENGH4EKKYMA7mDVkSbAVFNb0rU3Pw3c03ovbQVbpuNAbqez52P6RChf DBJY/2GrJvZIWP5jzehdgyhc44iuK3rXv6XK7Mg0Zw5lEia/Z8/NNWAUw1YQZSjh7R+n K/+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697125149; x=1697729949; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=5Wg3EaV0LyOJdSGTmlTY0VxnIGoAeFlp+VouKoS5lNQ=; b=TMX/6SSGUaRgvE+wiwYJ7+kxM5YHF6u2uMuND5XAUngZ36EOSfwoQ0z+BJTJ04pmqa wllvsSwI9GGzezI1dIgd5GR0mUUBHrkXVsDI+izekdF0K1DOGg8J714IYp9QFhEpRVjj qeqaZmvCC3QHYT4WZw4yAJGmC9vUiGuseJuqCr4PvbqXLBBmzygZWbuJ/fcSlyIX/5fB zpz57COpBxhgTUC06WL6HTuZlmU73N+BaylM8BUrHF6bEXPdUe/Q2ZOi0aCQDFjv9OiH 2J4Zy4ibJ0NnSwGm+uhWyGoTR66bK4pO9tPwGgaKKpP/yudsP6VFLBfr+0wL8VPRLUfm 5kLQ== X-Gm-Message-State: AOJu0YwFWb2tq/fxQ6jLfzofa+raPUfEX1oItaTIEg1qIK4htrXTOEAi 9jdvl1uSK8cZj71EUQDuEGWTog== X-Received: by 2002:a5d:5f04:0:b0:32d:8872:aacb with SMTP id cl4-20020a5d5f04000000b0032d8872aacbmr4751690wrb.53.1697125149337; Thu, 12 Oct 2023 08:39:09 -0700 (PDT) Received: from ?IPV6:2a05:6e02:1041:c10:c49e:e1a5:3210:b8c0? ([2a05:6e02:1041:c10:c49e:e1a5:3210:b8c0]) by smtp.googlemail.com with ESMTPSA id f8-20020adfe908000000b0032d8ce46caasm2778956wrm.93.2023.10.12.08.39.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 12 Oct 2023 08:39:08 -0700 (PDT) Message-ID: Date: Thu, 12 Oct 2023 17:39:08 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] Subject: thermal: Fix potential race condition in suspend/resume Content-Language: en-US To: Bo Ye , "Rafael J. Wysocki" , Amit Kucheria , Zhang Rui , Matthias Brugger , AngeloGioacchino Del Regno Cc: yugang.wang@mediatek.com, yongdong.zhang@mediatek.com, browse.zhang@mediatek.com, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org References: <20230916113327.85693-1-bo.ye@mediatek.com> From: Daniel Lezcano In-Reply-To: <20230916113327.85693-1-bo.ye@mediatek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Thu, 12 Oct 2023 08:39:25 -0700 (PDT) On 16/09/2023 13:33, Bo Ye wrote: > From: "yugang.wang" > > Body: > This patch fixes a race condition during system resume. It occurs if > the system is exiting a suspend state and a user is trying to > register/unregister a thermal zone concurrently. The root cause is > that both actions access the `thermal_tz_list`. I'm not sure the tasks are already thawed during POST_RESTORE, so no user can unload a driver and then reaching the race window. Is that an observed issue? > In detail: > > 1. At PM_POST_SUSPEND during the resume, the system reads all thermal > zones in `thermal_tz_list`, then resets and updates their > temperatures. > 2. When registering/unregistering a thermal zone, the > `thermal_tz_list` gets manipulated. > > These two actions might occur concurrently, causing a race condition. > To solve this issue, we introduce a mutex lock to protect > `thermal_tz_list` from being modified while it's being read and > updated during the resume from suspend. > > Kernel oops excerpt related to this fix: > > [ 5201.869845] [T316822] pc: [0xffffffeb7d4876f0] mutex_lock+0x34/0x170 > [ 5201.869856] [T316822] lr: [0xffffffeb7ca98a84] thermal_pm_notify+0xd4/0x26c > [... cut for brevity ...] > [ 5201.871061] [T316822] suspend_prepare+0x150/0x470 > [ 5201.871067] [T316822] enter_state+0x84/0x6f4 > [ 5201.871076] [T316822] state_store+0x15c/0x1e8 > > Change-Id: Ifdbdecba17093f91eab7e36ce04b46d311ca6568 > Signed-off-by: yugang.wang > Signed-off-by: Bo Ye > --- > drivers/thermal/thermal_core.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c > index 8717a3343512..a7a18ed57b6d 100644 > --- a/drivers/thermal/thermal_core.c > +++ b/drivers/thermal/thermal_core.c > @@ -1529,12 +1529,14 @@ static int thermal_pm_notify(struct notifier_block *nb, > case PM_POST_HIBERNATION: > case PM_POST_RESTORE: > case PM_POST_SUSPEND: > + mutex_lock(&thermal_list_lock); > atomic_set(&in_suspend, 0); > list_for_each_entry(tz, &thermal_tz_list, node) { > thermal_zone_device_init(tz); > thermal_zone_device_update(tz, > THERMAL_EVENT_UNSPECIFIED); > } > + mutex_unlock(&thermal_list_lock); > break; > default: > break; -- Linaro.org │ Open source software for ARM SoCs Follow Linaro: Facebook | Twitter | Blog