[PATCH v5 4/6] sched/core: Pause KCOV in __schedule()
From: Karl Mehltretter
Date: Sat Nov 07 2026 - 08:18:57 EST
kernel/sched/ is built without KCOV instrumentation, but it calls code
that is instrumented with KCOV, such as sched_clock(), architecture
CPU-capacity helpers and profile_hits().
During preemption and schedule() calls, these callees can add
nondeterministic scheduler coverage to current.
With CONFIG_KCOV_SELFTEST added to x86_64 defconfig, the interrupt
selftest fails under QEMU, detecting spurious coverage in
arch_scale_cpu_capacity().
Annotating each callee would spread exclusions across architectures.
Pause across __schedule() instead, extending the scheduler exclusion to
its callees.
KCOV_PAUSED remains set while a task is switched out. The guard in its
resumed __schedule() frame restores the prior state.
Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
---
kernel/sched/core.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index 3f13170c2939..1691eb19f31a 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7219,6 +7219,9 @@ static void __sched notrace __schedule(int sched_mode)
struct rq *rq;
int cpu;
+ /* Callees instrumented with KCOV would leak coverage into current. */
+ kcov_pause_scope();
+
/* Trace preemptions consistently with task switches */
trace_sched_entry_tp(sched_mode == SM_PREEMPT);
--
2.39.5