Received: by 2002:a05:6358:53a8:b0:117:f937:c515 with SMTP id z40csp4414317rwe; Mon, 17 Apr 2023 12:15:25 -0700 (PDT) X-Google-Smtp-Source: AKy350YNK3UaEnTkOcg6hi4WTt1RGt6LfgFEfsz46VMknBF/4ho0QgUgsu9AT2j4sM7+vQfrYwf4 X-Received: by 2002:a05:6a20:4925:b0:dd:df53:4351 with SMTP id ft37-20020a056a20492500b000dddf534351mr15600131pzb.40.1681758924974; Mon, 17 Apr 2023 12:15:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681758924; cv=none; d=google.com; s=arc-20160816; b=refIwTepSTbmwXMIq9MyxNToT3DEZc2VHpj5fRB5DI2E7n3Muydu0RBMS70VWM8PMa PZMbXyIyqYQ2rzpR9RHyc7o9p+5PZp7WJRevl2OUuDTB26BRddjheT3JsocFzayXr/8/ psn47ef+OzVlYAwWCwFpz7CAHja8Ih3ncidVGRPPZZyKQJbtyT7FPp/YpiGnSz4729Hq IDKCaFzbbk53wwAUEPzpVwT3p3JbbpaRdq9YAUbe68qaKDlhtyXXCL7jB4B9vHJ2acqW qCA3w3FqaR02akb76iFZudQ5MMCk+Rk/OLylQ0McIRFgeONaHaMV6Qt7rqXBUEAosBbz 6R+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:date:from:dkim-signature; bh=um1aePTMmxrWsi2GLli2ilatx36oHvor21ECPKcsLyA=; b=oHei8vQWmD9cS1Nl39uYWMvy/5dapfC/OMCOOszyW/EKqGPWMmGBZHxu8i/Oddhiby BGwsuPI+SkDEtiCANAQzsDanfvWeXcJPJiGV/vjPWKhwcLgTNgewa85zjm0dOX1Q62Hg u6bkwEsB91txSGLMR3FxJR+b34pZOzvgY14npw9I4QMFRT14tpIklnB5axh0+6SW2i96 11I5MwLI8vCSOrhpS7nVLmkv/vXZx6fFUyiCCHfD6USSmoQqZ1bof2uh3XDBEuajuK81 hlqgQ9l6u6UGVnDZHS/hMPL1qpw6uWnyuGv/FCXTZ5tFqVf7en+Wd92FzJe60LOqYGEJ Sy2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=PzxDxYeo; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j15-20020a654d4f000000b0050c164c8e99si11985401pgt.436.2023.04.17.12.15.09; Mon, 17 Apr 2023 12:15:24 -0700 (PDT) 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=@gmail.com header.s=20221208 header.b=PzxDxYeo; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230352AbjDQTJQ (ORCPT + 99 others); Mon, 17 Apr 2023 15:09:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229554AbjDQTJL (ORCPT ); Mon, 17 Apr 2023 15:09:11 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AA915BA7; Mon, 17 Apr 2023 12:09:10 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id h24-20020a17090a9c1800b002404be7920aso27390338pjp.5; Mon, 17 Apr 2023 12:09:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1681758549; x=1684350549; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:from:to :cc:subject:date:message-id:reply-to; bh=um1aePTMmxrWsi2GLli2ilatx36oHvor21ECPKcsLyA=; b=PzxDxYeono/BrAzsGyYXWDmTFFWDf7M6HLd2Tsdcl30qrD8mj5+PR+80VlrQiL71ub PJxIkIJy7ljO6nWTfAWam6ozw6SQRg4X4B9YOImYPLgKg6lNk4h5qB4O8DneqPd5+W3c hOac/dY/0a/rtMD4uFmoNVPckiQSJ2I8iCnkohK75LSG+BPakGpi/wYy1DCdz8rWuk8t eldm5Koz0uJ7Jg9ILUp+ideegrPrNHnnX0nr9hMmtHZp0hm/k9bvSyglo8HIlgFv81K0 9mLZTtLLFnkb2afxb+itZ2cq8Ki+iLDS1ZuvO3/xTAYwehRC8Mudtx+S48FJNIUzbiFi qqoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681758549; x=1684350549; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=um1aePTMmxrWsi2GLli2ilatx36oHvor21ECPKcsLyA=; b=g3M0mnc8OYJ6B8dn96Vde8fK51OtEOtULTtc/Ri1rhsrE0f+4Yi+P5HYpRW/Q+GD20 pEczGZi3bfiUZrtR+jZDprFpuqXCcWVl946SR2Pg+Ex0eKWYHlGbUfkuZtuQgV3iIjEq L8K7XzyQLpBH6XHWEFPzfuViizDpU/ZOeLyJpTgGkHuQDTBobK5GeI/QhG8/gOP//Qi0 puxuWzWFdFQXDH40AaddEBolnXER9ApOSIMSwAUsvisj8f7AJTp4jwECsCSqz+3yogEH +QYbBTLUISI0TbjUykybzs98IukzSe/PJq4gy+zzC5EMcks/6pc2jkxy+kRrRZl2nkZN aPOw== X-Gm-Message-State: AAQBX9c505qGZ78GbKQt3byvLTRQdUcN0IhCmBXTc8MYLweiLEsy7bUI Kin+ehkJ3BNRKxXRBb1UQdMkpNSSPgpdVg== X-Received: by 2002:a17:903:187:b0:19d:1834:92b9 with SMTP id z7-20020a170903018700b0019d183492b9mr17780346plg.56.1681758549386; Mon, 17 Apr 2023 12:09:09 -0700 (PDT) Received: from kazuki-mac ([2400:4051:ea3:5910:ae9:b36:cd78:dae1]) by smtp.gmail.com with ESMTPSA id n23-20020a170902969700b001a27e5ee634sm6038077plp.33.2023.04.17.12.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Apr 2023 12:09:08 -0700 (PDT) From: Kazuki H X-Google-Original-From: Kazuki H Date: Tue, 18 Apr 2023 04:09:03 +0900 To: "Rafael J. Wysocki" Cc: linux-pm@vger.kernel.org, Hector Martin , Sven Peter , "Rafael J. Wysocki" , Daniel Lezcano , Len Brown , Pavel Machek , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-kernel@vger.kernel.org Subject: Re: [PATCH 3/3] PM: s2idle: Fully block the system from entering s2idle when cpuidle isn't supported Message-ID: References: <20230316074750.289025-1-kazukih0205@gmail.com> <20230316074750.289025-3-kazukih0205@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Hi, apologies for the late response. On Mon, Mar 27, 2023 at 07:43:02PM +0200, Rafael J. Wysocki wrote: > On Thu, Mar 16, 2023 at 8:49 AM Kazuki H wrote: > > > > s2idle isn't supported on platforms that don't support cpuidle as of > > 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() > > too"). > > This simply isn't correct. > > As of the above commit, s2idle was still supported without cpuidle as > long as arch_cpu_idle() worked. Sorry I linked the wrong commit, ef2b22ac540c (cpuidle / sleep: Use broadcast timer for states that stop local timer) is the correct one. This adds this block of code if (cpuidle_not_available(drv, dev)) goto use_default; which prevents this code, critical for s2idle, from executing if (idle_should_freeze()) { entered_state = cpuidle_enter_freeze(drv, dev); if (entered_state >= 0) { local_irq_enable(); goto exit_idle; } reflect = false; next_state = cpuidle_find_deepest_state(drv, dev); } else { reflect = true; /* * Ask the cpuidle framework to choose a convenient idle state. */ next_state = cpuidle_select(drv, dev); } > > There is a check in the cpuidle subsystem which would prevent the > > system from entering s2idle. However, there is nothing in the suspend > > framework which prevents this, which can cause the suspend subsystem to > > think that the machine is entering s2idle while the cpuidle subsystem is > > not, which can completely break the system. > > > > Block the machine from entering s2idle when cpuidle isn't supported in > > the suspend subsystem as well. > > First, please explain why the cpuidle_not_available() check in > cpuidle_idle_call() is not sufficient to avoid the breakage. cpuidle_idle_call() doesn't notify the PM subsystem that the host doesn't support s2idle. We need a seperate check here, otherwise the PM subsystem will happily continue entering s2idle without the other subsystem's knowledge. > > > Link: https://lore.kernel.org/all/20230204152747.drte4uitljzngdt6@kazuki-mac > > Fixes: 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too") > > Signed-off-by: Kazuki H > > --- > > kernel/power/main.c | 12 +++++++++--- > > kernel/power/suspend.c | 5 +++++ > > 2 files changed, 14 insertions(+), 3 deletions(-) > > > > diff --git a/kernel/power/main.c b/kernel/power/main.c > > index 31ec4a9b9d70..b14765447989 100644 > > --- a/kernel/power/main.c > > +++ b/kernel/power/main.c > > @@ -133,6 +133,8 @@ static ssize_t mem_sleep_show(struct kobject *kobj, struct kobj_attribute *attr, > > for (i = PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++) { > > if (i >= PM_SUSPEND_MEM && cxl_mem_active()) > > continue; > > + if (i == PM_SUSPEND_TO_IDLE && cpuidle_not_available()) > > + continue; > > Not really. > > > if (mem_sleep_states[i]) { > > const char *label = mem_sleep_states[i]; > > > > @@ -185,11 +187,15 @@ static ssize_t mem_sleep_store(struct kobject *kobj, struct kobj_attribute *attr > > } > > > > state = decode_suspend_state(buf, n); > > - if (state < PM_SUSPEND_MAX && state > PM_SUSPEND_ON) > > + if (state == PM_SUSPEND_TO_IDLE && cpuidle_not_available()) > > And same here. > > > + goto einval; > > + if (state < PM_SUSPEND_MAX && state > PM_SUSPEND_ON) { > > mem_sleep_current = state; > > - else > > - error = -EINVAL; > > + goto out; > > + } > > > > + einval: > > + error = -EINVAL; > > out: > > pm_autosleep_unlock(); > > return error ? error : n; > > diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c > > index 3f436282547c..55ddf525aaaf 100644 > > --- a/kernel/power/suspend.c > > +++ b/kernel/power/suspend.c > > @@ -556,6 +556,11 @@ static int enter_state(suspend_state_t state) > > > > trace_suspend_resume(TPS("suspend_enter"), state, true); > > if (state == PM_SUSPEND_TO_IDLE) { > > + if (cpuidle_not_available()) { > > + pr_warn("s2idle is unsupported when cpuidle is unavailable"); > > + return -EINVAL; > > + } > > + > > #ifdef CONFIG_PM_DEBUG > > if (pm_test_level != TEST_NONE && pm_test_level <= TEST_CPUS) { > > pr_warn("Unsupported test mode for suspend to idle, please choose none/freezer/devices/platform.\n"); > > -- > > Again, I need to understand what the problem is in the first place. Thanks, Kazuki