Received: by 10.223.176.5 with SMTP id f5csp735361wra; Fri, 2 Feb 2018 05:21:14 -0800 (PST) X-Google-Smtp-Source: AH8x227EXlYDiDzhWai/AO7fHz/VKfFm0QkQOR0rULoCC7db01FAnRrpKlNMv2BJIy14J+d0fk3L X-Received: by 2002:a17:902:9a9:: with SMTP id 38-v6mr34554598pln.202.1517577674609; Fri, 02 Feb 2018 05:21:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517577674; cv=none; d=google.com; s=arc-20160816; b=DWUI8/2sZw2MSCEzrPh74L64lbVCQK0t7IS1RavhPni93pc91lnLaGqXfBBzTgBPxc 8k0wD68qWOzWmtWu/xbIlyi1wVxM+u8nxK0jzsfGZnYQkb9UUEmFr8olhFa+C2n3J71K QrWP3pOzLIY+cSMKYOA+ElDZodS/0S+Pa0/HVJ/9ZiyaThz/n5owHYiRX/4ySXXd9q6Z 5NQyKgm2NO4vCELU9Z+dzlXIzLWoFjM9htLeOgF/0TadUdhB2eeaPMJdb+Lv6LhhDlJw xo/RwD2l9TmzDz4+IWzMe+V+ZmacPjwv95JjZiL118LUugdSQgsV8z3ZqILDD+xlBZGI EcVA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=4Pjor6ZOwRnkn3qScIYkUiHxdmSFjoTucF2TeHeLXTo=; b=cTEFQPgphH7fqRBROsKeMpPel6Xw1qg4JrjPQL/hih4ndSkatJxLWGBRpz86k94q62 c8nuMOqmI/J5Eh6L7JJFjGMU2udI6vUbtKK5diYN4GAw8abN3V/xZndQ0T3BgMrT7GfV E937Aq2x94/2Qixj8bQngw8/gukGomz34GqsgOmepqB/dSTBfP5MwAwNgOxnMhKEYgr2 wsCiYM8ME8J4rf+07ztOPiWv2hXZIry9zRKtmuKdGkwbO2OyE4XN5aK6R43Jdtr372p1 ynrx77STqnwyECIQxxG1pqjGNrkqdsALnLIJ5045FY7AsST8yMXDsuHUE2zO6Ohn8vx9 SSWg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=dN9t61z7; 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 m186si1794355pfm.25.2018.02.02.05.20.59; Fri, 02 Feb 2018 05:21:14 -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=fail header.i=@gmail.com header.s=20161025 header.b=dN9t61z7; 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 S1751946AbeBBNTn (ORCPT + 99 others); Fri, 2 Feb 2018 08:19:43 -0500 Received: from mail-oi0-f67.google.com ([209.85.218.67]:35250 "EHLO mail-oi0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751651AbeBBNTe (ORCPT ); Fri, 2 Feb 2018 08:19:34 -0500 Received: by mail-oi0-f67.google.com with SMTP id e15so5906478oiy.2; Fri, 02 Feb 2018 05:19:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=4Pjor6ZOwRnkn3qScIYkUiHxdmSFjoTucF2TeHeLXTo=; b=dN9t61z7WaiO+Foy/RFesVD6GPcXZWXBThDr3NzNkUPXa7xokjTNywoguOnkP43PC/ ChACWeAQZIcFo8fzKc0cags7jKWU0s+2P33HZ2JgSKo6hTr1gIPI2dkmsa8dCsCr0vwT OgOCc+xTWuioA8HunwFV784Ft0XZWcUdSOt2C/xvZFX2OfGswmK/ENoc7I7nUMn9J9AC vD7XpLJ0jtIxtP7wBPJptidVSOqoZ2esiFipmq+qbUQdKW8K8KNxvBb9o1OKuHWbZPjq N/8/eSgKj/PvJsG0Cf+FVdsWoWq2oOW6iynNjPl2fH31ygVSO4cxNFELq6RaMzuyRkFH eWew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=4Pjor6ZOwRnkn3qScIYkUiHxdmSFjoTucF2TeHeLXTo=; b=DC9Mf1tdKgbcYs7nAipiIxLpHBGs9HOpOLNd3GRuXwwUdERWmPXx7+g93AO1XQXYgi QdTslkul6s1ve4vHVNJ+tsUFOZWbeGel9aRklqPwPXdrYHXYUeWtMMqOs6XOZiCNPnFf BpT5CXipo3FEGng/RMbwyBsADV540NS4JXLwX7YmjpYXgYuyHXexI1owX2/l0fm/x7/c Vmp+CeKgdC5ioO2AY2gwFbK4/oTEK3jjDhtKDWj98ot3GlFaz8z0Wicf6XAc5VcAtBXB 0SzemCT9ohAIP1KgMYGj5oWSn7bWVO379fHmJMy59avhYJ8GGREnJ2cbdMcl4KvwPI9E Z/zw== X-Gm-Message-State: AKwxytdU7ifdMSKtdtRiykdS5uBMUK1pWl3BUrjRadnXSuz9Lu7ooUI3 g/pFWd3fV6Kdnip7jI7ThxHm1WFTUBjKL1+pbFU= X-Received: by 10.202.222.139 with SMTP id v133mr10721524oig.298.1517577574050; Fri, 02 Feb 2018 05:19:34 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.46.234 with HTTP; Fri, 2 Feb 2018 05:19:33 -0800 (PST) In-Reply-To: <7d50aeb5-cc2d-521b-2f31-5477e6e18f20@codeaurora.org> References: <1949391.4ffJqIIJSQ@aspire.rjw.lan> <7d50aeb5-cc2d-521b-2f31-5477e6e18f20@codeaurora.org> From: "Rafael J. Wysocki" Date: Fri, 2 Feb 2018 14:19:33 +0100 X-Google-Sender-Auth: zRFmxgAt_J1Jl9iVDVHywo_Bkn0 Message-ID: Subject: Re: Query related to usage of cpufreq_suspend() & cpufreq_resume To: Prateek Sood Cc: "Rafael J. Wysocki" , Viresh Kumar , Linux PM , Linux Kernel Mailing List , gkohli@codeaurora.org, linux-arm-msm , Bo Yan Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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.