From patchwork Thu Mar 16 06:37:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kazuki Hashimoto X-Patchwork-Id: 70589 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp321041wrt; Wed, 15 Mar 2023 23:48:39 -0700 (PDT) X-Google-Smtp-Source: AK7set/+J1ImY2fOJf082bmWudYY25rhNp+1IlDSJDSkdj4lR6u+WXEPZmclTWAWU0/YpHJpMFtQ X-Received: by 2002:a17:903:41c5:b0:19c:171a:d342 with SMTP id u5-20020a17090341c500b0019c171ad342mr2789093ple.37.1678949318734; Wed, 15 Mar 2023 23:48:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678949318; cv=none; d=google.com; s=arc-20160816; b=INhLTp0YRGJJ2OBib9419+BYN0dbKpawYJsBg/MT62wgO0LIVU4OCJ+eBTYNEIgikU 7iIaWwgU6iIFpTH2EJ6OqkbxTfvflCvksQ7TdwwpttGr5U4x4jzmsHb2YpmkH1j1QPbG AS2+iVI/ljdTFGTfRGnBw1+eKseIgrey8lYNGSNw0Rz8N1eJsjGcARMOuOVw3ANGsFEj z9QW7ua9lg4F7Ck8tPJBZ07w/thxdZk4xTTOx2YtjMl+1gV3mQrPkp5lphiK5qCBx9Ii uqF9yUAq4iKt+PLB0QQEEkQjREDtcHbUXPk4XJeYKJCa6EEExWCNP1p1Nl4Zs/NzUx2j /lnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=Cm9FeMy4GVQb6Y304/sdZ2D3L6nSGw+tgNkZCTPzffM=; b=pyVfhmH2abUiL1NofXMfhrwHzA+4FgO1aHyhX3ExoSjJLmcPj69kcUS/ZxKKMH3NTj /R/h5hauMHS5k4fUfd1KWECD4E3s521h0KzQeJjs7OKP7rYHEiwjnMec5e+cmYo7mhho pGn7SJwPBulDfIRtdfG+2Ys909TZWi5ES/XMhd+Xz1TjVzfmN4oId1plN+PHrP0ZqR+U K1OJvKiklvUl6D0HEWF1dGqguaufpsEa1tTMU50L81mpeCF29useJTVFc0P0sEQe1Xt7 sjDvDnouOoxJgw+4BunZj9vF9N0BK4QiLxXu4Iv9lLFtnUunCZKWGhNQWrg6QU69HI3t 5J2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=FllZhFiS; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kn5-20020a170903078500b001a059a1b56dsi7070991plb.16.2023.03.15.23.48.23; Wed, 15 Mar 2023 23:48:38 -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=fail header.i=@gmail.com header.s=20210112 header.b=FllZhFiS; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229754AbjCPGhf (ORCPT + 99 others); Thu, 16 Mar 2023 02:37:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49076 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229616AbjCPGhb (ORCPT ); Thu, 16 Mar 2023 02:37:31 -0400 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36861A90BF; Wed, 15 Mar 2023 23:37:24 -0700 (PDT) Received: by mail-pj1-x1031.google.com with SMTP id o6-20020a17090a9f8600b0023f32869993so389691pjp.1; Wed, 15 Mar 2023 23:37:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678948643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Cm9FeMy4GVQb6Y304/sdZ2D3L6nSGw+tgNkZCTPzffM=; b=FllZhFiS4t3MU/LFOgYnLK3f+3xQnobC/Eje5B3tri7nYEBsh1EY04bivKL5e3GZs1 OAltPEBoIuvjNsRPRPgN6TKdR0oDPyvKXJJwBoX8ycWivbCyNdrK15GzL9cjDKfBA34f 003QB6/Uk7/MDReoNc0gvkv2C9s1Mdfg2bWw1+skr58TWJqhUIWeMIgtxM8DjX1TYhue iSEs4xONpTaajb8xcLDuZRMFA725/67/vzUYpYap32wFFimZ1Rp6IcEdYJxuSuMW0KI5 8R9tn+7PtK8rbWV9Q40ZygxKF5w/pnHrCg4Q2NJm5Ekym1b9zZW3dbVWgNGC8w9aQRys BxSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678948643; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Cm9FeMy4GVQb6Y304/sdZ2D3L6nSGw+tgNkZCTPzffM=; b=lZLnrfKXPstiylmSUjNnLrObevR3p6OZuzfC2suHY6zmPsX0ruDV6T8JDCn+VxXBae QVa7/E4VAqdXOb0x8fLhYJNXe7/3iH+crW0lzusMbDpqZJqOS5TqASzopLQMerliUitl xfdCTZTphzpEMltxQsPSHSHetbSM4mP/6MFUJJCTUYugBOfeo07H3/HGmd8MoeZDKdWG FhV26tApJSVGXVS++TteNK9gq/aiKBQxVZMkyCDKwuzJZMO3WudcrT5QyO/2xm1dE+FB Co2D6/b1bWPXkuAfwALbQWzRT/KD+TQtiDxO3jJON81N4ZFiwjsbsiftGJSQsZV2bc72 kJeg== X-Gm-Message-State: AO0yUKWijUjgEBmrqOgDkCSKQLeACEtqL3uP9CCsddCImUgpPAzqHV5H aBRRM8A931R1NVJIQ3cmLwE= X-Received: by 2002:a17:90b:17d0:b0:23e:feef:38ef with SMTP id me16-20020a17090b17d000b0023efeef38efmr2662513pjb.41.1678948643027; Wed, 15 Mar 2023 23:37:23 -0700 (PDT) Received: from kazuki-mac.lan ([2400:4051:ea3:5910::789]) by smtp.gmail.com with ESMTPSA id kv3-20020a17090328c300b0019c919bccf8sm4736494plb.86.2023.03.15.23.37.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 23:37:22 -0700 (PDT) From: Kazuki H Cc: Hector Martin , Sven Peter , Kazuki H , "Rafael J. Wysocki" , Daniel Lezcano , Pavel Machek , Len Brown , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] cpuidle: Don't pass any values to cpuidle_not_available Date: Thu, 16 Mar 2023 15:37:11 +0900 Message-Id: <20230316063712.33353-1-kazukih0205@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) 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?1760505960943085139?= X-GMAIL-MSGID: =?utf-8?q?1760505960943085139?= There's no reason to pass any values to cpuidle_not_available() as the function works standalone. Since we're planning to use the function in other places, make it so to avoid code duplication. Signed-off-by: Kazuki H --- drivers/cpuidle/cpuidle.c | 6 ++++-- include/linux/cpuidle.h | 6 ++---- kernel/sched/idle.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c index 6eceb1988243..cc05acf4d2a8 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -48,9 +48,11 @@ void disable_cpuidle(void) off = 1; } -bool cpuidle_not_available(struct cpuidle_driver *drv, - struct cpuidle_device *dev) +bool cpuidle_not_available(void) { + struct cpuidle_device *dev = cpuidle_get_device(); + struct cpuidle_driver *drv = cpuidle_get_cpu_driver(dev); + return off || !initialized || !drv || !dev || !dev->enabled; } diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index fce476275e16..11de17924910 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -139,8 +139,7 @@ struct cpuidle_driver { #ifdef CONFIG_CPU_IDLE extern void disable_cpuidle(void); -extern bool cpuidle_not_available(struct cpuidle_driver *drv, - struct cpuidle_device *dev); +extern bool cpuidle_not_available(void); extern int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, @@ -174,8 +173,7 @@ static inline struct cpuidle_device *cpuidle_get_device(void) {return __this_cpu_read(cpuidle_devices); } #else static inline void disable_cpuidle(void) { } -static inline bool cpuidle_not_available(struct cpuidle_driver *drv, - struct cpuidle_device *dev) +static inline bool cpuidle_not_available(void) {return true; } static inline int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, bool *stop_tick) diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c index dbfc2eb5ccbd..558a5c987597 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -179,7 +179,7 @@ static void cpuidle_idle_call(void) return; } - if (cpuidle_not_available(drv, dev)) { + if (cpuidle_not_available()) { tick_nohz_idle_stop_tick(); default_idle_call(); From patchwork Thu Mar 16 06:37:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kazuki Hashimoto X-Patchwork-Id: 70587 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:604a:0:0:0:0:0 with SMTP id j10csp320483wrt; Wed, 15 Mar 2023 23:46:36 -0700 (PDT) X-Google-Smtp-Source: AK7set/RvNmxnykFlLbyWO7de+fxGzH9j6DyW/6iHdZ4o6+RmUFfB0imy76RwjYSF/21+H4teu6r X-Received: by 2002:a17:902:dacf:b0:1a0:712e:1c8f with SMTP id q15-20020a170902dacf00b001a0712e1c8fmr2656676plx.34.1678949196685; Wed, 15 Mar 2023 23:46:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678949196; cv=none; d=google.com; s=arc-20160816; b=0zfdIkgH0OQp0nKpmQtHH0NiFhPnoapVw4bg5RRNomT//T6qHCbj8CYlFPGTuIyEUz DiRvQmGSFFDur4SV2BhYTyAZ3/3YI/7UBROp8+sq/WAnzWOju9YnAzTaZcqLvVw9EwDX uwLvQcXNNm6wPOJ8muHXk9V4XBYblbkuXB0Je3tjhnTljlxz3JXz+5b1iser+zRyc36S OdVgiVbPLzb0Z1VDYNA0z1D3UVQKkoUrD/+Z13Ugzu9MRq5vpRNp9cTmcl5O7OJohYwp 6uw057MoOHSYJ6yq41WuGBUiSNr7JLQg8wvyf4ZA7KgfiWgeYP9zLveip3TLH3ls59UB EFsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=FqZfoUoxy8iXzcBbOibqnO/QMawNVpGzC8pVpMz5OXw=; b=aTT2LBAbTKikYK2WdOIO02HZsvg5Sax0ZCd98O5hBbx+OtFf8+zoztTIUt25Og3pqZ fyeHPZqEQYqzNilEPO9iQV3ZOFuqX8pIi2Qv62ZrqYfpuPcZxuKqFXjXIQcVvUipRxci f8vcGIDWtpbuBUz2nl801Yp3RkyUO0GeFtTUq8lVKaDXKj6fojeav6kywF1YshfcEcnM ciR9kXqKTllAe/kem/b3/KiLvNjE+HRZ4+Y9Najhyb5fGmKfjz641bX7vM7VRCWIYS3b IicvIve1KruehMvM8MceU/a8xcW/Bp3hDNPaO2mL42iUXh0lgbLbyAQFw3UhKmPlOou/ 2vqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20210112 header.b=JMs0rD4c; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id m13-20020a170902db0d00b0019fe9a63cf2si3619469plx.609.2023.03.15.23.46.21; Wed, 15 Mar 2023 23:46:36 -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=fail header.i=@gmail.com header.s=20210112 header.b=JMs0rD4c; 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=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229786AbjCPGht (ORCPT + 99 others); Thu, 16 Mar 2023 02:37:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbjCPGhm (ORCPT ); Thu, 16 Mar 2023 02:37:42 -0400 Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E771BA8E8D; Wed, 15 Mar 2023 23:37:30 -0700 (PDT) Received: by mail-pl1-x629.google.com with SMTP id o11so712562ple.1; Wed, 15 Mar 2023 23:37:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678948647; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FqZfoUoxy8iXzcBbOibqnO/QMawNVpGzC8pVpMz5OXw=; b=JMs0rD4cQCx8cqdr/zvl+I5qPwmOLOYhVQJktHL7BfRkKgKvgf2mjkb+rst3GommLY 7ba3P6m7tvq90zsLFklXbt2BbVQ/59mpFxkIXRxyrg4d2qh3e3H6Fo1glkVpV7sSyaqM 7wzGs1mvQlhcDMmBAt+Xtqi7DzcnzWQabTNKjkVteP4RaZhG3SARwuRrodkVZGzl6Nvk IYyy1xzwhPiKluCtnUkcPuPDR1UUyrqFRhzrxiCPXx8M0YR00CK+EH6qnAyILjkNIoe9 4effejcgLd9T6Eht3vkfCeW4Gi15esbycvKU3GrBg1gDNVJEJqqkkGqlifwEaGEMUElz 9FZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678948647; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FqZfoUoxy8iXzcBbOibqnO/QMawNVpGzC8pVpMz5OXw=; b=vMHg4JahxYbDNxqdVimV1g8PN9LqQ4529XOp22MlM7N/lveqKb+0UftUf0PAQHqV6b m8LWtRaC1IQ/ZSv85UfNf6ggqbRBPbOUqNONSROcpuAEKxe81/SrQ6vEvRKeM1b46G/3 nZBH+/9i3d4lH7/XUcQPmFlmzSP1O2wI0j6rrT9rpInKPWfSitM2W0MCsdNFkgQ9BhD4 PWfr3it2ce6aSYsoUO33/gq7Eyy/Ni28+93O40N+8iIJ8yic5+I3hUkLZWN9eYkfzN6+ 2YzY8cB1JxaiPErLO8ap67JpHJ7bwDsyuJ0ZskCua1Ngtq3e9e/hWZaMOGpE0yMWGX1s VnkA== X-Gm-Message-State: AO0yUKXZjG2p/qo21QLDj5TUdlItQzK9e8Ha1V3FpajypSKohECYLUfB OUDqVmetcLA4YdUbYc3YFMk= X-Received: by 2002:a17:903:1d2:b0:1a0:7508:dae6 with SMTP id e18-20020a17090301d200b001a07508dae6mr2250006plh.63.1678948647498; Wed, 15 Mar 2023 23:37:27 -0700 (PDT) Received: from kazuki-mac.lan ([2400:4051:ea3:5910::789]) by smtp.gmail.com with ESMTPSA id kv3-20020a17090328c300b0019c919bccf8sm4736494plb.86.2023.03.15.23.37.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Mar 2023 23:37:27 -0700 (PDT) From: Kazuki H Cc: Hector Martin , Sven Peter , Kazuki H , "Rafael J. Wysocki" , Daniel Lezcano , Pavel Machek , Len Brown , Ingo Molnar , Peter Zijlstra , Juri Lelli , Vincent Guittot , Dietmar Eggemann , Steven Rostedt , Ben Segall , Mel Gorman , Daniel Bristot de Oliveira , Valentin Schneider , linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] PM: s2idle: Fully block the system from entering s2idle when cpuidle isn't supported Date: Thu, 16 Mar 2023 15:37:12 +0900 Message-Id: <20230316063712.33353-2-kazukih0205@gmail.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230316063712.33353-1-kazukih0205@gmail.com> References: <20230316063712.33353-1-kazukih0205@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-1.8 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 autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net To: unlisted-recipients:; (no To-header on input) 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?1760505832548466733?= X-GMAIL-MSGID: =?utf-8?q?1760505832548466733?= s2idle isn't supported on platforms that don't support cpuidle as of 31a3409065d1 ("cpuidle / sleep: Do sanity checks in cpuidle_enter_freeze() too"). 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. 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; 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()) + 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");