aboutsummaryrefslogtreecommitdiffstats
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/cgroup.c31
-rw-r--r--kernel/trace/ftrace.c18
-rw-r--r--kernel/trace/ring_buffer.c26
-rw-r--r--kernel/trace/trace.c227
-rw-r--r--kernel/trace/trace.h18
-rw-r--r--kernel/trace/trace_event_perf.c10
-rw-r--r--kernel/trace/trace_events.c98
-rw-r--r--kernel/trace/trace_events_filter.c4
-rw-r--r--kernel/trace/trace_functions.c2
-rw-r--r--kernel/trace/trace_functions_graph.c54
-rw-r--r--kernel/trace/trace_kprobe.c29
-rw-r--r--kernel/trace/trace_mmiotrace.c8
-rw-r--r--kernel/trace/trace_output.c14
-rw-r--r--kernel/trace/trace_syscalls.c26
-rw-r--r--kernel/trace/trace_uprobe.c2
-rw-r--r--kernel/wait.c3
16 files changed, 280 insertions, 290 deletions
diff --git a/kernel/cgroup.c b/kernel/cgroup.c
index 0e0b20b8c5db..789ec4683db3 100644
--- a/kernel/cgroup.c
+++ b/kernel/cgroup.c
@@ -1845,36 +1845,43 @@ out:
1845EXPORT_SYMBOL_GPL(cgroup_path); 1845EXPORT_SYMBOL_GPL(cgroup_path);
1846 1846
1847/** 1847/**
1848 * task_cgroup_path_from_hierarchy - cgroup path of a task on a hierarchy 1848 * task_cgroup_path - cgroup path of a task in the first cgroup hierarchy
1849 * @task: target task 1849 * @task: target task
1850 * @hierarchy_id: the hierarchy to look up @task's cgroup from
1851 * @buf: the buffer to write the path into 1850 * @buf: the buffer to write the path into
1852 * @buflen: the length of the buffer 1851 * @buflen: the length of the buffer
1853 * 1852 *
1854 * Determine @task's cgroup on the hierarchy specified by @hierarchy_id and 1853 * Determine @task's cgroup on the first (the one with the lowest non-zero
1855 * copy its path into @buf. This function grabs cgroup_mutex and shouldn't 1854 * hierarchy_id) cgroup hierarchy and copy its path into @buf. This
1856 * be used inside locks used by cgroup controller callbacks. 1855 * function grabs cgroup_mutex and shouldn't be used inside locks used by
1856 * cgroup controller callbacks.
1857 *
1858 * Returns 0 on success, fails with -%ENAMETOOLONG if @buflen is too short.
1857 */ 1859 */
1858int task_cgroup_path_from_hierarchy(struct task_struct *task, int hierarchy_id, 1860int task_cgroup_path(struct task_struct *task, char *buf, size_t buflen)
1859 char *buf, size_t buflen)
1860{ 1861{
1861 struct cgroupfs_root *root; 1862 struct cgroupfs_root *root;
1862 struct cgroup *cgrp = NULL; 1863 struct cgroup *cgrp;
1863 int ret = -ENOENT; 1864 int hierarchy_id = 1, ret = 0;
1865
1866 if (buflen < 2)
1867 return -ENAMETOOLONG;
1864 1868
1865 mutex_lock(&cgroup_mutex); 1869 mutex_lock(&cgroup_mutex);
1866 1870
1867 root = idr_find(&cgroup_hierarchy_idr, hierarchy_id); 1871 root = idr_get_next(&cgroup_hierarchy_idr, &hierarchy_id);
1872
1868 if (root) { 1873 if (root) {
1869 cgrp = task_cgroup_from_root(task, root); 1874 cgrp = task_cgroup_from_root(task, root);
1870 ret = cgroup_path(cgrp, buf, buflen); 1875 ret = cgroup_path(cgrp, buf, buflen);
1876 } else {
1877 /* if no hierarchy exists, everyone is in "/" */
1878 memcpy(buf, "/", 2);
1871 } 1879 }
1872 1880
1873 mutex_unlock(&cgroup_mutex); 1881 mutex_unlock(&cgroup_mutex);
1874
1875 return ret; 1882 return ret;
1876} 1883}
1877EXPORT_SYMBOL_GPL(task_cgroup_path_from_hierarchy); 1884EXPORT_SYMBOL_GPL(task_cgroup_path);
1878 1885
1879/* 1886/*
1880 * Control Group taskset 1887 * Control Group taskset
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 67708f46baae..8ce9eefc5bb4 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -1441,12 +1441,22 @@ ftrace_hash_move(struct ftrace_ops *ops, int enable,
1441 * the hashes are freed with call_rcu_sched(). 1441 * the hashes are freed with call_rcu_sched().
1442 */ 1442 */
1443static int 1443static int
1444ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip) 1444ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip, void *regs)
1445{ 1445{
1446 struct ftrace_hash *filter_hash; 1446 struct ftrace_hash *filter_hash;
1447 struct ftrace_hash *notrace_hash; 1447 struct ftrace_hash *notrace_hash;
1448 int ret; 1448 int ret;
1449 1449
1450#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS
1451 /*
1452 * There's a small race when adding ops that the ftrace handler
1453 * that wants regs, may be called without them. We can not
1454 * allow that handler to be called if regs is NULL.
1455 */
1456 if (regs == NULL && (ops->flags & FTRACE_OPS_FL_SAVE_REGS))
1457 return 0;
1458#endif
1459
1450 filter_hash = rcu_dereference_raw_notrace(ops->filter_hash); 1460 filter_hash = rcu_dereference_raw_notrace(ops->filter_hash);
1451 notrace_hash = rcu_dereference_raw_notrace(ops->notrace_hash); 1461 notrace_hash = rcu_dereference_raw_notrace(ops->notrace_hash);
1452 1462
@@ -4218,7 +4228,7 @@ static inline void ftrace_startup_enable(int command) { }
4218# define ftrace_shutdown_sysctl() do { } while (0) 4228# define ftrace_shutdown_sysctl() do { } while (0)
4219 4229
4220static inline int 4230static inline int
4221ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip) 4231ftrace_ops_test(struct ftrace_ops *ops, unsigned long ip, void *regs)
4222{ 4232{
4223 return 1; 4233 return 1;
4224} 4234}
@@ -4241,7 +4251,7 @@ ftrace_ops_control_func(unsigned long ip, unsigned long parent_ip,
4241 do_for_each_ftrace_op(op, ftrace_control_list) { 4251 do_for_each_ftrace_op(op, ftrace_control_list) {
4242 if (!(op->flags & FTRACE_OPS_FL_STUB) && 4252 if (!(op->flags & FTRACE_OPS_FL_STUB) &&
4243 !ftrace_function_local_disabled(op) && 4253 !ftrace_function_local_disabled(op) &&
4244 ftrace_ops_test(op, ip)) 4254 ftrace_ops_test(op, ip, regs))
4245 op->func(ip, parent_ip, op, regs); 4255 op->func(ip, parent_ip, op, regs);
4246 } while_for_each_ftrace_op(op); 4256 } while_for_each_ftrace_op(op);
4247 trace_recursion_clear(TRACE_CONTROL_BIT); 4257 trace_recursion_clear(TRACE_CONTROL_BIT);
@@ -4274,7 +4284,7 @@ __ftrace_ops_list_func(unsigned long ip, unsigned long parent_ip,
4274 */ 4284 */
4275 preempt_disable_notrace(); 4285 preempt_disable_notrace();
4276 do_for_each_ftrace_op(op, ftrace_ops_list) { 4286 do_for_each_ftrace_op(op, ftrace_ops_list) {
4277 if (ftrace_ops_test(op, ip)) 4287 if (ftrace_ops_test(op, ip, regs))
4278 op->func(ip, parent_ip, op, regs); 4288 op->func(ip, parent_ip, op, regs);
4279 } while_for_each_ftrace_op(op); 4289 } while_for_each_ftrace_op(op);
4280 preempt_enable_notrace(); 4290 preempt_enable_notrace();
diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
index e444ff88f0a4..cc2f66f68dc5 100644
--- a/kernel/trace/ring_buffer.c
+++ b/kernel/trace/ring_buffer.c
@@ -36,11 +36,11 @@ int ring_buffer_print_entry_header(struct trace_seq *s)
36{ 36{
37 int ret; 37 int ret;
38 38
39 ret = trace_seq_printf(s, "# compressed entry header\n"); 39 ret = trace_seq_puts(s, "# compressed entry header\n");
40 ret = trace_seq_printf(s, "\ttype_len : 5 bits\n"); 40 ret = trace_seq_puts(s, "\ttype_len : 5 bits\n");
41 ret = trace_seq_printf(s, "\ttime_delta : 27 bits\n"); 41 ret = trace_seq_puts(s, "\ttime_delta : 27 bits\n");
42 ret = trace_seq_printf(s, "\tarray : 32 bits\n"); 42 ret = trace_seq_puts(s, "\tarray : 32 bits\n");
43 ret = trace_seq_printf(s, "\n"); 43 ret = trace_seq_putc(s, '\n');
44 ret = trace_seq_printf(s, "\tpadding : type == %d\n", 44 ret = trace_seq_printf(s, "\tpadding : type == %d\n",
45 RINGBUF_TYPE_PADDING); 45 RINGBUF_TYPE_PADDING);
46 ret = trace_seq_printf(s, "\ttime_extend : type == %d\n", 46 ret = trace_seq_printf(s, "\ttime_extend : type == %d\n",
@@ -1066,7 +1066,7 @@ static int rb_check_list(struct ring_buffer_per_cpu *cpu_buffer,
1066} 1066}
1067 1067
1068/** 1068/**
1069 * check_pages - integrity check of buffer pages 1069 * rb_check_pages - integrity check of buffer pages
1070 * @cpu_buffer: CPU buffer with pages to test 1070 * @cpu_buffer: CPU buffer with pages to test
1071 * 1071 *
1072 * As a safety measure we check to make sure the data pages have not 1072 * As a safety measure we check to make sure the data pages have not
@@ -1258,7 +1258,7 @@ static int rb_cpu_notify(struct notifier_block *self,
1258#endif 1258#endif
1259 1259
1260/** 1260/**
1261 * ring_buffer_alloc - allocate a new ring_buffer 1261 * __ring_buffer_alloc - allocate a new ring_buffer
1262 * @size: the size in bytes per cpu that is needed. 1262 * @size: the size in bytes per cpu that is needed.
1263 * @flags: attributes to set for the ring buffer. 1263 * @flags: attributes to set for the ring buffer.
1264 * 1264 *
@@ -1607,6 +1607,7 @@ static void update_pages_handler(struct work_struct *work)
1607 * ring_buffer_resize - resize the ring buffer 1607 * ring_buffer_resize - resize the ring buffer
1608 * @buffer: the buffer to resize. 1608 * @buffer: the buffer to resize.
1609 * @size: the new size. 1609 * @size: the new size.
1610 * @cpu_id: the cpu buffer to resize
1610 * 1611 *
1611 * Minimum size is 2 * BUF_PAGE_SIZE. 1612 * Minimum size is 2 * BUF_PAGE_SIZE.
1612 * 1613 *
@@ -3956,11 +3957,11 @@ EXPORT_SYMBOL_GPL(ring_buffer_consume);
3956 * expected. 3957 * expected.
3957 * 3958 *
3958 * After a sequence of ring_buffer_read_prepare calls, the user is 3959 * After a sequence of ring_buffer_read_prepare calls, the user is
3959 * expected to make at least one call to ring_buffer_prepare_sync. 3960 * expected to make at least one call to ring_buffer_read_prepare_sync.
3960 * Afterwards, ring_buffer_read_start is invoked to get things going 3961 * Afterwards, ring_buffer_read_start is invoked to get things going
3961 * for real. 3962 * for real.
3962 * 3963 *
3963 * This overall must be paired with ring_buffer_finish. 3964 * This overall must be paired with ring_buffer_read_finish.
3964 */ 3965 */
3965struct ring_buffer_iter * 3966struct ring_buffer_iter *
3966ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu) 3967ring_buffer_read_prepare(struct ring_buffer *buffer, int cpu)
@@ -4009,7 +4010,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_read_prepare_sync);
4009 * an intervening ring_buffer_read_prepare_sync must have been 4010 * an intervening ring_buffer_read_prepare_sync must have been
4010 * performed. 4011 * performed.
4011 * 4012 *
4012 * Must be paired with ring_buffer_finish. 4013 * Must be paired with ring_buffer_read_finish.
4013 */ 4014 */
4014void 4015void
4015ring_buffer_read_start(struct ring_buffer_iter *iter) 4016ring_buffer_read_start(struct ring_buffer_iter *iter)
@@ -4031,7 +4032,7 @@ ring_buffer_read_start(struct ring_buffer_iter *iter)
4031EXPORT_SYMBOL_GPL(ring_buffer_read_start); 4032EXPORT_SYMBOL_GPL(ring_buffer_read_start);
4032 4033
4033/** 4034/**
4034 * ring_buffer_finish - finish reading the iterator of the buffer 4035 * ring_buffer_read_finish - finish reading the iterator of the buffer
4035 * @iter: The iterator retrieved by ring_buffer_start 4036 * @iter: The iterator retrieved by ring_buffer_start
4036 * 4037 *
4037 * This re-enables the recording to the buffer, and frees the 4038 * This re-enables the recording to the buffer, and frees the
@@ -4346,6 +4347,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_swap_cpu);
4346/** 4347/**
4347 * ring_buffer_alloc_read_page - allocate a page to read from buffer 4348 * ring_buffer_alloc_read_page - allocate a page to read from buffer
4348 * @buffer: the buffer to allocate for. 4349 * @buffer: the buffer to allocate for.
4350 * @cpu: the cpu buffer to allocate.
4349 * 4351 *
4350 * This function is used in conjunction with ring_buffer_read_page. 4352 * This function is used in conjunction with ring_buffer_read_page.
4351 * When reading a full page from the ring buffer, these functions 4353 * When reading a full page from the ring buffer, these functions
@@ -4403,7 +4405,7 @@ EXPORT_SYMBOL_GPL(ring_buffer_free_read_page);
4403 * to swap with a page in the ring buffer. 4405 * to swap with a page in the ring buffer.
4404 * 4406 *
4405 * for example: 4407 * for example:
4406 * rpage = ring_buffer_alloc_read_page(buffer); 4408 * rpage = ring_buffer_alloc_read_page(buffer, cpu);
4407 * if (!rpage) 4409 * if (!rpage)
4408 * return error; 4410 * return error;
4409 * ret = ring_buffer_read_page(buffer, &rpage, len, cpu, 0); 4411 * ret = ring_buffer_read_page(buffer, &rpage, len, cpu, 0);
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 0cd500bffd9b..882ec1dd1515 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -1224,18 +1224,17 @@ void tracing_reset_current(int cpu)
1224 tracing_reset(&global_trace.trace_buffer, cpu); 1224 tracing_reset(&global_trace.trace_buffer, cpu);
1225} 1225}
1226 1226
1227/* Must have trace_types_lock held */
1227void tracing_reset_all_online_cpus(void) 1228void tracing_reset_all_online_cpus(void)
1228{ 1229{
1229 struct trace_array *tr; 1230 struct trace_array *tr;
1230 1231
1231 mutex_lock(&trace_types_lock);
1232 list_for_each_entry(tr, &ftrace_trace_arrays, list) { 1232 list_for_each_entry(tr, &ftrace_trace_arrays, list) {
1233 tracing_reset_online_cpus(&tr->trace_buffer); 1233 tracing_reset_online_cpus(&tr->trace_buffer);
1234#ifdef CONFIG_TRACER_MAX_TRACE 1234#ifdef CONFIG_TRACER_MAX_TRACE
1235 tracing_reset_online_cpus(&tr->max_buffer); 1235 tracing_reset_online_cpus(&tr->max_buffer);
1236#endif 1236#endif
1237 } 1237 }
1238 mutex_unlock(&trace_types_lock);
1239} 1238}
1240 1239
1241#define SAVED_CMDLINES 128 1240#define SAVED_CMDLINES 128
@@ -2843,6 +2842,17 @@ static int s_show(struct seq_file *m, void *v)
2843 return 0; 2842 return 0;
2844} 2843}
2845 2844
2845/*
2846 * Should be used after trace_array_get(), trace_types_lock
2847 * ensures that i_cdev was already initialized.
2848 */
2849static inline int tracing_get_cpu(struct inode *inode)
2850{
2851 if (inode->i_cdev) /* See trace_create_cpu_file() */
2852 return (long)inode->i_cdev - 1;
2853 return RING_BUFFER_ALL_CPUS;
2854}
2855
2846static const struct seq_operations tracer_seq_ops = { 2856static const struct seq_operations tracer_seq_ops = {
2847 .start = s_start, 2857 .start = s_start,
2848 .next = s_next, 2858 .next = s_next,
@@ -2851,9 +2861,9 @@ static const struct seq_operations tracer_seq_ops = {
2851}; 2861};
2852 2862
2853static struct trace_iterator * 2863static struct trace_iterator *
2854__tracing_open(struct trace_array *tr, struct trace_cpu *tc, 2864__tracing_open(struct inode *inode, struct file *file, bool snapshot)
2855 struct inode *inode, struct file *file, bool snapshot)
2856{ 2865{
2866 struct trace_array *tr = inode->i_private;
2857 struct trace_iterator *iter; 2867 struct trace_iterator *iter;
2858 int cpu; 2868 int cpu;
2859 2869
@@ -2894,8 +2904,8 @@ __tracing_open(struct trace_array *tr, struct trace_cpu *tc,
2894 iter->trace_buffer = &tr->trace_buffer; 2904 iter->trace_buffer = &tr->trace_buffer;
2895 iter->snapshot = snapshot; 2905 iter->snapshot = snapshot;
2896 iter->pos = -1; 2906 iter->pos = -1;
2907 iter->cpu_file = tracing_get_cpu(inode);
2897 mutex_init(&iter->mutex); 2908 mutex_init(&iter->mutex);
2898 iter->cpu_file = tc->cpu;
2899 2909
2900 /* Notify the tracer early; before we stop tracing. */ 2910 /* Notify the tracer early; before we stop tracing. */
2901 if (iter->trace && iter->trace->open) 2911 if (iter->trace && iter->trace->open)
@@ -2971,45 +2981,22 @@ static int tracing_open_generic_tr(struct inode *inode, struct file *filp)
2971 filp->private_data = inode->i_private; 2981 filp->private_data = inode->i_private;
2972 2982
2973 return 0; 2983 return 0;
2974
2975}
2976
2977static int tracing_open_generic_tc(struct inode *inode, struct file *filp)
2978{
2979 struct trace_cpu *tc = inode->i_private;
2980 struct trace_array *tr = tc->tr;
2981
2982 if (tracing_disabled)
2983 return -ENODEV;
2984
2985 if (trace_array_get(tr) < 0)
2986 return -ENODEV;
2987
2988 filp->private_data = inode->i_private;
2989
2990 return 0;
2991
2992} 2984}
2993 2985
2994static int tracing_release(struct inode *inode, struct file *file) 2986static int tracing_release(struct inode *inode, struct file *file)
2995{ 2987{
2988 struct trace_array *tr = inode->i_private;
2996 struct seq_file *m = file->private_data; 2989 struct seq_file *m = file->private_data;
2997 struct trace_iterator *iter; 2990 struct trace_iterator *iter;
2998 struct trace_array *tr;
2999 int cpu; 2991 int cpu;
3000 2992
3001 /* Writes do not use seq_file, need to grab tr from inode */
3002 if (!(file->f_mode & FMODE_READ)) { 2993 if (!(file->f_mode & FMODE_READ)) {
3003 struct trace_cpu *tc = inode->i_private; 2994 trace_array_put(tr);
3004
3005 trace_array_put(tc->tr);
3006 return 0; 2995 return 0;
3007 } 2996 }
3008 2997
2998 /* Writes do not use seq_file */
3009 iter = m->private; 2999 iter = m->private;
3010 tr = iter->tr;
3011 trace_array_put(tr);
3012
3013 mutex_lock(&trace_types_lock); 3000 mutex_lock(&trace_types_lock);
3014 3001
3015 for_each_tracing_cpu(cpu) { 3002 for_each_tracing_cpu(cpu) {
@@ -3023,6 +3010,9 @@ static int tracing_release(struct inode *inode, struct file *file)
3023 if (!iter->snapshot) 3010 if (!iter->snapshot)
3024 /* reenable tracing if it was previously enabled */ 3011 /* reenable tracing if it was previously enabled */
3025 tracing_start_tr(tr); 3012 tracing_start_tr(tr);
3013
3014 __trace_array_put(tr);
3015
3026 mutex_unlock(&trace_types_lock); 3016 mutex_unlock(&trace_types_lock);
3027 3017
3028 mutex_destroy(&iter->mutex); 3018 mutex_destroy(&iter->mutex);
@@ -3042,15 +3032,6 @@ static int tracing_release_generic_tr(struct inode *inode, struct file *file)
3042 return 0; 3032 return 0;
3043} 3033}
3044 3034
3045static int tracing_release_generic_tc(struct inode *inode, struct file *file)
3046{
3047 struct trace_cpu *tc = inode->i_private;
3048 struct trace_array *tr = tc->tr;
3049
3050 trace_array_put(tr);
3051 return 0;
3052}
3053
3054static int tracing_single_release_tr(struct inode *inode, struct file *file) 3035static int tracing_single_release_tr(struct inode *inode, struct file *file)
3055{ 3036{
3056 struct trace_array *tr = inode->i_private; 3037 struct trace_array *tr = inode->i_private;
@@ -3062,8 +3043,7 @@ static int tracing_single_release_tr(struct inode *inode, struct file *file)
3062 3043
3063static int tracing_open(struct inode *inode, struct file *file) 3044static int tracing_open(struct inode *inode, struct file *file)
3064{ 3045{
3065 struct trace_cpu *tc = inode->i_private; 3046 struct trace_array *tr = inode->i_private;
3066 struct trace_array *tr = tc->tr;
3067 struct trace_iterator *iter; 3047 struct trace_iterator *iter;
3068 int ret = 0; 3048 int ret = 0;
3069 3049
@@ -3071,16 +3051,17 @@ static int tracing_open(struct inode *inode, struct file *file)
3071 return -ENODEV; 3051 return -ENODEV;
3072 3052
3073 /* If this file was open for write, then erase contents */ 3053 /* If this file was open for write, then erase contents */
3074 if ((file->f_mode & FMODE_WRITE) && 3054 if ((file->f_mode & FMODE_WRITE) && (file->f_flags & O_TRUNC)) {
3075 (file->f_flags & O_TRUNC)) { 3055 int cpu = tracing_get_cpu(inode);
3076 if (tc->cpu == RING_BUFFER_ALL_CPUS) 3056
3057 if (cpu == RING_BUFFER_ALL_CPUS)
3077 tracing_reset_online_cpus(&tr->trace_buffer); 3058 tracing_reset_online_cpus(&tr->trace_buffer);
3078 else 3059 else
3079 tracing_reset(&tr->trace_buffer, tc->cpu); 3060 tracing_reset(&tr->trace_buffer, cpu);
3080 } 3061 }
3081 3062
3082 if (file->f_mode & FMODE_READ) { 3063 if (file->f_mode & FMODE_READ) {
3083 iter = __tracing_open(tr, tc, inode, file, false); 3064 iter = __tracing_open(inode, file, false);
3084 if (IS_ERR(iter)) 3065 if (IS_ERR(iter))
3085 ret = PTR_ERR(iter); 3066 ret = PTR_ERR(iter);
3086 else if (trace_flags & TRACE_ITER_LATENCY_FMT) 3067 else if (trace_flags & TRACE_ITER_LATENCY_FMT)
@@ -3447,6 +3428,7 @@ tracing_trace_options_write(struct file *filp, const char __user *ubuf,
3447static int tracing_trace_options_open(struct inode *inode, struct file *file) 3428static int tracing_trace_options_open(struct inode *inode, struct file *file)
3448{ 3429{
3449 struct trace_array *tr = inode->i_private; 3430 struct trace_array *tr = inode->i_private;
3431 int ret;
3450 3432
3451 if (tracing_disabled) 3433 if (tracing_disabled)
3452 return -ENODEV; 3434 return -ENODEV;
@@ -3454,7 +3436,11 @@ static int tracing_trace_options_open(struct inode *inode, struct file *file)
3454 if (trace_array_get(tr) < 0) 3436 if (trace_array_get(tr) < 0)
3455 return -ENODEV; 3437 return -ENODEV;
3456 3438
3457 return single_open(file, tracing_trace_options_show, inode->i_private); 3439 ret = single_open(file, tracing_trace_options_show, inode->i_private);
3440 if (ret < 0)
3441 trace_array_put(tr);
3442
3443 return ret;
3458} 3444}
3459 3445
3460static const struct file_operations tracing_iter_fops = { 3446static const struct file_operations tracing_iter_fops = {
@@ -3537,14 +3523,14 @@ static const char readme_msg[] =
3537 "\n snapshot\t\t- Like 'trace' but shows the content of the static snapshot buffer\n" 3523 "\n snapshot\t\t- Like 'trace' but shows the content of the static snapshot buffer\n"
3538 "\t\t\t Read the contents for more information\n" 3524 "\t\t\t Read the contents for more information\n"
3539#endif 3525#endif
3540#ifdef CONFIG_STACKTRACE 3526#ifdef CONFIG_STACK_TRACER
3541 " stack_trace\t\t- Shows the max stack trace when active\n" 3527 " stack_trace\t\t- Shows the max stack trace when active\n"
3542 " stack_max_size\t- Shows current max stack size that was traced\n" 3528 " stack_max_size\t- Shows current max stack size that was traced\n"
3543 "\t\t\t Write into this file to reset the max size (trigger a new trace)\n" 3529 "\t\t\t Write into this file to reset the max size (trigger a new trace)\n"
3544#ifdef CONFIG_DYNAMIC_FTRACE 3530#ifdef CONFIG_DYNAMIC_FTRACE
3545 " stack_trace_filter\t- Like set_ftrace_filter but limits what stack_trace traces\n" 3531 " stack_trace_filter\t- Like set_ftrace_filter but limits what stack_trace traces\n"
3546#endif 3532#endif
3547#endif /* CONFIG_STACKTRACE */ 3533#endif /* CONFIG_STACK_TRACER */
3548; 3534;
3549 3535
3550static ssize_t 3536static ssize_t
@@ -3941,8 +3927,7 @@ tracing_max_lat_write(struct file *filp, const char __user *ubuf,
3941 3927
3942static int tracing_open_pipe(struct inode *inode, struct file *filp) 3928static int tracing_open_pipe(struct inode *inode, struct file *filp)
3943{ 3929{
3944 struct trace_cpu *tc = inode->i_private; 3930 struct trace_array *tr = inode->i_private;
3945 struct trace_array *tr = tc->tr;
3946 struct trace_iterator *iter; 3931 struct trace_iterator *iter;
3947 int ret = 0; 3932 int ret = 0;
3948 3933
@@ -3958,6 +3943,7 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)
3958 iter = kzalloc(sizeof(*iter), GFP_KERNEL); 3943 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
3959 if (!iter) { 3944 if (!iter) {
3960 ret = -ENOMEM; 3945 ret = -ENOMEM;
3946 __trace_array_put(tr);
3961 goto out; 3947 goto out;
3962 } 3948 }
3963 3949
@@ -3987,9 +3973,9 @@ static int tracing_open_pipe(struct inode *inode, struct file *filp)
3987 if (trace_clocks[tr->clock_id].in_ns) 3973 if (trace_clocks[tr->clock_id].in_ns)
3988 iter->iter_flags |= TRACE_FILE_TIME_IN_NS; 3974 iter->iter_flags |= TRACE_FILE_TIME_IN_NS;
3989 3975
3990 iter->cpu_file = tc->cpu; 3976 iter->tr = tr;
3991 iter->tr = tc->tr; 3977 iter->trace_buffer = &tr->trace_buffer;
3992 iter->trace_buffer = &tc->tr->trace_buffer; 3978 iter->cpu_file = tracing_get_cpu(inode);
3993 mutex_init(&iter->mutex); 3979 mutex_init(&iter->mutex);
3994 filp->private_data = iter; 3980 filp->private_data = iter;
3995 3981
@@ -4012,8 +3998,7 @@ fail:
4012static int tracing_release_pipe(struct inode *inode, struct file *file) 3998static int tracing_release_pipe(struct inode *inode, struct file *file)
4013{ 3999{
4014 struct trace_iterator *iter = file->private_data; 4000 struct trace_iterator *iter = file->private_data;
4015 struct trace_cpu *tc = inode->i_private; 4001 struct trace_array *tr = inode->i_private;
4016 struct trace_array *tr = tc->tr;
4017 4002
4018 mutex_lock(&trace_types_lock); 4003 mutex_lock(&trace_types_lock);
4019 4004
@@ -4366,15 +4351,16 @@ static ssize_t
4366tracing_entries_read(struct file *filp, char __user *ubuf, 4351tracing_entries_read(struct file *filp, char __user *ubuf,
4367 size_t cnt, loff_t *ppos) 4352 size_t cnt, loff_t *ppos)
4368{ 4353{
4369 struct trace_cpu *tc = filp->private_data; 4354 struct inode *inode = file_inode(filp);
4370 struct trace_array *tr = tc->tr; 4355 struct trace_array *tr = inode->i_private;
4356 int cpu = tracing_get_cpu(inode);
4371 char buf[64]; 4357 char buf[64];
4372 int r = 0; 4358 int r = 0;
4373 ssize_t ret; 4359 ssize_t ret;
4374 4360
4375 mutex_lock(&trace_types_lock); 4361 mutex_lock(&trace_types_lock);
4376 4362
4377 if (tc->cpu == RING_BUFFER_ALL_CPUS) { 4363 if (cpu == RING_BUFFER_ALL_CPUS) {
4378 int cpu, buf_size_same; 4364 int cpu, buf_size_same;
4379 unsigned long size; 4365 unsigned long size;
4380 4366
@@ -4401,7 +4387,7 @@ tracing_entries_read(struct file *filp, char __user *ubuf,
4401 } else 4387 } else
4402 r = sprintf(buf, "X\n"); 4388 r = sprintf(buf, "X\n");
4403 } else 4389 } else
4404 r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->trace_buffer.data, tc->cpu)->entries >> 10); 4390 r = sprintf(buf, "%lu\n", per_cpu_ptr(tr->trace_buffer.data, cpu)->entries >> 10);
4405 4391
4406 mutex_unlock(&trace_types_lock); 4392 mutex_unlock(&trace_types_lock);
4407 4393
@@ -4413,7 +4399,8 @@ static ssize_t
4413tracing_entries_write(struct file *filp, const char __user *ubuf, 4399tracing_entries_write(struct file *filp, const char __user *ubuf,
4414 size_t cnt, loff_t *ppos) 4400 size_t cnt, loff_t *ppos)
4415{ 4401{
4416 struct trace_cpu *tc = filp->private_data; 4402 struct inode *inode = file_inode(filp);
4403 struct trace_array *tr = inode->i_private;
4417 unsigned long val; 4404 unsigned long val;
4418 int ret; 4405 int ret;
4419 4406
@@ -4427,8 +4414,7 @@ tracing_entries_write(struct file *filp, const char __user *ubuf,
4427 4414
4428 /* value is in KB */ 4415 /* value is in KB */
4429 val <<= 10; 4416 val <<= 10;
4430 4417 ret = tracing_resize_ring_buffer(tr, val, tracing_get_cpu(inode));
4431 ret = tracing_resize_ring_buffer(tc->tr, val, tc->cpu);
4432 if (ret < 0) 4418 if (ret < 0)
4433 return ret; 4419 return ret;
4434 4420
@@ -4689,8 +4675,7 @@ struct ftrace_buffer_info {
4689#ifdef CONFIG_TRACER_SNAPSHOT 4675#ifdef CONFIG_TRACER_SNAPSHOT
4690static int tracing_snapshot_open(struct inode *inode, struct file *file) 4676static int tracing_snapshot_open(struct inode *inode, struct file *file)
4691{ 4677{
4692 struct trace_cpu *tc = inode->i_private; 4678 struct trace_array *tr = inode->i_private;
4693 struct trace_array *tr = tc->tr;
4694 struct trace_iterator *iter; 4679 struct trace_iterator *iter;
4695 struct seq_file *m; 4680 struct seq_file *m;
4696 int ret = 0; 4681 int ret = 0;
@@ -4699,26 +4684,29 @@ static int tracing_snapshot_open(struct inode *inode, struct file *file)
4699 return -ENODEV; 4684 return -ENODEV;
4700 4685
4701 if (file->f_mode & FMODE_READ) { 4686 if (file->f_mode & FMODE_READ) {
4702 iter = __tracing_open(tr, tc, inode, file, true); 4687 iter = __tracing_open(inode, file, true);
4703 if (IS_ERR(iter)) 4688 if (IS_ERR(iter))
4704 ret = PTR_ERR(iter); 4689 ret = PTR_ERR(iter);
4705 } else { 4690 } else {
4706 /* Writes still need the seq_file to hold the private data */ 4691 /* Writes still need the seq_file to hold the private data */
4692 ret = -ENOMEM;
4707 m = kzalloc(sizeof(*m), GFP_KERNEL); 4693 m = kzalloc(sizeof(*m), GFP_KERNEL);
4708 if (!m) 4694 if (!m)
4709 return -ENOMEM; 4695 goto out;
4710 iter = kzalloc(sizeof(*iter), GFP_KERNEL); 4696 iter = kzalloc(sizeof(*iter), GFP_KERNEL);
4711 if (!iter) { 4697 if (!iter) {
4712 kfree(m); 4698 kfree(m);
4713 return -ENOMEM; 4699 goto out;
4714 } 4700 }
4701 ret = 0;
4702
4715 iter->tr = tr; 4703 iter->tr = tr;
4716 iter->trace_buffer = &tc->tr->max_buffer; 4704 iter->trace_buffer = &tr->max_buffer;
4717 iter->cpu_file = tc->cpu; 4705 iter->cpu_file = tracing_get_cpu(inode);
4718 m->private = iter; 4706 m->private = iter;
4719 file->private_data = m; 4707 file->private_data = m;
4720 } 4708 }
4721 4709out:
4722 if (ret < 0) 4710 if (ret < 0)
4723 trace_array_put(tr); 4711 trace_array_put(tr);
4724 4712
@@ -4873,11 +4861,11 @@ static const struct file_operations tracing_pipe_fops = {
4873}; 4861};
4874 4862
4875static const struct file_operations tracing_entries_fops = { 4863static const struct file_operations tracing_entries_fops = {
4876 .open = tracing_open_generic_tc, 4864 .open = tracing_open_generic_tr,
4877 .read = tracing_entries_read, 4865 .read = tracing_entries_read,
4878 .write = tracing_entries_write, 4866 .write = tracing_entries_write,
4879 .llseek = generic_file_llseek, 4867 .llseek = generic_file_llseek,
4880 .release = tracing_release_generic_tc, 4868 .release = tracing_release_generic_tr,
4881}; 4869};
4882 4870
4883static const struct file_operations tracing_total_entries_fops = { 4871static const struct file_operations tracing_total_entries_fops = {
@@ -4929,8 +4917,7 @@ static const struct file_operations snapshot_raw_fops = {
4929 4917
4930static int tracing_buffers_open(struct inode *inode, struct file *filp) 4918static int tracing_buffers_open(struct inode *inode, struct file *filp)
4931{ 4919{
4932 struct trace_cpu *tc = inode->i_private; 4920 struct trace_array *tr = inode->i_private;
4933 struct trace_array *tr = tc->tr;
4934 struct ftrace_buffer_info *info; 4921 struct ftrace_buffer_info *info;
4935 int ret; 4922 int ret;
4936 4923
@@ -4948,10 +4935,8 @@ static int tracing_buffers_open(struct inode *inode, struct file *filp)
4948 4935
4949 mutex_lock(&trace_types_lock); 4936 mutex_lock(&trace_types_lock);
4950 4937
4951 tr->ref++;
4952
4953 info->iter.tr = tr; 4938 info->iter.tr = tr;
4954 info->iter.cpu_file = tc->cpu; 4939 info->iter.cpu_file = tracing_get_cpu(inode);
4955 info->iter.trace = tr->current_trace; 4940 info->iter.trace = tr->current_trace;
4956 info->iter.trace_buffer = &tr->trace_buffer; 4941 info->iter.trace_buffer = &tr->trace_buffer;
4957 info->spare = NULL; 4942 info->spare = NULL;
@@ -5268,14 +5253,14 @@ static ssize_t
5268tracing_stats_read(struct file *filp, char __user *ubuf, 5253tracing_stats_read(struct file *filp, char __user *ubuf,
5269 size_t count, loff_t *ppos) 5254 size_t count, loff_t *ppos)
5270{ 5255{
5271 struct trace_cpu *tc = filp->private_data; 5256 struct inode *inode = file_inode(filp);
5272 struct trace_array *tr = tc->tr; 5257 struct trace_array *tr = inode->i_private;
5273 struct trace_buffer *trace_buf = &tr->trace_buffer; 5258 struct trace_buffer *trace_buf = &tr->trace_buffer;
5259 int cpu = tracing_get_cpu(inode);
5274 struct trace_seq *s; 5260 struct trace_seq *s;
5275 unsigned long cnt; 5261 unsigned long cnt;
5276 unsigned long long t; 5262 unsigned long long t;
5277 unsigned long usec_rem; 5263 unsigned long usec_rem;
5278 int cpu = tc->cpu;
5279 5264
5280 s = kmalloc(sizeof(*s), GFP_KERNEL); 5265 s = kmalloc(sizeof(*s), GFP_KERNEL);
5281 if (!s) 5266 if (!s)
@@ -5328,9 +5313,10 @@ tracing_stats_read(struct file *filp, char __user *ubuf,
5328} 5313}
5329 5314
5330static const struct file_operations tracing_stats_fops = { 5315static const struct file_operations tracing_stats_fops = {
5331 .open = tracing_open_generic, 5316 .open = tracing_open_generic_tr,
5332 .read = tracing_stats_read, 5317 .read = tracing_stats_read,
5333 .llseek = generic_file_llseek, 5318 .llseek = generic_file_llseek,
5319 .release = tracing_release_generic_tr,
5334}; 5320};
5335 5321
5336#ifdef CONFIG_DYNAMIC_FTRACE 5322#ifdef CONFIG_DYNAMIC_FTRACE
@@ -5519,10 +5505,20 @@ static struct dentry *tracing_dentry_percpu(struct trace_array *tr, int cpu)
5519 return tr->percpu_dir; 5505 return tr->percpu_dir;
5520} 5506}
5521 5507
5508static struct dentry *
5509trace_create_cpu_file(const char *name, umode_t mode, struct dentry *parent,
5510 void *data, long cpu, const struct file_operations *fops)
5511{
5512 struct dentry *ret = trace_create_file(name, mode, parent, data, fops);
5513
5514 if (ret) /* See tracing_get_cpu() */
5515 ret->d_inode->i_cdev = (void *)(cpu + 1);
5516 return ret;
5517}
5518
5522static void 5519static void
5523tracing_init_debugfs_percpu(struct trace_array *tr, long cpu) 5520tracing_init_debugfs_percpu(struct trace_array *tr, long cpu)
5524{ 5521{
5525 struct trace_array_cpu *data = per_cpu_ptr(tr->trace_buffer.data, cpu);
5526 struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu); 5522 struct dentry *d_percpu = tracing_dentry_percpu(tr, cpu);
5527 struct dentry *d_cpu; 5523 struct dentry *d_cpu;
5528 char cpu_dir[30]; /* 30 characters should be more than enough */ 5524 char cpu_dir[30]; /* 30 characters should be more than enough */
@@ -5538,28 +5534,28 @@ tracing_init_debugfs_percpu(struct trace_array *tr, long cpu)
5538 } 5534 }
5539 5535
5540 /* per cpu trace_pipe */ 5536 /* per cpu trace_pipe */
5541 trace_create_file("trace_pipe", 0444, d_cpu, 5537 trace_create_cpu_file("trace_pipe", 0444, d_cpu,
5542 (void *)&data->trace_cpu, &tracing_pipe_fops); 5538 tr, cpu, &tracing_pipe_fops);
5543 5539
5544 /* per cpu trace */ 5540 /* per cpu trace */
5545 trace_create_file("trace", 0644, d_cpu, 5541 trace_create_cpu_file("trace", 0644, d_cpu,
5546 (void *)&data->trace_cpu, &tracing_fops); 5542 tr, cpu, &tracing_fops);
5547 5543
5548 trace_create_file("trace_pipe_raw", 0444, d_cpu, 5544 trace_create_cpu_file("trace_pipe_raw", 0444, d_cpu,
5549 (void *)&data->trace_cpu, &tracing_buffers_fops); 5545 tr, cpu, &tracing_buffers_fops);
5550 5546
5551 trace_create_file("stats", 0444, d_cpu, 5547 trace_create_cpu_file("stats", 0444, d_cpu,
5552 (void *)&data->trace_cpu, &tracing_stats_fops); 5548 tr, cpu, &tracing_stats_fops);
5553 5549
5554 trace_create_file("buffer_size_kb", 0444, d_cpu, 5550 trace_create_cpu_file("buffer_size_kb", 0444, d_cpu,
5555 (void *)&data->trace_cpu, &tracing_entries_fops); 5551 tr, cpu, &tracing_entries_fops);
5556 5552
5557#ifdef CONFIG_TRACER_SNAPSHOT 5553#ifdef CONFIG_TRACER_SNAPSHOT
5558 trace_create_file("snapshot", 0644, d_cpu, 5554 trace_create_cpu_file("snapshot", 0644, d_cpu,
5559 (void *)&data->trace_cpu, &snapshot_fops); 5555 tr, cpu, &snapshot_fops);
5560 5556
5561 trace_create_file("snapshot_raw", 0444, d_cpu, 5557 trace_create_cpu_file("snapshot_raw", 0444, d_cpu,
5562 (void *)&data->trace_cpu, &snapshot_raw_fops); 5558 tr, cpu, &snapshot_raw_fops);
5563#endif 5559#endif
5564} 5560}
5565 5561
@@ -5868,17 +5864,6 @@ struct dentry *trace_instance_dir;
5868static void 5864static void
5869init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer); 5865init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer);
5870 5866
5871static void init_trace_buffers(struct trace_array *tr, struct trace_buffer *buf)
5872{
5873 int cpu;
5874
5875 for_each_tracing_cpu(cpu) {
5876 memset(per_cpu_ptr(buf->data, cpu), 0, sizeof(struct trace_array_cpu));
5877 per_cpu_ptr(buf->data, cpu)->trace_cpu.cpu = cpu;
5878 per_cpu_ptr(buf->data, cpu)->trace_cpu.tr = tr;
5879 }
5880}
5881
5882static int 5867static int
5883allocate_trace_buffer(struct trace_array *tr, struct trace_buffer *buf, int size) 5868allocate_trace_buffer(struct trace_array *tr, struct trace_buffer *buf, int size)
5884{ 5869{
@@ -5896,8 +5881,6 @@ allocate_trace_buffer(struct trace_array *tr, struct trace_buffer *buf, int size
5896 return -ENOMEM; 5881 return -ENOMEM;
5897 } 5882 }
5898 5883
5899 init_trace_buffers(tr, buf);
5900
5901 /* Allocate the first page for all buffers */ 5884 /* Allocate the first page for all buffers */
5902 set_buffer_entries(&tr->trace_buffer, 5885 set_buffer_entries(&tr->trace_buffer,
5903 ring_buffer_size(tr->trace_buffer.buffer, 0)); 5886 ring_buffer_size(tr->trace_buffer.buffer, 0));
@@ -5964,17 +5947,15 @@ static int new_instance_create(const char *name)
5964 if (allocate_trace_buffers(tr, trace_buf_size) < 0) 5947 if (allocate_trace_buffers(tr, trace_buf_size) < 0)
5965 goto out_free_tr; 5948 goto out_free_tr;
5966 5949
5967 /* Holder for file callbacks */
5968 tr->trace_cpu.cpu = RING_BUFFER_ALL_CPUS;
5969 tr->trace_cpu.tr = tr;
5970
5971 tr->dir = debugfs_create_dir(name, trace_instance_dir); 5950 tr->dir = debugfs_create_dir(name, trace_instance_dir);
5972 if (!tr->dir) 5951 if (!tr->dir)
5973 goto out_free_tr; 5952 goto out_free_tr;
5974 5953
5975 ret = event_trace_add_tracer(tr->dir, tr); 5954 ret = event_trace_add_tracer(tr->dir, tr);
5976 if (ret) 5955 if (ret) {
5956 debugfs_remove_recursive(tr->dir);
5977 goto out_free_tr; 5957 goto out_free_tr;
5958 }
5978 5959
5979 init_tracer_debugfs(tr, tr->dir); 5960 init_tracer_debugfs(tr, tr->dir);
5980 5961
@@ -6120,13 +6101,13 @@ init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer)
6120 tr, &tracing_iter_fops); 6101 tr, &tracing_iter_fops);
6121 6102
6122 trace_create_file("trace", 0644, d_tracer, 6103 trace_create_file("trace", 0644, d_tracer,
6123 (void *)&tr->trace_cpu, &tracing_fops); 6104 tr, &tracing_fops);
6124 6105
6125 trace_create_file("trace_pipe", 0444, d_tracer, 6106 trace_create_file("trace_pipe", 0444, d_tracer,
6126 (void *)&tr->trace_cpu, &tracing_pipe_fops); 6107 tr, &tracing_pipe_fops);
6127 6108
6128 trace_create_file("buffer_size_kb", 0644, d_tracer, 6109 trace_create_file("buffer_size_kb", 0644, d_tracer,
6129 (void *)&tr->trace_cpu, &tracing_entries_fops); 6110 tr, &tracing_entries_fops);
6130 6111
6131 trace_create_file("buffer_total_size_kb", 0444, d_tracer, 6112 trace_create_file("buffer_total_size_kb", 0444, d_tracer,
6132 tr, &tracing_total_entries_fops); 6113 tr, &tracing_total_entries_fops);
@@ -6141,11 +6122,11 @@ init_tracer_debugfs(struct trace_array *tr, struct dentry *d_tracer)
6141 &trace_clock_fops); 6122 &trace_clock_fops);
6142 6123
6143 trace_create_file("tracing_on", 0644, d_tracer, 6124 trace_create_file("tracing_on", 0644, d_tracer,
6144 tr, &rb_simple_fops); 6125 tr, &rb_simple_fops);
6145 6126
6146#ifdef CONFIG_TRACER_SNAPSHOT 6127#ifdef CONFIG_TRACER_SNAPSHOT
6147 trace_create_file("snapshot", 0644, d_tracer, 6128 trace_create_file("snapshot", 0644, d_tracer,
6148 (void *)&tr->trace_cpu, &snapshot_fops); 6129 tr, &snapshot_fops);
6149#endif 6130#endif
6150 6131
6151 for_each_tracing_cpu(cpu) 6132 for_each_tracing_cpu(cpu)
@@ -6439,10 +6420,6 @@ __init static int tracer_alloc_buffers(void)
6439 6420
6440 global_trace.flags = TRACE_ARRAY_FL_GLOBAL; 6421 global_trace.flags = TRACE_ARRAY_FL_GLOBAL;
6441 6422
6442 /* Holder for file callbacks */
6443 global_trace.trace_cpu.cpu = RING_BUFFER_ALL_CPUS;
6444 global_trace.trace_cpu.tr = &global_trace;
6445
6446 INIT_LIST_HEAD(&global_trace.systems); 6423 INIT_LIST_HEAD(&global_trace.systems);
6447 INIT_LIST_HEAD(&global_trace.events); 6424 INIT_LIST_HEAD(&global_trace.events);
6448 list_add(&global_trace.list, &ftrace_trace_arrays); 6425 list_add(&global_trace.list, &ftrace_trace_arrays);
diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
index 4a4f6e1828b6..afaae41b0a02 100644
--- a/kernel/trace/trace.h
+++ b/kernel/trace/trace.h
@@ -130,19 +130,12 @@ enum trace_flag_type {
130 130
131struct trace_array; 131struct trace_array;
132 132
133struct trace_cpu {
134 struct trace_array *tr;
135 struct dentry *dir;
136 int cpu;
137};
138
139/* 133/*
140 * The CPU trace array - it consists of thousands of trace entries 134 * The CPU trace array - it consists of thousands of trace entries
141 * plus some other descriptor data: (for example which task started 135 * plus some other descriptor data: (for example which task started
142 * the trace, etc.) 136 * the trace, etc.)
143 */ 137 */
144struct trace_array_cpu { 138struct trace_array_cpu {
145 struct trace_cpu trace_cpu;
146 atomic_t disabled; 139 atomic_t disabled;
147 void *buffer_page; /* ring buffer spare */ 140 void *buffer_page; /* ring buffer spare */
148 141
@@ -196,7 +189,6 @@ struct trace_array {
196 bool allocated_snapshot; 189 bool allocated_snapshot;
197#endif 190#endif
198 int buffer_disabled; 191 int buffer_disabled;
199 struct trace_cpu trace_cpu; /* place holder */
200#ifdef CONFIG_FTRACE_SYSCALLS 192#ifdef CONFIG_FTRACE_SYSCALLS
201 int sys_refcount_enter; 193 int sys_refcount_enter;
202 int sys_refcount_exit; 194 int sys_refcount_exit;
@@ -214,7 +206,6 @@ struct trace_array {
214 struct dentry *event_dir; 206 struct dentry *event_dir;
215 struct list_head systems; 207 struct list_head systems;
216 struct list_head events; 208 struct list_head events;
217 struct task_struct *waiter;
218 int ref; 209 int ref;
219}; 210};
220 211
@@ -680,6 +671,15 @@ extern int trace_selftest_startup_sched_switch(struct tracer *trace,
680 struct trace_array *tr); 671 struct trace_array *tr);
681extern int trace_selftest_startup_branch(struct tracer *trace, 672extern int trace_selftest_startup_branch(struct tracer *trace,
682 struct trace_array *tr); 673 struct trace_array *tr);
674/*
675 * Tracer data references selftest functions that only occur
676 * on boot up. These can be __init functions. Thus, when selftests
677 * are enabled, then the tracers need to reference __init functions.
678 */
679#define __tracer_data __refdata
680#else
681/* Tracers are seldom changed. Optimize when selftests are disabled. */
682#define __tracer_data __read_mostly
683#endif /* CONFIG_FTRACE_STARTUP_TEST */ 683#endif /* CONFIG_FTRACE_STARTUP_TEST */
684 684
685extern void *head_page(struct trace_array_cpu *data); 685extern void *head_page(struct trace_array_cpu *data);
diff --git a/kernel/trace/trace_event_perf.c b/kernel/trace/trace_event_perf.c
index 84b1e045faba..80c36bcf66e8 100644
--- a/kernel/trace/trace_event_perf.c
+++ b/kernel/trace/trace_event_perf.c
@@ -236,6 +236,10 @@ __kprobes void *perf_trace_buf_prepare(int size, unsigned short type,
236 236
237 BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(unsigned long)); 237 BUILD_BUG_ON(PERF_MAX_TRACE_SIZE % sizeof(unsigned long));
238 238
239 if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE,
240 "perf buffer not large enough"))
241 return NULL;
242
239 pc = preempt_count(); 243 pc = preempt_count();
240 244
241 *rctxp = perf_swevent_get_recursion_context(); 245 *rctxp = perf_swevent_get_recursion_context();
@@ -266,6 +270,10 @@ perf_ftrace_function_call(unsigned long ip, unsigned long parent_ip,
266 struct pt_regs regs; 270 struct pt_regs regs;
267 int rctx; 271 int rctx;
268 272
273 head = this_cpu_ptr(event_function.perf_events);
274 if (hlist_empty(head))
275 return;
276
269#define ENTRY_SIZE (ALIGN(sizeof(struct ftrace_entry) + sizeof(u32), \ 277#define ENTRY_SIZE (ALIGN(sizeof(struct ftrace_entry) + sizeof(u32), \
270 sizeof(u64)) - sizeof(u32)) 278 sizeof(u64)) - sizeof(u32))
271 279
@@ -279,8 +287,6 @@ perf_ftrace_function_call(unsigned long ip, unsigned long parent_ip,
279 287
280 entry->ip = ip; 288 entry->ip = ip;
281 entry->parent_ip = parent_ip; 289 entry->parent_ip = parent_ip;
282
283 head = this_cpu_ptr(event_function.perf_events);
284 perf_trace_buf_submit(entry, ENTRY_SIZE, rctx, 0, 290 perf_trace_buf_submit(entry, ENTRY_SIZE, rctx, 0,
285 1, &regs, head, NULL); 291 1, &regs, head, NULL);
286 292
diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
index 7d854290bf81..898f868833f2 100644
--- a/kernel/trace/trace_events.c
+++ b/kernel/trace/trace_events.c
@@ -826,59 +826,33 @@ enum {
826static void *f_next(struct seq_file *m, void *v, loff_t *pos) 826static void *f_next(struct seq_file *m, void *v, loff_t *pos)
827{ 827{
828 struct ftrace_event_call *call = m->private; 828 struct ftrace_event_call *call = m->private;
829 struct ftrace_event_field *field;
830 struct list_head *common_head = &ftrace_common_fields; 829 struct list_head *common_head = &ftrace_common_fields;
831 struct list_head *head = trace_get_fields(call); 830 struct list_head *head = trace_get_fields(call);
831 struct list_head *node = v;
832 832
833 (*pos)++; 833 (*pos)++;
834 834
835 switch ((unsigned long)v) { 835 switch ((unsigned long)v) {
836 case FORMAT_HEADER: 836 case FORMAT_HEADER:
837 if (unlikely(list_empty(common_head))) 837 node = common_head;
838 return NULL; 838 break;
839
840 field = list_entry(common_head->prev,
841 struct ftrace_event_field, link);
842 return field;
843 839
844 case FORMAT_FIELD_SEPERATOR: 840 case FORMAT_FIELD_SEPERATOR:
845 if (unlikely(list_empty(head))) 841 node = head;
846 return NULL; 842 break;
847
848 field = list_entry(head->prev, struct ftrace_event_field, link);
849 return field;
850 843
851 case FORMAT_PRINTFMT: 844 case FORMAT_PRINTFMT:
852 /* all done */ 845 /* all done */
853 return NULL; 846 return NULL;
854 } 847 }
855 848
856 field = v; 849 node = node->prev;
857 if (field->link.prev == common_head) 850 if (node == common_head)
858 return (void *)FORMAT_FIELD_SEPERATOR; 851 return (void *)FORMAT_FIELD_SEPERATOR;
859 else if (field->link.prev == head) 852 else if (node == head)
860 return (void *)FORMAT_PRINTFMT; 853 return (void *)FORMAT_PRINTFMT;
861 854 else
862 field = list_entry(field->link.prev, struct ftrace_event_field, link); 855 return node;
863
864 return field;
865}
866
867static void *f_start(struct seq_file *m, loff_t *pos)
868{
869 loff_t l = 0;
870 void *p;
871
872 /* Start by showing the header */
873 if (!*pos)
874 return (void *)FORMAT_HEADER;
875
876 p = (void *)FORMAT_HEADER;
877 do {
878 p = f_next(m, p, &l);
879 } while (p && l < *pos);
880
881 return p;
882} 856}
883 857
884static int f_show(struct seq_file *m, void *v) 858static int f_show(struct seq_file *m, void *v)
@@ -904,8 +878,7 @@ static int f_show(struct seq_file *m, void *v)
904 return 0; 878 return 0;
905 } 879 }
906 880
907 field = v; 881 field = list_entry(v, struct ftrace_event_field, link);
908
909 /* 882 /*
910 * Smartly shows the array type(except dynamic array). 883 * Smartly shows the array type(except dynamic array).
911 * Normal: 884 * Normal:
@@ -932,6 +905,17 @@ static int f_show(struct seq_file *m, void *v)
932 return 0; 905 return 0;
933} 906}
934 907
908static void *f_start(struct seq_file *m, loff_t *pos)
909{
910 void *p = (void *)FORMAT_HEADER;
911 loff_t l = 0;
912
913 while (l < *pos && p)
914 p = f_next(m, p, &l);
915
916 return p;
917}
918
935static void f_stop(struct seq_file *m, void *p) 919static void f_stop(struct seq_file *m, void *p)
936{ 920{
937} 921}
@@ -963,23 +947,14 @@ static ssize_t
963event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos) 947event_id_read(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
964{ 948{
965 struct ftrace_event_call *call = filp->private_data; 949 struct ftrace_event_call *call = filp->private_data;
966 struct trace_seq *s; 950 char buf[32];
967 int r; 951 int len;
968 952
969 if (*ppos) 953 if (*ppos)
970 return 0; 954 return 0;
971 955
972 s = kmalloc(sizeof(*s), GFP_KERNEL); 956 len = sprintf(buf, "%d\n", call->event.type);
973 if (!s) 957 return simple_read_from_buffer(ubuf, cnt, ppos, buf, len);
974 return -ENOMEM;
975
976 trace_seq_init(s);
977 trace_seq_printf(s, "%d\n", call->event.type);
978
979 r = simple_read_from_buffer(ubuf, cnt, ppos,
980 s->buffer, s->len);
981 kfree(s);
982 return r;
983} 958}
984 959
985static ssize_t 960static ssize_t
@@ -1218,6 +1193,7 @@ show_header(struct file *filp, char __user *ubuf, size_t cnt, loff_t *ppos)
1218 1193
1219static int ftrace_event_avail_open(struct inode *inode, struct file *file); 1194static int ftrace_event_avail_open(struct inode *inode, struct file *file);
1220static int ftrace_event_set_open(struct inode *inode, struct file *file); 1195static int ftrace_event_set_open(struct inode *inode, struct file *file);
1196static int ftrace_event_release(struct inode *inode, struct file *file);
1221 1197
1222static const struct seq_operations show_event_seq_ops = { 1198static const struct seq_operations show_event_seq_ops = {
1223 .start = t_start, 1199 .start = t_start,
@@ -1245,7 +1221,7 @@ static const struct file_operations ftrace_set_event_fops = {
1245 .read = seq_read, 1221 .read = seq_read,
1246 .write = ftrace_event_write, 1222 .write = ftrace_event_write,
1247 .llseek = seq_lseek, 1223 .llseek = seq_lseek,
1248 .release = seq_release, 1224 .release = ftrace_event_release,
1249}; 1225};
1250 1226
1251static const struct file_operations ftrace_enable_fops = { 1227static const struct file_operations ftrace_enable_fops = {
@@ -1323,6 +1299,15 @@ ftrace_event_open(struct inode *inode, struct file *file,
1323 return ret; 1299 return ret;
1324} 1300}
1325 1301
1302static int ftrace_event_release(struct inode *inode, struct file *file)
1303{
1304 struct trace_array *tr = inode->i_private;
1305
1306 trace_array_put(tr);
1307
1308 return seq_release(inode, file);
1309}
1310
1326static int 1311static int
1327ftrace_event_avail_open(struct inode *inode, struct file *file) 1312ftrace_event_avail_open(struct inode *inode, struct file *file)
1328{ 1313{
@@ -1336,12 +1321,19 @@ ftrace_event_set_open(struct inode *inode, struct file *file)
1336{ 1321{
1337 const struct seq_operations *seq_ops = &show_set_event_seq_ops; 1322 const struct seq_operations *seq_ops = &show_set_event_seq_ops;
1338 struct trace_array *tr = inode->i_private; 1323 struct trace_array *tr = inode->i_private;
1324 int ret;
1325
1326 if (trace_array_get(tr) < 0)
1327 return -ENODEV;
1339 1328
1340 if ((file->f_mode & FMODE_WRITE) && 1329 if ((file->f_mode & FMODE_WRITE) &&
1341 (file->f_flags & O_TRUNC)) 1330 (file->f_flags & O_TRUNC))
1342 ftrace_clear_events(tr); 1331 ftrace_clear_events(tr);
1343 1332
1344 return ftrace_event_open(inode, file, seq_ops); 1333 ret = ftrace_event_open(inode, file, seq_ops);
1334 if (ret < 0)
1335 trace_array_put(tr);
1336 return ret;
1345} 1337}
1346 1338
1347static struct event_subsystem * 1339static struct event_subsystem *
diff --git a/kernel/trace/trace_events_filter.c b/kernel/trace/trace_events_filter.c
index 0d883dc057d6..0c7b75a8acc8 100644
--- a/kernel/trace/trace_events_filter.c
+++ b/kernel/trace/trace_events_filter.c
@@ -646,7 +646,7 @@ void print_event_filter(struct ftrace_event_call *call, struct trace_seq *s)
646 if (filter && filter->filter_string) 646 if (filter && filter->filter_string)
647 trace_seq_printf(s, "%s\n", filter->filter_string); 647 trace_seq_printf(s, "%s\n", filter->filter_string);
648 else 648 else
649 trace_seq_printf(s, "none\n"); 649 trace_seq_puts(s, "none\n");
650 mutex_unlock(&event_mutex); 650 mutex_unlock(&event_mutex);
651} 651}
652 652
@@ -660,7 +660,7 @@ void print_subsystem_event_filter(struct event_subsystem *system,
660 if (filter && filter->filter_string) 660 if (filter && filter->filter_string)
661 trace_seq_printf(s, "%s\n", filter->filter_string); 661 trace_seq_printf(s, "%s\n", filter->filter_string);
662 else 662 else
663 trace_seq_printf(s, DEFAULT_SYS_FILTER_MESSAGE "\n"); 663 trace_seq_puts(s, DEFAULT_SYS_FILTER_MESSAGE "\n");
664 mutex_unlock(&event_mutex); 664 mutex_unlock(&event_mutex);
665} 665}
666 666
diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index b863f93b30f3..38fe1483c508 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -199,7 +199,7 @@ static int func_set_flag(u32 old_flags, u32 bit, int set)
199 return 0; 199 return 0;
200} 200}
201 201
202static struct tracer function_trace __read_mostly = 202static struct tracer function_trace __tracer_data =
203{ 203{
204 .name = "function", 204 .name = "function",
205 .init = function_trace_init, 205 .init = function_trace_init,
diff --git a/kernel/trace/trace_functions_graph.c b/kernel/trace/trace_functions_graph.c
index 8388bc99f2ee..b5c09242683d 100644
--- a/kernel/trace/trace_functions_graph.c
+++ b/kernel/trace/trace_functions_graph.c
@@ -446,7 +446,7 @@ print_graph_proc(struct trace_seq *s, pid_t pid)
446 446
447 /* First spaces to align center */ 447 /* First spaces to align center */
448 for (i = 0; i < spaces / 2; i++) { 448 for (i = 0; i < spaces / 2; i++) {
449 ret = trace_seq_printf(s, " "); 449 ret = trace_seq_putc(s, ' ');
450 if (!ret) 450 if (!ret)
451 return TRACE_TYPE_PARTIAL_LINE; 451 return TRACE_TYPE_PARTIAL_LINE;
452 } 452 }
@@ -457,7 +457,7 @@ print_graph_proc(struct trace_seq *s, pid_t pid)
457 457
458 /* Last spaces to align center */ 458 /* Last spaces to align center */
459 for (i = 0; i < spaces - (spaces / 2); i++) { 459 for (i = 0; i < spaces - (spaces / 2); i++) {
460 ret = trace_seq_printf(s, " "); 460 ret = trace_seq_putc(s, ' ');
461 if (!ret) 461 if (!ret)
462 return TRACE_TYPE_PARTIAL_LINE; 462 return TRACE_TYPE_PARTIAL_LINE;
463 } 463 }
@@ -503,7 +503,7 @@ verif_pid(struct trace_seq *s, pid_t pid, int cpu, struct fgraph_data *data)
503 ------------------------------------------ 503 ------------------------------------------
504 504
505 */ 505 */
506 ret = trace_seq_printf(s, 506 ret = trace_seq_puts(s,
507 " ------------------------------------------\n"); 507 " ------------------------------------------\n");
508 if (!ret) 508 if (!ret)
509 return TRACE_TYPE_PARTIAL_LINE; 509 return TRACE_TYPE_PARTIAL_LINE;
@@ -516,7 +516,7 @@ verif_pid(struct trace_seq *s, pid_t pid, int cpu, struct fgraph_data *data)
516 if (ret == TRACE_TYPE_PARTIAL_LINE) 516 if (ret == TRACE_TYPE_PARTIAL_LINE)
517 return TRACE_TYPE_PARTIAL_LINE; 517 return TRACE_TYPE_PARTIAL_LINE;
518 518
519 ret = trace_seq_printf(s, " => "); 519 ret = trace_seq_puts(s, " => ");
520 if (!ret) 520 if (!ret)
521 return TRACE_TYPE_PARTIAL_LINE; 521 return TRACE_TYPE_PARTIAL_LINE;
522 522
@@ -524,7 +524,7 @@ verif_pid(struct trace_seq *s, pid_t pid, int cpu, struct fgraph_data *data)
524 if (ret == TRACE_TYPE_PARTIAL_LINE) 524 if (ret == TRACE_TYPE_PARTIAL_LINE)
525 return TRACE_TYPE_PARTIAL_LINE; 525 return TRACE_TYPE_PARTIAL_LINE;
526 526
527 ret = trace_seq_printf(s, 527 ret = trace_seq_puts(s,
528 "\n ------------------------------------------\n\n"); 528 "\n ------------------------------------------\n\n");
529 if (!ret) 529 if (!ret)
530 return TRACE_TYPE_PARTIAL_LINE; 530 return TRACE_TYPE_PARTIAL_LINE;
@@ -645,7 +645,7 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr,
645 ret = print_graph_proc(s, pid); 645 ret = print_graph_proc(s, pid);
646 if (ret == TRACE_TYPE_PARTIAL_LINE) 646 if (ret == TRACE_TYPE_PARTIAL_LINE)
647 return TRACE_TYPE_PARTIAL_LINE; 647 return TRACE_TYPE_PARTIAL_LINE;
648 ret = trace_seq_printf(s, " | "); 648 ret = trace_seq_puts(s, " | ");
649 if (!ret) 649 if (!ret)
650 return TRACE_TYPE_PARTIAL_LINE; 650 return TRACE_TYPE_PARTIAL_LINE;
651 } 651 }
@@ -657,9 +657,9 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr,
657 return ret; 657 return ret;
658 658
659 if (type == TRACE_GRAPH_ENT) 659 if (type == TRACE_GRAPH_ENT)
660 ret = trace_seq_printf(s, "==========>"); 660 ret = trace_seq_puts(s, "==========>");
661 else 661 else
662 ret = trace_seq_printf(s, "<=========="); 662 ret = trace_seq_puts(s, "<==========");
663 663
664 if (!ret) 664 if (!ret)
665 return TRACE_TYPE_PARTIAL_LINE; 665 return TRACE_TYPE_PARTIAL_LINE;
@@ -668,7 +668,7 @@ print_graph_irq(struct trace_iterator *iter, unsigned long addr,
668 if (ret != TRACE_TYPE_HANDLED) 668 if (ret != TRACE_TYPE_HANDLED)
669 return ret; 669 return ret;
670 670
671 ret = trace_seq_printf(s, "\n"); 671 ret = trace_seq_putc(s, '\n');
672 672
673 if (!ret) 673 if (!ret)
674 return TRACE_TYPE_PARTIAL_LINE; 674 return TRACE_TYPE_PARTIAL_LINE;
@@ -705,13 +705,13 @@ trace_print_graph_duration(unsigned long long duration, struct trace_seq *s)
705 len += strlen(nsecs_str); 705 len += strlen(nsecs_str);
706 } 706 }
707 707
708 ret = trace_seq_printf(s, " us "); 708 ret = trace_seq_puts(s, " us ");
709 if (!ret) 709 if (!ret)
710 return TRACE_TYPE_PARTIAL_LINE; 710 return TRACE_TYPE_PARTIAL_LINE;
711 711
712 /* Print remaining spaces to fit the row's width */ 712 /* Print remaining spaces to fit the row's width */
713 for (i = len; i < 7; i++) { 713 for (i = len; i < 7; i++) {
714 ret = trace_seq_printf(s, " "); 714 ret = trace_seq_putc(s, ' ');
715 if (!ret) 715 if (!ret)
716 return TRACE_TYPE_PARTIAL_LINE; 716 return TRACE_TYPE_PARTIAL_LINE;
717 } 717 }
@@ -731,13 +731,13 @@ print_graph_duration(unsigned long long duration, struct trace_seq *s,
731 /* No real adata, just filling the column with spaces */ 731 /* No real adata, just filling the column with spaces */
732 switch (duration) { 732 switch (duration) {
733 case DURATION_FILL_FULL: 733 case DURATION_FILL_FULL:
734 ret = trace_seq_printf(s, " | "); 734 ret = trace_seq_puts(s, " | ");
735 return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; 735 return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
736 case DURATION_FILL_START: 736 case DURATION_FILL_START:
737 ret = trace_seq_printf(s, " "); 737 ret = trace_seq_puts(s, " ");
738 return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; 738 return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
739 case DURATION_FILL_END: 739 case DURATION_FILL_END:
740 ret = trace_seq_printf(s, " |"); 740 ret = trace_seq_puts(s, " |");
741 return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE; 741 return ret ? TRACE_TYPE_HANDLED : TRACE_TYPE_PARTIAL_LINE;
742 } 742 }
743 743
@@ -745,10 +745,10 @@ print_graph_duration(unsigned long long duration, struct trace_seq *s,
745 if (flags & TRACE_GRAPH_PRINT_OVERHEAD) { 745 if (flags & TRACE_GRAPH_PRINT_OVERHEAD) {
746 /* Duration exceeded 100 msecs */ 746 /* Duration exceeded 100 msecs */
747 if (duration > 100000ULL) 747 if (duration > 100000ULL)
748 ret = trace_seq_printf(s, "! "); 748 ret = trace_seq_puts(s, "! ");
749 /* Duration exceeded 10 msecs */ 749 /* Duration exceeded 10 msecs */
750 else if (duration > 10000ULL) 750 else if (duration > 10000ULL)
751 ret = trace_seq_printf(s, "+ "); 751 ret = trace_seq_puts(s, "+ ");
752 } 752 }
753 753
754 /* 754 /*
@@ -757,7 +757,7 @@ print_graph_duration(unsigned long long duration, struct trace_seq *s,
757 * to fill out the space. 757 * to fill out the space.
758 */ 758 */
759 if (ret == -1) 759 if (ret == -1)
760 ret = trace_seq_printf(s, " "); 760 ret = trace_seq_puts(s, " ");
761 761
762 /* Catching here any failure happenned above */ 762 /* Catching here any failure happenned above */
763 if (!ret) 763 if (!ret)
@@ -767,7 +767,7 @@ print_graph_duration(unsigned long long duration, struct trace_seq *s,
767 if (ret != TRACE_TYPE_HANDLED) 767 if (ret != TRACE_TYPE_HANDLED)
768 return ret; 768 return ret;
769 769
770 ret = trace_seq_printf(s, "| "); 770 ret = trace_seq_puts(s, "| ");
771 if (!ret) 771 if (!ret)
772 return TRACE_TYPE_PARTIAL_LINE; 772 return TRACE_TYPE_PARTIAL_LINE;
773 773
@@ -817,7 +817,7 @@ print_graph_entry_leaf(struct trace_iterator *iter,
817 817
818 /* Function */ 818 /* Function */
819 for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) { 819 for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) {
820 ret = trace_seq_printf(s, " "); 820 ret = trace_seq_putc(s, ' ');
821 if (!ret) 821 if (!ret)
822 return TRACE_TYPE_PARTIAL_LINE; 822 return TRACE_TYPE_PARTIAL_LINE;
823 } 823 }
@@ -858,7 +858,7 @@ print_graph_entry_nested(struct trace_iterator *iter,
858 858
859 /* Function */ 859 /* Function */
860 for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) { 860 for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) {
861 ret = trace_seq_printf(s, " "); 861 ret = trace_seq_putc(s, ' ');
862 if (!ret) 862 if (!ret)
863 return TRACE_TYPE_PARTIAL_LINE; 863 return TRACE_TYPE_PARTIAL_LINE;
864 } 864 }
@@ -917,7 +917,7 @@ print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s,
917 if (ret == TRACE_TYPE_PARTIAL_LINE) 917 if (ret == TRACE_TYPE_PARTIAL_LINE)
918 return TRACE_TYPE_PARTIAL_LINE; 918 return TRACE_TYPE_PARTIAL_LINE;
919 919
920 ret = trace_seq_printf(s, " | "); 920 ret = trace_seq_puts(s, " | ");
921 if (!ret) 921 if (!ret)
922 return TRACE_TYPE_PARTIAL_LINE; 922 return TRACE_TYPE_PARTIAL_LINE;
923 } 923 }
@@ -1117,7 +1117,7 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
1117 1117
1118 /* Closing brace */ 1118 /* Closing brace */
1119 for (i = 0; i < trace->depth * TRACE_GRAPH_INDENT; i++) { 1119 for (i = 0; i < trace->depth * TRACE_GRAPH_INDENT; i++) {
1120 ret = trace_seq_printf(s, " "); 1120 ret = trace_seq_putc(s, ' ');
1121 if (!ret) 1121 if (!ret)
1122 return TRACE_TYPE_PARTIAL_LINE; 1122 return TRACE_TYPE_PARTIAL_LINE;
1123 } 1123 }
@@ -1129,7 +1129,7 @@ print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
1129 * belongs to, write out the function name. 1129 * belongs to, write out the function name.
1130 */ 1130 */
1131 if (func_match) { 1131 if (func_match) {
1132 ret = trace_seq_printf(s, "}\n"); 1132 ret = trace_seq_puts(s, "}\n");
1133 if (!ret) 1133 if (!ret)
1134 return TRACE_TYPE_PARTIAL_LINE; 1134 return TRACE_TYPE_PARTIAL_LINE;
1135 } else { 1135 } else {
@@ -1179,13 +1179,13 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent,
1179 /* Indentation */ 1179 /* Indentation */
1180 if (depth > 0) 1180 if (depth > 0)
1181 for (i = 0; i < (depth + 1) * TRACE_GRAPH_INDENT; i++) { 1181 for (i = 0; i < (depth + 1) * TRACE_GRAPH_INDENT; i++) {
1182 ret = trace_seq_printf(s, " "); 1182 ret = trace_seq_putc(s, ' ');
1183 if (!ret) 1183 if (!ret)
1184 return TRACE_TYPE_PARTIAL_LINE; 1184 return TRACE_TYPE_PARTIAL_LINE;
1185 } 1185 }
1186 1186
1187 /* The comment */ 1187 /* The comment */
1188 ret = trace_seq_printf(s, "/* "); 1188 ret = trace_seq_puts(s, "/* ");
1189 if (!ret) 1189 if (!ret)
1190 return TRACE_TYPE_PARTIAL_LINE; 1190 return TRACE_TYPE_PARTIAL_LINE;
1191 1191
@@ -1216,7 +1216,7 @@ print_graph_comment(struct trace_seq *s, struct trace_entry *ent,
1216 s->len--; 1216 s->len--;
1217 } 1217 }
1218 1218
1219 ret = trace_seq_printf(s, " */\n"); 1219 ret = trace_seq_puts(s, " */\n");
1220 if (!ret) 1220 if (!ret)
1221 return TRACE_TYPE_PARTIAL_LINE; 1221 return TRACE_TYPE_PARTIAL_LINE;
1222 1222
@@ -1448,7 +1448,7 @@ static struct trace_event graph_trace_ret_event = {
1448 .funcs = &graph_functions 1448 .funcs = &graph_functions
1449}; 1449};
1450 1450
1451static struct tracer graph_trace __read_mostly = { 1451static struct tracer graph_trace __tracer_data = {
1452 .name = "function_graph", 1452 .name = "function_graph",
1453 .open = graph_trace_open, 1453 .open = graph_trace_open,
1454 .pipe_open = graph_trace_open, 1454 .pipe_open = graph_trace_open,
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 7ed6976493c8..3811487e7a7a 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -243,11 +243,11 @@ find_event_file_link(struct trace_probe *tp, struct ftrace_event_file *file)
243static int 243static int
244disable_trace_probe(struct trace_probe *tp, struct ftrace_event_file *file) 244disable_trace_probe(struct trace_probe *tp, struct ftrace_event_file *file)
245{ 245{
246 struct event_file_link *link = NULL;
247 int wait = 0;
246 int ret = 0; 248 int ret = 0;
247 249
248 if (file) { 250 if (file) {
249 struct event_file_link *link;
250
251 link = find_event_file_link(tp, file); 251 link = find_event_file_link(tp, file);
252 if (!link) { 252 if (!link) {
253 ret = -EINVAL; 253 ret = -EINVAL;
@@ -255,10 +255,7 @@ disable_trace_probe(struct trace_probe *tp, struct ftrace_event_file *file)
255 } 255 }
256 256
257 list_del_rcu(&link->list); 257 list_del_rcu(&link->list);
258 /* synchronize with kprobe_trace_func/kretprobe_trace_func */ 258 wait = 1;
259 synchronize_sched();
260 kfree(link);
261
262 if (!list_empty(&tp->files)) 259 if (!list_empty(&tp->files))
263 goto out; 260 goto out;
264 261
@@ -271,8 +268,22 @@ disable_trace_probe(struct trace_probe *tp, struct ftrace_event_file *file)
271 disable_kretprobe(&tp->rp); 268 disable_kretprobe(&tp->rp);
272 else 269 else
273 disable_kprobe(&tp->rp.kp); 270 disable_kprobe(&tp->rp.kp);
271 wait = 1;
274 } 272 }
275 out: 273 out:
274 if (wait) {
275 /*
276 * Synchronize with kprobe_trace_func/kretprobe_trace_func
277 * to ensure disabled (all running handlers are finished).
278 * This is not only for kfree(), but also the caller,
279 * trace_remove_event_call() supposes it for releasing
280 * event_call related objects, which will be accessed in
281 * the kprobe_trace_func/kretprobe_trace_func.
282 */
283 synchronize_sched();
284 kfree(link); /* Ignored if link == NULL */
285 }
286
276 return ret; 287 return ret;
277} 288}
278 289
@@ -1087,9 +1098,6 @@ kprobe_perf_func(struct trace_probe *tp, struct pt_regs *regs)
1087 __size = sizeof(*entry) + tp->size + dsize; 1098 __size = sizeof(*entry) + tp->size + dsize;
1088 size = ALIGN(__size + sizeof(u32), sizeof(u64)); 1099 size = ALIGN(__size + sizeof(u32), sizeof(u64));
1089 size -= sizeof(u32); 1100 size -= sizeof(u32);
1090 if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE,
1091 "profile buffer not large enough"))
1092 return;
1093 1101
1094 entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx); 1102 entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx);
1095 if (!entry) 1103 if (!entry)
@@ -1120,9 +1128,6 @@ kretprobe_perf_func(struct trace_probe *tp, struct kretprobe_instance *ri,
1120 __size = sizeof(*entry) + tp->size + dsize; 1128 __size = sizeof(*entry) + tp->size + dsize;
1121 size = ALIGN(__size + sizeof(u32), sizeof(u64)); 1129 size = ALIGN(__size + sizeof(u32), sizeof(u64));
1122 size -= sizeof(u32); 1130 size -= sizeof(u32);
1123 if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE,
1124 "profile buffer not large enough"))
1125 return;
1126 1131
1127 entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx); 1132 entry = perf_trace_buf_prepare(size, call->event.type, regs, &rctx);
1128 if (!entry) 1133 if (!entry)
diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
index a5e8f4878bfa..b3dcfb2f0fef 100644
--- a/kernel/trace/trace_mmiotrace.c
+++ b/kernel/trace/trace_mmiotrace.c
@@ -90,7 +90,7 @@ static int mmio_print_pcidev(struct trace_seq *s, const struct pci_dev *dev)
90 if (drv) 90 if (drv)
91 ret += trace_seq_printf(s, " %s\n", drv->name); 91 ret += trace_seq_printf(s, " %s\n", drv->name);
92 else 92 else
93 ret += trace_seq_printf(s, " \n"); 93 ret += trace_seq_puts(s, " \n");
94 return ret; 94 return ret;
95} 95}
96 96
@@ -107,7 +107,7 @@ static void mmio_pipe_open(struct trace_iterator *iter)
107 struct header_iter *hiter; 107 struct header_iter *hiter;
108 struct trace_seq *s = &iter->seq; 108 struct trace_seq *s = &iter->seq;
109 109
110 trace_seq_printf(s, "VERSION 20070824\n"); 110 trace_seq_puts(s, "VERSION 20070824\n");
111 111
112 hiter = kzalloc(sizeof(*hiter), GFP_KERNEL); 112 hiter = kzalloc(sizeof(*hiter), GFP_KERNEL);
113 if (!hiter) 113 if (!hiter)
@@ -209,7 +209,7 @@ static enum print_line_t mmio_print_rw(struct trace_iterator *iter)
209 (rw->value >> 0) & 0xff, rw->pc, 0); 209 (rw->value >> 0) & 0xff, rw->pc, 0);
210 break; 210 break;
211 default: 211 default:
212 ret = trace_seq_printf(s, "rw what?\n"); 212 ret = trace_seq_puts(s, "rw what?\n");
213 break; 213 break;
214 } 214 }
215 if (ret) 215 if (ret)
@@ -245,7 +245,7 @@ static enum print_line_t mmio_print_map(struct trace_iterator *iter)
245 secs, usec_rem, m->map_id, 0UL, 0); 245 secs, usec_rem, m->map_id, 0UL, 0);
246 break; 246 break;
247 default: 247 default:
248 ret = trace_seq_printf(s, "map what?\n"); 248 ret = trace_seq_puts(s, "map what?\n");
249 break; 249 break;
250 } 250 }
251 if (ret) 251 if (ret)
diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
index bb922d9ee51b..34e7cbac0c9c 100644
--- a/kernel/trace/trace_output.c
+++ b/kernel/trace/trace_output.c
@@ -78,7 +78,7 @@ enum print_line_t trace_print_printk_msg_only(struct trace_iterator *iter)
78 78
79 trace_assign_type(field, entry); 79 trace_assign_type(field, entry);
80 80
81 ret = trace_seq_printf(s, "%s", field->buf); 81 ret = trace_seq_puts(s, field->buf);
82 if (!ret) 82 if (!ret)
83 return TRACE_TYPE_PARTIAL_LINE; 83 return TRACE_TYPE_PARTIAL_LINE;
84 84
@@ -558,14 +558,14 @@ seq_print_userip_objs(const struct userstack_entry *entry, struct trace_seq *s,
558 if (ret) 558 if (ret)
559 ret = trace_seq_puts(s, "??"); 559 ret = trace_seq_puts(s, "??");
560 if (ret) 560 if (ret)
561 ret = trace_seq_puts(s, "\n"); 561 ret = trace_seq_putc(s, '\n');
562 continue; 562 continue;
563 } 563 }
564 if (!ret) 564 if (!ret)
565 break; 565 break;
566 if (ret) 566 if (ret)
567 ret = seq_print_user_ip(s, mm, ip, sym_flags); 567 ret = seq_print_user_ip(s, mm, ip, sym_flags);
568 ret = trace_seq_puts(s, "\n"); 568 ret = trace_seq_putc(s, '\n');
569 } 569 }
570 570
571 if (mm) 571 if (mm)
@@ -579,7 +579,7 @@ seq_print_ip_sym(struct trace_seq *s, unsigned long ip, unsigned long sym_flags)
579 int ret; 579 int ret;
580 580
581 if (!ip) 581 if (!ip)
582 return trace_seq_printf(s, "0"); 582 return trace_seq_putc(s, '0');
583 583
584 if (sym_flags & TRACE_ITER_SYM_OFFSET) 584 if (sym_flags & TRACE_ITER_SYM_OFFSET)
585 ret = seq_print_sym_offset(s, "%s", ip); 585 ret = seq_print_sym_offset(s, "%s", ip);
@@ -964,14 +964,14 @@ static enum print_line_t trace_fn_trace(struct trace_iterator *iter, int flags,
964 goto partial; 964 goto partial;
965 965
966 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) { 966 if ((flags & TRACE_ITER_PRINT_PARENT) && field->parent_ip) {
967 if (!trace_seq_printf(s, " <-")) 967 if (!trace_seq_puts(s, " <-"))
968 goto partial; 968 goto partial;
969 if (!seq_print_ip_sym(s, 969 if (!seq_print_ip_sym(s,
970 field->parent_ip, 970 field->parent_ip,
971 flags)) 971 flags))
972 goto partial; 972 goto partial;
973 } 973 }
974 if (!trace_seq_printf(s, "\n")) 974 if (!trace_seq_putc(s, '\n'))
975 goto partial; 975 goto partial;
976 976
977 return TRACE_TYPE_HANDLED; 977 return TRACE_TYPE_HANDLED;
@@ -1210,7 +1210,7 @@ static enum print_line_t trace_stack_print(struct trace_iterator *iter,
1210 1210
1211 if (!seq_print_ip_sym(s, *p, flags)) 1211 if (!seq_print_ip_sym(s, *p, flags))
1212 goto partial; 1212 goto partial;
1213 if (!trace_seq_puts(s, "\n")) 1213 if (!trace_seq_putc(s, '\n'))
1214 goto partial; 1214 goto partial;
1215 } 1215 }
1216 1216
diff --git a/kernel/trace/trace_syscalls.c b/kernel/trace/trace_syscalls.c
index 322e16461072..8fd03657bc7d 100644
--- a/kernel/trace/trace_syscalls.c
+++ b/kernel/trace/trace_syscalls.c
@@ -175,7 +175,7 @@ print_syscall_exit(struct trace_iterator *iter, int flags,
175 entry = syscall_nr_to_meta(syscall); 175 entry = syscall_nr_to_meta(syscall);
176 176
177 if (!entry) { 177 if (!entry) {
178 trace_seq_printf(s, "\n"); 178 trace_seq_putc(s, '\n');
179 return TRACE_TYPE_HANDLED; 179 return TRACE_TYPE_HANDLED;
180 } 180 }
181 181
@@ -566,15 +566,15 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id)
566 if (!sys_data) 566 if (!sys_data)
567 return; 567 return;
568 568
569 head = this_cpu_ptr(sys_data->enter_event->perf_events);
570 if (hlist_empty(head))
571 return;
572
569 /* get the size after alignment with the u32 buffer size field */ 573 /* get the size after alignment with the u32 buffer size field */
570 size = sizeof(unsigned long) * sys_data->nb_args + sizeof(*rec); 574 size = sizeof(unsigned long) * sys_data->nb_args + sizeof(*rec);
571 size = ALIGN(size + sizeof(u32), sizeof(u64)); 575 size = ALIGN(size + sizeof(u32), sizeof(u64));
572 size -= sizeof(u32); 576 size -= sizeof(u32);
573 577
574 if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE,
575 "perf buffer not large enough"))
576 return;
577
578 rec = (struct syscall_trace_enter *)perf_trace_buf_prepare(size, 578 rec = (struct syscall_trace_enter *)perf_trace_buf_prepare(size,
579 sys_data->enter_event->event.type, regs, &rctx); 579 sys_data->enter_event->event.type, regs, &rctx);
580 if (!rec) 580 if (!rec)
@@ -583,8 +583,6 @@ static void perf_syscall_enter(void *ignore, struct pt_regs *regs, long id)
583 rec->nr = syscall_nr; 583 rec->nr = syscall_nr;
584 syscall_get_arguments(current, regs, 0, sys_data->nb_args, 584 syscall_get_arguments(current, regs, 0, sys_data->nb_args,
585 (unsigned long *)&rec->args); 585 (unsigned long *)&rec->args);
586
587 head = this_cpu_ptr(sys_data->enter_event->perf_events);
588 perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head, NULL); 586 perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head, NULL);
589} 587}
590 588
@@ -642,18 +640,14 @@ static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
642 if (!sys_data) 640 if (!sys_data)
643 return; 641 return;
644 642
643 head = this_cpu_ptr(sys_data->exit_event->perf_events);
644 if (hlist_empty(head))
645 return;
646
645 /* We can probably do that at build time */ 647 /* We can probably do that at build time */
646 size = ALIGN(sizeof(*rec) + sizeof(u32), sizeof(u64)); 648 size = ALIGN(sizeof(*rec) + sizeof(u32), sizeof(u64));
647 size -= sizeof(u32); 649 size -= sizeof(u32);
648 650
649 /*
650 * Impossible, but be paranoid with the future
651 * How to put this check outside runtime?
652 */
653 if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE,
654 "exit event has grown above perf buffer size"))
655 return;
656
657 rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size, 651 rec = (struct syscall_trace_exit *)perf_trace_buf_prepare(size,
658 sys_data->exit_event->event.type, regs, &rctx); 652 sys_data->exit_event->event.type, regs, &rctx);
659 if (!rec) 653 if (!rec)
@@ -661,8 +655,6 @@ static void perf_syscall_exit(void *ignore, struct pt_regs *regs, long ret)
661 655
662 rec->nr = syscall_nr; 656 rec->nr = syscall_nr;
663 rec->ret = syscall_get_return_value(current, regs); 657 rec->ret = syscall_get_return_value(current, regs);
664
665 head = this_cpu_ptr(sys_data->exit_event->perf_events);
666 perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head, NULL); 658 perf_trace_buf_submit(rec, size, rctx, 0, 1, regs, head, NULL);
667} 659}
668 660
diff --git a/kernel/trace/trace_uprobe.c b/kernel/trace/trace_uprobe.c
index d5d0cd368a56..a23d2d71188e 100644
--- a/kernel/trace/trace_uprobe.c
+++ b/kernel/trace/trace_uprobe.c
@@ -818,8 +818,6 @@ static void uprobe_perf_print(struct trace_uprobe *tu,
818 818
819 size = SIZEOF_TRACE_ENTRY(is_ret_probe(tu)); 819 size = SIZEOF_TRACE_ENTRY(is_ret_probe(tu));
820 size = ALIGN(size + tu->size + sizeof(u32), sizeof(u64)) - sizeof(u32); 820 size = ALIGN(size + tu->size + sizeof(u32), sizeof(u64)) - sizeof(u32);
821 if (WARN_ONCE(size > PERF_MAX_TRACE_SIZE, "profile buffer not large enough"))
822 return;
823 821
824 preempt_disable(); 822 preempt_disable();
825 head = this_cpu_ptr(call->perf_events); 823 head = this_cpu_ptr(call->perf_events);
diff --git a/kernel/wait.c b/kernel/wait.c
index ce0daa320a26..dec68bd4e9d8 100644
--- a/kernel/wait.c
+++ b/kernel/wait.c
@@ -333,7 +333,8 @@ int __wait_on_atomic_t(wait_queue_head_t *wq, struct wait_bit_queue *q,
333 prepare_to_wait(wq, &q->wait, mode); 333 prepare_to_wait(wq, &q->wait, mode);
334 val = q->key.flags; 334 val = q->key.flags;
335 if (atomic_read(val) == 0) 335 if (atomic_read(val) == 0)
336 ret = (*action)(val); 336 break;
337 ret = (*action)(val);
337 } while (!ret && atomic_read(val) != 0); 338 } while (!ret && atomic_read(val) != 0);
338 finish_wait(wq, &q->wait); 339 finish_wait(wq, &q->wait);
339 return ret; 340 return ret;