All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/3] sched/preempt: Check notrace preempt-count updates
@ 2026-11-26  2:30 Karl Mehltretter
  2026-11-26  2:30 ` [PATCH v2 1/3] arm64: Always inline raw preempt count updates Karl Mehltretter
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Karl Mehltretter @ 2026-11-26  2:30 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Steven Rostedt, Masami Hiramatsu,
	Catalin Marinas, Will Deacon
  Cc: Karl Mehltretter, Mark Rutland, Mathieu Desnoyers, Hongyan Xia,
	Song Liu, Juri Lelli, Vincent Guittot, Dietmar Eggemann,
	Ben Segall, Mel Gorman, Valentin Schneider, K Prateek Nayak,
	linux-arm-kernel, linux-trace-kernel, linux-kernel

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)


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2026-11-27 13:42 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-26  2:30 [PATCH v2 0/3] sched/preempt: Check notrace preempt-count updates Karl Mehltretter
2026-11-26  2:30 ` [PATCH v2 1/3] arm64: Always inline raw preempt count updates Karl Mehltretter
2026-11-26  2:48   ` sashiko-bot
2026-11-26  3:52   ` Li kunyu
2026-11-27 13:41   ` Catalin Marinas
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-27 13:42   ` Catalin Marinas
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
2026-11-26 18:34 ` [PATCH v2 0/3] sched/preempt: Check notrace preempt-count updates Peter Zijlstra

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.