Re: [PATCH v2 4/6] sched/core: Pause KCOV in __schedule()
From: Peter Zijlstra
Date: Wed Aug 12 2026 - 09:21:04 EST
On Tue, Aug 11, 2026 at 05:41:09PM +0200, Karl Mehltretter wrote:
> kernel/sched/ is not instrumented,
It bloody well is; there is no noinstr here, just a notrace.
> 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.
>
> Fixes: 5c9a8750a640 ("kernel: add kcov code coverage")
> Assisted-by: Claude:claude-fable-5
> Signed-off-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>
> ---
> Notes:
> v2:
> - take guard(kcov_pause)()
> - clarify the test configuration and reword the pause comment
>
> kernel/sched/core.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index 3cbf817f52a4a..e49f0bfa0ca73 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -7073,6 +7073,9 @@ static void __sched notrace __schedule(int sched_mode)
> struct rq *rq;
> int cpu;
>
> + /* Instrumented callees would leak coverage into current. */
This comment makes about as much sense as your Changelog.
> + guard(kcov_pause)();
> +
> /* Trace preemptions consistently with task switches */
> trace_sched_entry_tp(sched_mode == SM_PREEMPT);
>
> --
> 2.53.0