]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
ring-buffer: Do not allow events in NMI with generic atomic64 cmpxchg()
authorSteven Rostedt <rostedt@goodmis.org>
Mon, 20 Jan 2025 23:56:56 +0000 (18:56 -0500)
committerSteven Rostedt (Google) <rostedt@goodmis.org>
Tue, 21 Jan 2025 20:19:00 +0000 (15:19 -0500)
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: c84897c0ff592 ("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>
kernel/trace/ring_buffer.c

index 6d61ff78926b5e18ef73281cd19610e43199af68..b8e0ae15ca5b6d46886b8fb2a533ebd8b727edfd 100644 (file)
@@ -4398,8 +4398,13 @@ rb_reserve_next_event(struct trace_buffer *buffer,
        int nr_loops = 0;
        int add_ts_default;
 
-       /* ring buffer does cmpxchg, make sure it is safe in NMI context */
-       if (!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) &&
+       /*
+        * ring buffer does cmpxchg as well as atomic64 operations
+        * (which some archs use locking for atomic64), make sure this
+        * is safe in NMI context
+        */
+       if ((!IS_ENABLED(CONFIG_ARCH_HAVE_NMI_SAFE_CMPXCHG) ||
+            IS_ENABLED(CONFIG_GENERIC_ATOMIC64)) &&
            (unlikely(in_nmi()))) {
                return NULL;
        }