Received: by 10.223.176.5 with SMTP id f5csp747075wra; Fri, 2 Feb 2018 05:32:35 -0800 (PST) X-Google-Smtp-Source: AH8x2264vhVLPn3IlHB+OI+KfQrcPnI7JMWzljVZhOeou6X2jGTeXfT1THHdvu8o90FaimOQ82NJ X-Received: by 2002:a17:902:8f98:: with SMTP id z24-v6mr35954026plo.311.1517578355344; Fri, 02 Feb 2018 05:32:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517578355; cv=none; d=google.com; s=arc-20160816; b=ya8jfsKaEeemgAehOW2JAr0geoC+R3SLHQxlB7+Y6Z7ZcrcRl0mDLnb4INmk/EjYHj B/+rryYhVZOR0vjZfb3BYmOrhI5AgG6ts9NrmpQqzJEgjGc5vt7TpikulhSnP8RUtHDl vzCOXh05TF7GWlXxMsyjzd/qVpUmWzLpIwy1R9aBWt1/5WU/fDeifL/IUpbFkASHu1gU Qr8zbA7L2XXGtRXaT4nF55PqmXweMzhiqkR2ZyF76b0W2zYe98XKdQOKV2njmx+8AYn0 n/F/sbfNpf9DJJopE7qFrqqGKxYseVWkQ1XUdqciZLkbseNymXZMb51eHbIGHiZ/3yR4 qIYg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=hfwkFSVralTWmZ9ZQlHapUhxJ/6ChvEbXyiOETPdsmk=; b=dqLWtgH75D1g+Du8uQGkHrUC+NPg0YDcca0gOPLO9J03qOVKoukXWWdZjjG2VNlMUy 02AHQB4T/XsqWj1vQFOLpmklCD5eP+HTh2AjOCYk4FA/6nyO67G97pklpZdXVM/MlcxL rWfYhN4fH72mvf7R9yyQoYvd+Q/DA5gcRX0Zf5eUUAQLVoRvcVMZ702C9s+YxRFESDCi 8mv+A0ILz/WIHPTKZLXaowO6utrBxcQmx3zR6bguxXbAVkiMiPJsRReEZoxXP77DpQ+m ZPDCARO6jVXGJWBA4lrXZ03lv1uQZGN+KCyj7KBqBgoNlyGe5q4wAFMdGYp5orWNMiWO WWxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=WKe+RNwP; dkim=pass header.i=@codeaurora.org header.s=default header.b=ewy2gY7k; 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 j1si1432717pgt.674.2018.02.02.05.32.20; Fri, 02 Feb 2018 05:32:35 -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; dkim=pass header.i=@codeaurora.org header.s=default header.b=WKe+RNwP; dkim=pass header.i=@codeaurora.org header.s=default header.b=ewy2gY7k; 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 S1751792AbeBBNaD (ORCPT + 99 others); Fri, 2 Feb 2018 08:30:03 -0500 Received: from smtp.codeaurora.org ([198.145.29.96]:36510 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751584AbeBBN34 (ORCPT ); Fri, 2 Feb 2018 08:29:56 -0500 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 89960606AC; Fri, 2 Feb 2018 13:29:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1517578195; bh=fBwtozu8nvi99Fqqo5sFM1vCL2ZjaEjvX4h8I+dwrcA=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=WKe+RNwPNBvBcy/87bItxIx/TuWW68ZiwopjDiRhxsDjMv0u7e11XiKwxS0hLESqN RJ2XP3WUuFtaJzeDqGM8GxZUwAi8HxSDUnVqmstwTd0AX7DhEvFxMGk1OZ21qEs3hh 7wCeGOTj9kur4uTqNtO81ISXIVM92zqVZ09wqIZU= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [10.204.79.19] (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: prsood@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 8776F6050D; Fri, 2 Feb 2018 13:29:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1517578194; bh=fBwtozu8nvi99Fqqo5sFM1vCL2ZjaEjvX4h8I+dwrcA=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=ewy2gY7kUrxr7NUFCQwVyhererBQF1p8pKnYikbhLEnWZlY0SVDhqWkIgnnOQvmHd k750Olt0WrJ8NmwBVcN7bdzL8o8O+2icMIeAGPeTUf1F26qjOFnpd15nlhYIqx2Oxh Cdc6XNLbL290UrSwiBGq8t+0348yhJ9fKl5Ua3i0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 8776F6050D Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=prsood@codeaurora.org Subject: Re: Query related to usage of cpufreq_suspend() & cpufreq_resume To: "Rafael J. Wysocki" Cc: "Rafael J. Wysocki" , Viresh Kumar , Linux PM , Linux Kernel Mailing List , gkohli@codeaurora.org, linux-arm-msm , Bo Yan References: <1949391.4ffJqIIJSQ@aspire.rjw.lan> <7d50aeb5-cc2d-521b-2f31-5477e6e18f20@codeaurora.org> From: Prateek Sood Message-ID: <41912873-42d2-88a6-551a-5a0f732874d0@codeaurora.org> Date: Fri, 2 Feb 2018 18:59:50 +0530 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 02/02/2018 06:49 PM, Rafael J. Wysocki wrote: > On Fri, Feb 2, 2018 at 1:53 PM, Prateek Sood wrote: >> On 02/02/2018 05:18 PM, Rafael J. Wysocki wrote: >>> 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 for the inputs, I will send a formal patch. > > Bo Yan has posted something really similar already, however: > > https://patchwork.kernel.org/patch/10181101/ > > so I would prefer to apply a new version of that one with the latest > comment taken into account: > > https://patchwork.kernel.org/patch/10183075/ > > for the credit to go to the first submitter. > Thanks for the information Rafael. I believe safety check in both cpufreq_suspend() and cpufreq_resume() would be a good thing to have. -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc., is a member of Code Aurora Forum, a Linux Foundation Collaborative Project