Skip to contentSkip to conversation

tracing: Updates for 4.5

GIT PULL Steven Rostedt 1 participant 1 message Jan 12, 2016

Subsystems (10)
x86 Kselftest Library code BPF +6 more subsystems
lore
Share & tools
lore

Steven Rostedt

author maintainer
#0 lore raw

Linus,

Not much new with tracing for this release. Mostly just clean ups and minor fixes.

Here's what else is new:

o A new TRACE_EVENT_FN_COND macro, combining both _FN and _COND for those that want both.

o New selftest to test the instance create and delete

o Better debug output when ftrace fails

Please pull the latest trace-v4.5 tree, which can be found at:

git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
trace-v4.5

Tag SHA1: ed21d378b25dc8650479d7b4683d1eb680beb712 Head SHA1: 5156dca34a3e1e1edac2d0dabf43d8632909b7aa

Abel Vesa (1):
ftrace: Join functions ftrace_module_init() and ftrace_init_module()

Chuyu Hu (1):
tracing: Fix comment to use tracing_on over tracing_enable

Denis Kirjanov (1):
tracing: Introduce TRACE_EVENT_FN_COND macro

Jerry Snitselaar (1):
tracing: Use seq_buf_used() in seq_buf_to_user() instead of len

Julia Lawall (1):
bpf: Constify bpf_verifier_ops structure

Li Bin (5):
ftrace: Fix a typo in comment
ia64: ftrace: Fix the comments for ftrace_modify_code()
sh: ftrace: Fix the comments for ftrace_modify_code()
metag: ftrace: Fix the comments for ftrace_modify_code
x86: ftrace: Fix the comments for ftrace_modify_code_direct()

Qiu Peiyang (1):
ftrace: Fix the race between ftrace and insmod

Steven Rostedt (Red Hat) (14):
ring-buffer: Update read stamp with first real commit on page
ring-buffer: Put back the length if crossed page with add_timestamp
ftracetest: Add instance create and delete test
ring-buffer: Use READ_ONCE() for most tail_page access
ring-buffer: Remove redundant update of page timestamp
ring-buffer: Process commits whenever moving to a new page.
ftrace: Add new type to distinguish what kind of ftrace_bug()
ftrace: Add variable ftrace_expected for archs to show expected code
ftrace: Show all tramps registered to a record on ftrace_bug()
ftrace: Fix output of enabled_functions for showing tramp
ftrace: Remove use of control list and ops
ftrace: Have ftrace_ops_get_func() handle RCU and PER_CPU flags too
ftrace: Clean up ftrace_module_init() code
ftrace: Add infrastructure for delayed enabling of module functions

Tom Zanussi (1):
tracing: Update cond flag when enabling or disabling a trigger

----

 arch/ia64/kernel/ftrace.c                          |  12 +-
 arch/metag/kernel/ftrace.c                         |  11 +-
 arch/sh/kernel/ftrace.c                            |  12 +-
 arch/x86/kernel/ftrace.c                           |  21 +-
 include/linux/ftrace.h                             |  56 ++-
 include/linux/tracepoint.h                         |   4 +
 include/trace/define_trace.h                       |   6 +
 include/trace/trace_events.h                       |   6 +
 kernel/trace/bpf_trace.c                           |   2 +-
 kernel/trace/ftrace.c                              | 451 ++++++++++++---------
 kernel/trace/ring_buffer.c                         |  74 ++--
 kernel/trace/trace.h                               |   6 +-
 kernel/trace/trace_event_perf.c                    |   2 +-
 kernel/trace/trace_events_trigger.c                |  10 +-
 lib/seq_buf.c                                      |   6 +-
 .../selftests/ftrace/test.d/instances/instance.tc  |  90 ++++
 16 files changed, 485 insertions(+), 284 deletions(-)
 create mode 100644 tools/testing/selftests/ftrace/test.d/instances/instance.tc

---------------------------

