Skip to content

Commit cd2375a

Browse files
committed
ring-buffer: Do not allow events in NMI with generic atomic64 cmpxchg()
Some architectures can not safely do atomic64 operations in NMI context. Since the ring buffer relies on atomic64 operations to do its time keeping, if an event is requested in NMI context, reject it for these architectures. Cc: stable@vger.kernel.org Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Desnoyers <mathieu.desnoyers@efficios.com> Cc: Andrew Morton <akpm@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Andreas Larsson <andreas@gaisler.com> Link: https://lore.kernel.org/20250120235721.407068250@goodmis.org Fixes: c84897c ("ring-buffer: Remove 32bit timestamp logic") Closes: https://lore.kernel.org/all/86fb4f86-a0e4-45a2-a2df-3154acc4f086@gaisler.com/ Reported-by: Ludwig Rydberg <ludwig.rydberg@gaisler.com> Reviewed-by: Masami Hiramatsu (Google) <mhiramat@kernel.org> Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
1 parent 6e31b75 commit cd2375a

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

kernel/trace/ring_buffer.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4398,8 +4398,13 @@ rb_reserve_next_event(struct trace_buffer *buffer,
43984398
int nr_loops = 0;
43994399
int add_ts_default;
44004400

4401-
/* ring buffer does cmpxchg, make sure it is safe in NMI context */
4402-
if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) &&
4401+
/*
4402+
* ring buffer does cmpxchg as well as atomic64 operations
4403+
* (which some archs use locking for atomic64), make sure this
4404+
* is safe in NMI context
4405+
*/
4406+
if ((!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) ||
4407+
IS_ENABLED(CONFIG_GENERIC_ATOMIC64)) &&
44034408
(unlikely(in_nmi()))) {
44044409
return NULL;
44054410
}

0 commit comments

Comments
 (0)