mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] sched/idle: Destroy on-stack hrtimer in play_idle_precise()
@ 2026-10-15  2:50 Hui Su
  2026-10-15  7:02 ` Peter Zijlstra
  2026-10-15  7:19 ` K Prateek Nayak
  0 siblings, 2 replies; 3+ messages in thread
From: Hui Su @ 2026-10-15  2:50 UTC (permalink / raw)
  To: mingo, peterz, juri.lelli, vincent.guittot
  Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid,
	kprateek.nayak, linux-kernel, Hui Su

play_idle_precise() initializes it.timer with hrtimer_setup_on_stack(),
but does not call destroy_hrtimer_on_stack() before the stack object
goes out of scope.

With CONFIG_DEBUG_OBJECTS_TIMERS, hrtimer_setup_on_stack() registers the
timer as an on-stack debug object. Such objects must be removed before
leaving the function which allocated them.

Call destroy_hrtimer_on_stack() after the expiry loop to balance the
on-stack timer lifetime.

Fixes: c1de45ca831a ("sched/idle: Add support for tasks that inject idle")
Signed-off-by: Hui Su <sh_def@163.com>
---
Tested on x86_64 combined candidate tree:

- hrtimer setup/free oracle: PASS (127/127 and 129/129)

- bzImage and modules build: PASS

- Branch-specific validation after split: NOT RUN

 kernel/sched/idle.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
index eb73b65ce6c4..96adec3f0a6d 100644
--- a/kernel/sched/idle.c
+++ b/kernel/sched/idle.c
@@ -436,6 +436,7 @@ void play_idle_precise(u64 duration_ns, u64 latency_ns)
 
 	while (!READ_ONCE(it.done))
 		do_idle();
+	destroy_hrtimer_on_stack(&it.timer);
 
 	cpuidle_use_deepest_state(0);
 	current->flags &= ~PF_IDLE;

base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053


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

* Re: [PATCH] sched/idle: Destroy on-stack hrtimer in play_idle_precise()
  2026-10-15  2:50 [PATCH] sched/idle: Destroy on-stack hrtimer in play_idle_precise() Hui Su
@ 2026-10-15  7:02 ` Peter Zijlstra
  2026-10-15  7:19 ` K Prateek Nayak
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Zijlstra @ 2026-10-15  7:02 UTC (permalink / raw)
  To: Hui Su
  Cc: mingo, juri.lelli, vincent.guittot, dietmar.eggemann, rostedt,
	bsegall, mgorman, vschneid, kprateek.nayak, linux-kernel,
	Thomas Gleixner

On Thu, Oct 15, 2026 at 11:50:28AM +0900, Hui Su wrote:
> play_idle_precise() initializes it.timer with hrtimer_setup_on_stack(),
> but does not call destroy_hrtimer_on_stack() before the stack object
> goes out of scope.
> 
> With CONFIG_DEBUG_OBJECTS_TIMERS, hrtimer_setup_on_stack() registers the
> timer as an on-stack debug object. Such objects must be removed before
> leaving the function which allocated them.
> 
> Call destroy_hrtimer_on_stack() after the expiry loop to balance the
> on-stack timer lifetime.

Maybe, but I'm hating on this.

For one, the hrtimer_setup_on_stack() comment doesn't mention
destroy_hrtimer_on_stack(), so how are we to know.

Secondly, we have __cleanup(), which gives us the opportunity to
actually do the right thing and create a better interface.


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

* Re: [PATCH] sched/idle: Destroy on-stack hrtimer in play_idle_precise()
  2026-10-15  2:50 [PATCH] sched/idle: Destroy on-stack hrtimer in play_idle_precise() Hui Su
  2026-10-15  7:02 ` Peter Zijlstra
@ 2026-10-15  7:19 ` K Prateek Nayak
  1 sibling, 0 replies; 3+ messages in thread
From: K Prateek Nayak @ 2026-10-15  7:19 UTC (permalink / raw)
  To: Hui Su, mingo, peterz, juri.lelli, vincent.guittot
  Cc: dietmar.eggemann, rostedt, bsegall, mgorman, vschneid, linux-kernel

Hello Hui,

On 10/15/2026 8:20 AM, Hui Su wrote:
> play_idle_precise() initializes it.timer with hrtimer_setup_on_stack(),
> but does not call destroy_hrtimer_on_stack() before the stack object
> goes out of scope.
> 
> With CONFIG_DEBUG_OBJECTS_TIMERS, hrtimer_setup_on_stack() registers the
> timer as an on-stack debug object. Such objects must be removed before
> leaving the function which allocated them.
> 
> Call destroy_hrtimer_on_stack() after the expiry loop to balance the
> on-stack timer lifetime.
> 
> Fixes: c1de45ca831a ("sched/idle: Add support for tasks that inject idle")
> Signed-off-by: Hui Su <sh_def@163.com>

Feel free to include:

Reviewed-by: K Prateek Nayak <kprateek.nayak@amd.com>
Tested-by: K Prateek Nayak <kprateek.nayak@amd.com>

> ---
> Tested on x86_64 combined candidate tree:
> 
> - hrtimer setup/free oracle: PASS (127/127 and 129/129)
> 
> - bzImage and modules build: PASS
> 
> - Branch-specific validation after split: NOT RUN
> 
>  kernel/sched/idle.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/kernel/sched/idle.c b/kernel/sched/idle.c
> index eb73b65ce6c4..96adec3f0a6d 100644
> --- a/kernel/sched/idle.c
> +++ b/kernel/sched/idle.c
> @@ -436,6 +436,7 @@ void play_idle_precise(u64 duration_ns, u64 latency_ns)
>  
>  	while (!READ_ONCE(it.done))
>  		do_idle();

nit. I would rather have that newline before destroy_hrtimer_on_stack()
than after but that is just me :-)

No need to resend for that nit.

> +	destroy_hrtimer_on_stack(&it.timer);
>  
>  	cpuidle_use_deepest_state(0);
>  	current->flags &= ~PF_IDLE;
> 
> base-commit: 0fcb05b72344f40806cbe810de8872f1698bf053
> 

-- 
Thanks and Regards,
Prateek


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

end of thread, other threads:[~2026-10-15  7:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-15  2:50 [PATCH] sched/idle: Destroy on-stack hrtimer in play_idle_precise() Hui Su
2026-10-15  7:02 ` Peter Zijlstra
2026-10-15  7:19 ` K Prateek Nayak

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

all inboxes | Powered by JetHome®