[PATCH v3 4/6] sched/core: Pause KCOV in __schedule()

From: Karl Mehltretter

Date: Mon Sep 14 2026 - 01:49:17 EST


kernel/sched/ is built without KCOV instrumentation, but callees such
as sched_clock(), architecture CPU-capacity helpers and profile_hits() are.

During preemption and schedule() calls, instrumented 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.

Assisted-by: LLM
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 ae97c63842a4..54b5c5383fe6 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7116,6 +7116,9 @@ static void __sched notrace __schedule(int sched_mode)
struct rq *rq;
int cpu;

+ /* Instrumented callees would leak coverage into current. */
+ guard(kcov_pause)();
+
/* Trace preemptions consistently with task switches */
trace_sched_entry_tp(sched_mode == SM_PREEMPT);

--
2.53.0