Re: [PATCH 4/5] sched: pause KCOV in try_to_wake_up()
From: Bradley Morgan
Date: Fri Aug 07 2026 - 21:29:15 EST
On 7 August 2026 21:50:26 BST, Karl Mehltretter <kmehltretter@xxxxxxxxx>
wrote:
>try_to_wake_up() is uninstrumented, but it calls instrumented helpers
>such as kthread_is_per_cpu(), CPU capacity helpers and SCHED_HRTICK
>arming. They can record into current while in_task() is true.
>
>CONFIG_KCOV_SELFTEST exposes this under PREEMPT_RT. The interrupt
>selftest fails on x86_64 in kthread_is_per_cpu(): RT runs the timer
>softirq in a thread, so the wakeup runs in task context during the
>selftest's spin. The same helpers leak into non-RT syscall wakeups such
>as a pipe write waking a reader.
>
>Pause all of try_to_wake_up(). Wrapping only select_task_rq() would miss
>SCHED_HRTICK arming during enqueue.
>
>Fixes: 5c9a8750a640 ("kernel: add kcov code coverage")
>Assisted-by: Claude:claude-opus-4-8
>Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
I don't mind.
Reviewed-by: Bradley Morgan <include@xxxxxxxxx>
I saw sashikos "kind" reply, this isn't a bug, but a scoped guard,
could be built.
considering it would future proof against somebody adding a early return
later.
but tbh that's more a patch 1 decision to make.
>---
> kernel/sched/core.c | 3 +++
> 1 file changed, 3 insertions(+)
>
>diff --git a/kernel/sched/core.c b/kernel/sched/core.c
>index d5663df6c702..1e562a7ff0af 100644
>--- a/kernel/sched/core.c
>+++ b/kernel/sched/core.c
>@@ -4252,6 +4252,8 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
> {
> guard(preempt)();
> int cpu, success = 0;
>+ /* KCOV: sched/ is uninstrumented but the wakeup callees are not. */
>+ unsigned int kcov_paused = kcov_pause(current);
>
> wake_flags |= WF_TTWU;
>
>@@ -4418,6 +4420,7 @@ int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
> if (success)
> ttwu_stat(p, task_cpu(p), wake_flags);
>
>+ kcov_resume(current, kcov_paused);
> return success;
> }
>
>
Thanks!