]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
cpuidle: Init cpuidle only for present CPUs
authorJacky Bai <ping.bai@nxp.com>
Fri, 7 Mar 2025 14:55:47 +0000 (22:55 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Wed, 12 Mar 2025 20:31:59 +0000 (21:31 +0100)
for_each_possible_cpu() is currently used to initialize cpuidle
in below cpuidle drivers:
  drivers/cpuidle/cpuidle-arm.c
  drivers/cpuidle/cpuidle-big_little.c
  drivers/cpuidle/cpuidle-psci.c
  drivers/cpuidle/cpuidle-qcom-spm.c
  drivers/cpuidle/cpuidle-riscv-sbi.c

However, in cpu_dev_register_generic(), for_each_present_cpu()
is used to register CPU devices which means the CPU devices are
only registered for present CPUs and not all possible CPUs.

With nosmp or maxcpus=0, only the boot CPU is present, lead
to the failure:

  |  Failed to register cpuidle device for cpu1

Then rollback to cancel all CPUs' cpuidle registration.

Change for_each_possible_cpu() to for_each_present_cpu() in the
above cpuidle drivers to ensure it only registers cpuidle devices
for CPUs that are actually present.

Fixes: b0c69e1214bc ("drivers: base: Use present CPUs in GENERIC_CPU_DEVICES")
Reviewed-by: Dhruva Gole <d-gole@ti.com>
Reviewed-by: Sudeep Holla <sudeep.holla@arm.com>
Tested-by: Yuanjie Yang <quic_yuanjiey@quicinc.com>
Signed-off-by: Jacky Bai <ping.bai@nxp.com>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Link: https://patch.msgid.link/20250307145547.2784821-1-ping.bai@nxp.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/cpuidle/cpuidle-arm.c
drivers/cpuidle/cpuidle-big_little.c
drivers/cpuidle/cpuidle-psci.c
drivers/cpuidle/cpuidle-qcom-spm.c
drivers/cpuidle/cpuidle-riscv-sbi.c

index caba6f4bb1b793e86eedfaaa296b14e3fcf0f36a..e044fefdb81678ba6d9a3393fc3e83e1529a8026 100644 (file)
@@ -137,9 +137,9 @@ out_kfree_drv:
 /*
  * arm_idle_init - Initializes arm cpuidle driver
  *
- * Initializes arm cpuidle driver for all CPUs, if any CPU fails
- * to register cpuidle driver then rollback to cancel all CPUs
- * registration.
+ * Initializes arm cpuidle driver for all present CPUs, if any
+ * CPU fails to register cpuidle driver then rollback to cancel
+ * all CPUs registration.
  */
 static int __init arm_idle_init(void)
 {
@@ -147,7 +147,7 @@ static int __init arm_idle_init(void)
        struct cpuidle_driver *drv;
        struct cpuidle_device *dev;
 
-       for_each_possible_cpu(cpu) {
+       for_each_present_cpu(cpu) {
                ret = arm_idle_init_cpu(cpu);
                if (ret)
                        goto out_fail;
index 74972deda0ead3851305e2dabef066b1aa702162..4abba42fcc311273795d00ff6977a132916e6a9f 100644 (file)
@@ -148,7 +148,7 @@ static int __init bl_idle_driver_init(struct cpuidle_driver *drv, int part_id)
        if (!cpumask)
                return -ENOMEM;
 
-       for_each_possible_cpu(cpu)
+       for_each_present_cpu(cpu)
                if (smp_cpuid_part(cpu) == part_id)
                        cpumask_set_cpu(cpu, cpumask);
 
index 2562dc001fc1de69732ef28f383d2809262a3d96..a4594c3d6562d3f9da1cb5daeadab936e5a69c6c 100644 (file)
@@ -400,7 +400,7 @@ deinit:
 /*
  * psci_idle_probe - Initializes PSCI cpuidle driver
  *
- * Initializes PSCI cpuidle driver for all CPUs, if any CPU fails
+ * Initializes PSCI cpuidle driver for all present CPUs, if any CPU fails
  * to register cpuidle driver then rollback to cancel all CPUs
  * registration.
  */
@@ -410,7 +410,7 @@ static int psci_cpuidle_probe(struct platform_device *pdev)
        struct cpuidle_driver *drv;
        struct cpuidle_device *dev;
 
-       for_each_possible_cpu(cpu) {
+       for_each_present_cpu(cpu) {
                ret = psci_idle_init_cpu(&pdev->dev, cpu);
                if (ret)
                        goto out_fail;
index 3ab240e0e12292ec1b0e1460becd9cbcf9d02802..5f386761b1562aabaff4493f99e2eaa8601e47a7 100644 (file)
@@ -135,7 +135,7 @@ static int spm_cpuidle_drv_probe(struct platform_device *pdev)
        if (ret)
                return dev_err_probe(&pdev->dev, ret, "set warm boot addr failed");
 
-       for_each_possible_cpu(cpu) {
+       for_each_present_cpu(cpu) {
                ret = spm_cpuidle_register(&pdev->dev, cpu);
                if (ret && ret != -ENODEV) {
                        dev_err(&pdev->dev,
index 0c92a628bbd40e3b18b83a7f20a50fef0e8fa3ae..0fe1ece9fbdca42a4d04bc0ef89383e3049c89cd 100644 (file)
@@ -529,8 +529,8 @@ static int sbi_cpuidle_probe(struct platform_device *pdev)
                        return ret;
        }
 
-       /* Initialize CPU idle driver for each CPU */
-       for_each_possible_cpu(cpu) {
+       /* Initialize CPU idle driver for each present CPU */
+       for_each_present_cpu(cpu) {
                ret = sbi_cpuidle_init_cpu(&pdev->dev, cpu);
                if (ret) {
                        pr_debug("HART%ld: idle driver init failed\n",