mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Karl Mehltretter <kmehltretter@gmail.com>
To: Peter Zijlstra <peterz@infradead.org>,
	Ingo Molnar <mingo@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Catalin Marinas <catalin.marinas@arm.com>,
	Will Deacon <will@kernel.org>
Cc: Karl Mehltretter <kmehltretter@gmail.com>,
	Mark Rutland <mark.rutland@arm.com>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>,
	Hongyan Xia <hongyan.xia@transsion.com>,
	Song Liu <song@kernel.org>, Juri Lelli <juri.lelli@redhat.com>,
	Vincent Guittot <vincent.guittot@linaro.org>,
	Dietmar Eggemann <dietmar.eggemann@arm.com>,
	Ben Segall <bsegall@google.com>, Mel Gorman <mgorman@suse.de>,
	Valentin Schneider <vschneid@redhat.com>,
	K Prateek Nayak <kprateek.nayak@amd.com>,
	linux-arm-kernel@lists.infradead.org,
	linux-trace-kernel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH v2 0/3] sched/preempt: Check notrace preempt-count updates
Date: Thu, 26 Nov 2026 03:30:51 +0100	[thread overview]
Message-ID: <cover.1795631277.git.kmehltretter@gmail.com> (raw)

With CONFIG_DEBUG_PREEMPT, the notrace preemption macros bypass the
underflow and near-overflow checks used by ordinary operations. Add
checked noinstr updates for their existing callers and share validation
with preempt_count_add() and preempt_count_sub().

Patches 1 and 2 mark the arm64 raw preempt-count and reschedule helpers
__always_inline, matching x86, s390 and asm-generic, so noinstr callers
keep them in their own section.

Patch 3 also disables branch profiling with DEBUG_PREEMPT to prevent
instrumentation from reaching noinstr text, covering both
PROFILE_ANNOTATED_BRANCHES and PROFILE_ALL_BRANCHES.

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

Changes in v2:
- Patches 1 and 2: no code changes, added Hongyan Xia's Reviewed-by.
- Patch 3: replace the Makefile CFLAGS override with a !DEBUG_PREEMPT
  dependency on the Branch Profiling Kconfig choice (Steven Rostedt).
- Patch 3: remove the unused __preempt_count_inc() and
  __preempt_count_dec() macros and clarify the changelog wording
  (Hongyan Xia).

Link to v1:

  https://lore.kernel.org/r/cover.1794814699.git.kmehltretter@gmail.com

This series is independently useful and also provides the checked count
updates 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:

  https://lore.kernel.org/r/20261029093219.GH1779021@noisy.programming.kicks-ass.net

The series is based on Linus's tree at commit 4dce97c6c265
("Merge tag 'ext4_for_linus-7.4-rc5' of
git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4", after
v7.4-rc4).

Testing:

- Kconfig: x86-64, arm64 and arm builds with Clang 22.1.8 verified both
  branch-profiling modes, DEBUG_PREEMPT and non-debug configurations,
  !CONFIG_PREEMPTION with PREEMPT_COUNT=y, plus allmodconfig,
  allyesconfig and defconfig + debug.config.
- arm64 v2 runtime: Clang 22.1.8, W=1, PREEMPT, DEBUG_PREEMPT,
  PROVE_LOCKING, FTRACE and PREEMPT_TRACER. Full Image and external
  module builds passed, .noinstr.text disassembly showed no
  ftrace_likely_update() or outlined preempt-count calls, and QEMU
  boots verified balanced load/unload, underflow rejection and
  near-overflow detection at 0xf5.
- Additional v1 testing (C code in arch/arm64/include/asm/preempt.h and
  kernel/sched/core.c unchanged): x86-64 Clang 19 objtool noinstr
  validation and nested-KVM runs, arm64 GCC 14.2 PREEMPT_RT and
  allmodconfig builds plus native Axion boot, and ARC, C-SKY and MIPS
  builds and QEMU tests.

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          | 23 +++++++++++++-----
 kernel/sched/core.c              | 40 ++++++++++++++++++++++++++++----
 kernel/trace/Kconfig             |  1 +
 4 files changed, 59 insertions(+), 15 deletions(-)


base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
-- 
2.39.5 (Apple Git-154)


             reply	other threads:[~2026-11-26  2:31 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  2:30 Karl Mehltretter [this message]
2026-11-26  2:30 ` [PATCH v2 1/3] arm64: Always inline raw preempt count updates Karl Mehltretter
2026-11-26  2:30 ` [PATCH v2 2/3] arm64: Always inline preempt count and reschedule checks Karl Mehltretter
2026-11-26  2:51   ` Hongyan Xia
2026-11-26  2:30 ` [PATCH v2 3/3] sched/preempt: Check preempt counts in notrace helpers Karl Mehltretter
2026-11-26  2:55   ` Hongyan Xia

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.1795631277.git.kmehltretter@gmail.com \
    --to=kmehltretter@gmail.com \
    --cc=bsegall@google.com \
    --cc=catalin.marinas@arm.com \
    --cc=dietmar.eggemann@arm.com \
    --cc=hongyan.xia@transsion.com \
    --cc=juri.lelli@redhat.com \
    --cc=kprateek.nayak@amd.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=mathieu.desnoyers@efficios.com \
    --cc=mgorman@suse.de \
    --cc=mhiramat@kernel.org \
    --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 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®