* [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver
@ 2025-11-21 1:06 Val Packett
2025-11-21 13:10 ` Rafael J. Wysocki
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Val Packett @ 2025-11-21 1:06 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Christian Loehle,
Artem Bityutskiy
Cc: Val Packett, linux-arm-kernel, linux-arm-msm, Rafael J. Wysocki,
linux-pm, linux-kernel
On Device Tree platforms, the latency and target residency values come
directly from device trees, which are numerous and weren't all written
with cpuidle invariants in mind. For example, qcom/hamoa.dtsi currently
trips this check: exit latency 680000 > residency 600000.
Instead of harshly rejecting the entire cpuidle driver with a mysterious
error message, print a warning and set the target residency value to be
equal to the exit latency.
Fixes: 76934e495cdc ("cpuidle: Add sanity check for exit latency and target residency")
Signed-off-by: Val Packett <val@packett.cool>
---
drivers/cpuidle/driver.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
index 1c295a93d582..06aeb59c1017 100644
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -199,8 +199,11 @@ static int __cpuidle_driver_init(struct cpuidle_driver *drv)
* exceed its target residency which is assumed in cpuidle in
* multiple places.
*/
- if (s->exit_latency_ns > s->target_residency_ns)
- return -EINVAL;
+ if (s->exit_latency_ns > s->target_residency_ns) {
+ pr_warn("cpuidle: state %d: exit latency %lld > residency %lld (fixing)\n",
+ i, s->exit_latency_ns, s->target_residency_ns);
+ s->target_residency_ns = s->exit_latency_ns;
+ }
}
return 0;
--
2.51.0
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver
2025-11-21 1:06 [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver Val Packett
@ 2025-11-21 13:10 ` Rafael J. Wysocki
2025-11-25 16:23 ` [PATCH v1] cpuidle: Warn instead of bailing out if target residency check fails Rafael J. Wysocki
2025-11-21 13:16 ` [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver Artem Bityutskiy
2025-11-21 14:50 ` Konrad Dybcio
2 siblings, 1 reply; 8+ messages in thread
From: Rafael J. Wysocki @ 2025-11-21 13:10 UTC (permalink / raw)
To: Val Packett
Cc: Rafael J. Wysocki, Daniel Lezcano, Christian Loehle,
Artem Bityutskiy, linux-arm-kernel, linux-arm-msm,
Rafael J. Wysocki, linux-pm, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 2583 bytes --]
On Fri, Nov 21, 2025 at 2:08 AM Val Packett <val@packett.cool> wrote:
>
> On Device Tree platforms, the latency and target residency values come
> directly from device trees, which are numerous and weren't all written
> with cpuidle invariants in mind. For example, qcom/hamoa.dtsi currently
> trips this check: exit latency 680000 > residency 600000.
So this breaks cpuidle expectations and it doesn't work correctly on
the affected platforms.
> Instead of harshly rejecting the entire cpuidle driver with a mysterious
> error message, print a warning and set the target residency value to be
> equal to the exit latency.
This generally doesn't work because the new target residency may be
greater than the target residency of the next state.
> Fixes: 76934e495cdc ("cpuidle: Add sanity check for exit latency and target residency")
> Signed-off-by: Val Packett <val@packett.cool>
> ---
> drivers/cpuidle/driver.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
> index 1c295a93d582..06aeb59c1017 100644
> --- a/drivers/cpuidle/driver.c
> +++ b/drivers/cpuidle/driver.c
> @@ -199,8 +199,11 @@ static int __cpuidle_driver_init(struct cpuidle_driver *drv)
> * exceed its target residency which is assumed in cpuidle in
> * multiple places.
> */
> - if (s->exit_latency_ns > s->target_residency_ns)
> - return -EINVAL;
> + if (s->exit_latency_ns > s->target_residency_ns) {
> + pr_warn("cpuidle: state %d: exit latency %lld > residency %lld (fixing)\n",
> + i, s->exit_latency_ns, s->target_residency_ns);
> + s->target_residency_ns = s->exit_latency_ns;
And you also need to update s->target_residency.
Moreover, that needs to be done when all of the target residency and
exit latency values have been computed and full sanitization of all
the states would need to be done (including the ordering checks), but
the kernel has insufficient information to do that (for instance, if
the ordering is not as expected, it is not clear how to fix it up).
Even the above sanitization is unlikely to result in the intended
behavior.
So if returning the error code doesn't work, printing a warning is as
much as can be done, like in the attached patch.
If this works for you, I'll submit it properly later.
> + }
> }
>
> return 0;
> --
[-- Attachment #2: cpuidle-warn.patch --]
[-- Type: text/x-patch, Size: 1542 bytes --]
---
drivers/cpuidle/driver.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -8,6 +8,8 @@
* This code is licenced under the GPL.
*/
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
#include <linux/mutex.h>
#include <linux/module.h>
#include <linux/sched.h>
@@ -152,7 +154,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 int __cpuidle_driver_init(struct cpuidle_driver *drv)
+static void __cpuidle_driver_init(struct cpuidle_driver *drv)
{
int i;
@@ -195,15 +197,13 @@ static int __cpuidle_driver_init(struct
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.
+ * Warn if the exit latency of a CPU idle state exceeds its
+ * target residency which is assumed to never happen in cpuidle
+ * in multiple places.
*/
if (s->exit_latency_ns > s->target_residency_ns)
- return -EINVAL;
+ pr_warn("Idle state %d target residency too low\n", i);
}
-
- return 0;
}
/**
@@ -233,9 +233,7 @@ static int __cpuidle_register_driver(str
if (cpuidle_disabled())
return -ENODEV;
- ret = __cpuidle_driver_init(drv);
- if (ret)
- return ret;
+ __cpuidle_driver_init(drv);
ret = __cpuidle_set_driver(drv);
if (ret)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver
2025-11-21 1:06 [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver Val Packett
2025-11-21 13:10 ` Rafael J. Wysocki
@ 2025-11-21 13:16 ` Artem Bityutskiy
2025-11-21 13:23 ` Rafael J. Wysocki
2025-11-21 14:50 ` Konrad Dybcio
2 siblings, 1 reply; 8+ messages in thread
From: Artem Bityutskiy @ 2025-11-21 13:16 UTC (permalink / raw)
To: Val Packett, Rafael J. Wysocki, Daniel Lezcano, Christian Loehle
Cc: linux-arm-kernel, linux-arm-msm, Rafael J. Wysocki, linux-pm,
linux-kernel
On Thu, 2025-11-20 at 22:06 -0300, Val Packett wrote:
> On Device Tree platforms, the latency and target residency values come
> directly from device trees, which are numerous and weren't all written
> with cpuidle invariants in mind. For example, qcom/hamoa.dtsi currently
> trips this check: exit latency 680000 > residency 600000.
>
> Instead of harshly rejecting the entire cpuidle driver with a mysterious
> error message, print a warning and set the target residency value to be
> equal to the exit latency.
>
> Fixes: 76934e495cdc ("cpuidle: Add sanity check for exit latency and target residency")
> Signed-off-by: Val Packett <val@packett.cool>
> ---
> drivers/cpuidle/driver.c | 7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
> index 1c295a93d582..06aeb59c1017 100644
> --- a/drivers/cpuidle/driver.c
> +++ b/drivers/cpuidle/driver.c
> @@ -199,8 +199,11 @@ static int __cpuidle_driver_init(struct cpuidle_driver *drv)
> * exceed its target residency which is assumed in cpuidle in
> * multiple places.
> */
> - if (s->exit_latency_ns > s->target_residency_ns)
> - return -EINVAL;
> + if (s->exit_latency_ns > s->target_residency_ns) {
> + pr_warn("cpuidle: state %d: exit latency %lld > residency %lld (fixing)\n",
> + i, s->exit_latency_ns, s->target_residency_ns);
> + s->target_residency_ns = s->exit_latency_ns;
> + }
> }
Ideally, in a perfect world, driver.c should verify input data and
reject bad input, rather than correct bad input.
So ideally, if there is an idle driver between DT and driver.c (like
intel_idle.c in case of Intel), that would be its job to correct DT
data.
But I'm not familiar with DT platforms, so I don't know if there is a
driver/piece of SW between DT parsing and driver.c that could handle
this correction at an earlier stage.
The reason I think this patch is not ideal is because it changes the
input data at the core framework level, and in theory the change may be
surprising to users. In general, sometimes rejecting bluntly is better
than correcting in a possibly unexpected way.
Artem.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver
2025-11-21 13:16 ` [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver Artem Bityutskiy
@ 2025-11-21 13:23 ` Rafael J. Wysocki
0 siblings, 0 replies; 8+ messages in thread
From: Rafael J. Wysocki @ 2025-11-21 13:23 UTC (permalink / raw)
To: Artem Bityutskiy
Cc: Val Packett, Rafael J. Wysocki, Daniel Lezcano, Christian Loehle,
linux-arm-kernel, linux-arm-msm, Rafael J. Wysocki, linux-pm,
linux-kernel
On Fri, Nov 21, 2025 at 2:16 PM Artem Bityutskiy
<artem.bityutskiy@linux.intel.com> wrote:
>
> On Thu, 2025-11-20 at 22:06 -0300, Val Packett wrote:
> > On Device Tree platforms, the latency and target residency values come
> > directly from device trees, which are numerous and weren't all written
> > with cpuidle invariants in mind. For example, qcom/hamoa.dtsi currently
> > trips this check: exit latency 680000 > residency 600000.
> >
> > Instead of harshly rejecting the entire cpuidle driver with a mysterious
> > error message, print a warning and set the target residency value to be
> > equal to the exit latency.
> >
> > Fixes: 76934e495cdc ("cpuidle: Add sanity check for exit latency and target residency")
> > Signed-off-by: Val Packett <val@packett.cool>
> > ---
> > drivers/cpuidle/driver.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
> > index 1c295a93d582..06aeb59c1017 100644
> > --- a/drivers/cpuidle/driver.c
> > +++ b/drivers/cpuidle/driver.c
> > @@ -199,8 +199,11 @@ static int __cpuidle_driver_init(struct cpuidle_driver *drv)
> > * exceed its target residency which is assumed in cpuidle in
> > * multiple places.
> > */
> > - if (s->exit_latency_ns > s->target_residency_ns)
> > - return -EINVAL;
> > + if (s->exit_latency_ns > s->target_residency_ns) {
> > + pr_warn("cpuidle: state %d: exit latency %lld > residency %lld (fixing)\n",
> > + i, s->exit_latency_ns, s->target_residency_ns);
> > + s->target_residency_ns = s->exit_latency_ns;
> > + }
> > }
>
> Ideally, in a perfect world, driver.c should verify input data and
> reject bad input, rather than correct bad input.
>
> So ideally, if there is an idle driver between DT and driver.c (like
> intel_idle.c in case of Intel), that would be its job to correct DT
> data.
>
> But I'm not familiar with DT platforms, so I don't know if there is a
> driver/piece of SW between DT parsing and driver.c that could handle
> this correction at an earlier stage.
>
> The reason I think this patch is not ideal is because it changes the
> input data at the core framework level, and in theory the change may be
> surprising to users. In general, sometimes rejecting bluntly is better
> than correcting in a possibly unexpected way.
Unless rejecting it causes the functionality to be missing entirely
and users have no straightforward way to fix it up.
As I said in my reply, what can be done in this situation is to print
a warning when assumptions are not met.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver
2025-11-21 1:06 [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver Val Packett
2025-11-21 13:10 ` Rafael J. Wysocki
2025-11-21 13:16 ` [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver Artem Bityutskiy
@ 2025-11-21 14:50 ` Konrad Dybcio
2 siblings, 0 replies; 8+ messages in thread
From: Konrad Dybcio @ 2025-11-21 14:50 UTC (permalink / raw)
To: Val Packett, Rafael J. Wysocki, Daniel Lezcano, Christian Loehle,
Artem Bityutskiy, Maulik Shah, Bjorn Andersson
Cc: linux-arm-kernel, linux-arm-msm, Rafael J. Wysocki, linux-pm,
linux-kernel
On 11/21/25 2:06 AM, Val Packett wrote:
> On Device Tree platforms, the latency and target residency values come
> directly from device trees, which are numerous and weren't all written
> with cpuidle invariants in mind. For example, qcom/hamoa.dtsi currently
> trips this check: exit latency 680000 > residency 600000.
>
> Instead of harshly rejecting the entire cpuidle driver with a mysterious
> error message, print a warning and set the target residency value to be
> equal to the exit latency.
>
> Fixes: 76934e495cdc ("cpuidle: Add sanity check for exit latency and target residency")
> Signed-off-by: Val Packett <val@packett.cool>
> ---
FWIW this is caused by:
--- hamoa.dtsi
cluster_c4: cpu-sleep-0 {
compatible = "arm,idle-state";
idle-state-name = "ret";
arm,psci-suspend-param = <0x00000004>;
entry-latency-us = <180>;
exit-latency-us = <500>;
min-residency-us = <600>;
};
which notably lacks 'wakeup-latency-us', which triggers this code path:
/*
* If wakeup-latency-us is missing, default to entry+exit
* latencies as defined in idle states bindings
*/
idle_state->exit_latency = entry_latency + exit_latency;
which fails this sanity check because 500+180=680 > 600
(which would have been good to note somewhere)
+Maulik can we fix up the numbers somehow?
Konrad
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH v1] cpuidle: Warn instead of bailing out if target residency check fails
2025-11-21 13:10 ` Rafael J. Wysocki
@ 2025-11-25 16:23 ` Rafael J. Wysocki
2025-11-25 16:50 ` Christian Loehle
2025-11-26 5:29 ` Val Packett
0 siblings, 2 replies; 8+ messages in thread
From: Rafael J. Wysocki @ 2025-11-25 16:23 UTC (permalink / raw)
To: Val Packett
Cc: Daniel Lezcano, Christian Loehle, Artem Bityutskiy,
linux-arm-kernel, linux-arm-msm, Rafael J. Wysocki, linux-pm,
linux-kernel
On Friday, November 21, 2025 2:10:57 PM CET Rafael J. Wysocki wrote:
> On Fri, Nov 21, 2025 at 2:08 AM Val Packett <val@packett.cool> wrote:
> >
> > On Device Tree platforms, the latency and target residency values come
> > directly from device trees, which are numerous and weren't all written
> > with cpuidle invariants in mind. For example, qcom/hamoa.dtsi currently
> > trips this check: exit latency 680000 > residency 600000.
>
> So this breaks cpuidle expectations and it doesn't work correctly on
> the affected platforms.
>
> > Instead of harshly rejecting the entire cpuidle driver with a mysterious
> > error message, print a warning and set the target residency value to be
> > equal to the exit latency.
>
> This generally doesn't work because the new target residency may be
> greater than the target residency of the next state.
>
> > Fixes: 76934e495cdc ("cpuidle: Add sanity check for exit latency and target residency")
> > Signed-off-by: Val Packett <val@packett.cool>
> > ---
> > drivers/cpuidle/driver.c | 7 +++++--
> > 1 file changed, 5 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
> > index 1c295a93d582..06aeb59c1017 100644
> > --- a/drivers/cpuidle/driver.c
> > +++ b/drivers/cpuidle/driver.c
> > @@ -199,8 +199,11 @@ static int __cpuidle_driver_init(struct cpuidle_driver *drv)
> > * exceed its target residency which is assumed in cpuidle in
> > * multiple places.
> > */
> > - if (s->exit_latency_ns > s->target_residency_ns)
> > - return -EINVAL;
> > + if (s->exit_latency_ns > s->target_residency_ns) {
> > + pr_warn("cpuidle: state %d: exit latency %lld > residency %lld (fixing)\n",
> > + i, s->exit_latency_ns, s->target_residency_ns);
> > + s->target_residency_ns = s->exit_latency_ns;
>
> And you also need to update s->target_residency.
>
> Moreover, that needs to be done when all of the target residency and
> exit latency values have been computed and full sanitization of all
> the states would need to be done (including the ordering checks), but
> the kernel has insufficient information to do that (for instance, if
> the ordering is not as expected, it is not clear how to fix it up).
> Even the above sanitization is unlikely to result in the intended
> behavior.
>
> So if returning the error code doesn't work, printing a warning is as
> much as can be done, like in the attached patch.
>
> If this works for you, I'll submit it properly later.
>
No response, so I assume no objections.
---
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
It turns out that the change in commit 76934e495cdc ("cpuidle: Add
sanity check for exit latency and target residency") goes too far
because there are systems in the field on which the check introduced
by that commit does not pass.
For this reason, change __cpuidle_driver_init() return type back to void
and make it print a warning when the check mentioned above does not
pass.
Fixes: 76934e495cdc ("cpuidle: Add sanity check for exit latency and target residency")
Reported-by: Val Packett <val@packett.cool>
Closes: https://lore.kernel.org/linux-pm/20251121010756.6687-1-val@packett.cool/
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/cpuidle/driver.c | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
--- a/drivers/cpuidle/driver.c
+++ b/drivers/cpuidle/driver.c
@@ -8,6 +8,8 @@
* This code is licenced under the GPL.
*/
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
#include <linux/mutex.h>
#include <linux/module.h>
#include <linux/sched.h>
@@ -152,7 +154,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 int __cpuidle_driver_init(struct cpuidle_driver *drv)
+static void __cpuidle_driver_init(struct cpuidle_driver *drv)
{
int i;
@@ -195,15 +197,13 @@ static int __cpuidle_driver_init(struct
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.
+ * Warn if the exit latency of a CPU idle state exceeds its
+ * target residency which is assumed to never happen in cpuidle
+ * in multiple places.
*/
if (s->exit_latency_ns > s->target_residency_ns)
- return -EINVAL;
+ pr_warn("Idle state %d target residency too low\n", i);
}
-
- return 0;
}
/**
@@ -233,9 +233,7 @@ static int __cpuidle_register_driver(str
if (cpuidle_disabled())
return -ENODEV;
- ret = __cpuidle_driver_init(drv);
- if (ret)
- return ret;
+ __cpuidle_driver_init(drv);
ret = __cpuidle_set_driver(drv);
if (ret)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v1] cpuidle: Warn instead of bailing out if target residency check fails
2025-11-25 16:23 ` [PATCH v1] cpuidle: Warn instead of bailing out if target residency check fails Rafael J. Wysocki
@ 2025-11-25 16:50 ` Christian Loehle
2025-11-26 5:29 ` Val Packett
1 sibling, 0 replies; 8+ messages in thread
From: Christian Loehle @ 2025-11-25 16:50 UTC (permalink / raw)
To: Rafael J. Wysocki, Val Packett
Cc: Daniel Lezcano, Artem Bityutskiy, linux-arm-kernel, linux-arm-msm,
Rafael J. Wysocki, linux-pm, linux-kernel
On 11/25/25 16:23, Rafael J. Wysocki wrote:
> On Friday, November 21, 2025 2:10:57 PM CET Rafael J. Wysocki wrote:
>> On Fri, Nov 21, 2025 at 2:08 AM Val Packett <val@packett.cool> wrote:
>>>
>>> On Device Tree platforms, the latency and target residency values come
>>> directly from device trees, which are numerous and weren't all written
>>> with cpuidle invariants in mind. For example, qcom/hamoa.dtsi currently
>>> trips this check: exit latency 680000 > residency 600000.
>>
>> So this breaks cpuidle expectations and it doesn't work correctly on
>> the affected platforms.
>>
>>> Instead of harshly rejecting the entire cpuidle driver with a mysterious
>>> error message, print a warning and set the target residency value to be
>>> equal to the exit latency.
>>
>> This generally doesn't work because the new target residency may be
>> greater than the target residency of the next state.
>>
>>> Fixes: 76934e495cdc ("cpuidle: Add sanity check for exit latency and target residency")
>>> Signed-off-by: Val Packett <val@packett.cool>
>>> ---
>>> drivers/cpuidle/driver.c | 7 +++++--
>>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
>>> index 1c295a93d582..06aeb59c1017 100644
>>> --- a/drivers/cpuidle/driver.c
>>> +++ b/drivers/cpuidle/driver.c
>>> @@ -199,8 +199,11 @@ static int __cpuidle_driver_init(struct cpuidle_driver *drv)
>>> * exceed its target residency which is assumed in cpuidle in
>>> * multiple places.
>>> */
>>> - if (s->exit_latency_ns > s->target_residency_ns)
>>> - return -EINVAL;
>>> + if (s->exit_latency_ns > s->target_residency_ns) {
>>> + pr_warn("cpuidle: state %d: exit latency %lld > residency %lld (fixing)\n",
>>> + i, s->exit_latency_ns, s->target_residency_ns);
>>> + s->target_residency_ns = s->exit_latency_ns;
>>
>> And you also need to update s->target_residency.
>>
>> Moreover, that needs to be done when all of the target residency and
>> exit latency values have been computed and full sanitization of all
>> the states would need to be done (including the ordering checks), but
>> the kernel has insufficient information to do that (for instance, if
>> the ordering is not as expected, it is not clear how to fix it up).
>> Even the above sanitization is unlikely to result in the intended
>> behavior.
>>
>> So if returning the error code doesn't work, printing a warning is as
>> much as can be done, like in the attached patch.
>>
>> If this works for you, I'll submit it properly later.
>>
>
> No response, so I assume no objections.
>
> ---
> From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
>
> It turns out that the change in commit 76934e495cdc ("cpuidle: Add
> sanity check for exit latency and target residency") goes too far
> because there are systems in the field on which the check introduced
> by that commit does not pass.
>
> For this reason, change __cpuidle_driver_init() return type back to void
> and make it print a warning when the check mentioned above does not
> pass.
>
> Fixes: 76934e495cdc ("cpuidle: Add sanity check for exit latency and target residency")
> Reported-by: Val Packett <val@packett.cool>
> Closes: https://lore.kernel.org/linux-pm/20251121010756.6687-1-val@packett.cool/
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> drivers/cpuidle/driver.c | 18 ++++++++----------
> 1 file changed, 8 insertions(+), 10 deletions(-)
>
> --- a/drivers/cpuidle/driver.c
> +++ b/drivers/cpuidle/driver.c
> @@ -8,6 +8,8 @@
> * This code is licenced under the GPL.
> */
>
> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> +
> #include <linux/mutex.h>
> #include <linux/module.h>
> #include <linux/sched.h>
> @@ -152,7 +154,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 int __cpuidle_driver_init(struct cpuidle_driver *drv)
> +static void __cpuidle_driver_init(struct cpuidle_driver *drv)
> {
> int i;
>
> @@ -195,15 +197,13 @@ static int __cpuidle_driver_init(struct
> 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.
> + * Warn if the exit latency of a CPU idle state exceeds its
> + * target residency which is assumed to never happen in cpuidle
> + * in multiple places.
> */
> if (s->exit_latency_ns > s->target_residency_ns)
> - return -EINVAL;
> + pr_warn("Idle state %d target residency too low\n", i);
> }
> -
> - return 0;
> }
>
> /**
> @@ -233,9 +233,7 @@ static int __cpuidle_register_driver(str
> if (cpuidle_disabled())
> return -ENODEV;
>
> - ret = __cpuidle_driver_init(drv);
> - if (ret)
> - return ret;
> + __cpuidle_driver_init(drv);
>
> ret = __cpuidle_set_driver(drv);
> if (ret)
>
FWIW I also prefer this to a weird fixing-up-states logic that we would never test!
Reviewed-by: Christian Loehle <christian.loehle@arm.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH v1] cpuidle: Warn instead of bailing out if target residency check fails
2025-11-25 16:23 ` [PATCH v1] cpuidle: Warn instead of bailing out if target residency check fails Rafael J. Wysocki
2025-11-25 16:50 ` Christian Loehle
@ 2025-11-26 5:29 ` Val Packett
1 sibling, 0 replies; 8+ messages in thread
From: Val Packett @ 2025-11-26 5:29 UTC (permalink / raw)
To: Rafael J. Wysocki
Cc: Daniel Lezcano, Christian Loehle, Artem Bityutskiy,
linux-arm-kernel, linux-arm-msm, Rafael J. Wysocki, linux-pm,
linux-kernel
On 11/25/25 1:23 PM, Rafael J. Wysocki wrote:
> On Friday, November 21, 2025 2:10:57 PM CET Rafael J. Wysocki wrote:
>> On Fri, Nov 21, 2025 at 2:08 AM Val Packett <val@packett.cool> wrote:
>>> On Device Tree platforms, the latency and target residency values come
>>> directly from device trees, which are numerous and weren't all written
>>> with cpuidle invariants in mind. For example, qcom/hamoa.dtsi currently
>>> trips this check: exit latency 680000 > residency 600000.
>> So this breaks cpuidle expectations and it doesn't work correctly on
>> the affected platforms.
>>
>>> Instead of harshly rejecting the entire cpuidle driver with a mysterious
>>> error message, print a warning and set the target residency value to be
>>> equal to the exit latency.
>> This generally doesn't work because the new target residency may be
>> greater than the target residency of the next state.
>>
>>> Fixes: 76934e495cdc ("cpuidle: Add sanity check for exit latency and target residency")
>>> Signed-off-by: Val Packett <val@packett.cool>
>>> ---
>>> drivers/cpuidle/driver.c | 7 +++++--
>>> 1 file changed, 5 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
>>> index 1c295a93d582..06aeb59c1017 100644
>>> --- a/drivers/cpuidle/driver.c
>>> +++ b/drivers/cpuidle/driver.c
>>> @@ -199,8 +199,11 @@ static int __cpuidle_driver_init(struct cpuidle_driver *drv)
>>> * exceed its target residency which is assumed in cpuidle in
>>> * multiple places.
>>> */
>>> - if (s->exit_latency_ns > s->target_residency_ns)
>>> - return -EINVAL;
>>> + if (s->exit_latency_ns > s->target_residency_ns) {
>>> + pr_warn("cpuidle: state %d: exit latency %lld > residency %lld (fixing)\n",
>>> + i, s->exit_latency_ns, s->target_residency_ns);
>>> + s->target_residency_ns = s->exit_latency_ns;
>> And you also need to update s->target_residency.
>>
>> Moreover, that needs to be done when all of the target residency and
>> exit latency values have been computed and full sanitization of all
>> the states would need to be done (including the ordering checks), but
>> the kernel has insufficient information to do that (for instance, if
>> the ordering is not as expected, it is not clear how to fix it up).
>> Even the above sanitization is unlikely to result in the intended
>> behavior.
>>
>> So if returning the error code doesn't work, printing a warning is as
>> much as can be done, like in the attached patch.
>>
>> If this works for you, I'll submit it properly later.
>>
> No response, so I assume no objections. [..]
Right, only printing a warning is fine of course.
~val
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2025-11-26 5:29 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-21 1:06 [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver Val Packett
2025-11-21 13:10 ` Rafael J. Wysocki
2025-11-25 16:23 ` [PATCH v1] cpuidle: Warn instead of bailing out if target residency check fails Rafael J. Wysocki
2025-11-25 16:50 ` Christian Loehle
2025-11-26 5:29 ` Val Packett
2025-11-21 13:16 ` [PATCH] cpuidle: warn and fixup on sanity check instead of rejecting the driver Artem Bityutskiy
2025-11-21 13:23 ` Rafael J. Wysocki
2025-11-21 14:50 ` Konrad Dybcio
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).