arch/ia64/kernel/ftrace.c +5 -7
index 3b0c2aa07857..cee411e647ca 100644
@@ -97,13 +97,11 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
 	unsigned char replaced[MCOUNT_INSN_SIZE];
 
 	/*
-	 * Note: Due to modules and __init, code can
-	 *  disappear and change, we need to protect against faulting
-	 *  as well as code changing. We do this by using the
-	 *  probe_kernel_* functions.
-	 *
-	 * No real locking needed, this code is run through
-	 * kstop_machine, or before SMP starts.
+	 * Note:
+	 * We are paranoid about modifying text, as if a bug was to happen, it
+	 * could cause us to read or write to someplace that could cause harm.
+	 * Carefully read and modify the code with probe_kernel_*(), and make
+	 * sure what we read is what we expected it to be before modifying it.
 	 */
 
 	if (!do_check)
arch/metag/kernel/ftrace.c +5 -6
index ed1d685157c2..ac8c039b0318 100644
@@ -54,12 +54,11 @@ static int ftrace_modify_code(unsigned long pc, unsigned char *old_code,
 	unsigned char replaced[MCOUNT_INSN_SIZE];
 
 	/*
-	 * Note: Due to modules and __init, code can
-	 *  disappear and change, we need to protect against faulting
-	 *  as well as code changing.
-	 *
-	 * No real locking needed, this code is run through
-	 * kstop_machine.
+	 * Note:
+	 * We are paranoid about modifying text, as if a bug was to happen, it
+	 * could cause us to read or write to someplace that could cause harm.
+	 * Carefully read and modify the code with probe_kernel_*(), and make
+	 * sure what we read is what we expected it to be before modifying it.
 	 */
 
 	/* read the text we want to modify */
arch/sh/kernel/ftrace.c +5 -7
index 079d70e6d74b..38993e09ef03 100644
@@ -212,13 +212,11 @@ static int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
 	unsigned char replaced[MCOUNT_INSN_SIZE];
 
 	/*
-	 * Note: Due to modules and __init, code can
-	 *  disappear and change, we need to protect against faulting
-	 *  as well as code changing. We do this by using the
-	 *  probe_kernel_* functions.
-	 *
-	 * No real locking needed, this code is run through
-	 * kstop_machine, or before SMP starts.
+	 * Note:
+	 * We are paranoid about modifying text, as if a bug was to happen, it
+	 * could cause us to read or write to someplace that could cause harm.
+	 * Carefully read and modify the code with probe_kernel_*(), and make
+	 * sure what we read is what we expected it to be before modifying it.
 	 */
 
 	/* read the text we want to modify */
arch/x86/kernel/ftrace.c +14 -7
index 311bcf338f07..29408d6d6626 100644
@@ -105,14 +105,14 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
 {
 	unsigned char replaced[MCOUNT_INSN_SIZE];
 
+	ftrace_expected = old_code;
+
 	/*
-	 * Note: Due to modules and __init, code can
-	 *  disappear and change, we need to protect against faulting
-	 *  as well as code changing. We do this by using the
-	 *  probe_kernel_* functions.
-	 *
-	 * No real locking needed, this code is run through
-	 * kstop_machine, or before SMP starts.
+	 * Note:
+	 * We are paranoid about modifying text, as if a bug was to happen, it
+	 * could cause us to read or write to someplace that could cause harm.
+	 * Carefully read and modify the code with probe_kernel_*(), and make
+	 * sure what we read is what we expected it to be before modifying it.
 	 */
 
 	/* read the text we want to modify */
@@ -154,6 +154,8 @@ int ftrace_make_nop(struct module *mod,
 	if (addr == MCOUNT_ADDR)
 		return ftrace_modify_code_direct(rec->ip, old, new);
 
+	ftrace_expected = NULL;
+
 	/* Normal cases use add_brk_on_nop */
 	WARN_ONCE(1, "invalid use of ftrace_make_nop");
 	return -EINVAL;
@@ -220,6 +222,7 @@ int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
 				 unsigned long addr)
 {
 	WARN_ON(1);
+	ftrace_expected = NULL;
 	return -EINVAL;
 }
 
@@ -314,6 +317,8 @@ static int add_break(unsigned long ip, const char *old)
 	if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
 		return -EFAULT;
 
+	ftrace_expected = old;
+
 	/* Make sure it is what we expect it to be */
 	if (memcmp(replaced, old, MCOUNT_INSN_SIZE) != 0)
 		return -EINVAL;
@@ -413,6 +418,8 @@ static int remove_breakpoint(struct dyn_ftrace *rec)
 		ftrace_addr = ftrace_get_addr_curr(rec);
 		nop = ftrace_call_replace(ip, ftrace_addr);
 
+		ftrace_expected = nop;
+
 		if (memcmp(&ins[1], &nop[1], MCOUNT_INSN_SIZE - 1) != 0)
 			return -EINVAL;
 	}
include/linux/ftrace.h +37 -19

137 lines not on this page · raw message

include/linux/tracepoint.h +4 -0
index 696a339c592c..45b3fcf7dd3c 100644
@@ -493,6 +493,10 @@ extern void syscall_unregfunc(void);
 #define TRACE_EVENT_FN(name, proto, args, struct,		\
 		assign, print, reg, unreg)			\
 	DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
