mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andrew Morton <akpm@linux-foundation.org>
To: Karl Mehltretter <kmehltretter@gmail.com>
Cc: Andrey Konovalov <andreyknvl@gmail.com>,
	Alexander Potapenko <glider@google.com>,
	Dmitry Vyukov <dvyukov@google.com>,
	Marco Elver <elver@google.com>,
	Bradley Morgan <brads@mainlining.org>,
	Anna-Maria Behnsen <anna-maria@linutronix.de>,
	Frederic Weisbecker <frederic@kernel.org>,
	Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>,
	Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	Sebastian Andrzej Siewior <bigeasy@linutronix.de>,
	Clark Williams <clrkwllms@kernel.org>,
	linux-rt-devel@lists.linux.dev, kasan-dev@googlegroups.com,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 4/6] sched/core: Pause KCOV in __schedule()
Date: Fri, 30 Oct 2026 14:23:54 -0700	[thread overview]
Message-ID: <20261030142354.bbc5e7f26fbfb6a8eee21290@linux-foundation.org> (raw)
In-Reply-To: <20261005185803.39170-5-kmehltretter@gmail.com>

On Mon,  5 Oct 2026 20:58:01 +0200 Karl Mehltretter <kmehltretter@gmail.com> wrote:

> 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.
> 
> ...
>
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c

I applied this series and poked around in kernel/sched/core.i, with CONFIG_KCOV=n:

> @@ -7123,6 +7123,9 @@ static void __sched notrace __schedule(int sched_mode)
>  	struct rq *rq;
>  	int cpu;
>  
> +	/* Callees instrumented with KCOV would leak coverage into current. */
> +	guard(kcov_pause)();
> +
>  	/* Trace preemptions consistently with task switches */
>  	trace_sched_entry_tp(sched_mode == SM_PREEMPT);

This expands to

 class_kcov_pause_t __UNIQUE_ID_guard_1782 __attribute__((__cleanup__(class_kcov_pause_destructor))) = class_kcov_pause_constructor();

and class_kcov_pause_constructor() is

static inline 	__attribute__((__gnu_inline__))
		__attribute__((__unused__))
		__attribute__((no_instrument_function))
		__attribute__((__always_inline__))
class_kcov_pause_t class_kcov_pause_constructor(void)
{
		class_kcov_pause_t _t = { .lock = (void*)1 },
			*_T __attribute__((__unused__)) = &_t;
		_T->paused = __kcov_pause();
		return _t;
}

Adding all this goop to core scheduler functions on non-KCOV kernels
won't be terribly popular!

A bit of macro magic can trivially make all this go away for non-KCOV
kernels.  The overhead is probably acceptable with CONFIG_KCOV=y
kernels - seems it's only enabled for debug/research/fuzzing kernels.

Ditto the hrtimer change.  Aim to make these patches produce no change
in generated code with CONFIG_KCOV=n.



  reply	other threads:[~2026-10-30 21:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-05 18:57 [PATCH v4 0/6] kcov: Keep timer and scheduler noise out of task coverage Karl Mehltretter
2026-10-05 18:57 ` [PATCH v4 1/6] kcov: Use unsigned int for kcov_start() mode parameter Karl Mehltretter
2026-10-05 18:57 ` [PATCH v4 2/6] kcov: Add a kcov_pause guard Karl Mehltretter
2026-10-05 18:58 ` [PATCH v4 3/6] hrtimer: Pause KCOV during deferred rearm Karl Mehltretter
2026-10-05 18:58 ` [PATCH v4 4/6] sched/core: Pause KCOV in __schedule() Karl Mehltretter
2026-10-30 21:23   ` Andrew Morton [this message]
2026-10-05 18:58 ` [PATCH v4 5/6] sched/core: Pause KCOV in try_to_wake_up() Karl Mehltretter
2026-10-05 18:58 ` [PATCH v4 6/6] sched/core: Pause KCOV in wake_up_new_task() Karl Mehltretter

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=20261030142354.bbc5e7f26fbfb6a8eee21290@linux-foundation.org \
    --to=akpm@linux-foundation.org \
    --cc=andreyknvl@gmail.com \
    --cc=anna-maria@linutronix.de \
    --cc=bigeasy@linutronix.de \
    --cc=brads@mainlining.org \
    --cc=bsegall@google.com \
    --cc=clrkwllms@kernel.org \
    --cc=dietmar.eggemann@arm.com \
    --cc=dvyukov@google.com \
    --cc=elver@google.com \
    --cc=frederic@kernel.org \
    --cc=glider@google.com \
    --cc=juri.lelli@redhat.com \
    --cc=kasan-dev@googlegroups.com \
    --cc=kmehltretter@gmail.com \
    --cc=kprateek.nayak@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rt-devel@lists.linux.dev \
    --cc=mgorman@suse.de \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=rostedt@goodmis.org \
    --cc=tglx@kernel.org \
    --cc=vincent.guittot@linaro.org \
    --cc=vschneid@redhat.com \
    /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

all inboxes | Powered by JetHome®