From: Karl Mehltretter <kmehltretter@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
Andrey Konovalov <andreyknvl@gmail.com>,
Dmitry Vyukov <dvyukov@google.com>,
Alexander Potapenko <glider@google.com>,
Marco Elver <elver@google.com>,
Bradley Morgan <include@grrlz.net>,
kasan-dev@googlegroups.com, linux-kernel@vger.kernel.org,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>
Subject: [PATCH 3/5] sched: pause KCOV in __schedule()
Date: Fri, 7 Aug 2026 22:50:25 +0200 [thread overview]
Message-ID: <20260807205027.31972-4-kmehltretter@gmail.com> (raw)
In-Reply-To: <20260807205027.31972-1-kmehltretter@gmail.com>
kernel/sched/ is not instrumented, 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, the interrupt selftest fails on x86_64
defconfig under QEMU, detecting spurious coverage in
arch_scale_cpu_capacity(). On arm64 the same class of leak appears in
sched_clock(), once the separate arm64 interrupt-accounting leak is
suppressed.
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. Its resumed
__schedule() frame restores the prior state.
Fixes: 5c9a8750a640 ("kernel: add kcov code coverage")
Assisted-by: Claude:claude-opus-4-8
Assisted-by: Claude:claude-fable-5
Signed-off-by: Karl Mehltretter <kmehltretter@gmail.com>
---
kernel/sched/core.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/kernel/sched/core.c b/kernel/sched/core.c
index b6a8fbbdd538..d5663df6c702 100644
--- a/kernel/sched/core.c
+++ b/kernel/sched/core.c
@@ -7069,10 +7069,14 @@ static void __sched notrace __schedule(int sched_mode)
bool is_switch = false;
unsigned long *switch_count;
unsigned long prev_state;
+ unsigned int kcov_paused;
struct rq_flags rf;
struct rq *rq;
int cpu;
+ /* KCOV: sched/ is uninstrumented but the __schedule() callees are not. */
+ kcov_paused = kcov_pause(current);
+
/* Trace preemptions consistently with task switches */
trace_sched_entry_tp(sched_mode == SM_PREEMPT);
@@ -7239,6 +7243,7 @@ static void __sched notrace __schedule(int sched_mode)
raw_spin_rq_unlock_irq(rq);
}
trace_sched_exit_tp(is_switch);
+ kcov_resume(current, kcov_paused);
}
void __noreturn do_task_dead(void)
--
2.53.0
next prev parent reply other threads:[~2026-08-07 20:50 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-07 20:50 [PATCH 0/5] kcov: suppress timer and scheduler coverage leaks Karl Mehltretter
2026-08-07 20:50 ` [PATCH 1/5] kcov: add kcov_pause()/kcov_resume() helpers Karl Mehltretter
2026-08-08 1:16 ` Bradley Morgan
2026-08-07 20:50 ` [PATCH 2/5] hrtimer: pause KCOV during deferred rearm Karl Mehltretter
2026-08-08 1:19 ` Bradley Morgan
2026-08-07 20:50 ` Karl Mehltretter [this message]
2026-08-08 1:21 ` [PATCH 3/5] sched: pause KCOV in __schedule() Bradley Morgan
2026-08-07 20:50 ` [PATCH 4/5] sched: pause KCOV in try_to_wake_up() Karl Mehltretter
2026-08-07 21:00 ` sashiko-bot
2026-08-08 1:28 ` Bradley Morgan
2026-08-07 20:50 ` [PATCH 5/5] sched: pause KCOV in wake_up_new_task() Karl Mehltretter
2026-08-08 1:36 ` Bradley Morgan
2026-08-08 8:44 ` [PATCH 0/5] kcov: suppress timer and scheduler coverage leaks Peter Zijlstra
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260807205027.31972-4-kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=andreyknvl@gmail.com \
--cc=dvyukov@google.com \
--cc=elver@google.com \
--cc=glider@google.com \
--cc=include@grrlz.net \
--cc=juri.lelli@redhat.com \
--cc=kasan-dev@googlegroups.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=vincent.guittot@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox