[PATCH v2 09/16] arm64: Mark the preempt count helpers notrace

From: Song Liu

Date: Thu Oct 22 2026 - 21:15:32 EST


ftrace_test_recursion_trylock() reads preempt_count() to find the
current context, and preempt_disable_notrace() and
preempt_enable_notrace() use __preempt_count_add(),
__preempt_count_sub(), __preempt_count_dec_and_test() and
should_resched(). On arm64 these are plain inline functions. If the
compiler emits one of them out of line, that copy is untraced only
because inline implies notrace, and tracing it would recurse before the
recursion check takes effect.

Mark them, and preempt_count_set(), notrace explicitly. The x86 and
generic versions are __always_inline. No functional change.

Assisted-by: Claude:claude-opus-5
Signed-off-by: Song Liu <song@xxxxxxxxxx>
---
arch/arm64/include/asm/preempt.h | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/arch/arm64/include/asm/preempt.h b/arch/arm64/include/asm/preempt.h
index 932ea4b62042..0441938c9e7e 100644
--- a/arch/arm64/include/asm/preempt.h
+++ b/arch/arm64/include/asm/preempt.h
@@ -7,12 +7,12 @@
#define PREEMPT_NEED_RESCHED BIT(32)
#define PREEMPT_ENABLED (PREEMPT_NEED_RESCHED)

-static inline int preempt_count(void)
+static inline int notrace preempt_count(void)
{
return READ_ONCE(current_thread_info()->preempt.count);
}

-static inline void preempt_count_set(u64 pc)
+static inline void notrace preempt_count_set(u64 pc)
{
/* Preserve existing value of PREEMPT_NEED_RESCHED */
WRITE_ONCE(current_thread_info()->preempt.count, pc);
@@ -41,21 +41,21 @@ static inline bool test_preempt_need_resched(void)
return !current_thread_info()->preempt.need_resched;
}

-static inline void __preempt_count_add(int val)
+static inline void notrace __preempt_count_add(int val)
{
u32 pc = READ_ONCE(current_thread_info()->preempt.count);
pc += val;
WRITE_ONCE(current_thread_info()->preempt.count, pc);
}

-static inline void __preempt_count_sub(int val)
+static inline void notrace __preempt_count_sub(int val)
{
u32 pc = READ_ONCE(current_thread_info()->preempt.count);
pc -= val;
WRITE_ONCE(current_thread_info()->preempt.count, pc);
}

-static inline bool __preempt_count_dec_and_test(void)
+static inline bool notrace __preempt_count_dec_and_test(void)
{
struct thread_info *ti = current_thread_info();
u64 pc = READ_ONCE(ti->preempt_count);
@@ -73,7 +73,7 @@ static inline bool __preempt_count_dec_and_test(void)
return !pc || !READ_ONCE(ti->preempt_count);
}

-static inline bool should_resched(int preempt_offset)
+static inline bool notrace should_resched(int preempt_offset)
{
u64 pc = READ_ONCE(current_thread_info()->preempt_count);
return pc == preempt_offset;
--
2.53.0-Meta