* [PATCH v3] cpuidle: psci: Init cpuidle only for present CPUs
@ 2025-03-06 6:18 Jacky Bai
2025-03-06 10:53 ` Ulf Hansson
0 siblings, 1 reply; 4+ messages in thread
From: Jacky Bai @ 2025-03-06 6:18 UTC (permalink / raw)
To: lpieralisi, sudeep.holla, rafael, ulf.hansson, daniel.lezcano,
james.morse, d-gole
Cc: linux-pm, linux-arm-kernel, linux-kernel, imx, khilman,
quic_tingweiz, quic_yuanjiey
for_each_possible_cpu() is currently used to initialize cpuidle
in the PSCI cpuidle driver.
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, leading
to the failure:
| Failed to register cpuidle device for cpu1
Change for_each_possible_cpu() to for_each_present_cpu() in the
PSCI cpuidle driver 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>
---
- v2 changes:
- Improve the changelog as suggested by Sudeep
---
drivers/cpuidle/cpuidle-psci.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c
index 2562dc001fc1..00117e9b33e8 100644
--- a/drivers/cpuidle/cpuidle-psci.c
+++ b/drivers/cpuidle/cpuidle-psci.c
@@ -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;
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v3] cpuidle: psci: Init cpuidle only for present CPUs
2025-03-06 6:18 [PATCH v3] cpuidle: psci: Init cpuidle only for present CPUs Jacky Bai
@ 2025-03-06 10:53 ` Ulf Hansson
2025-03-06 12:42 ` Sudeep Holla
0 siblings, 1 reply; 4+ messages in thread
From: Ulf Hansson @ 2025-03-06 10:53 UTC (permalink / raw)
To: Jacky Bai
Cc: lpieralisi, sudeep.holla, rafael, daniel.lezcano, james.morse,
d-gole, linux-pm, linux-arm-kernel, linux-kernel, imx, khilman,
quic_tingweiz, quic_yuanjiey
On Thu, 6 Mar 2025 at 07:17, Jacky Bai <ping.bai@nxp.com> wrote:
>
> for_each_possible_cpu() is currently used to initialize cpuidle
> in the PSCI cpuidle driver.
>
> 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, leading
> to the failure:
>
> | Failed to register cpuidle device for cpu1
>
> Change for_each_possible_cpu() to for_each_present_cpu() in the
> PSCI cpuidle driver 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>
Is this problem specific to cpuidle-psci?
Others are using for_each_possible_cpu() when registering their cpuidle drivers.
Kind regards
Uffe
> ---
> - v2 changes:
> - Improve the changelog as suggested by Sudeep
> ---
> drivers/cpuidle/cpuidle-psci.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/cpuidle/cpuidle-psci.c b/drivers/cpuidle/cpuidle-psci.c
> index 2562dc001fc1..00117e9b33e8 100644
> --- a/drivers/cpuidle/cpuidle-psci.c
> +++ b/drivers/cpuidle/cpuidle-psci.c
> @@ -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;
> --
> 2.34.1
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v3] cpuidle: psci: Init cpuidle only for present CPUs
2025-03-06 10:53 ` Ulf Hansson
@ 2025-03-06 12:42 ` Sudeep Holla
2025-03-07 2:33 ` Jacky Bai
0 siblings, 1 reply; 4+ messages in thread
From: Sudeep Holla @ 2025-03-06 12:42 UTC (permalink / raw)
To: Ulf Hansson
Cc: Jacky Bai, lpieralisi, rafael, daniel.lezcano, james.morse,
d-gole, linux-pm, linux-arm-kernel, linux-kernel, imx, khilman,
quic_tingweiz, quic_yuanjiey
On Thu, Mar 06, 2025 at 11:53:14AM +0100, Ulf Hansson wrote:
> On Thu, 6 Mar 2025 at 07:17, Jacky Bai <ping.bai@nxp.com> wrote:
> >
> > for_each_possible_cpu() is currently used to initialize cpuidle
> > in the PSCI cpuidle driver.
> >
> > 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, leading
> > to the failure:
> >
> > | Failed to register cpuidle device for cpu1
> >
> > Change for_each_possible_cpu() to for_each_present_cpu() in the
> > PSCI cpuidle driver 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>
>
> Is this problem specific to cpuidle-psci?
>
> Others are using for_each_possible_cpu() when registering their cpuidle drivers.
>
Good point. I assumed as this was very old patch, only this is left without
conversion to using present_cpumask. Looks like there are many other drivers
that need similar change. May be PSCI is most commonly used ones these days
and hardly anyone tests with nosmp or maxcpus=1 on those platforms.
But yes, all the users of for_each_possible_cpu() need to move to
for_each_present_cpu() if they are relying on CPU device being registered.
--
Regards,
Sudeep
^ permalink raw reply [flat|nested] 4+ messages in thread
* RE: [PATCH v3] cpuidle: psci: Init cpuidle only for present CPUs
2025-03-06 12:42 ` Sudeep Holla
@ 2025-03-07 2:33 ` Jacky Bai
0 siblings, 0 replies; 4+ messages in thread
From: Jacky Bai @ 2025-03-07 2:33 UTC (permalink / raw)
To: Sudeep Holla, Ulf Hansson
Cc: lpieralisi@kernel.org, rafael@kernel.org,
daniel.lezcano@linaro.org, james.morse@arm.com, d-gole@ti.com,
linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, imx@lists.linux.dev,
khilman@baylibre.com, quic_tingweiz@quicinc.com,
quic_yuanjiey@quicinc.com
> Subject: Re: [PATCH v3] cpuidle: psci: Init cpuidle only for present CPUs
>
> On Thu, Mar 06, 2025 at 11:53:14AM +0100, Ulf Hansson wrote:
> > On Thu, 6 Mar 2025 at 07:17, Jacky Bai <ping.bai@nxp.com> wrote:
> > >
> > > for_each_possible_cpu() is currently used to initialize cpuidle in
> > > the PSCI cpuidle driver.
> > >
> > > 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, leading to
> > > the failure:
> > >
> > > | Failed to register cpuidle device for cpu1
> > >
> > > Change for_each_possible_cpu() to for_each_present_cpu() in the PSCI
> > > cpuidle driver 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>
> >
> > Is this problem specific to cpuidle-psci?
> >
> > Others are using for_each_possible_cpu() when registering their cpuidle
> drivers.
> >
>
> Good point. I assumed as this was very old patch, only this is left without
> conversion to using present_cpumask. Looks like there are many other drivers
> that need similar change. May be PSCI is most commonly used ones these
> days and hardly anyone tests with nosmp or maxcpus=1 on those platforms.
>
> But yes, all the users of for_each_possible_cpu() need to move to
> for_each_present_cpu() if they are relying on CPU device being registered.
>
Yes, there are several other cpuidle drivers should have the similar issue, also
some other driver like cpufreq also need to covert to use present mask.
I will do a further check and fix them all together.
BR
> --
> Regards,
> Sudeep
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-03-07 2:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-06 6:18 [PATCH v3] cpuidle: psci: Init cpuidle only for present CPUs Jacky Bai
2025-03-06 10:53 ` Ulf Hansson
2025-03-06 12:42 ` Sudeep Holla
2025-03-07 2:33 ` Jacky Bai
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).