linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [for-linus][PATCH 0/2] tracing: A couple of fixes for 5.16
@ 2021-11-11  1:22 Steven Rostedt
  2021-11-11  1:22 ` [for-linus][PATCH 1/2] ring-buffer: Protect ring_buffer_reset() from reentrancy Steven Rostedt
  2021-11-11  1:22 ` [for-linus][PATCH 2/2] ftrace/direct: Fix lockup in modify_ftrace_direct_multi Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2021-11-11  1:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton

  git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next

Head SHA1: 2e6e9058d13a22a6fdd36a8c444ac71d9656003a


Jiri Olsa (1):
      ftrace/direct: Fix lockup in modify_ftrace_direct_multi

Steven Rostedt (VMware) (1):
      ring-buffer: Protect ring_buffer_reset() from reentrancy

----
 kernel/trace/ftrace.c      | 3 ++-
 kernel/trace/ring_buffer.c | 5 +++++
 2 files changed, 7 insertions(+), 1 deletion(-)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [for-linus][PATCH 1/2] ring-buffer: Protect ring_buffer_reset() from reentrancy
  2021-11-11  1:22 [for-linus][PATCH 0/2] tracing: A couple of fixes for 5.16 Steven Rostedt
@ 2021-11-11  1:22 ` Steven Rostedt
  2021-11-11  1:22 ` [for-linus][PATCH 2/2] ftrace/direct: Fix lockup in modify_ftrace_direct_multi Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2021-11-11  1:22 UTC (permalink / raw)
  To: linux-kernel
  Cc: Ingo Molnar, Andrew Morton, stable, Tzvetomir Stoyanov (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

The resetting of the entire ring buffer use to simply go through and reset
each individual CPU buffer that had its own protection and synchronization.
But this was very slow, due to performing a synchronization for each CPU.
The code was reshuffled to do one disabling of all CPU buffers, followed
by a single RCU synchronization, and then the resetting of each of the CPU
buffers. But unfortunately, the mutex that prevented multiple occurrences
of resetting the buffer was not moved to the upper function, and there is
nothing to protect from it.

Take the ring buffer mutex around the global reset.

Cc: stable@vger.kernel.org
Fixes: b23d7a5f4a07a ("ring-buffer: speed up buffer resets by avoiding synchronize_rcu for each CPU")
Reported-by: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/ring_buffer.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index f6520d0a4c8c..2699e9e562b1 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -5228,6 +5228,9 @@ void ring_buffer_reset(struct trace_buffer *buffer)
 	struct ring_buffer_per_cpu *cpu_buffer;
 	int cpu;
 
+	/* prevent another thread from changing buffer sizes */
+	mutex_lock(&buffer->mutex);
+
 	for_each_buffer_cpu(buffer, cpu) {
 		cpu_buffer = buffer->buffers[cpu];
 
@@ -5246,6 +5249,8 @@ void ring_buffer_reset(struct trace_buffer *buffer)
 		atomic_dec(&cpu_buffer->record_disabled);
 		atomic_dec(&cpu_buffer->resize_disabled);
 	}
+
+	mutex_unlock(&buffer->mutex);
 }
 EXPORT_SYMBOL_GPL(ring_buffer_reset);
 
-- 
2.33.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [for-linus][PATCH 2/2] ftrace/direct: Fix lockup in modify_ftrace_direct_multi
  2021-11-11  1:22 [for-linus][PATCH 0/2] tracing: A couple of fixes for 5.16 Steven Rostedt
  2021-11-11  1:22 ` [for-linus][PATCH 1/2] ring-buffer: Protect ring_buffer_reset() from reentrancy Steven Rostedt
@ 2021-11-11  1:22 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2021-11-11  1:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: Ingo Molnar, Andrew Morton, Jiri Olsa

From: Jiri Olsa <jolsa@redhat.com>

We can't call unregister_ftrace_function under ftrace_lock.

Link: https://lkml.kernel.org/r/20211109114217.1645296-1-jolsa@kernel.org

Fixes: ed29271894aa ("ftrace/direct: Do not disable when switching direct callers")
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/ftrace.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index b4ed1a301232..fc49e8809a56 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -5602,10 +5602,11 @@ int modify_ftrace_direct_multi(struct ftrace_ops *ops, unsigned long addr)
 		}
 	}
 
+	mutex_unlock(&ftrace_lock);
+
 	/* Removing the tmp_ops will add the updated direct callers to the functions */
 	unregister_ftrace_function(&tmp_ops);
 
-	mutex_unlock(&ftrace_lock);
  out_direct:
 	mutex_unlock(&direct_mutex);
 	return err;
-- 
2.33.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-11-11  1:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-11  1:22 [for-linus][PATCH 0/2] tracing: A couple of fixes for 5.16 Steven Rostedt
2021-11-11  1:22 ` [for-linus][PATCH 1/2] ring-buffer: Protect ring_buffer_reset() from reentrancy Steven Rostedt
2021-11-11  1:22 ` [for-linus][PATCH 2/2] ftrace/direct: Fix lockup in modify_ftrace_direct_multi Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).