[PATCH v5 5/6] sched/core: Pause KCOV in try_to_wake_up()
From: Karl Mehltretter
Date: Sat Nov 07 2026 - 08:18:01 EST
try_to_wake_up() is built without KCOV instrumentation, but it calls
helpers instrumented with KCOV, such as kthread_is_per_cpu(), CPU
capacity helpers and SCHED_HRTICK arming. They can record into current
while in_task() is true.
During task-context wakeups such as a pipe write waking a reader, these
helpers record coverage that depends on the target task and runqueue
state into the waking task. Before commit feb5c9a2447a ("softirq:
Preserve interrupt context on return from interrupt"), the IRQ-exit
ktimersd wakeup under PREEMPT_RT also ran in task context and failed
CONFIG_KCOV_SELFTEST in kthread_is_per_cpu().
Pause the wakeup body with kcov_pause_scope(). Take it before the
preemption guard so preemption is re-enabled while KCOV remains paused.
Wrapping only select_task_rq() would miss SCHED_HRTICK arming during
enqueue.
Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
---
kernel/sched/core.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 1691eb19f31a..4bd0d5736ccf 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -4323,6 +4323,8 @@ bool ttwu_state_match(struct task_struct *p, unsigned int state, int *success)
*/
int try_to_wake_up(struct task_struct *p, unsigned int state, int wake_flags)
{
+ /* Callees instrumented with KCOV would leak coverage into current. */
+ kcov_pause_scope();
guard(preempt)();
int cpu, success = 0;
--
2.39.5