[PATCH v2] cpuidle: Add sanity check for exit latency and target residency
From: Rafael J. Wysocki
Date: Fri Nov 07 2025 - 14:07:33 EST
From: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
Make __cpuidle_driver_init() fail if the exit latency of one of the
driver's idle states is less than its exit latency which would break
cpuidle assumptions.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@xxxxxxxxx>
---
v1 -> v2: Make __cpuidle_driver_init() fail if the check is not passed (Artem).
---
drivers/cpuidle/driver.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -152,7 +152,7 @@ static void cpuidle_setup_broadcast_time
* __cpuidle_driver_init - initialize the driver's internal data
* @drv: a valid pointer to a struct cpuidle_driver
*/
-static void __cpuidle_driver_init(struct cpuidle_driver *drv)
+static int __cpuidle_driver_init(struct cpuidle_driver *drv)
{
int i;
@@ -193,7 +193,17 @@ static void __cpuidle_driver_init(struct
s->exit_latency_ns = 0;
else
s->exit_latency = div_u64(s->exit_latency_ns, NSEC_PER_USEC);
+
+ /*
+ * Ensure that the exit latency of a CPU idle state does not
+ * exceed its target residency which is assumed in cpuidle in
+ * multiple places.
+ */
+ if (s->exit_latency_ns > s->target_residency_ns)
+ return -EINVAL;
}
+
+ return 0;
}
/**
@@ -223,7 +233,9 @@ static int __cpuidle_register_driver(str
if (cpuidle_disabled())
return -ENODEV;
- __cpuidle_driver_init(drv);
+ ret = __cpuidle_driver_init(drv);
+ if (ret)
+ return ret;
ret = __cpuidle_set_driver(drv);
if (ret)