]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/4.14.48/tracing-make-the-snapshot-trigger-work-with-instances.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 4.14.48 / tracing-make-the-snapshot-trigger-work-with-instances.patch
1 From 2824f5033248600673e3e126a4d135363cbfd9ac Mon Sep 17 00:00:00 2001
2 From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>
3 Date: Mon, 28 May 2018 10:56:36 -0400
4 Subject: tracing: Make the snapshot trigger work with instances
5
6 From: Steven Rostedt (VMware) <rostedt@goodmis.org>
7
8 commit 2824f5033248600673e3e126a4d135363cbfd9ac upstream.
9
10 The snapshot trigger currently only affects the main ring buffer, even when
11 it is used by the instances. This can be confusing as the snapshot trigger
12 is listed in the instance.
13
14 > # cd /sys/kernel/tracing
15 > # mkdir instances/foo
16 > # echo snapshot > instances/foo/events/syscalls/sys_enter_fchownat/trigger
17 > # echo top buffer > trace_marker
18 > # echo foo buffer > instances/foo/trace_marker
19 > # touch /tmp/bar
20 > # chown rostedt /tmp/bar
21 > # cat instances/foo/snapshot
22 # tracer: nop
23 #
24 #
25 # * Snapshot is freed *
26 #
27 # Snapshot commands:
28 # echo 0 > snapshot : Clears and frees snapshot buffer
29 # echo 1 > snapshot : Allocates snapshot buffer, if not already allocated.
30 # Takes a snapshot of the main buffer.
31 # echo 2 > snapshot : Clears snapshot buffer (but does not allocate or free)
32 # (Doesn't have to be '2' works with any number that
33 # is not a '0' or '1')
34
35 > # cat snapshot
36 # tracer: nop
37 #
38 # _-----=> irqs-off
39 # / _----=> need-resched
40 # | / _---=> hardirq/softirq
41 # || / _--=> preempt-depth
42 # ||| / delay
43 # TASK-PID CPU# |||| TIMESTAMP FUNCTION
44 # | | | |||| | |
45 bash-1189 [000] .... 111.488323: tracing_mark_write: top buffer
46
47 Not only did the snapshot occur in the top level buffer, but the instance
48 snapshot buffer should have been allocated, and it is still free.
49
50 Cc: stable@vger.kernel.org
51 Fixes: 85f2b08268c01 ("tracing: Add basic event trigger framework")
52 Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
53 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
54
55 ---
56 kernel/trace/trace.c | 12 ++++++------
57 kernel/trace/trace.h | 11 +++++++++++
58 kernel/trace/trace_events_trigger.c | 10 ++++++++--
59 3 files changed, 25 insertions(+), 8 deletions(-)
60
61 --- a/kernel/trace/trace.c
62 +++ b/kernel/trace/trace.c
63 @@ -894,7 +894,7 @@ int __trace_bputs(unsigned long ip, cons
64 EXPORT_SYMBOL_GPL(__trace_bputs);
65
66 #ifdef CONFIG_TRACER_SNAPSHOT
67 -static void tracing_snapshot_instance(struct trace_array *tr)
68 +void tracing_snapshot_instance(struct trace_array *tr)
69 {
70 struct tracer *tracer = tr->current_trace;
71 unsigned long flags;
72 @@ -950,7 +950,7 @@ static int resize_buffer_duplicate_size(
73 struct trace_buffer *size_buf, int cpu_id);
74 static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);
75
76 -static int alloc_snapshot(struct trace_array *tr)
77 +int tracing_alloc_snapshot_instance(struct trace_array *tr)
78 {
79 int ret;
80
81 @@ -996,7 +996,7 @@ int tracing_alloc_snapshot(void)
82 struct trace_array *tr = &global_trace;
83 int ret;
84
85 - ret = alloc_snapshot(tr);
86 + ret = tracing_alloc_snapshot_instance(tr);
87 WARN_ON(ret < 0);
88
89 return ret;
90 @@ -5400,7 +5400,7 @@ static int tracing_set_tracer(struct tra
91
92 #ifdef CONFIG_TRACER_MAX_TRACE
93 if (t->use_max_tr && !had_max_tr) {
94 - ret = alloc_snapshot(tr);
95 + ret = tracing_alloc_snapshot_instance(tr);
96 if (ret < 0)
97 goto out;
98 }
99 @@ -6378,7 +6378,7 @@ tracing_snapshot_write(struct file *filp
100 }
101 #endif
102 if (!tr->allocated_snapshot) {
103 - ret = alloc_snapshot(tr);
104 + ret = tracing_alloc_snapshot_instance(tr);
105 if (ret < 0)
106 break;
107 }
108 @@ -7099,7 +7099,7 @@ ftrace_trace_snapshot_callback(struct tr
109 return ret;
110
111 out_reg:
112 - ret = alloc_snapshot(tr);
113 + ret = tracing_alloc_snapshot_instance(tr);
114 if (ret < 0)
115 goto out;
116
117 --- a/kernel/trace/trace.h
118 +++ b/kernel/trace/trace.h
119 @@ -1807,6 +1807,17 @@ static inline void __init trace_event_in
120 static inline void trace_event_eval_update(struct trace_eval_map **map, int len) { }
121 #endif
122
123 +#ifdef CONFIG_TRACER_SNAPSHOT
124 +void tracing_snapshot_instance(struct trace_array *tr);
125 +int tracing_alloc_snapshot_instance(struct trace_array *tr);
126 +#else
127 +static inline void tracing_snapshot_instance(struct trace_array *tr) { }
128 +static inline int tracing_alloc_snapshot_instance(struct trace_array *tr)
129 +{
130 + return 0;
131 +}
132 +#endif
133 +
134 extern struct trace_iterator *tracepoint_print_iter;
135
136 #endif /* _LINUX_KERNEL_TRACE_H */
137 --- a/kernel/trace/trace_events_trigger.c
138 +++ b/kernel/trace/trace_events_trigger.c
139 @@ -642,6 +642,7 @@ event_trigger_callback(struct event_comm
140 trigger_data->count = -1;
141 trigger_data->ops = trigger_ops;
142 trigger_data->cmd_ops = cmd_ops;
143 + trigger_data->private_data = file;
144 INIT_LIST_HEAD(&trigger_data->list);
145 INIT_LIST_HEAD(&trigger_data->named_list);
146
147 @@ -1042,7 +1043,12 @@ static struct event_command trigger_trac
148 static void
149 snapshot_trigger(struct event_trigger_data *data, void *rec)
150 {
151 - tracing_snapshot();
152 + struct trace_event_file *file = data->private_data;
153 +
154 + if (file)
155 + tracing_snapshot_instance(file->tr);
156 + else
157 + tracing_snapshot();
158 }
159
160 static void
161 @@ -1064,7 +1070,7 @@ register_snapshot_trigger(char *glob, st
162 {
163 int ret = register_trigger(glob, ops, data, file);
164
165 - if (ret > 0 && tracing_alloc_snapshot() != 0) {
166 + if (ret > 0 && tracing_alloc_snapshot_instance(file->tr) != 0) {
167 unregister_trigger(glob, ops, data, file);
168 ret = 0;
169 }