From patchwork Wed Dec 14 13:16:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 33203 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp214723wrn; Wed, 14 Dec 2022 05:21:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf7J/rJUBf5gMQWszSWs1naSlV+KF2AGUIRQiQnZH7bwwl1Ut2eFJAj5s8s7e1TPvJWdtMAx X-Received: by 2002:a17:906:3c17:b0:7c0:dfb7:4476 with SMTP id h23-20020a1709063c1700b007c0dfb74476mr20523113ejg.57.1671024116509; Wed, 14 Dec 2022 05:21:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671024116; cv=none; d=google.com; s=arc-20160816; b=aa2wG8sYRPLNQoUhd1Z8bb+TeSNy+vXvBoXAZJjTl/LdlydkDEsTqxnLvEPcxn6gYm EfzTioi7CLI04oE/18JHPqZRtXQ364Wqw/XMzfTVWm0vIDbsRzPxIMNCjaXBRFAEbgCe TI5xXQBz8spbjwJB9izRrP7ldmvw7k8wlT5Xvm4aKFdse7mrlGL6GrveDbkmvje3vzV5 J8BV49ZBiVOFAcpWvzAv+8zqdQAbwNGgpEwbFbqpYogcnukfwhEinXVz5tWQxu3s4r5l QuMjgi3keXadZfDIewYxuavOfdzQg3995yLiTDMiBlmwUeyFsu6PyDH98TdouKUM0ANK BlcA== 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 :dkim-signature; bh=O6CsdFBHVS2h9kZL7zyRx1ZoGEA0/RKrgluBbLo1PvE=; b=xoonjEV8bWHzEs5K9BYBh6F+RQb4jhm9vzA4ro0MGj82MQgJ4evkBc2n4wXFrgzMY/ 14VbXO3VV9+HUsphvRpIAGqpNGMOY8rIHiTU/JUPDZLo6fr8nxaZ4TjnlpjW5CrJf11o S0u10Ni+x6dd4CLF2aNh81IXADKjXKOHNgK3/jxnhEsERpPzxKFE5AYZr6D/TWwbHp2K +ASE0XCHB7gJclbpYzYRVtGIKQD7TUn7b1QwZ3gJCQfqdPPGEA13bKxoBRuvOFPpe6HQ 6Qq8iXXC4SPTCXeHr1OmBzkDtK+YZSDYr4zn1v7Mx+y9QojOP/JWQiH+TEpouqRDCUAf PBIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Mw6CY3gg; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go37-20020a1709070da500b0078e1206d934si11785788ejc.162.2022.12.14.05.21.32; Wed, 14 Dec 2022 05:21:56 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Mw6CY3gg; 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 S238608AbiLNNTS (ORCPT + 99 others); Wed, 14 Dec 2022 08:19:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238463AbiLNNS7 (ORCPT ); Wed, 14 Dec 2022 08:18:59 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EACBA1B1F0; Wed, 14 Dec 2022 05:18:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A6CC9B818B4; Wed, 14 Dec 2022 13:18:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 52F83C43396; Wed, 14 Dec 2022 13:18:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671023934; bh=UCFo0ATECrapHBfgYnwVb9qzMIvCn8cEKis++tPi5aQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Mw6CY3ggr5HWgJSWziERMPdFzl7QJU9BkCjeghJp4NfImECloE5Dvq9Me4wyTK+RU YJCd72fDDShia2IrQj5qG374opeBTWoL5Z+Ohc3gMGxcZVoV46n2QrkO6Wzp2zlwWX EFTKIYIjbrVhNDAB+TWY/IdUF64KIcAQwOV4YJWUvq5nRs95QyzW//bnQlDeg57hmt cza83BCXlOTLYq89wqaFuYdToOLxyYfI49mZxrq2bZn4vD4khDtv84ROLimgDdfo0G ZMf9uE4v/pFJMx7s94q8Z16qJKtaqXMprQ53RSIlIEMibLdp1p1L451elxdLiKpZEO BXHhj5DW51Deg== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1p5RfO-0000gI-EO; Wed, 14 Dec 2022 14:19:22 +0100 From: Johan Hovold To: Daniel Lezcano , "Rafael J. Wysocki" Cc: Amit Kucheria , Thara Gopinath , Andy Gross , Bjorn Andersson , Konrad Dybcio , Zhang Rui , Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Dmitry Baryshkov , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, Johan Hovold Subject: [PATCH 1/4] thermal/drivers/qcom: fix set_trip_temp() deadlock Date: Wed, 14 Dec 2022 14:16:14 +0100 Message-Id: <20221214131617.2447-2-johan+linaro@kernel.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221214131617.2447-1-johan+linaro@kernel.org> References: <20221214131617.2447-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752195784053115590?= X-GMAIL-MSGID: =?utf-8?q?1752195784053115590?= The set_trip_temp() callback is used when changing the trip temperature through sysfs. As it is called with the thermal-zone-device lock held it must not use thermal_zone_get_trip() directly or it will deadlock. Fixes: 78c3e2429be8 ("thermal/drivers/qcom: Use generic thermal_zone_get_trip() function") Signed-off-by: Johan Hovold --- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 2 +- drivers/thermal/thermal_core.c | 1 + include/linux/thermal.h | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c index 58055a7abaf6..bfaec74f13b2 100644 --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -270,7 +270,7 @@ static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz, int trip_id, in struct thermal_trip trip; int ret; - ret = thermal_zone_get_trip(chip->tz_dev, trip_id, &trip); + ret = __thermal_zone_get_trip(chip->tz_dev, trip_id, &trip); if (ret) return ret; diff --git a/drivers/thermal/thermal_core.c b/drivers/thermal/thermal_core.c index c24c9efcd175..d9a3d9566d73 100644 --- a/drivers/thermal/thermal_core.c +++ b/drivers/thermal/thermal_core.c @@ -1214,6 +1214,7 @@ int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, return tz->ops->get_trip_type(tz, trip_id, &trip->type); } +EXPORT_SYMBOL_GPL(__thermal_zone_get_trip); int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, struct thermal_trip *trip) diff --git a/include/linux/thermal.h b/include/linux/thermal.h index e2797f314d99..30353e4b1424 100644 --- a/include/linux/thermal.h +++ b/include/linux/thermal.h @@ -334,6 +334,8 @@ static inline void devm_thermal_of_zone_unregister(struct device *dev, } #endif +int __thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, + struct thermal_trip *trip); int thermal_zone_get_trip(struct thermal_zone_device *tz, int trip_id, struct thermal_trip *trip); From patchwork Wed Dec 14 13:16:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 33201 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp214579wrn; Wed, 14 Dec 2022 05:21:43 -0800 (PST) X-Google-Smtp-Source: AA0mqf5Ca3quBWe8ijs7LL4XlHvV3/JXVS8kMIE1G9FsF3j5JIAMbyFyYd0aqjF+d7qK80zrApEP X-Received: by 2002:a17:906:a148:b0:7af:bc9:5e51 with SMTP id bu8-20020a170906a14800b007af0bc95e51mr21335686ejb.41.1671024103078; Wed, 14 Dec 2022 05:21:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671024103; cv=none; d=google.com; s=arc-20160816; b=rBDG4YTlS5TkQaYhNNYkhiRPD+PPwhICeFFl6nvj9bPyGllXlb2NWDxVaspwlZ6bif 7Nc5Idn1KhaoIiE/bp+/s7tk+r8pJ1iAa1X0HkFY8p2xkSN4Ub6R2Cqi7smhaiqyHEYv S4j4XVwlsiNHtNCuKSNyGgcBcTZNOvP2PNGxecKaKcwY+rHdOULh0PtespDkjlKH2hnW pyB7aEIq5NrBtvyUoPpP9juTaymbZGdNakmhpytFyDvTWglAQ9DI+neNmPNBBHyQgkvC s/E1aueL+nv75E+EJssegKxb26ZKxm/SDixZXj+z07/rt8Z9QQTeWEBmk9CnMFizhIHu USRg== 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 :dkim-signature; bh=a4hI6UsBiw7aCkL0PcywkQ0FEO8YbDmUUU/KycZpHwY=; b=vIvrKqtdeb1RbY/GBK+mHUZrriaGtsKdmCfiuRPRc2VX7Lu92LsVJIJEYMwPp/VoWM SydHLsU1/C7jVR5gzigZX43DOs4GyLhcrPk4iZ4tZU7insJBqVynhhD8h6aDwnzW6Lm1 H4/UGCJS9Ti6inJE7HRSrV7wIqBxD1abd/htEVomfixJ2CBll1bm2Bf2S5OHW35xzPb5 vHenHfSnCg3EIV3i+XSiZ1YgfCY7hjU7ys4apkxOrVoxd3bKsWjW9iWCIShLVTqfdUY/ m81qhyF+2me32KUneAqIor9ZXZ9OOdJi4IOFv9AWr1bxiF6GwwrcZmLWG7dCRvgYuY5j w39g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=e2WaLz9u; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id fj3-20020a1709069c8300b007c1100d2875si11777540ejc.750.2022.12.14.05.21.17; Wed, 14 Dec 2022 05:21:43 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=e2WaLz9u; 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 S238481AbiLNNTI (ORCPT + 99 others); Wed, 14 Dec 2022 08:19:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238446AbiLNNS5 (ORCPT ); Wed, 14 Dec 2022 08:18:57 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E53EAEE16; Wed, 14 Dec 2022 05:18:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 989F0B818B1; Wed, 14 Dec 2022 13:18:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 43BDEC433D2; Wed, 14 Dec 2022 13:18:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671023934; bh=I3NjFkga/P0GdNEJyAvlKrNR4+s/YWzEm5lbyRY0s9o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=e2WaLz9uLD0YeDJNA+Ip5rqhGSXG1u8qeishyJFdMYLR6Q4x2qHmyPIxxxb5STvGM A/G5AzxETsvPhBcetsWvZUtJipLXsjwDoDXwif3Wi1NdluMHisdWXhaROrgnmVs5eV XB+913GHKWDIleY8/bmovAaooXU5CJk+5jxkG5EewY6aaaF4Kj1t8DzP8MzeoHnpxh Z6NzORvKUPLloBA4ok1WE85k7cJZWuR9mD/2FAakMLTfbTGaCc08HkNIPhxAFvdatL cxbqlyACrKBkyTZBicZB6GTYFHuLEAP5mA/ccsZXdtdB8lT1vjB50P3vCOj5Q221nb qY++E7gwzKEoA== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1p5RfO-0000gK-Hc; Wed, 14 Dec 2022 14:19:22 +0100 From: Johan Hovold To: Daniel Lezcano , "Rafael J. Wysocki" Cc: Amit Kucheria , Thara Gopinath , Andy Gross , Bjorn Andersson , Konrad Dybcio , Zhang Rui , Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Dmitry Baryshkov , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, Johan Hovold Subject: [PATCH 2/4] thermal/drivers/exynos: fix set_trip_temp() deadlock Date: Wed, 14 Dec 2022 14:16:15 +0100 Message-Id: <20221214131617.2447-3-johan+linaro@kernel.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221214131617.2447-1-johan+linaro@kernel.org> References: <20221214131617.2447-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752195769957637581?= X-GMAIL-MSGID: =?utf-8?q?1752195769957637581?= The set_trip_temp() callback is used when changing the trip temperature through sysfs. As it is called with the thermal-zone-device lock held it must not use thermal_zone_get_trip() directly or it will deadlock. Fixes: 169865e317f2 ("thermal/drivers/exynos: Use generic thermal_zone_get_trip() function") Signed-off-by: Johan Hovold --- drivers/thermal/samsung/exynos_tmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c index 37465af59262..cf9028f80415 100644 --- a/drivers/thermal/samsung/exynos_tmu.c +++ b/drivers/thermal/samsung/exynos_tmu.c @@ -354,7 +354,7 @@ static void exynos4210_tmu_set_trip_temp(struct exynos_tmu_data *data, struct thermal_trip trip; u8 ref, th_code; - if (thermal_zone_get_trip(data->tzd, 0, &trip)) + if (__thermal_zone_get_trip(data->tzd, 0, &trip)) return; ref = trip.temperature / MCELSIUS; From patchwork Wed Dec 14 13:16:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 33204 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp214810wrn; Wed, 14 Dec 2022 05:22:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf7n+Wu8hyLEYp5eDdrjB5WyHRxqgp8H6r2Q/OIkL/xPyXFjaIzHmHr/hHepeXyrGqLRJTIO X-Received: by 2002:a17:906:d18f:b0:7b2:75c6:6d3c with SMTP id c15-20020a170906d18f00b007b275c66d3cmr20420197ejz.74.1671024127863; Wed, 14 Dec 2022 05:22:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671024127; cv=none; d=google.com; s=arc-20160816; b=K8D5noHLKJUXXfPU5+fy9rWw/iO7s/3jSHjaNinNqGET+FmuJY5qsE44k20fOF4d36 7UWhvrkEW6xMgMUjn2rZzrpPdvb0E8RCNB4kbsLOovQcGohNLx0x2QtFZZKHHWg20mhW dxmMjRLY97o+/69cnoiigUHYMA01VMsgJAC1shU+jmMrl5bqyRv6LUazqDOOPTq7dWE5 +3zAAswSTLx70YUjAzTbbDwe81J89VD9RSAAkUxgbS5jU38Tbz446Wq5RPs6zSNt/oXL 5DOX+U7e3R7tY8h537mYy80pE1+qPUBGSfAwxlVYJdUfDP04Wy8EdXTA8Vf+aBxdDSXX VC/A== 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 :dkim-signature; bh=QljZUV13XD4olbDUKuz1zm2aCzLRxJJCfhe3kR1SKRs=; b=NfkSXh6p54/co59zDMLiKTWqseWLH48rnbeAziQWly6fjRufPkwEtrYDpMr4CP6TyQ XHx8TcC6y8EJVeNajaGP5swC2mOfUAs0cdpHFsbfCuHiC5plbOu1Q/pm6rDr3ouhryqV pEQU0Ev8njK4+PUSdKbIQ7Okw12TJZ59XJR2O0A3YAcIA3rbwL83Xoty7D4XvbBv4RnR wJb1iuk+BQTFrpgqgL3YuFYiPA3n+S/iRXDYWKH9/YK0z15eQ1Ox4djGFuG4Lb2yPi5J RycP/eX8eiD7YULzNBDFA61D4UT1s4SXC2uuP4/uwUz7etg0H5bGAH5bePAaYay6rmgF Mhuw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z4tNaPYh; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ga8-20020a1709070c0800b007c10bb9225bsi12208075ejc.975.2022.12.14.05.21.43; Wed, 14 Dec 2022 05:22:07 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Z4tNaPYh; 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 S238615AbiLNNTW (ORCPT + 99 others); Wed, 14 Dec 2022 08:19:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44450 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238496AbiLNNS7 (ORCPT ); Wed, 14 Dec 2022 08:18:59 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 003D2205CD; Wed, 14 Dec 2022 05:18:56 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B3F66B818B6; Wed, 14 Dec 2022 13:18:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 501A3C433AA; Wed, 14 Dec 2022 13:18:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671023934; bh=pUvEkaZ93TrgdiMPgbWAhQQFmdmtaGqKxLqih4iKcMU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z4tNaPYhQ+umQ4W+AIlhusLg33i3tL1Gzd+nFpK3a5GHUosvVNTKfE0eJCahr7dE1 CURwKN+RXbUdavJnJhKY3PDISjPRiiwBvEpmC2SFEkdO+6yS2GPi9UCXXjWnH590uR MGGSLN2uIftEE8nVGaZeyydpxpUIDRddNRdmaq59jH63UYufTlNQ0p5u+CwbLxFpKd /Pg7Ba/xUdWIxSBuUvLKeA2+qWEx96ZYaEXrvsikDfaiF82URpzZT7F07RVImf90Ay sDfZj/sR8i1I4Wy3CVA+3GVBZXe6ybbozYBy8+sCz2CGT4albApv6ipWn2qJZJBvz4 jksoqniLJGFFQ== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1p5RfO-0000gM-KX; Wed, 14 Dec 2022 14:19:22 +0100 From: Johan Hovold To: Daniel Lezcano , "Rafael J. Wysocki" Cc: Amit Kucheria , Thara Gopinath , Andy Gross , Bjorn Andersson , Konrad Dybcio , Zhang Rui , Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Dmitry Baryshkov , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, Johan Hovold Subject: [PATCH 3/4] thermal/drivers/tegra: fix set_trip_temp() deadlock Date: Wed, 14 Dec 2022 14:16:16 +0100 Message-Id: <20221214131617.2447-4-johan+linaro@kernel.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221214131617.2447-1-johan+linaro@kernel.org> References: <20221214131617.2447-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752195795650658524?= X-GMAIL-MSGID: =?utf-8?q?1752195795650658524?= The set_trip_temp() callback is used when changing the trip temperature through sysfs. As it is called with the thermal-zone-device lock held it must not use thermal_zone_get_trip() directly or it will deadlock. Fixes: 56d7b397cc29 ("thermal/drivers/tegra: Use generic thermal_zone_get_trip() function") Signed-off-by: Johan Hovold --- drivers/thermal/tegra/soctherm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/thermal/tegra/soctherm.c b/drivers/thermal/tegra/soctherm.c index 4203e74e2f79..220873298d77 100644 --- a/drivers/thermal/tegra/soctherm.c +++ b/drivers/thermal/tegra/soctherm.c @@ -594,7 +594,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip if (!tz) return -EINVAL; - ret = thermal_zone_get_trip(tz, trip_id, &trip); + ret = __thermal_zone_get_trip(tz, trip_id, &trip); if (ret) return ret; From patchwork Wed Dec 14 13:16:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 33202 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp214603wrn; Wed, 14 Dec 2022 05:21:44 -0800 (PST) X-Google-Smtp-Source: AA0mqf7AZmFUIoUB+kDgDMLe6zXOoILvDBER9/kYvvbGhWq7EIgF8E8Ty/yaMB65ag6JSyA6MVIT X-Received: by 2002:a17:906:c088:b0:7c4:a773:4d72 with SMTP id f8-20020a170906c08800b007c4a7734d72mr3071597ejz.64.1671024104837; Wed, 14 Dec 2022 05:21:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671024104; cv=none; d=google.com; s=arc-20160816; b=ytUMaS6yKgT2OungOSBs9vHgTNK62BXmzT8ez/7CljCNLC6WD0qF6A0jpc/q5xxhnR NzzVn6KrDrfRWyJVUG9rkza6YcP/kZND7KIg2YV9CeMwtHDv+cb/Ct7j8Wd8lWPXLMj3 i/0JIB/mrH7lI2du0Is2vTfEt22v2jmKlmL4VmLjxn5UbTIeDgiFhq0kmD8MN1a/417Y rNiQzDTPReji28v9i55UQ+wJ9aQU+fDggZ84kpej1mOt3ih5Dk6/0wj5CXXKpicVuG5O oVW4glsgW43HWZiL5xorf8ANuVWqZr3xRSxcexb9HuVd/0tDnb8Mygq/9pSXgq6LU667 lDUQ== 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 :dkim-signature; bh=pZG2OvNILux+d/lbx8l3pM2EykA4OmReb45nk+2sFPo=; b=GWxRNs3iRc3GIDg8LO3lkMI5/gDLNPYI+t3451aSeeKTM9PtbP6HYQQkRtHLYtRBmL 9oB3ZYwYd8V1OP9Xvsf00fVn2aLbfAlJgchVMMuJ09FSPpsoYwQL+nibYcJD0ukXplIS AIvWjF7xVPdDOfmVc95FJDzy/258Hesw19rIOiP9CsF5o3EC2E/nHD9SLnOKNpn65ezf 3H6Hx6jrfQWZkmE+Q2FOQvdO7TqcDyWYFYpubagNf9uxm+U2bVPtKeObeb7OXtuz/1vR W5p9DTnZsF91sPHdXSfwTh85jXdvvcvdp2PafbaknLvcRPqCLstLITR6EV2PQMB47JJD RKlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QP7v+ZzV; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds22-20020a170907725600b007c185c81f57si5861812ejc.326.2022.12.14.05.21.20; Wed, 14 Dec 2022 05:21:44 -0800 (PST) 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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=QP7v+ZzV; 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 S238584AbiLNNTN (ORCPT + 99 others); Wed, 14 Dec 2022 08:19:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238520AbiLNNTA (ORCPT ); Wed, 14 Dec 2022 08:19:00 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12920209AC; Wed, 14 Dec 2022 05:18:57 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id C3B0DB818BA; Wed, 14 Dec 2022 13:18:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4A14FC433EF; Wed, 14 Dec 2022 13:18:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1671023934; bh=xwJ2F+HL8Yk0Fx3XqoMXtNfS5GIPd1gzxcsg5dDoon8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=QP7v+ZzVI06/yPy1cj0gYDD7mG1of1hKuSt/w5bpOrTOsOETjgUEc6Dxsq65g4/hQ Fjy5ZqjxlEO4FPBy+HmWmxUARSuxIc328Fzp+FLLmftMf0i9OO7JDX0pfLb1AAELxO 4F2oUr73dVKcnjM84Sm1+0uoO332iQyxBEjrQDzgOhOchxhbfaBaP0GiecxfOpt8U7 2RgX4K0g69VvqkFaH3Oy4ffIl4AFigY7gl+xIltPIJbjXCwlSdgufiiDPMDhPmI97X cp5rZOCf/Bmf7NFqdGdEGrwTBsae1YJmG5SHuHSmoPTDEGuXLGZ97M7gAlRE+SBO+a iT520n6hJ8R2Q== Received: from johan by xi.lan with local (Exim 4.94.2) (envelope-from ) id 1p5RfO-0000gO-Nm; Wed, 14 Dec 2022 14:19:22 +0100 From: Johan Hovold To: Daniel Lezcano , "Rafael J. Wysocki" Cc: Amit Kucheria , Thara Gopinath , Andy Gross , Bjorn Andersson , Konrad Dybcio , Zhang Rui , Bartlomiej Zolnierkiewicz , Krzysztof Kozlowski , Alim Akhtar , Thierry Reding , Jonathan Hunter , Dmitry Baryshkov , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org, linux-samsung-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-tegra@vger.kernel.org, Johan Hovold Subject: [PATCH 4/4] thermal/drivers/qcom: fix lock inversion Date: Wed, 14 Dec 2022 14:16:17 +0100 Message-Id: <20221214131617.2447-5-johan+linaro@kernel.org> X-Mailer: git-send-email 2.37.4 In-Reply-To: <20221214131617.2447-1-johan+linaro@kernel.org> References: <20221214131617.2447-1-johan+linaro@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752195771718440198?= X-GMAIL-MSGID: =?utf-8?q?1752195771718440198?= The thermal-zone-device lock is held by core when setting trip points and the driver takes its chip lock in the corresponding callback. Fetching the thermal trip points using thermal_zone_get_trip() also involves taking the thermal-zone-device lock, which means that the chip lock can not be held when doing so. Drop the chip lock temporarily during probe to avoid the lock inversion that was detected by lockdep: ====================================================== WARNING: possible circular locking dependency detected 6.1.0-next-20221213 #122 Not tainted ------------------------------------------------------ systemd-udevd/264 is trying to acquire lock: ffff741e444a0920 (&chip->lock){+.+.}-{3:3}, at: qpnp_tm_get_temp+0xb4/0x1b0 [qcom_spmi_temp_alarm] but task is already holding lock: ffff741e44341618 (&tz->lock){+.+.}-{3:3}, at: thermal_zone_device_update+0x2c/0x70 which lock already depends on the new lock. Fixes: 78c3e2429be8 ("thermal/drivers/qcom: Use generic thermal_zone_get_trip() function") Signed-off-by: Johan Hovold --- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c index bfaec74f13b2..e2429676d0d2 100644 --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -348,7 +348,12 @@ static int qpnp_tm_init(struct qpnp_tm_chip *chip) if (stage) chip->temp = qpnp_tm_decode_temp(chip, stage); + mutex_unlock(&chip->lock); + crit_temp = qpnp_tm_get_critical_trip_temp(chip); + + mutex_lock(&chip->lock); + ret = qpnp_tm_update_critical_trip_temp(chip, crit_temp); if (ret < 0) goto out;