Skip to content

Commit 76934e4

Browse files
committed
cpuidle: Add sanity check for exit latency and target residency
Make __cpuidle_driver_init() fail if the exit latency of one of the driver's idle states is less than its target residency which would break cpuidle assumptions. Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Reviewed-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Reviewed-by: Christian Loehle <christian.loehle@arm.com> [ rjw: Changelog fix ] Link: https://patch.msgid.link/12779486.O9o76ZdvQC@rafael.j.wysocki Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
1 parent 07d8157 commit 76934e4

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

drivers/cpuidle/driver.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ static void cpuidle_setup_broadcast_timer(void *arg)
152152
* __cpuidle_driver_init - initialize the driver's internal data
153153
* @drv: a valid pointer to a struct cpuidle_driver
154154
*/
155-
static void __cpuidle_driver_init(struct cpuidle_driver *drv)
155+
static int __cpuidle_driver_init(struct cpuidle_driver *drv)
156156
{
157157
int i;
158158

@@ -193,7 +193,17 @@ static void __cpuidle_driver_init(struct cpuidle_driver *drv)
193193
s->exit_latency_ns = 0;
194194
else
195195
s->exit_latency = div_u64(s->exit_latency_ns, NSEC_PER_USEC);
196+
197+
/*
198+
* Ensure that the exit latency of a CPU idle state does not
199+
* exceed its target residency which is assumed in cpuidle in
200+
* multiple places.
201+
*/
202+
if (s->exit_latency_ns > s->target_residency_ns)
203+
return -EINVAL;
196204
}
205+
206+
return 0;
197207
}
198208

199209
/**
@@ -223,7 +233,9 @@ static int __cpuidle_register_driver(struct cpuidle_driver *drv)
223233
if (cpuidle_disabled())
224234
return -ENODEV;
225235

226-
__cpuidle_driver_init(drv);
236+
ret = __cpuidle_driver_init(drv);
237+
if (ret)
238+
return ret;
227239

228240
ret = __cpuidle_set_driver(drv);
229241
if (ret)

0 commit comments

Comments
 (0)