All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/2] [GIT PULL] tracing: Two minor updates
@ 2017-10-04 15:22 Steven Rostedt
  2017-10-04 15:22 ` [PATCH 1/2] ftrace: Fix kmemleak in unregister_ftrace_graph Steven Rostedt
  2017-10-04 15:22 ` [PATCH 2/2] rcu: Remove extraneous READ_ONCE()s from rcu_irq_{enter,exit}() Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2017-10-04 15:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Ingo Molnar, Andrew Morton


Linus,

Two updates.

 - A memory fix with left over code from spliting out ftrace_ops
   and function graph tracer, where the function graph tracer could
   reset the trampoline pointer, leaving the old trampoline not to
   be freed (memory leak).

 - The update to Paul's patch that added the unnecessary READ_ONCE().
   This removes the unnecessary READ_ONCE() instead of having to rebase
   the branch to update the patch that added it.

Please pull the latest trace-v4.14-rc1-3 tree, which can be found at:


  git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
trace-v4.14-rc1-3

Tag SHA1: 3860b8ee2c2850d80277992ba1d0275514ee1238
Head SHA1: f39b536ce9248e9799ff900358d6f073ab2e6c55


Paul E. McKenney (1):
      rcu: Remove extraneous READ_ONCE()s from rcu_irq_{enter,exit}()

Shu Wang (1):
      ftrace: Fix kmemleak in unregister_ftrace_graph

----
 kernel/rcu/tree.c     |  4 ++--
 kernel/trace/ftrace.c | 14 --------------
 2 files changed, 2 insertions(+), 16 deletions(-)

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

* [PATCH 1/2] ftrace: Fix kmemleak in unregister_ftrace_graph
  2017-10-04 15:22 [PATCH 0/2] [GIT PULL] tracing: Two minor updates Steven Rostedt
@ 2017-10-04 15:22 ` Steven Rostedt
  2017-10-04 15:22 ` [PATCH 2/2] rcu: Remove extraneous READ_ONCE()s from rcu_irq_{enter,exit}() Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2017-10-04 15:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Ingo Molnar, Andrew Morton, stable, Shu Wang

