Merge tag 'trace-v4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 30 Oct 2018 16:49:56 +0000 (09:49 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 30 Oct 2018 16:49:56 +0000 (09:49 -0700)
Pull tracing updates from Steven Rostedt:
 "The biggest change here is the updates to kprobes

  Back in January I posted patches to create function based events.
  These were the events that you suggested I make to allow developers to
  easily create events in code where no trace event exists. After
  posting those changes for review, it was suggested that we implement
  this instead with kprobes.

  The problem with kprobes is that the interface is too complex and
  needs to be simplified. Masami Hiramatsu posted patches in March and
  I've been playing with them a bit. There's been a bit of clean up in
  the kprobe code that was inspired by the function based event patches,
  and a couple of enhancements to the kprobe event interface.

   - If the arch supports it (we added support for x86), you can place a
     kprobe event at the start of a function and use $arg1, $arg2, etc
     to reference the arguments of a function. (Before you needed to
     know what register or where on the stack the argument was).

   - The second is a way to see array of events. For example, if you
     reference a mac address, you can add:

echo 'p:mac ip_rcv perm_addr=+574($arg2):x8[6]' > kprobe_events

     And this will produce:

mac: (ip_rcv+0x0/0x140) perm_addr={0x52,0x54,0x0,0xc0,0x76,0xec}

  Other changes include

   - Exporting trace_dump_stack to modules

   - Have the stack tracer trace the entire stack (stop trying to remove
     tracing itself, as we keep removing too much).

   - Added support for SDT in uprobes"

[ SDT - "Statically Defined Tracing" are userspace markers for tracing.
  Let's not use random TLA's in explanations unless they are fairly
  well-established as generic (at least for kernel people) - Linus ]

* tag 'trace-v4.20' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (24 commits)
  tracing: Have stack tracer trace full stack
  tracing: Export trace_dump_stack to modules
  tracing: probeevent: Fix uninitialized used of offset in parse args
  tracing/kprobes: Allow kprobe-events to record module symbol
  tracing/kprobes: Check the probe on unloaded module correctly
  tracing/uprobes: Fix to return -EFAULT if copy_from_user failed
  tracing: probeevent: Add $argN for accessing function args
  x86: ptrace: Add function argument access API
  tracing: probeevent: Add array type support
  tracing: probeevent: Add symbol type
  tracing: probeevent: Unify fetch_insn processing common part
  tracing: probeevent: Append traceprobe_ for exported function
  tracing: probeevent: Return consumed bytes of dynamic area
  tracing: probeevent: Unify fetch type tables
  tracing: probeevent: Introduce new argument fetching code
  tracing: probeevent: Remove NOKPROBE_SYMBOL from print functions
  tracing: probeevent: Cleanup argument field definition
  tracing: probeevent: Cleanup print argument functions
  trace_uprobe: support reference counter in fd-based uprobe
  perf probe: Support SDT markers having reference counter (semaphore)
  ...

1  2 
arch/Kconfig
arch/x86/Kconfig
arch/x86/include/asm/ptrace.h
kernel/events/core.c
kernel/events/uprobes.c

diff --cc arch/Kconfig
Simple merge
Simple merge
index 143c99499531cc1b0f7d50a7190d211664b7bd8b,c2304b25e2fdebf1aa74ba484fe4738078cd4486..8a7fc0cca2d17fde3258d00326327f9ec765c969
@@@ -273,19 -248,52 +273,57 @@@ extern long probe_kernel_read(void *dst
  static inline unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
                                                      unsigned int n)
  {
 -      unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
 -      addr += n;
 -      if (regs_within_kernel_stack(regs, (unsigned long)addr))
 -              return *addr;
 -      else
 -              return 0;
 +      unsigned long *addr;
 +      unsigned long val;
 +      long ret;
 +
 +      addr = regs_get_kernel_stack_nth_addr(regs, n);
 +      if (addr) {
 +              ret = probe_kernel_read(&val, addr, sizeof(val));
 +              if (!ret)
 +                      return val;
 +      }
 +      return 0;
  }
  
+ /**
+  * regs_get_kernel_argument() - get Nth function argument in kernel
+  * @regs:     pt_regs of that context
+  * @n:                function argument number (start from 0)
+  *
+  * regs_get_argument() returns @n th argument of the function call.
+  * Note that this chooses most probably assignment, in some case
+  * it can be incorrect.
+  * This is expected to be called from kprobes or ftrace with regs
+  * where the top of stack is the return address.
+  */
+ static inline unsigned long regs_get_kernel_argument(struct pt_regs *regs,
+                                                    unsigned int n)
+ {
+       static const unsigned int argument_offs[] = {
+ #ifdef __i386__
+               offsetof(struct pt_regs, ax),
+               offsetof(struct pt_regs, cx),
+               offsetof(struct pt_regs, dx),
+ #define NR_REG_ARGUMENTS 3
+ #else
+               offsetof(struct pt_regs, di),
+               offsetof(struct pt_regs, si),
+               offsetof(struct pt_regs, dx),
+               offsetof(struct pt_regs, cx),
+               offsetof(struct pt_regs, r8),
+               offsetof(struct pt_regs, r9),
+ #define NR_REG_ARGUMENTS 6
+ #endif
+       };
+       if (n >= NR_REG_ARGUMENTS) {
+               n -= NR_REG_ARGUMENTS - 1;
+               return regs_get_kernel_stack_nth(regs, n);
+       } else
+               return regs_get_register(regs, argument_offs[n]);
+ }
  #define arch_has_single_step()        (1)
  #ifdef CONFIG_X86_DEBUGCTLMSR
  #define arch_has_block_step() (1)
Simple merge
Simple merge