[PATCH 1/2] ftrace: prevent ftrace_special from recursion



Impact: stop ftrace_special from recursion

The ftrace_special is used to help debug areas of the kernel.
Because of this, if it is put in certain locations, the fact that
it allows recursion can become a problem if the kernel developer
using does not realize that.

This patch changes ftrace_special to not allow recursion into itself
to make it more robust.

It also changes from preempt disable interrupts disable to prevent
any loss of trace entries.

Signed-off-by: Steven Rostedt <srostedt@xxxxxxxxxx>
---
kernel/trace/trace.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 5d3dd8a..50f3237 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -960,6 +960,7 @@ ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)
{
struct trace_array *tr = &global_trace;
struct trace_array_cpu *data;
+ unsigned long flags;
int cpu;
int pc;

@@ -967,14 +968,15 @@ ftrace_special(unsigned long arg1, unsigned long arg2, unsigned long arg3)
return;

pc = preempt_count();
- preempt_disable_notrace();
+ local_irq_save(flags);
cpu = raw_smp_processor_id();
data = tr->data[cpu];

- if (likely(!atomic_read(&data->disabled)))
+ if (likely(atomic_inc_return(&data->disabled) == 1))
ftrace_trace_special(tr, data, arg1, arg2, arg3, pc);

- preempt_enable_notrace();
+ atomic_dec(&data->disabled);
+ local_irq_restore(flags);
}

#ifdef CONFIG_FUNCTION_TRACER
--
1.5.6.5

--
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



Relevant Pages

  • Re: [PATCH 1/1] cpusets/sched_domain reconciliation
    ... I could fix them, but I ... wouldn't be very confident that the result works at runtime. ... Recursion is a big no-no in kernel. ...
    (Linux-Kernel)
  • Re: Shared libraries worth it?
    ... When the second process asks for mmap, the kernel says "I already ... have one mapping; I'll just give the second process the same pages, ... this explains why separate executables are never shared ... In order to understand recursion you must first understand recursion. ...
    (comp.os.linux.development.apps)
  • Re: pthread RW locks in linux
    ... i686 i686 i386 GNU/Linux ... The kernel version is largely irrelevant. ... version of glibc you are using. ... In order to understand recursion you must first understand recursion. ...
    (comp.programming.threads)
  • Re: Bug in pthread on Debian?
    ... worked instantly on the new kernel. ... their machines if they get deadlock problems. ... little or very significant resistance to "just upgrade the kernel". ... In order to understand recursion you must first understand recursion. ...
    (comp.unix.programmer)
  • Re: Allocation of threads on a dual CPU system?
    ... Only kernel knows that, so it would have to be a system call. ... What is "the number of the CPU" ... I believe you mis-understood what gethostid returns. ... In order to understand recursion you must first understand recursion. ...
    (comp.os.linux.development.apps)