[-- Attachment #1: 0001-ftrace-Fix-kmemleak-in-unregister_ftrace_graph.patch --]
[-- Type: text/plain, Size: 2898 bytes --]

From: Shu Wang <shuwang@redhat.com>

The trampoline allocated by function tracer was overwriten by function_graph
tracer, and caused a memory leak. The save_global_trampoline should have
saved the previous trampoline in register_ftrace_graph() and restored it in
unregister_ftrace_graph(). But as it is implemented, save_global_trampoline was
only used in unregister_ftrace_graph as default value 0, and it overwrote the
previous trampoline's value. Causing the previous allocated trampoline to be
lost.

kmmeleak backtrace:
    kmemleak_vmalloc+0x77/0xc0
    __vmalloc_node_range+0x1b5/0x2c0
    module_alloc+0x7c/0xd0
    arch_ftrace_update_trampoline+0xb5/0x290
    ftrace_startup+0x78/0x210
    register_ftrace_function+0x8b/0xd0
    function_trace_init+0x4f/0x80
    tracing_set_tracer+0xe6/0x170
    tracing_set_trace_write+0x90/0xd0
    __vfs_write+0x37/0x170
    vfs_write+0xb2/0x1b0
    SyS_write+0x55/0xc0
    do_syscall_64+0x67/0x180
    return_from_SYSCALL_64+0x0/0x6a

[
  Looking further into this, I found that this was left over from when the
  function and function graph tracers shared the same ftrace_ops. But in
  commit 5f151b2401 ("ftrace: Fix function_profiler and function tracer
  together"), the two were separated, and the save_global_trampoline no
  longer was necessary (and it may have been broken back then too).
  -- Steven Rostedt
]

Link: http://lkml.kernel.org/r/20170912021454.5976-1-shuwang@redhat.com

Cc: stable@vger.kernel.org
Fixes: 5f151b2401 ("ftrace: Fix function_profiler and function tracer together")
Signed-off-by: Shu Wang <shuwang@redhat.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/ftrace.c | 14 --------------
 1 file changed, 14 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 6abfafd7f173..8319e09e15b9 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -4954,9 +4954,6 @@ static char ftrace_graph_buf[FTRACE_FILTER_SIZE] __initdata;
 static char ftrace_graph_notrace_buf[FTRACE_FILTER_SIZE] __initdata;
 static int ftrace_graph_set_hash(struct ftrace_hash *hash, char *buffer);
 
-static unsigned long save_global_trampoline;
-static unsigned long save_global_flags;
-
 static int __init set_graph_function(char *str)
 {
 	strlcpy(ftrace_graph_buf, str, FTRACE_FILTER_SIZE);
@@ -6808,17 +6805,6 @@ void unregister_ftrace_graph(void)
 	unregister_pm_notifier(&ftrace_suspend_notifier);
 	unregister_trace_sched_switch(ftrace_graph_probe_sched_switch, NULL);
 
-#ifdef CONFIG_DYNAMIC_FTRACE
-	/*
-	 * Function graph does not allocate the trampoline, but
-	 * other global_ops do. We need to reset the ALLOC_TRAMP flag
-	 * if one was used.
-	 */
-	global_ops.trampoline = save_global_trampoline;
-	if (save_global_flags & FTRACE_OPS_FL_ALLOC_TRAMP)
-		global_ops.flags |= FTRACE_OPS_FL_ALLOC_TRAMP;
-#endif
-
  out:
 	mutex_unlock(&ftrace_lock);
 }
-- 
2.13.2

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

* [PATCH 2/2] rcu: Remove extraneous READ_ONCE()s from rcu_irq_{enter,exit}()
  2017-10-04 15:22 [PATCH 0/2] [GIT PULL] tracing: Two minor updates Steven Rostedt
  2017-10-04 15:22 ` [PATCH 1/2] ftrace: Fix kmemleak in unregister_ftrace_graph Steven Rostedt
@ 2017-10-04 15:22 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2017-10-04 15:22 UTC (permalink / raw)
  To: linux-kernel; +Cc: Linus Torvalds, Ingo Molnar, Andrew Morton, Paul E. McKenney

[-- Attachment #1: 0002-rcu-Remove-extraneous-READ_ONCE-s-from-rcu_irq_-ente.patch --]
[-- Type: text/plain, Size: 1678 bytes --]

From: "Paul E. McKenney" <paulmck@linux.vnet.ibm.com>

The read of ->dynticks_nmi_nesting in rcu_irq_enter() and rcu_irq_exit()
is currently protected with READ_ONCE().  However, this protection is
unnecessary because (1) ->dynticks_nmi_nesting is updated only by the
current CPU, (2) Although NMI handlers can update this field, they reset
it back to its old value before return, and (3) Interrupts are disabled,
so nothing else can modify it.  The value of ->dynticks_nmi_nesting is
thus effectively constant, and so no protection is required.

This commit therefore removes the READ_ONCE() protection from these
two accesses.

Link: http://lkml.kernel.org/r/20170926031902.GA2074@linux.vnet.ibm.com

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/rcu/tree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
index 63bee8e1b193..c03152f7e458 100644
--- a/kernel/rcu/tree.c
+++ b/kernel/rcu/tree.c
@@ -890,7 +890,7 @@ void rcu_irq_exit(void)
 	rdtp = this_cpu_ptr(&rcu_dynticks);
 
 	/* Page faults can happen in NMI handlers, so check... */
-	if (READ_ONCE(rdtp->dynticks_nmi_nesting))
+	if (rdtp->dynticks_nmi_nesting)
 		return;
 
 	WARN_ON_ONCE(IS_ENABLED(CONFIG_RCU_EQS_DEBUG) &&
@@ -1027,7 +1027,7 @@ void rcu_irq_enter(void)
 	rdtp = this_cpu_ptr(&rcu_dynticks);
 
 	/* Page faults can happen in NMI handlers, so check... */
-	if (READ_ONCE(rdtp->dynticks_nmi_nesting))
+	if (rdtp->dynticks_nmi_nesting)
 		return;
 
 	oldval = rdtp->dynticks_nesting;
-- 
2.13.2

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

end of thread, other threads:[~2017-10-04 15:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-04 15:22 [PATCH 0/2] [GIT PULL] tracing: Two minor updates Steven Rostedt
2017-10-04 15:22 ` [PATCH 1/2] ftrace: Fix kmemleak in unregister_ftrace_graph Steven Rostedt
2017-10-04 15:22 ` [PATCH 2/2] rcu: Remove extraneous READ_ONCE()s from rcu_irq_{enter,exit}() Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.