From: Peter Zijlstra <peterz@infradead.org>
To: Chris Down <chris@chrisdown.name>
Cc: Ingo Molnar <mingo@redhat.com>, Kees Cook <kees@kernel.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>,
Ard Biesheuvel <ardb@kernel.org>, Will Deacon <will@kernel.org>,
Sami Tolvanen <samitolvanen@google.com>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>,
Arnd Bergmann <arnd@arndb.de>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
linux-arm-kernel@lists.infradead.org,
linux-riscv@lists.infradead.org, linux-doc@vger.kernel.org,
linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org,
kernel-team@meta.com
Subject: Re: [PATCH 2/3] sched/core: Add sched_stack_end_check= boot parameter
Date: Tue, 27 Oct 2026 11:17:03 +0100 [thread overview]
Message-ID: <20261027101703.GB2668564@noisy.programming.kicks-ass.net> (raw)
In-Reply-To: <3d2bb6a8508b9d801878bb82c88165a1b1ff5f40.1793082868.git.chris@chrisdown.name>
On Tue, Oct 27, 2026 at 02:36:21PM +0800, Chris Down wrote:
> CONFIG_SCHED_STACK_END_CHECK makes schedule_debug() check the magic at
> the end of the outgoing task's stack and panic if it has been
> overwritten.
>
> Right now this can only be configured by setting the Kconfig option at
> build time. At Meta we have it on for some hosts and off for others,
> since it is helpful but adds cost on context switching. That means today
> we have to build separate kernels for each, which is less than ideal.
>
> So let's make this configurable at boot time. In benchmarking sched pipe
> and sched messaging performance is unaffected.
>
> Signed-off-by: Chris Down <chris@chrisdown.name>
> ---
> .../admin-guide/kernel-parameters.txt | 8 +++++
> kernel/sched/core.c | 33 +++++++++++++++----
> 2 files changed, 35 insertions(+), 6 deletions(-)
>
> diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt
> index fbee7b544903..95911d33c0fe 100644
> --- a/Documentation/admin-guide/kernel-parameters.txt
> +++ b/Documentation/admin-guide/kernel-parameters.txt
> @@ -6811,6 +6811,14 @@ Kernel parameters
> core priority to both SMT siblings, so this option
> does not favor either sibling.
>
> + sched_stack_end_check= [KNL]
> + Format: <bool>
> + Check the magic value at the end of the outgoing
> + task's stack (and its shadow call stack, if any) on
> + every call to schedule(), and panic if it has been
> + overwritten.
> + Default set by CONFIG_SCHED_STACK_END_CHECK.
> +
> sched_verbose [KNL,EARLY] Enables verbose scheduler debug messages.
>
> schedstats= [KNL,X86] Enable or disable scheduled statistics.
> diff --git a/kernel/sched/core.c b/kernel/sched/core.c
> index fc269fd10192..c1fb86b813bb 100644
> --- a/kernel/sched/core.c
> +++ b/kernel/sched/core.c
> @@ -6143,18 +6143,39 @@ static noinline void __schedule_bug(struct task_struct *prev)
> add_taint(TAINT_WARN, LOCKDEP_STILL_OK);
> }
>
> +static DEFINE_STATIC_KEY_MAYBE_RO(CONFIG_SCHED_STACK_END_CHECK, sched_stack_end_check);
> +
> +static int __init setup_sched_stack_end_check(char *str)
> +{
> + bool enable;
> +
> + if (kstrtobool(str, &enable)) {
> + pr_warn("Unable to parse sched_stack_end_check=\n");
> + return 0;
> + }
> +
> + if (enable)
> + static_branch_enable(&sched_stack_end_check);
> + else
> + static_branch_disable(&sched_stack_end_check);
> +
> + return 1;
> +}
> +__setup("sched_stack_end_check=", setup_sched_stack_end_check);
> +
> /*
> * Various schedule()-time debugging checks and statistics:
> */
> static inline void schedule_debug(struct task_struct *prev, bool preempt)
> {
> -#ifdef CONFIG_SCHED_STACK_END_CHECK
> - if (task_stack_end_corrupted(prev))
> - panic("corrupted stack end detected inside scheduler\n");
> + if (static_branch_maybe(CONFIG_SCHED_STACK_END_CHECK,
> + &sched_stack_end_check)) {
> + if (task_stack_end_corrupted(prev))
> + panic("corrupted stack end detected inside scheduler\n");
>
> - if (scs_is_enabled() && task_scs_end_corrupted(prev))
> - panic("corrupted shadow stack detected inside scheduler\n");
> -#endif
> + if (scs_is_enabled() && task_scs_end_corrupted(prev))
> + panic("corrupted shadow stack detected inside scheduler\n");
> + }
I just noticed that there's a number of task_stack_end_corrupted()
checks that:
- do not also do task_scs_end_corrupted(); should
task_scs_end_corrupted() be put inside task_stack_end_corrupted() to
make sure they're always done in tandem and the shadow stack check
isn't lost?
- should these other sites also respect this switch? It seems weird to
only have this one site affected.
next prev parent reply other threads:[~2026-10-27 10:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-27 6:36 [PATCH 0/3] Make the scheduler stack end check selectable at boot Chris Down
2026-10-27 6:36 ` [PATCH 1/3] sched/core: Skip the shadow stack end check when SCS is disabled Chris Down
2026-10-27 10:08 ` Peter Zijlstra
2026-10-27 6:36 ` [PATCH 2/3] sched/core: Add sched_stack_end_check= boot parameter Chris Down
2026-10-27 10:17 ` Peter Zijlstra [this message]
2026-10-27 23:34 ` Randy Dunlap
2026-10-27 6:36 ` [PATCH 3/3] lkdtm/bugs: Add CORRUPT_STACK_END to test the scheduler stack end check Chris Down
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=20261027101703.GB2668564@noisy.programming.kicks-ass.net \
--to=peterz@infradead.org \
--cc=alex@ghiti.fr \
--cc=aou@eecs.berkeley.edu \
--cc=ardb@kernel.org \
--cc=arnd@arndb.de \
--cc=bsegall@google.com \
--cc=chris@chrisdown.name \
--cc=corbet@lwn.net \
--cc=dietmar.eggemann@arm.com \
--cc=gregkh@linuxfoundation.org \
--cc=juri.lelli@redhat.com \
--cc=kees@kernel.org \
--cc=kernel-team@meta.com \
--cc=kprateek.nayak@amd.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mgorman@suse.de \
--cc=mingo@redhat.com \
--cc=palmer@dabbelt.com \
--cc=pjw@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rostedt@goodmis.org \
--cc=samitolvanen@google.com \
--cc=skhan@linuxfoundation.org \
--cc=vincent.guittot@linaro.org \
--cc=vschneid@redhat.com \
--cc=will@kernel.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
all inboxes | Powered by JetHome®