+#define TRACE_EVENT_FN_COND(name, proto, args, cond, struct,		\
+		assign, print, reg, unreg)			\
+	DECLARE_TRACE_CONDITION(name, PARAMS(proto),	\
+			PARAMS(args), PARAMS(cond))
 #define TRACE_EVENT_CONDITION(name, proto, args, cond,		\
 			      struct, assign, print)		\
 	DECLARE_TRACE_CONDITION(name, PARAMS(proto),		\
include/trace/define_trace.h +6 -0
index 2d8639ea64d5..6e3945f64102 100644
@@ -40,6 +40,11 @@
 		assign, print, reg, unreg)			\
 	DEFINE_TRACE_FN(name, reg, unreg)
 
+#undef TRACE_EVENT_FN_COND
+#define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct,		\
+		assign, print, reg, unreg)			\
+	DEFINE_TRACE_FN(name, reg, unreg)
+
 #undef DEFINE_EVENT
 #define DEFINE_EVENT(template, name, proto, args) \
 	DEFINE_TRACE(name)
@@ -93,6 +98,7 @@
 
 #undef TRACE_EVENT
 #undef TRACE_EVENT_FN
+#undef TRACE_EVENT_FN_COND
 #undef TRACE_EVENT_CONDITION
 #undef DECLARE_EVENT_CLASS
 #undef DEFINE_EVENT
include/trace/trace_events.h +6 -0
index de996cf61053..170c93bbdbb7 100644
@@ -123,6 +123,12 @@ TRACE_MAKE_SYSTEM_STR();
 	TRACE_EVENT(name, PARAMS(proto), PARAMS(args),			\
 		PARAMS(tstruct), PARAMS(assign), PARAMS(print))		\
 
+#undef TRACE_EVENT_FN_COND
+#define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct,	\
+		assign, print, reg, unreg)				\
+	TRACE_EVENT_CONDITION(name, PARAMS(proto), PARAMS(args), PARAMS(cond),		\
+		PARAMS(tstruct), PARAMS(assign), PARAMS(print))		\
+
 #undef TRACE_EVENT_FLAGS
 #define TRACE_EVENT_FLAGS(name, value)					\
 	__TRACE_EVENT_FLAGS(name, value)
kernel/trace/bpf_trace.c +1 -1
index 4228fd3682c3..45dd798bcd37 100644
@@ -316,7 +316,7 @@ static bool kprobe_prog_is_valid_access(int off, int size, enum bpf_access_type
 	return true;
 }
 
