Merge tag 'trace-v4.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
authorLinus Torvalds <torvalds@linux-foundation.org>
Thu, 23 Aug 2018 20:07:00 +0000 (13:07 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 23 Aug 2018 20:07:00 +0000 (13:07 -0700)
Pull tracing fixes from Steven Rostedt:
 "Masami found an off by one bug in the code that keeps "notrace"
  functions from being traced by kprobes. During my testing, I found
  that there's places that we may want to add kprobes to notrace, thus
  we may end up changing this code before 4.19 is released.

  The history behind this change is that we found that adding kprobes to
  various notrace functions caused the kernel to crashed. We took the
  safe route and decided not to allow kprobes to trace any notrace
  function.

  But because notrace is added to functions that just cause weird side
  effects to the function tracer, but are still safe, preventing kprobes
  for all notrace functios may be too much of a big hammer.

  One such place is __schedule() is marked notrace, to keep function
  tracer from doing strange recursive loops when it gets traced with
  NEED_RESCHED set. With this change, one can not add kprobes to the
  scheduler.

  Masami also added code to use gcov on ftrace"

* tag 'trace-v4.19-1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace:
  tracing/kprobes: Fix to check notrace function with correct range
  tracing: Allow gcov profiling on only ftrace subsystem

1  2 
kernel/trace/Kconfig
kernel/trace/trace_kprobe.c

diff --combined kernel/trace/Kconfig
index c042a455afc6a109a45ae5b58e360d0dec67bcc2,aec44d838283faf342b964627999b1f00538d162..5e3de28c7677396aaa4360dcf2f51fb9b365b626
@@@ -558,7 -558,7 +558,7 @@@ config FUNCTION_PROFILE
          in debugfs called function_profile_enabled which defaults to zero.
          When a 1 is echoed into this file profiling begins, and when a
          zero is entered, profiling stops. A "functions" file is created in
 -        the trace_stats directory; this file shows the list of functions that
 +        the trace_stat directory; this file shows the list of functions that
          have been hit and their counters.
  
          If in doubt, say N.
@@@ -642,7 -642,7 +642,7 @@@ config HIST_TRIGGER
          Inter-event tracing of quantities such as latencies is also
          supported using hist triggers under this option.
  
 -        See Documentation/trace/histogram.txt.
 +        See Documentation/trace/histogram.rst.
          If in doubt, say N.
  
  config MMIOTRACE_TEST
@@@ -774,6 -774,18 +774,18 @@@ config TRACING_EVENTS_GPI
        help
          Enable tracing events for gpio subsystem
  
+ config GCOV_PROFILE_FTRACE
+       bool "Enable GCOV profiling on ftrace subsystem"
+       depends on GCOV_KERNEL
+       help
+         Enable GCOV profiling on ftrace subsystem for checking
+         which functions/lines are tested.
+         If unsure, say N.
+         Note that on a kernel compiled with this config, ftrace will
+         run significantly slower.
  endif # FTRACE
  
  endif # TRACING_SUPPORT
index 2bfb2bbeb3d22cb6f2aa475902599eacb8a725a8,ad384b31fe01d800f438c23e4f1382f7e2567767..c30032367aab4a5c83a013d615830cda97a82f8a
@@@ -513,7 -513,14 +513,14 @@@ static bool within_notrace_func(struct 
        if (!addr || !kallsyms_lookup_size_offset(addr, &size, &offset))
                return false;
  
-       return !ftrace_location_range(addr - offset, addr - offset + size);
+       /* Get the entry address of the target function */
+       addr -= offset;
+       /*
+        * Since ftrace_location_range() does inclusive range check, we need
+        * to subtract 1 byte from the end address.
+        */
+       return !ftrace_location_range(addr, addr + size - 1);
  }
  #else
  #define within_notrace_func(tk)       (false)
@@@ -1255,11 -1262,16 +1262,11 @@@ kprobe_perf_func(struct trace_kprobe *t
  
                /*
                 * We need to check and see if we modified the pc of the
 -               * pt_regs, and if so clear the kprobe and return 1 so that we
 -               * don't do the single stepping.
 -               * The ftrace kprobe handler leaves it up to us to re-enable
 -               * preemption here before returning if we've modified the ip.
 +               * pt_regs, and if so return 1 so that we don't do the
 +               * single stepping.
                 */
 -              if (orig_ip != instruction_pointer(regs)) {
 -                      reset_current_kprobe();
 -                      preempt_enable_no_resched();
 +              if (orig_ip != instruction_pointer(regs))
                        return 1;
 -              }
                if (!ret)
                        return 0;
        }