History

Merge tag 'trace-v4.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace

Pull tracing fixes from Steven Rostedt: "Three minor updates - Use the new GFP_RETRY_MAYFAIL to be more aggressive in allocating memory for the ring buffer without causing OOMs - Fix a memory leak in adding and removing instances - Add __rcu annotation to be able to debug RCU usage of function tracing a bit better" * tag 'trace-v4.13-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: trace: fix the errors caused by incompatible type of RCU variables tracing: Fix kmemleak in instance_rmdir tracing/ring_buffer: Try harder to allocate

Linus Torvalds committed 9 years ago

Commit f79ec882 parents b0a7528 f86f4186 files · +40 −26Browse files

Unified · Split

6 files
  1. include/linux/ftrace.h +3 −3
  2. include/linux/trace_events.h +1 −1
  3. kernel/trace/ftrace.c +27 −14
  4. kernel/trace/ring_buffer.c +5 −5
  5. kernel/trace/trace.c +1 −0
  6. kernel/trace/trace.h +3 −3
include/linux/ftrace.h+3−3
@@ -145,8 +145,8 @@ enum { · 144 unmodified lines
145145 #ifdef CONFIG_DYNAMIC_FTRACE
146146 /* The hash used to know what functions callbacks trace */
147147 struct ftrace_ops_hash {
148− struct ftrace_hash *notrace_hash;
149− struct ftrace_hash *filter_hash;
148+ struct ftrace_hash __rcu *notrace_hash;
149+ struct ftrace_hash __rcu *filter_hash;
150150 struct mutex regex_lock;
151151 };
152152
@@ -168,7 +168,7 @@ static inline void ftrace_free_init_mem(void) { } · 15 unmodified lines
168168 */
169169 struct ftrace_ops {
170170 ftrace_func_t func;
171− struct ftrace_ops *next;
171+ struct ftrace_ops __rcu *next;
172172 unsigned long flags;
173173 void *private;
174174 ftrace_func_t saved_func;
include/linux/trace_events.h+1−1
@@ -338,7 +338,7 @@ enum { · 337 unmodified lines
338338 struct trace_event_file {
339339 struct list_head list;
340340 struct trace_event_call *event_call;
341− struct event_filter *filter;
341+ struct event_filter __rcu *filter;
342342 struct dentry *dir;
343343 struct trace_array *tr;
344344 struct trace_subsystem_dir *system;
kernel/trace/ftrace.c+27−14
@@ -113,7 +113,7 @@ static int ftrace_disabled __read_mostly; · 112 unmodified lines
113113
114114 static DEFINE_MUTEX(ftrace_lock);
115115
116−static struct ftrace_ops *ftrace_ops_list __read_mostly = &ftrace_list_end;
116+static struct ftrace_ops __rcu *ftrace_ops_list __read_mostly = &ftrace_list_end;
117117 ftrace_func_t ftrace_trace_function __read_mostly = ftrace_stub;
118118 static struct ftrace_ops global_ops;
119119
@@ -169,8 +169,11 @@ int ftrace_nr_registered_ops(void) · 49 unmodified lines
169169
170170 mutex_lock(&ftrace_lock);
171171
172− for (ops = ftrace_ops_list;
173− ops != &ftrace_list_end; ops = ops->next)
172+ for (ops = rcu_dereference_protected(ftrace_ops_list,
173+ lockdep_is_held(&ftrace_lock));
174+ ops != &ftrace_list_end;
175+ ops = rcu_dereference_protected(ops->next,
176+ lockdep_is_held(&ftrace_lock)))
174177 cnt++;
175178
176179 mutex_unlock(&ftrace_lock);
@@ -275,10 +278,11 @@ static void update_ftrace_function(void) · 98 unmodified lines
275278 * If there's only one ftrace_ops registered, the ftrace_ops_list
276279 * will point to the ops we want.
277280 */
278− set_function_trace_op = ftrace_ops_list;
281+ set_function_trace_op = rcu_dereference_protected(ftrace_ops_list,
282+ lockdep_is_held(&ftrace_lock));
279283
280284 /* If there's no ftrace_ops registered, just call the stub function */
281− if (ftrace_ops_list == &ftrace_list_end) {
285+ if (set_function_trace_op == &ftrace_list_end) {
282286 func = ftrace_stub;
283287
284288 /*
@@ -286,7 +290,8 @@ static void update_ftrace_function(void) · 1 unmodified line
286290 * recursion safe and not dynamic and the arch supports passing ops,
287291 * then have the mcount trampoline call the function directly.
288292 */
289− } else if (ftrace_ops_list->next == &ftrace_list_end) {
293+ } else if (rcu_dereference_protected(ftrace_ops_list->next,
294+ lockdep_is_held(&ftrace_lock)) == &ftrace_list_end) {
290295 func = ftrace_ops_get_list_func(ftrace_ops_list);
291296
292297 } else {
@@ -348,9 +353,11 @@ int using_ftrace_ops_list_func(void) · 55 unmodified lines
348353 return ftrace_trace_function == ftrace_ops_list_func;
349354 }
350355
351−static void add_ftrace_ops(struct ftrace_ops **list, struct ftrace_ops *ops)
356+static void add_ftrace_ops(struct ftrace_ops __rcu **list,
357+ struct ftrace_ops *ops)
352358 {
353− ops->next = *list;
359+ rcu_assign_pointer(ops->next, *list);
360+
354361 /*
355362 * We are entering ops into the list but another
356363 * CPU might be walking that list. We need to make sure
@@ -360,7 +367,8 @@ static void add_ftrace_ops(struct ftrace_ops **list, struct ftrace_ops *ops) · 3 unmodified lines
360367 rcu_assign_pointer(*list, ops);
361368 }
362369
363−static int remove_ftrace_ops(struct ftrace_ops **list, struct ftrace_ops *ops)
370+static int remove_ftrace_ops(struct ftrace_ops __rcu **list,
371+ struct ftrace_ops *ops)
364372 {
365373 struct ftrace_ops **p;
366374
@@ -368,7 +376,10 @@ static int remove_ftrace_ops(struct ftrace_ops **list, struct ftrace_ops *ops) · 1 unmodified line
368376 * If we are removing the last function, then simply point
369377 * to the ftrace_stub.
370378 */
371− if (*list == ops && ops->next == &ftrace_list_end) {
379+ if (rcu_dereference_protected(*list,
380+ lockdep_is_held(&ftrace_lock)) == ops &&
381+ rcu_dereference_protected(ops->next,
382+ lockdep_is_held(&ftrace_lock)) == &ftrace_list_end) {
372383 *list = &ftrace_list_end;
373384 return 0;
374385 }
@@ -1569,8 +1580,8 @@ ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip, void *regs) · 1194 unmodified lines
15691580 return 0;
15701581 #endif
15711582
1572− hash.filter_hash = rcu_dereference_raw_notrace(ops->func_hash->filter_hash);
1573− hash.notrace_hash = rcu_dereference_raw_notrace(ops->func_hash->notrace_hash);
1583+ rcu_assign_pointer(hash.filter_hash, ops->func_hash->filter_hash);
1584+ rcu_assign_pointer(hash.notrace_hash, ops->func_hash->notrace_hash);
15741585
15751586 if (hash_contains_ip(ip, &hash))
15761587 ret = 1;
@@ -2840,7 +2851,8 @@ static int ftrace_shutdown(struct ftrace_ops *ops, int command) · 1263 unmodified lines
28402851 * If there's no more ops registered with ftrace, run a
28412852 * sanity check to make sure all rec flags are cleared.
28422853 */
2843− if (ftrace_ops_list == &ftrace_list_end) {
2854+ if (rcu_dereference_protected(ftrace_ops_list,
2855+ lockdep_is_held(&ftrace_lock)) == &ftrace_list_end) {
28442856 struct ftrace_page *pg;
28452857 struct dyn_ftrace *rec;
28462858
@@ -6453,7 +6465,8 @@ ftrace_enable_sysctl(struct ctl_table *table, int write, · 3606 unmodified lines
64536465 if (ftrace_enabled) {
64546466
64556467 /* we are starting ftrace again */
6456− if (ftrace_ops_list != &ftrace_list_end)
6468+ if (rcu_dereference_protected(ftrace_ops_list,
6469+ lockdep_is_held(&ftrace_lock)) != &ftrace_list_end)
64576470 update_ftrace_function();
64586471
64596472 ftrace_startup_sysctl();
kernel/trace/ring_buffer.c+5−5
@@ -1136,12 +1136,12 @@ static int __rb_allocate_pages(long nr_pages, struct list_head *pages, int cpu) · 1135 unmodified lines
11361136 for (i = 0; i < nr_pages; i++) {
11371137 struct page *page;
11381138 /*
1139− * __GFP_NORETRY flag makes sure that the allocation fails
1140− * gracefully without invoking oom-killer and the system is
1141− * not destabilized.
1139+ * __GFP_RETRY_MAYFAIL flag makes sure that the allocation fails
1140+ * gracefully without invoking oom-killer and the system is not
1141+ * destabilized.
11421142 */
11431143 bpage = kzalloc_node(ALIGN(sizeof(*bpage), cache_line_size()),
1144− GFP_KERNEL | __GFP_NORETRY,
1144+ GFP_KERNEL | __GFP_RETRY_MAYFAIL,
11451145 cpu_to_node(cpu));
11461146 if (!bpage)
11471147 goto free_pages;
@@ -1149,7 +1149,7 @@ static int __rb_allocate_pages(long nr_pages, struct list_head *pages, int cpu) · 1 unmodified line
11491149 list_add(&bpage->list, pages);
11501150
11511151 page = alloc_pages_node(cpu_to_node(cpu),
1152− GFP_KERNEL | __GFP_NORETRY, 0);
1152+ GFP_KERNEL | __GFP_RETRY_MAYFAIL, 0);
11531153 if (!page)
11541154 goto free_pages;
11551155 bpage->page = page_address(page);
kernel/trace/trace.c+1−0
@@ -7774,6 +7774,7 @@ static int instance_rmdir(const char *name) · 7773 unmodified lines
77747774 }
77757775 kfree(tr->topts);
77767776
7777+ free_cpumask_var(tr->tracing_cpumask);
77777778 kfree(tr->name);
77787779 kfree(tr);
77797780
kernel/trace/trace.h+3−3
@@ -1210,9 +1210,9 @@ struct ftrace_event_field { · 1209 unmodified lines
12101210 struct event_filter {
12111211 int n_preds; /* Number assigned */
12121212 int a_preds; /* allocated */
1213− struct filter_pred *preds;
1214− struct filter_pred *root;
1215− char *filter_string;
1213+ struct filter_pred __rcu *preds;
1214+ struct filter_pred __rcu *root;
1215+ char *filter_string;
12161216 };
12171217
12181218 struct event_subsystem {