Linux Power Management development
 help / color / mirror / Atom feed
* [PATCH v2] cpuidle: teo: Do not return a disabled idle state
@ 2026-08-28  3:24 Xueqin Luo
  2026-08-28 15:49 ` Christian Loehle
  0 siblings, 1 reply; 2+ messages in thread
From: Xueqin Luo @ 2026-08-28  3:24 UTC (permalink / raw)
  To: rafael, daniel.lezcano, christian.loehle
  Cc: linux-pm, linux-kernel, Xueqin Luo

If idle state 0 is disabled and none of the enabled idle states satisfies
the PM QoS latency constraint, constraint_idx in teo_select() stays at its
initial value of 0, because the loop that updates it starts at state 1,
and so the candidate state index is capped at state 0, which is disabled,
and that state is returned to the caller.

The cpuidle core does not validate the returned state index against the
per-state disable flags, so the CPU ends up entering the disabled state 0.

To address this, ensure that constraint_idx is at least equal to the index
of the first enabled idle state (idx0), so that the candidate state is
never capped to a disabled one.

Fixes: c410a9a142f1 ("cpuidle: teo: Change the main idle state selection logic")
Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>
---
v1 -> v2:
    - Instead of falling back to idx0 after the candidate index has been
      capped to a disabled state, ensure that constraint_idx is at least
      equal to idx0 before the capping check (suggested by Rafael J. Wysocki).

 drivers/cpuidle/governors/teo.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c
index ac43b9b013b3..906f4f89e365 100644
--- a/drivers/cpuidle/governors/teo.c
+++ b/drivers/cpuidle/governors/teo.c
@@ -426,6 +426,17 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
 		}
 	}
 
+	/*
+	 * If the latency constraint does not allow any of the enabled idle
+	 * states to be used, the candidate state index will be capped to 0
+	 * by the check below, but state 0 may be disabled.  To prevent the
+	 * selection of a disabled state in that case, ensure that
+	 * constraint_idx is at least equal to the index of the first
+	 * enabled idle state.
+	 */
+	if (constraint_idx < idx0)
+		constraint_idx = idx0;
+
 	/*
 	 * If there is a latency constraint, it may be necessary to select an
 	 * idle state shallower than the current candidate one.
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] cpuidle: teo: Do not return a disabled idle state
  2026-08-28  3:24 [PATCH v2] cpuidle: teo: Do not return a disabled idle state Xueqin Luo
@ 2026-08-28 15:49 ` Christian Loehle
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Loehle @ 2026-08-28 15:49 UTC (permalink / raw)
  To: Xueqin Luo, rafael, daniel.lezcano; +Cc: linux-pm, linux-kernel

On 8/28/26 04:24, Xueqin Luo wrote:
> If idle state 0 is disabled and none of the enabled idle states satisfies
> the PM QoS latency constraint, constraint_idx in teo_select() stays at its
> initial value of 0, because the loop that updates it starts at state 1,
> and so the candidate state index is capped at state 0, which is disabled,
> and that state is returned to the caller.
> 
> The cpuidle core does not validate the returned state index against the
> per-state disable flags, so the CPU ends up entering the disabled state 0.
> 
> To address this, ensure that constraint_idx is at least equal to the index
> of the first enabled idle state (idx0), so that the candidate state is
> never capped to a disabled one.
> 
> Fixes: c410a9a142f1 ("cpuidle: teo: Change the main idle state selection logic")
> Signed-off-by: Xueqin Luo <luoxueqin@kylinos.cn>

Reviewed-by: Christian Loehle <christian.loehle@arm.com>

> ---
> v1 -> v2:
>     - Instead of falling back to idx0 after the candidate index has been
>       capped to a disabled state, ensure that constraint_idx is at least
>       equal to idx0 before the capping check (suggested by Rafael J. Wysocki).
> 
>  drivers/cpuidle/governors/teo.c | 11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/drivers/cpuidle/governors/teo.c b/drivers/cpuidle/governors/teo.c
> index ac43b9b013b3..906f4f89e365 100644
> --- a/drivers/cpuidle/governors/teo.c
> +++ b/drivers/cpuidle/governors/teo.c
> @@ -426,6 +426,17 @@ static int teo_select(struct cpuidle_driver *drv, struct cpuidle_device *dev,
>  		}
>  	}
>  
> +	/*
> +	 * If the latency constraint does not allow any of the enabled idle
> +	 * states to be used, the candidate state index will be capped to 0
> +	 * by the check below, but state 0 may be disabled.  To prevent the
> +	 * selection of a disabled state in that case, ensure that
> +	 * constraint_idx is at least equal to the index of the first
> +	 * enabled idle state.
> +	 */
> +	if (constraint_idx < idx0)
> +		constraint_idx = idx0;
> +
>  	/*
>  	 * If there is a latency constraint, it may be necessary to select an
>  	 * idle state shallower than the current candidate one.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-08-28 15:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-28  3:24 [PATCH v2] cpuidle: teo: Do not return a disabled idle state Xueqin Luo
2026-08-28 15:49 ` Christian Loehle

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox