From: Karl Mehltretter <kmehltretter@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Catalin Marinas <catalin.marinas@arm.com>,
Will Deacon <will@kernel.org>
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
Mark Rutland <mark.rutland@arm.com>,
Hongyan Xia <hongyan.xia@transsion.com>,
Song Liu <song@kernel.org>, Steven Rostedt <rostedt@goodmis.org>,
Juri Lelli <juri.lelli@redhat.com>,
Vincent Guittot <vincent.guittot@linaro.org>,
Dietmar Eggemann <dietmar.eggemann@arm.com>,
Valentin Schneider <vschneid@redhat.com>,
linux-arm-kernel@lists.infradead.org,
linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 0/3] sched/preempt: Check notrace preempt-count updates
Date: Mon, 16 Nov 2026 08:54:21 +0100 [thread overview]
Message-ID: <cover.1794814699.git.kmehltretter@gmail.com> (raw)
With CONFIG_DEBUG_PREEMPT, the notrace preemption macros bypass the
bounds checks used by ordinary operations. Add checked noinstr updates
for their existing callers and share validation with
preempt_count_add() and preempt_count_sub().
Patch 1 forces the arm64 raw updates called by the new helpers inline.
Patch 2 does the same for preempt_count(), which the helpers use, for
should_resched(), reached by the debug notrace enable path, and for the
existing non-debug __preempt_count_dec_and_test() path. The corresponding
x86, s390 and asm-generic operations are already __always_inline.
Patch 1 is extracted from Hongyan Xia's entry RFC. Song Liu also posted
notrace annotations for the same arm64 helpers:
https://lore.kernel.org/r/20261023011049.1164625-10-song@kernel.org
Patch 3 disables branch profiling for core.o when DEBUG_PREEMPT and
TRACE_BRANCH_PROFILING are both enabled. DEBUG_LOCKS_WARN_ON() evaluates
its condition before entering its instrumentation region, so profiling
that condition would call ftrace_likely_update() from noinstr text. The
scheduler Makefile already uses this per-object exclusion for
build_policy.o and build_utility.o.
The cost is loss of branch-profile data for the rest of core.o in that
configuration. Scheduler tracepoints and function tracing are unchanged.
A dedicated non-profiled object is the fallback if this object-wide cost
is considered too broad.
This series is independently useful. It also supplies the checked count
update planned for follow-up IRQ-entry work; it does not change IRQ entry,
trace-recursion lifetime or TRACE_CTX_TRANSITION.
This addresses Peter's suggestion here:
https://lore.kernel.org/r/20261029093219.GH1779021@noisy.programming.kicks-ass.net
The series is based on v7.4-rc2.
Testing:
- Clang 19.1.7 x86-64: a W=1 defconfig-derived build with
DEBUG_PREEMPT, annotated branch profiling, DEBUG_ENTRY and noinstr
validation passed. A nested-KVM boot passed the built-in and external
module checks and all five tracer workloads. A DEBUG_PREEMPT=n control
retained branch profiling for core.o and emitted no new helper symbols.
- GCC 14.2 arm64: a W=1 PREEMPT_RT build and allmodconfig passed. The
latter's nVHE object had no undefined references to the new helpers.
A native Axion boot passed the built-in and module checks and all five
tracers.
- GCC 14.2 and 16.2 ARC, C-SKY and MIPS: performance, size, all-branches
and forced-noinline core.o inspections passed without prohibited
noinstr relocations or branch-profile records. Full baseline and patched
kernels plus the external debug module built. Matching QEMU boots reached
the expected balanced and invalid-count markers on ARC and C-SKY UP and
MIPS UP/SMP. The patched kernels diagnosed every invalid operation;
rejected decrements retained their counts. An ARC DEBUG_PREEMPT=n
control retained core.o profiling without references to the new helpers.
The MIPS UP baseline and patched positive boots emitted the same three
existing smp_processor_id() diagnostics; the SMP boots emitted none.
I used an LLM to help extract and review the changes, write the test
harnesses and prepare the commit messages.
Hongyan Xia (1):
arm64: Always inline raw preempt count updates
Karl Mehltretter (2):
arm64: Always inline preempt count and reschedule checks
sched/preempt: Check preempt counts in notrace helpers
arch/arm64/include/asm/preempt.h | 10 ++++----
include/linux/preempt.h | 22 ++++++++++++++----
kernel/sched/Makefile | 3 +++
kernel/sched/core.c | 40 ++++++++++++++++++++++++++++----
4 files changed, 62 insertions(+), 13 deletions(-)
base-commit: 7475ea8b58616b33c04afb976cf0fbaad9dd63fb
next reply other threads:[~2026-11-16 7:54 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-16 7:54 Karl Mehltretter [this message]
2026-11-16 7:54 ` [PATCH 1/3] arm64: Always inline raw preempt count updates Karl Mehltretter
2026-11-16 8:16 ` sashiko-bot
2026-11-16 7:54 ` [PATCH 2/3] arm64: Always inline preempt count and reschedule checks Karl Mehltretter
2026-11-16 7:54 ` [PATCH 3/3] sched/preempt: Check preempt counts in notrace helpers 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=cover.1794814699.git.kmehltretter@gmail.com \
--to=kmehltretter@gmail.com \
--cc=catalin.marinas@arm.com \
--cc=dietmar.eggemann@arm.com \
--cc=hongyan.xia@transsion.com \
--cc=juri.lelli@redhat.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=song@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.