-static struct bpf_verifier_ops kprobe_prog_ops = {
+static const struct bpf_verifier_ops kprobe_prog_ops = {
 	.get_func_proto  = kprobe_prog_func_proto,
 	.is_valid_access = kprobe_prog_is_valid_access,
 };
kernel/trace/ftrace.c +264 -187

768 lines not on this page · raw message

kernel/trace/ring_buffer.c +35 -39

187 lines not on this page · raw message

kernel/trace/trace.h +2 -4
index 919d9d07686f..8414fa40bf27 100644
@@ -363,8 +363,8 @@ struct trace_option_dentry {
  * @name: the name chosen to select it on the available_tracers file
  * @init: called when one switches to this tracer (echo name > current_tracer)
  * @reset: called when one switches to another tracer
- * @start: called when tracing is unpaused (echo 1 > tracing_enabled)
- * @stop: called when tracing is paused (echo 0 > tracing_enabled)
+ * @start: called when tracing is unpaused (echo 1 > tracing_on)
+ * @stop: called when tracing is paused (echo 0 > tracing_on)
  * @update_thresh: called when tracing_thresh is updated
  * @open: called when the trace file is opened
  * @pipe_open: called when the trace_pipe file is opened
@@ -467,8 +467,6 @@ enum {
 	TRACE_INTERNAL_IRQ_BIT,
 	TRACE_INTERNAL_SIRQ_BIT,
 
-	TRACE_CONTROL_BIT,
-
 	TRACE_BRANCH_BIT,
 /*
  * Abuse of the trace_recursion.
kernel/trace/trace_event_perf.c +1 -1
index abfc903e741e..2649c85cd162 100644
@@ -334,7 +334,7 @@ static int perf_ftrace_function_register(struct perf_event *event)
 {
 	struct ftrace_ops *ops = &event->ftrace_ops;
 
-	ops->flags |= FTRACE_OPS_FL_CONTROL;
+	ops->flags |= FTRACE_OPS_FL_PER_CPU | FTRACE_OPS_FL_RCU;
 	ops->func = perf_ftrace_function_call;
 	return register_ftrace_function(ops);
 }
kernel/trace/trace_events_trigger.c +6 -4
index 42a4009fd75a..4d2f3ccc56f6 100644
@@ -543,11 +543,12 @@ static int register_trigger(char *glob, struct event_trigger_ops *ops,
 	list_add_rcu(&data->list, &file->triggers);
 	ret++;
 
+	update_cond_flag(file);
 	if (trace_event_trigger_enable_disable(file, 1) < 0) {
 		list_del_rcu(&data->list);
+		update_cond_flag(file);
 		ret--;
 	}
-	update_cond_flag(file);
 out:
 	return ret;
 }
@@ -575,8 +576,8 @@ static void unregister_trigger(char *glob, struct event_trigger_ops *ops,
 		if (data->cmd_ops->trigger_type == test->cmd_ops->trigger_type) {
 			unregistered = true;
 			list_del_rcu(&data->list);
-			update_cond_flag(file);
 			trace_event_trigger_enable_disable(file, 0);
+			update_cond_flag(file);
 			break;
 		}
 	}
@@ -1319,11 +1320,12 @@ static int event_enable_register_trigger(char *glob,
 	list_add_rcu(&data->list, &file->triggers);
 	ret++;
 
+	update_cond_flag(file);
 	if (trace_event_trigger_enable_disable(file, 1) < 0) {
 		list_del_rcu(&data->list);
+		update_cond_flag(file);
 		ret--;
 	}
-	update_cond_flag(file);
 out:
 	return ret;
 }
@@ -1344,8 +1346,8 @@ static void event_enable_unregister_trigger(char *glob,
 		    (enable_data->file == test_enable_data->file)) {
 			unregistered = true;
 			list_del_rcu(&data->list);
-			update_cond_flag(file);
 			trace_event_trigger_enable_disable(file, 0);
+			update_cond_flag(file);
 			break;
 		}
 	}
lib/seq_buf.c +4 -2
index 5c94e1012a91..cb18469e1f49 100644
@@ -306,10 +306,12 @@ int seq_buf_to_user(struct seq_buf *s, char __user *ubuf, int cnt)
 	if (!cnt)
 		return 0;
 
-	if (s->len <= s->readpos)
+	len = seq_buf_used(s);
+
+	if (len <= s->readpos)
 		return -EBUSY;
 
-	len = seq_buf_used(s) - s->readpos;
+	len -= s->readpos;
 	if (cnt > len)
 		cnt = len;
 	ret = copy_to_user(ubuf, s->buffer + s->readpos, cnt);
tools/testing/selftests/ftrace/test.d/instances/instance.tc new file +90 -0

90 lines not on this page · raw message