From nobody Sun Feb 8 19:03:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DB31C001B0 for ; Tue, 11 Jul 2023 05:54:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229769AbjGKFyh (ORCPT ); Tue, 11 Jul 2023 01:54:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229585AbjGKFya (ORCPT ); Tue, 11 Jul 2023 01:54:30 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9C0E195; Mon, 10 Jul 2023 22:54:29 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id 41be03b00d2f7-55bac17b442so4041832a12.3; Mon, 10 Jul 2023 22:54:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689054869; x=1691646869; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=pATxnRjw1kvbkvJOwnrnm5lR+PWjwDmKzZaehDZNMZU=; b=J2YdBxXTObGU48Mlg1QDs9/IFFLJTaAdZHwxFx67EdkgpuaTy9VzUan8q62OndaNBK krWqsHjhli9TJv4piybN/VGrEhfIg88Reqn1rorGP/xkRN3qVjSUuRs5/xNKkWIZn3dj D4+Xb1BnGbAWjxZAs6Qa9+wZpaSokuxonMC68/0c6MjqrBfq7MFXaWs9DKpBC3j3AlHH llHkjZtUkqehSGVHQup4Q4zmtrb/dBblnV28R/NMSZ19RbK13D74xVnHReSvwezEiGmt 5mCFawl60m7HbTqkUeslWnHXAyeYUEqkK4FrxjbQuwBwORM1sExFmXoNQ0lQ3TbrjVfS mqcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689054869; x=1691646869; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=pATxnRjw1kvbkvJOwnrnm5lR+PWjwDmKzZaehDZNMZU=; b=dhA0sz41J8QCCnuXiC/brncggNx6xXcBzsvxkCsZT9p4wrqgErnYsiWMJ+t6MerlkR pRAudO/sjDceXmaJMKsHGVKmBj3Co+9XwwvnGspHkdw6W4wp1DGZbfLyRYyo12k51iBx cuGykEssN2Pr0ZEyify2GitZ9rm/n0gGsEpOoRQ/Gvlbfn4D2qGI/kC1VBfb02v8oowx zZzzLSCDoSFI6jWEHICpstJPrF1UsZ4HlQ16BpYfe6tbPaFsknHZOt5OaIfdDRZpSL0t qdeVtp8ZneBd/xzyLHmPxRiiLSkxGVLk5gicathujKBERRd1jhKptiH7KOsNwsXDH7KH mdLA== X-Gm-Message-State: ABy/qLaWeMGxgNT+6VYntoF4N23C4PfR6fP1sLihK+2a7uYp/OJD9pmp qNmNQsPXJJma98l/HLn1c+sRmrjjVm8= X-Google-Smtp-Source: APBJJlFbC2r2TbKbAv2XntBUqFc4qfvmGXL0dlkqVhIHaiYtvBxuxn7DfaqhmSspLR2fLdd3xEO1Fg== X-Received: by 2002:a05:6a20:1612:b0:125:87b1:a30d with SMTP id l18-20020a056a20161200b0012587b1a30dmr19359235pzj.1.1689054869144; Mon, 10 Jul 2023 22:54:29 -0700 (PDT) Received: from j293.lan ([2400:4051:ea3:5910:5676:1078:8b85:c18f]) by smtp.gmail.com with ESMTPSA id bd5-20020a170902830500b001b8761c739csm878053plb.271.2023.07.10.22.54.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 22:54:28 -0700 (PDT) From: Kazuki Hashimoto Date: Tue, 11 Jul 2023 14:54:21 +0900 Subject: [PATCH 1/2] cpuidle: Don't pass any values to cpuidle_not_available MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230711-cpuidle-v1-1-f391224b3140@gmail.com> References: <20230711-cpuidle-v1-0-f391224b3140@gmail.com> In-Reply-To: <20230711-cpuidle-v1-0-f391224b3140@gmail.com> To: "Rafael J. Wysocki" , Daniel Lezcano , Ingo Molnar , Peter Zijlstra , Len Brown , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Hector Martin , Kazuki Hashimoto X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689054863; l=2377; i=kazukih0205@gmail.com; s=20230709; h=from:subject:message-id; bh=KEMzFSoNpLPvIqVf3L5RPIfQHsabNi9qRgonhXVECcU=; b=YeQaYzdMq0SvFc5ST91wRuJNDDD5zIEm+g2+iXejUAUavkAROyVFrnoHun4n0BUc5Dj4GUPAp 6alWWHJszE5D+XmnFhkpAv+C20AeVj21LgIN352NvjB8S8bhv9rfMvd X-Developer-Key: i=kazukih0205@gmail.com; a=ed25519; pk=r8m5wVK5lljix+hYnqXRT/GsxNkTADqXGmhdl7kykYY= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Hashimoto --- 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 737a026ef58a..c9ba51e0fa38 100644 --- a/drivers/cpuidle/cpuidle.c +++ b/drivers/cpuidle/cpuidle.c @@ -49,9 +49,11 @@ void disable_cpuidle(void) off =3D 1; } =20 -bool cpuidle_not_available(struct cpuidle_driver *drv, - struct cpuidle_device *dev) +bool cpuidle_not_available(void) { + struct cpuidle_device *dev =3D cpuidle_get_device(); + struct cpuidle_driver *drv =3D cpuidle_get_cpu_driver(dev); + return off || !initialized || !drv || !dev || !dev->enabled; } =20 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h index 3183aeb7f5b4..a0ce9b6d16ce 100644 --- a/include/linux/cpuidle.h +++ b/include/linux/cpuidle.h @@ -169,8 +169,7 @@ struct cpuidle_driver { =20 #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); =20 extern int cpuidle_select(struct cpuidle_driver *drv, struct cpuidle_device *dev, @@ -204,8 +203,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 342f58a329f5..865674d2e420 100644 --- a/kernel/sched/idle.c +++ b/kernel/sched/idle.c @@ -164,7 +164,7 @@ static void cpuidle_idle_call(void) * step to the grace period */ =20 - if (cpuidle_not_available(drv, dev)) { + if (cpuidle_not_available()) { tick_nohz_idle_stop_tick(); =20 default_idle_call(); --=20 2.41.0 From nobody Sun Feb 8 19:03:17 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67E9DEB64DC for ; Tue, 11 Jul 2023 05:54:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230513AbjGKFyk (ORCPT ); Tue, 11 Jul 2023 01:54:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37996 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbjGKFyf (ORCPT ); Tue, 11 Jul 2023 01:54:35 -0400 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92104E40; Mon, 10 Jul 2023 22:54:32 -0700 (PDT) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-666683eb028so2804971b3a.0; Mon, 10 Jul 2023 22:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689054872; x=1691646872; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=nk4niLNV6K0/PBl1ZDWCwqAEI3u1h+Q4tTNLOBHoMWM=; b=kWPuKebr23fLuFvrI3MW4ogXI6dr/IRwsu/v40oN4sHO1B15ZKtejInkzcOS8BLsMS fhZIJ76/5TOOSuk+vi2y0XQIsK2m8hi7MDkVqr3jbkgYbBsmLRhJoC5X63gijFpNGFbN f01mVUks/HfHprmN16QR5elSbGKmQpGfpIjzzGSWHStCrRl7De6V8oOmqYXmvB2yLpuR i1ARofJ/hSDSj5BNou5oNgOAkTQMPze7ru4UQn1L62Eu6HpnI1sCqkW+bg73KgAhDCkZ 4aL9MaFAbhZ1YsUsIbSdsUlKFWLvPjAbE8h/FIc46Xx93onlyxoEVynaDyEIeugwUgMU pm3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689054872; x=1691646872; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nk4niLNV6K0/PBl1ZDWCwqAEI3u1h+Q4tTNLOBHoMWM=; b=FAWYkeRkLx6h3aNIYKuf1cPaU2ezNP5AuapUvpPM0g0Echoj1c9YmCXaVEdkQAB1Lx DitnRqqPPsPoLlVob9c6ljDMLFDdS0wu84nQglQnuL0aTRoAI5KBkeDj+FEQbxxEqZy5 iBRgtmo/NSfL1unfK0/48k6Ih2ItjLioKuIa+AUSfpERbs0iopL313uffRWPD+UjbCbO 3dreCLm/wZ6jHvyUKOd9RjR0d5XHCPaIcZVROrDXuY2t7sMWZFPZ4JrzpIkl1rlIKAmE krd90RdDoyBQZA6rgjQ9vLl85LW/8NU0hFhYkt4g0QWoQggxaVpC9LsBpOXf+dvaiBai xTfA== X-Gm-Message-State: ABy/qLYsS05a2+c/jWd++ovBRKzjSwCxV95fE5BsUiKgkGO+eYiqwtNy NEmAQJXAYcGTX4mza5b4bNDqr2quuCw= X-Google-Smtp-Source: APBJJlEogGkNT4ZLN5vPivJF9MZxskDvW4C7eY2Gj7J+C8iQjwkmk1dh4d2I+BqDreEerwZ0ZeTRTw== X-Received: by 2002:a05:6a21:6811:b0:131:1bbd:dc50 with SMTP id wr17-20020a056a21681100b001311bbddc50mr6236730pzb.6.1689054872037; Mon, 10 Jul 2023 22:54:32 -0700 (PDT) Received: from j293.lan ([2400:4051:ea3:5910:5676:1078:8b85:c18f]) by smtp.gmail.com with ESMTPSA id bd5-20020a170902830500b001b8761c739csm878053plb.271.2023.07.10.22.54.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 22:54:31 -0700 (PDT) From: Kazuki Hashimoto Date: Tue, 11 Jul 2023 14:54:22 +0900 Subject: [PATCH 2/2] PM: s2idle: Fully prevent the system from entering s2idle when cpuidle isn't supported MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20230711-cpuidle-v1-2-f391224b3140@gmail.com> References: <20230711-cpuidle-v1-0-f391224b3140@gmail.com> In-Reply-To: <20230711-cpuidle-v1-0-f391224b3140@gmail.com> To: "Rafael J. Wysocki" , Daniel Lezcano , Ingo Molnar , Peter Zijlstra , Len Brown , Pavel Machek Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Hector Martin , Kazuki Hashimoto X-Mailer: b4 0.12.3 X-Developer-Signature: v=1; a=ed25519-sha256; t=1689054863; l=2849; i=kazukih0205@gmail.com; s=20230709; h=from:subject:message-id; bh=M0tNL3ccyxkfW5oli7KYKognuqR974/5Z/sS00RLTpY=; b=+vtnn6cnlTZTyDy/DLEZFml0G2vgNaqFHTs6ssNRATlNAiax2uJaMsh5C/xmGlJkeKHtBogaV dZBlmMupN8cAw3FQS8Ek1VDKZkTlEKdBC/p9vYQA1hluzM5WyJFYx2t X-Developer-Key: i=kazukih0205@gmail.com; a=ed25519; pk=r8m5wVK5lljix+hYnqXRT/GsxNkTADqXGmhdl7kykYY= Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In order for systems to properly enter s2idle, we need functions both in the idle subsystem (such as call_cpuidle_s2idle()) and the suspend subsystem to be executed. s2idle got blocked in the idle subsystem on platforms without cpuidle after commit ef2b22ac540c ("cpuidle / sleep: Use broadcast timer for states that = stop local timer"). However, the suspend subsystem doesn't have this, which can = cause the suspend subsystem to begin entering s2idle behind the idle subsystem's = back, which in turn can cause the system to enter s2idle even though all the func= tions necessary for s2idle hasn't been executed, breaking the system (e.g. ClOCK_MONOTONIC keeps ticking during suspend even though it's not sup= posed to). Prevent the system from entering s2idle when cpuidle isn't supported in the suspend subsystem as well. Fixes: ef2b22ac540c ("cpuidle / sleep: Use broadcast timer for states that = stop local timer") Signed-off-by: Kazuki Hashimoto --- 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 f6425ae3e8b0..82fedcf6032d 100644 --- a/kernel/power/main.c +++ b/kernel/power/main.c @@ -174,6 +174,8 @@ static ssize_t mem_sleep_show(struct kobject *kobj, str= uct kobj_attribute *attr, for (i =3D PM_SUSPEND_MIN; i < PM_SUSPEND_MAX; i++) { if (i >=3D PM_SUSPEND_MEM && cxl_mem_active()) continue; + if (i =3D=3D PM_SUSPEND_TO_IDLE && cpuidle_not_available()) + continue; if (mem_sleep_states[i]) { const char *label =3D mem_sleep_states[i]; =20 @@ -226,11 +228,15 @@ static ssize_t mem_sleep_store(struct kobject *kobj, = struct kobj_attribute *attr } =20 state =3D decode_suspend_state(buf, n); - if (state < PM_SUSPEND_MAX && state > PM_SUSPEND_ON) + if (state =3D=3D PM_SUSPEND_TO_IDLE && cpuidle_not_available()) + goto err; + if (state < PM_SUSPEND_MAX && state > PM_SUSPEND_ON) { mem_sleep_current =3D state; - else - error =3D -EINVAL; + goto out; + } =20 + err: + error =3D -EINVAL; out: pm_autosleep_unlock(); return error ? error : n; diff --git a/kernel/power/suspend.c b/kernel/power/suspend.c index fa3bf161d13f..02cc76c9109e 100644 --- a/kernel/power/suspend.c +++ b/kernel/power/suspend.c @@ -556,6 +556,11 @@ static int enter_state(suspend_state_t state) =20 trace_suspend_resume(TPS("suspend_enter"), state, true); if (state =3D=3D 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 !=3D TEST_NONE && pm_test_level <=3D TEST_CPUS) { pr_warn("Unsupported test mode for suspend to idle, please choose none/= freezer/devices/platform.\n"); --=20 2.41.0