Received: by 10.223.176.5 with SMTP id f5csp644230wra; Fri, 2 Feb 2018 03:52:53 -0800 (PST) X-Google-Smtp-Source: AH8x2259nIaTsxPuoh6J3t93KgvOo4EadJW7AKGyxpSnyv8J5fKGVfNPPLOtuxkkqVjEDSLKS8T+ X-Received: by 2002:a17:902:5417:: with SMTP id d23-v6mr34481335pli.330.1517572373400; Fri, 02 Feb 2018 03:52:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517572373; cv=none; d=google.com; s=arc-20160816; b=g7JpXH1ZVNpOGk0b53Ew+e5Tky7TGPfoEez+Ftqel+eA86bmTgqAF3wupx5Sn+0qgQ soGLG9zXNq1PJzpbR/YCbebCVqllVbxFkK5sbOXJV1GwdpOMbG1uSwqNc0eVZi1m8HmU 9eA5IkfYL0F32cJiXwu+XIr0ik9sra8Kb/fPb/5Gmc2Z6oFNF2bEDq4A61vtKKXX3mtc ymAu5uSXFqAI0uXArxCd4Dg71duEh5QsAE0BY1GLdQKwR+VvNsqDnMhU83DhgJXhrYV9 PoLU7DstPpAmQfNesX9XewxUve6OCye/raetKHa1LvccPowvJj5QeJl0/OJ4tKxWWBKK MIZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=2EdpE0BFtNunF20Oy22CghSmkXQzjSEZHCORD2eJOyI=; b=ZRvEVbTgs8Jw3qTvM9i9jUXnIediO/G/l4iUZKO4kTp6L8dc5b3POxSixxzML2aMCj euPXRNCGnA8TXZ5+G0w7hhotZLffQYVbRGTGtCc8t97Fr+GRaOOWKqUydaAYcL42+FBr ousa5p0Gl7qCcSGIW6Ja+SP0Hz0+mf+tDs1BMl2bZxs0ChtuS5/75LdgnrPQby9+Pk1J T5O8YRXDXydKXPGhjVN5C29WbgLFnfC03fqvUZ1mvQKrahuajRaXFa6sjTkV/5TdlrYv ON8OdZjzTv1uGkU5Xa57HbpN735LkZ0wV7LQ0Z7KYlZ2GxMnKAa99UOewdbcLNvZonw6 RdOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y7-v6si1606591plk.707.2018.02.02.03.52.38; Fri, 02 Feb 2018 03:52:53 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751824AbeBBLuN (ORCPT + 99 others); Fri, 2 Feb 2018 06:50:13 -0500 Received: from cloudserver094114.home.pl ([79.96.170.134]:54714 "EHLO cloudserver094114.home.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751580AbeBBLtu (ORCPT ); Fri, 2 Feb 2018 06:49:50 -0500 Received: from 79.184.255.223.ipv4.supernova.orange.pl (79.184.255.223) (HELO aspire.rjw.lan) by serwer1319399.home.pl (79.96.170.134) with SMTP (IdeaSmtpServer 0.82) id ca160ab88e1bf321; Fri, 2 Feb 2018 12:49:48 +0100 From: "Rafael J. Wysocki" To: Prateek Sood Cc: viresh.kumar@linaro.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, gkohli@codeaurora.org, linux-arm-msm@vger.kernel.org Subject: Re: Query related to usage of cpufreq_suspend() & cpufreq_resume Date: Fri, 02 Feb 2018 12:48:13 +0100 Message-ID: <1949391.4ffJqIIJSQ@aspire.rjw.lan> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Friday, February 2, 2018 12:41:58 PM CET Prateek Sood wrote: > Hi Viresh, > > One scenario is there where a kernel panic is observed in > cpufreq during suspend/resume. > > pm_suspend() > suspend_devices_and_enter() > dpm_suspend_start() > dpm_prepare() > > Failure in dpm_prepare() happend with following dmesg: > > [ 3746.316062] PM: Device xyz not prepared for power transition: code -16 > [ 3746.316071] PM: Some devices failed to suspend, or early wake event detected > > > pm_suspend() > suspend_devices_and_enter() > dpm_suspend_start() > dpm_prepare() //failed > dpm_resume_end() > dpm_resume() > cpufreq_resume() > cpufreq_start_governor() > sugov_start() > cpufreq_add_update_util_hook() > > After failure in dpm_prepare(), dpm_resume() called > cpufreq_resume(). Corresponding cpufreq_suspend() was not > called due to failure of dpm_prepare(). > > This resulted in WARN_ON(per_cpu(cpufreq_update_util_data, cpu)) > in cpufreq_add_update_util_hook() and cpufreq_add_update_util_hook->func > being inconsistent state. It caused crash in scheduler. > > Following are some of the ways to mitigate this issue. Could > you please provide feedback on below two approaches or suugest > a better way to fix this problem. > > -----------------------8<------------------------------ > > Co-developed-by: Gaurav Kohli > Signed-off-by: Gaurav Kohli > Signed-off-by: Prateek Sood > > diff --git a/drivers/base/power/main.c b/drivers/base/power/main.c > index 02a497e..732e5a2 100644 > --- a/drivers/base/power/main.c > +++ b/drivers/base/power/main.c > @@ -1038,6 +1038,7 @@ void dpm_resume(pm_message_t state) > { > struct device *dev; > ktime_t starttime = ktime_get(); > + bool valid_resume = false; > > trace_suspend_resume(TPS("dpm_resume"), state.event, true); > might_sleep(); > @@ -1055,6 +1056,7 @@ void dpm_resume(pm_message_t state) > } > > while (!list_empty(&dpm_suspended_list)) { > + valid_resume = true; > dev = to_device(dpm_suspended_list.next); > get_device(dev); > if (!is_async(dev)) { > @@ -1080,7 +1082,8 @@ void dpm_resume(pm_message_t state) > async_synchronize_full(); > dpm_show_time(starttime, state, 0, NULL); > > - cpufreq_resume(); > + if (valid_resume) > + cpufreq_resume(); > trace_suspend_resume(TPS("dpm_resume"), state.event, false); > } > > --------------------8<-------------------------------------- > > Signed-off-by: Prateek Sood > > diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c > index 421f318..439eab8 100644 > --- a/drivers/cpufreq/cpufreq.c > +++ b/drivers/cpufreq/cpufreq.c > @@ -1648,7 +1648,7 @@ void cpufreq_suspend(void) > { > struct cpufreq_policy *policy; > > - if (!cpufreq_driver) > + if (!cpufreq_driver || cpufreq_suspended) > return; > > if (!has_target() && !cpufreq_driver->suspend) > @@ -1683,7 +1683,7 @@ void cpufreq_resume(void) > struct cpufreq_policy *policy; > int ret; > > - if (!cpufreq_driver) > + if (!cpufreq_driver || !cpufreq_suspended) > return; > > cpufreq_suspended = false; Since we have cpufreq_suspended already, the second one is better. Thanks, Rafael