diff mbox series

ring-buffer: Do not record in NMI if the arch does not support cmpxchg in NMI

Message ID 20231213175403.6fc18540@gandalf.local.home (mailing list archive)
State Accepted
Commit 712292308af2265cd9b126aedfa987f10f452a33
Headers show
Series ring-buffer: Do not record in NMI if the arch does not support cmpxchg in NMI | expand

Commit Message

Steven Rostedt Dec. 13, 2023, 10:54 p.m. UTC
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>

As the ring buffer recording requires cmpxchg() to work, if the
architecture does not support cmpxchg in NMI, then do not do any recording
within an NMI.

Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
 kernel/trace/ring_buffer.c | 6 ++++++
 1 file changed, 6 insertions(+)
diff mbox series

Patch

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index 8f8887f025c9..caaffcdc6350 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -3719,6 +3719,12 @@  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) &&
+	    (unlikely(in_nmi()))) {
+		return NULL;
+	}
+
 	rb_start_commit(cpu_buffer);
 	/* The commit page can not change after this */