tracing: kprobes: Output kprobe event to printk buffer
authorMasami Hiramatsu <mhiramat@kernel.org>
Fri, 10 Jan 2020 16:05:31 +0000 (01:05 +0900)
committerSteven Rostedt (VMware) <rostedt@goodmis.org>
Mon, 13 Jan 2020 18:19:40 +0000 (13:19 -0500)
Since kprobe-events use event_trigger_unlock_commit_regs() directly,
that events doesn't show up in printk buffer if "tp_printk" is set.

Use trace_event_buffer_commit() in kprobe events so that it can
invoke output_printk() as same as other trace events.

Link: http://lkml.kernel.org/r/157867233085.17873.5210928676787339604.stgit@devnote2
Signed-off-by: Masami Hiramatsu <mhiramat@kernel.org>
[ Adjusted data var declaration placement in __kretprobe_trace_func() ]
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
include/linux/trace_events.h
kernel/trace/trace.c
kernel/trace/trace_events.c
kernel/trace/trace_kprobe.c

index 5f7b2b1fce2477cf45124ec9f777d4e5d2c72953..20948ee56f8c66361e597550fa2d83010e8a839d 100644 (file)
@@ -216,6 +216,7 @@ struct trace_event_buffer {
        void                            *entry;
        unsigned long                   flags;
        int                             pc;
+       struct pt_regs                  *regs;
 };
 
 void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer,
index b4294eb020f89688ee06b6b41f260ce31b5fd3ec..cb850d2c4bfac9c6a54fce02dbd0c59640ed9914 100644 (file)
@@ -2680,9 +2680,9 @@ void trace_event_buffer_commit(struct trace_event_buffer *fbuffer)
        if (static_key_false(&tracepoint_printk_key.key))
                output_printk(fbuffer);
 
-       event_trigger_unlock_commit(fbuffer->trace_file, fbuffer->buffer,
+       event_trigger_unlock_commit_regs(fbuffer->trace_file, fbuffer->buffer,
                                    fbuffer->event, fbuffer->entry,
-                                   fbuffer->flags, fbuffer->pc);
+                                   fbuffer->flags, fbuffer->pc, fbuffer->regs);
 }
 EXPORT_SYMBOL_GPL(trace_event_buffer_commit);
 
index a16d1b601c5c3c56df18f705c21c1c8ada9925d2..dfb736a964d693be595e4fb7f4cc9de23df48e15 100644 (file)
@@ -272,6 +272,7 @@ void *trace_event_buffer_reserve(struct trace_event_buffer *fbuffer,
        if (!fbuffer->event)
                return NULL;
 
+       fbuffer->regs = NULL;
        fbuffer->entry = ring_buffer_event_data(fbuffer->event);
        return fbuffer->entry;
 }
index 477b6b011e7dc93963aba2869916b70985e71382..33a6a661904bd3d274cbd72389660bebcedeb99b 100644 (file)
@@ -1175,35 +1175,35 @@ __kprobe_trace_func(struct trace_kprobe *tk, struct pt_regs *regs,
                    struct trace_event_file *trace_file)
 {
        struct kprobe_trace_entry_head *entry;
-       struct trace_buffer *buffer;
-       struct ring_buffer_event *event;
-       int size, dsize, pc;
-       unsigned long irq_flags;
        struct trace_event_call *call = trace_probe_event_call(&tk->tp);
+       struct trace_event_buffer fbuffer;
+       int dsize;
 
        WARN_ON(call != trace_file->event_call);
 
        if (trace_trigger_soft_disabled(trace_file))
                return;
 
-       local_save_flags(irq_flags);
-       pc = preempt_count();
+       local_save_flags(fbuffer.flags);
+       fbuffer.pc = preempt_count();
+       fbuffer.trace_file = trace_file;
 
        dsize = __get_data_size(&tk->tp, regs);
-       size = sizeof(*entry) + tk->tp.size + dsize;
 
-       event = trace_event_buffer_lock_reserve(&buffer, trace_file,
-                                               call->event.type,
-                                               size, irq_flags, pc);
-       if (!event)
+       fbuffer.event =
+               trace_event_buffer_lock_reserve(&fbuffer.buffer, trace_file,
+                                       call->event.type,
+                                       sizeof(*entry) + tk->tp.size + dsize,
+                                       fbuffer.flags, fbuffer.pc);
+       if (!fbuffer.event)
                return;
 
-       entry = ring_buffer_event_data(event);
+       fbuffer.regs = regs;
+       entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event);
        entry->ip = (unsigned long)tk->rp.kp.addr;
        store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize);
 
-       event_trigger_unlock_commit_regs(trace_file, buffer, event,
-                                        entry, irq_flags, pc, regs);
+       trace_event_buffer_commit(&fbuffer);
 }
 
 static void
@@ -1223,36 +1223,35 @@ __kretprobe_trace_func(struct trace_kprobe *tk, struct kretprobe_instance *ri,
                       struct trace_event_file *trace_file)
 {
        struct kretprobe_trace_entry_head *entry;
-       struct trace_buffer *buffer;
-       struct ring_buffer_event *event;
-       int size, pc, dsize;
-       unsigned long irq_flags;
+       struct trace_event_buffer fbuffer;
        struct trace_event_call *call = trace_probe_event_call(&tk->tp);
+       int dsize;
 
        WARN_ON(call != trace_file->event_call);
 
        if (trace_trigger_soft_disabled(trace_file))
                return;
 
-       local_save_flags(irq_flags);
-       pc = preempt_count();
+       local_save_flags(fbuffer.flags);
+       fbuffer.pc = preempt_count();
+       fbuffer.trace_file = trace_file;
 
        dsize = __get_data_size(&tk->tp, regs);
-       size = sizeof(*entry) + tk->tp.size + dsize;
-
-       event = trace_event_buffer_lock_reserve(&buffer, trace_file,
-                                               call->event.type,
-                                               size, irq_flags, pc);
-       if (!event)
+       fbuffer.event =
+               trace_event_buffer_lock_reserve(&fbuffer.buffer, trace_file,
+                                       call->event.type,
+                                       sizeof(*entry) + tk->tp.size + dsize,
+                                       fbuffer.flags, fbuffer.pc);
+       if (!fbuffer.event)
                return;
 
-       entry = ring_buffer_event_data(event);
+       fbuffer.regs = regs;
+       entry = fbuffer.entry = ring_buffer_event_data(fbuffer.event);
        entry->func = (unsigned long)tk->rp.kp.addr;
        entry->ret_ip = (unsigned long)ri->ret_addr;
        store_trace_args(&entry[1], &tk->tp, regs, sizeof(*entry), dsize);
 
-       event_trigger_unlock_commit_regs(trace_file, buffer, event,
-                                        entry, irq_flags, pc, regs);
+       trace_event_buffer_commit(&fbuffer);
 }
 
 static void