sched/preempt: Check notrace preempt-count updates
Get series with b4
b4 am [email protected]Versions newest first
- v1 Latest3 patches 0 repliesNew
Patches in v1 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/3 | arm64: Always inline raw preempt count updatesarch/ | +2 | 0 replies | |
| 2/3 | arm64: Always inline preempt count and reschedule checksarch/ | +3 | 0 replies | |
| 3/3 | sched/preempt: Check preempt counts in notrace helpersinclude/ kernel/ kernel/ | +57 | 0 replies |
Reviews trailers per patch
No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.
Cover letter [PATCH 0/3] sched/preempt: Check notrace preempt-count updates
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/[email protected]
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/[email protected]
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