Re: [PATCH v4] cpuidle: Init cpuidle only for present CPUs

From: Sudeep Holla
Date: Fri Mar 07 2025 - 04:51:39 EST


On Fri, Mar 07, 2025 at 04:03:03PM +0800, Jacky Bai wrote:
> 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-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@xxxxxx>
> Reviewed-by: Sudeep Holla <sudeep.holla@xxxxxxx>
> Tested-by: Yuanjie Yang <quic_yuanjiey@xxxxxxxxxxx>
> Signed-off-by: Jacky Bai <ping.bai@xxxxxxx>
> ---
> - v4 changes:
> - add changes for other cpuidle driver that has the similar issue
> as cpuidle-pcsi driver.
>
> - v3 changes:
> - improve the changelog as suggested by Sudeep
> ---
> drivers/cpuidle/cpuidle-arm.c | 8 ++++----
> drivers/cpuidle/cpuidle-big_little.c | 2 +-
> drivers/cpuidle/cpuidle-psci.c | 4 ++--
> drivers/cpuidle/cpuidle-riscv-sbi.c | 4 ++--


Why have you spared drivers/cpuidle/cpuidle-qcom-spm.c ? IIUC the issue
exists there as well.

--
Regards,
Sudeep