void *trace_find_next_entry_inc(struct trace_iterator *iter)
{
	iter->ent = __find_next_entry(iter, &iter->cpu,
				      &iter->lost_events, &iter->ts);

	if (iter->ent)
		trace_iterator_increment(iter);

	return iter->ent ? iter : NULL;
}

struct trace_iterator *tracepoint_print_iter;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};

static const struct file_operations tracing_fops = {
	.open		= tracing_open,
	.read		= seq_read,
	.write		= tracing_write_stub,
	.llseek		= tracing_lseek,
	.release	= tracing_release,
};


enum print_line_t print_trace_line(struct trace_iterator *iter)
{
	struct trace_array *tr = iter->tr;
	unsigned long trace_flags = tr->trace_flags;
	enum print_line_t ret;

	if (iter->lost_events) {
		trace_seq_printf(&iter->seq, "CPU:%d [LOST %lu EVENTS]\n",
				 iter->cpu, iter->lost_events);
		if (trace_seq_has_overflowed(&iter->seq))
			return TRACE_TYPE_PARTIAL_LINE;
	}

	if (iter->trace && iter->trace->print_line) {
		ret = iter->trace->print_line(iter);
		if (ret != TRACE_TYPE_UNHANDLED)
			return ret;
	}

	if (iter->ent->type == TRACE_BPUTS &&
			trace_flags & TRACE_ITER_PRINTK &&
			trace_flags & TRACE_ITER_PRINTK_MSGONLY)
		return trace_print_bputs_msg_only(iter);

	if (iter->ent->type == TRACE_BPRINT &&
			trace_flags & TRACE_ITER_PRINTK &&
			trace_flags & TRACE_ITER_PRINTK_MSGONLY)
		return trace_print_bprintk_msg_only(iter);

	if (iter->ent->type == TRACE_PRINT &&
			trace_flags & TRACE_ITER_PRINTK &&
			trace_flags & TRACE_ITER_PRINTK_MSGONLY)
		return trace_print_printk_msg_only(iter);

	if (trace_flags & TRACE_ITER_BIN)
		return print_bin_fmt(iter);

	if (trace_flags & TRACE_ITER_HEX)
		return print_hex_fmt(iter);

	if (trace_flags & TRACE_ITER_RAW)
		return print_raw_fmt(iter);

	return print_trace_fmt(iter);
}

tracing: Fix possible double free on failure of allocating trace buffer

Jing Xia and Chunyan Zhang reported that on failing to allocate part of the
tracing buffer, memory is freed, but the pointers that point to them are not
initialized back to NULL, and later paths may try to free the freed memory
again. Jing and Chunyan fixed one of the locations that does this, but
missed a spot.

Link: http://lkml.kernel.org/r/20171226071253.8968-1-chunyan.zhang@spreadtrum.com

Cc: stable@vger.kernel.org
Fixes: 737223fbca3b1 ("tracing: Consolidate buffer allocation code")
Reported-by: Jing Xia <jing.xia@spreadtrum.com>
Reported-by: Chunyan Zhang <chunyan.zhang@spreadtrum.com>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

struct trace_iterator *tracepoint_print_iter;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

enum ftrace_dump_mode ftrace_dump_on_oops;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

#define TRACE_DEFAULT_FLAGS						\
	(FUNCTION_DEFAULT_FLAGS |					\
	 TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |			\
	 TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO |		\
	 TRACE_ITER_RECORD_CMD | TRACE_ITER_OVERWRITE |			\
	 TRACE_ITER_IRQ_INFO | TRACE_ITER_MARKERS)

#define TOP_LEVEL_TRACE_FLAGS (TRACE_ITER_PRINTK |			\
	       TRACE_ITER_PRINTK_MSGONLY | TRACE_ITER_RECORD_CMD)

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;


static int tracing_release_generic_tr(struct inode *inode, struct file *file)
{
	struct trace_array *tr = inode->i_private;

	trace_array_put(tr);
	return 0;
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;


static void tracing_start_tr(struct trace_array *tr)
{
	struct ring_buffer *buffer;
	unsigned long flags;

	if (tracing_disabled)
		return;

	/* If global, we need to also start the max tracer */
	if (tr->flags & TRACE_ARRAY_FL_GLOBAL)
		return tracing_start();

	raw_spin_lock_irqsave(&tr->start_lock, flags);

	if (--tr->stop_count) {
		if (tr->stop_count < 0) {
			/* Someone screwed up their debugging */
			WARN_ON_ONCE(1);
			tr->stop_count = 0;
		}
		goto out;
	}

	buffer = tr->trace_buffer.buffer;
	if (buffer)
		ring_buffer_record_enable(buffer);

 out:
	raw_spin_unlock_irqrestore(&tr->start_lock, flags);
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;


get_total_entries(struct trace_buffer *buf,
		  unsigned long *total, unsigned long *entries)
{
	unsigned long count;
	int cpu;

	*total = 0;
	*entries = 0;

	for_each_tracing_cpu(cpu) {
		count = ring_buffer_entries_cpu(buf->buffer, cpu);
		/*
		 * If this buffer has skipped entries, then we hold all
		 * entries for the trace and we need to ignore the
		 * ones before the time stamp.
		 */
		if (per_cpu_ptr(buf->data, cpu)->skipped_entries) {
			count -= per_cpu_ptr(buf->data, cpu)->skipped_entries;
			/* total is the same as the entries */
			*total += count;
		} else
			*total += count +
				ring_buffer_overrun_cpu(buf->buffer, cpu);
		*entries += count;
	}
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};


static void enable_trace_buffered_event(void *data)
{
	/* Probably not needed, but do it anyway */
	smp_rmb();
	this_cpu_dec(trace_buffered_event_cnt);
}

static bool __read_mostly

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

static DEFINE_MUTEX(trace_eval_mutex);

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static DEFINE_SPINLOCK(tracepoint_iter_lock);

static DEFINE_MUTEX(tracepoint_printk_mutex);

static DEFINE_MUTEX(ftrace_export_lock);

static struct trace_export __rcu *ftrace_exports_list

static DEFINE_STATIC_KEY_FALSE(ftrace_exports_enabled);

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};


rm_trace_export(struct trace_export **list, struct trace_export *export)
{
	struct trace_export **p;

	for (p = list; *p != NULL; p = &(*p)->next)
		if (*p == export)
			break;

	if (*p != export)
		return -1;

	rcu_assign_pointer(*p, (*p)->next);

	return 0;
}

struct trace_iterator *tracepoint_print_iter;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};

static const struct file_operations tracing_fops = {
	.open		= tracing_open,
	.read		= seq_read,
	.write		= tracing_write_stub,
	.llseek		= tracing_lseek,
	.release	= tracing_release,
};


static int eval_map_show(struct seq_file *m, void *v)
{
	union trace_eval_map_item *ptr = v;

	seq_printf(m, "%s %ld (%s)\n",
		   ptr->map.eval_string, ptr->map.eval_value,
		   ptr->map.system);

	return 0;
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

union trace_eval_map_item

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;


dummy_set_flag(struct trace_array *tr, u32 old_flags, u32 bit, int set)
{
	return 0;
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};


tracing_cpumask_write(struct file *filp, const char __user *ubuf,
		      size_t count, loff_t *ppos)
{
	struct trace_array *tr = file_inode(filp)->i_private;
	cpumask_var_t tracing_cpumask_new;
	int err, cpu;

	if (!alloc_cpumask_var(&tracing_cpumask_new, GFP_KERNEL))
		return -ENOMEM;

	err = cpumask_parse_user(ubuf, count, tracing_cpumask_new);
	if (err)
		goto err_unlock;

	local_irq_disable();
	arch_spin_lock(&tr->max_lock);
	for_each_tracing_cpu(cpu) {
		/*
		 * Increase/decrease the disabled counter if we are
		 * about to flip a bit in the cpumask:
		 */
		if (cpumask_test_cpu(cpu, tr->tracing_cpumask) &&
				!cpumask_test_cpu(cpu, tracing_cpumask_new)) {
			atomic_inc(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled);
			ring_buffer_record_disable_cpu(tr->trace_buffer.buffer, cpu);
		}
		if (!cpumask_test_cpu(cpu, tr->tracing_cpumask) &&
				cpumask_test_cpu(cpu, tracing_cpumask_new)) {
			atomic_dec(&per_cpu_ptr(tr->trace_buffer.data, cpu)->disabled);
			ring_buffer_record_enable_cpu(tr->trace_buffer.buffer, cpu);
		}
	}
	arch_spin_unlock(&tr->max_lock);
	local_irq_enable();

	cpumask_copy(tr->tracing_cpumask, tracing_cpumask_new);
	free_cpumask_var(tracing_cpumask_new);

	return count;

err_unlock:
	free_cpumask_var(tracing_cpumask_new);

	return err;
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

cpumask_var_t __read_mostly

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;


tracing_free_buffer_release(struct inode *inode, struct file *filp)
{
	struct trace_array *tr = inode->i_private;

	/* disable tracing ? */
	if (tr->trace_flags & TRACE_ITER_STOP_ON_FREE)
		tracer_tracing_off(tr);
	/* resize the ring buffer to 0 */
	tracing_resize_ring_buffer(tr, 0, RING_BUFFER_ALL_CPUS);

	trace_array_put(tr);

	return 0;
}

struct trace_iterator *tracepoint_print_iter;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};

static const struct file_operations tracing_fops = {
	.open		= tracing_open,
	.read		= seq_read,
	.write		= tracing_write_stub,
	.llseek		= tracing_lseek,
	.release	= tracing_release,
};


void trace_array_put(struct trace_array *this_tr)
{
	mutex_lock(&trace_types_lock);
	__trace_array_put(this_tr);
	mutex_unlock(&trace_types_lock);
}

struct trace_iterator *tracepoint_print_iter;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};

static const struct file_operations tracing_fops = {
	.open		= tracing_open,
	.read		= seq_read,
	.write		= tracing_write_stub,
	.llseek		= tracing_lseek,
	.release	= tracing_release,
};


u64 ftrace_now(int cpu)
{
	return buffer_ftrace_now(&global_trace.trace_buffer, cpu);
}

int tracepoint_printk;

static int tracing_disabled = 1;

int __disable_trace_on_warning;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static int trace_buffered_event_ref;

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static int buffers_allocated;


void trace_latency_header(struct seq_file *m)
{
	struct trace_iterator *iter = m->private;
	struct trace_array *tr = iter->tr;

	/* print nothing if the buffers are empty */
	if (trace_empty(iter))
		return;

	if (iter->iter_flags & TRACE_FILE_LAT_FMT)
		print_trace_header(m, iter);

	if (!(tr->trace_flags & TRACE_ITER_VERBOSE))
		print_lat_help_header(m);
}


int trace_vprintk(unsigned long ip, const char *fmt, va_list args)
{
	return trace_array_vprintk(&global_trace, ip, fmt, args);
}

int tracepoint_printk;

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static int trace_buffered_event_ref;

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};

static const struct file_operations tracing_fops = {
	.open		= tracing_open,
	.read		= seq_read,
	.write		= tracing_write_stub,
	.llseek		= tracing_lseek,
	.release	= tracing_release,
};


static int tracing_open_generic_tr(struct inode *inode, struct file *filp)
{
	struct trace_array *tr = inode->i_private;

	if (tracing_disabled)
		return -ENODEV;

	if (trace_array_get(tr) < 0)
		return -ENODEV;

	filp->private_data = inode->i_private;

	return 0;
}


rb_simple_write(struct file *filp, const char __user *ubuf,
		size_t cnt, loff_t *ppos)
{
	struct trace_array *tr = filp->private_data;
	struct ring_buffer *buffer = tr->trace_buffer.buffer;
	unsigned long val;
	int ret;

	ret = kstrtoul_from_user(ubuf, cnt, 10, &val);
	if (ret)
		return ret;

	if (buffer) {
		mutex_lock(&trace_types_lock);
		if (val) {
			tracer_tracing_on(tr);
			if (tr->current_trace->start)
				tr->current_trace->start(tr);
		} else {
			tracer_tracing_off(tr);
			if (tr->current_trace->stop)
				tr->current_trace->stop(tr);
		}
		mutex_unlock(&trace_types_lock);
	}

	(*ppos)++;

	return cnt;
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;


static void get_tr_index(void *data, struct trace_array **ptr,
			 unsigned int *pindex)
{
	*pindex = *(unsigned char *)data;

	*ptr = container_of(data - *pindex, struct trace_array,
			    trace_flags_index);
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;


static void print_event_info(struct trace_buffer *buf, struct seq_file *m)
{
	unsigned long total;
	unsigned long entries;

	get_total_entries(buf, &total, &entries);
	seq_printf(m, "# entries-in-buffer/entries-written: %lu/%lu   #P:%d\n",
		   entries, total, num_online_cpus());
	seq_puts(m, "#\n");
}


void tracing_stop(void)
{
	struct ring_buffer *buffer;
	unsigned long flags;

	raw_spin_lock_irqsave(&global_trace.start_lock, flags);
	if (global_trace.stop_count++)
		goto out;

	/* Prevent the buffers from switching */
	arch_spin_lock(&global_trace.max_lock);

	buffer = global_trace.trace_buffer.buffer;
	if (buffer)
		ring_buffer_record_disable(buffer);

#ifdef CONFIG_TRACER_MAX_TRACE
	buffer = global_trace.max_buffer.buffer;
	if (buffer)
		ring_buffer_record_disable(buffer);
#endif

	arch_spin_unlock(&global_trace.max_lock);

 out:
	raw_spin_unlock_irqrestore(&global_trace.start_lock, flags);
}

struct trace_iterator *tracepoint_print_iter;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};


void trace_buffered_event_disable(void)
{
	int cpu;

	WARN_ON_ONCE(!mutex_is_locked(&event_mutex));

	if (WARN_ON_ONCE(!trace_buffered_event_ref))
		return;

	if (--trace_buffered_event_ref)
		return;

	preempt_disable();
	/* For each CPU, set the buffer as used. */
	smp_call_function_many(tracing_buffer_mask,
			       disable_trace_buffered_event, NULL, 1);
	preempt_enable();

	/* Wait for all current users to finish */
	synchronize_sched();

	for_each_tracing_cpu(cpu) {
		free_page((unsigned long)per_cpu(trace_buffered_event, cpu));
		per_cpu(trace_buffered_event, cpu) = NULL;
	}
	/*
	 * Make sure trace_buffered_event is NULL before clearing
	 * trace_buffered_event_cnt.
	 */
	smp_wmb();

	preempt_disable();
	/* Do the work on each cpu */
	smp_call_function_many(tracing_buffer_mask,
			       enable_trace_buffered_event, NULL, 1);
	preempt_enable();
}

int tracepoint_printk;

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static int trace_buffered_event_ref;

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static int buffers_allocated;


int trace_pid_write(struct trace_pid_list *filtered_pids,
		    struct trace_pid_list **new_pid_list,
		    const char __user *ubuf, size_t cnt)
{
	struct trace_pid_list *pid_list;
	struct trace_parser parser;
	unsigned long val;
	int nr_pids = 0;
	ssize_t read = 0;
	ssize_t ret = 0;
	loff_t pos;
	pid_t pid;

	if (trace_parser_get_init(&parser, PID_BUF_SIZE + 1))
		return -ENOMEM;

	/*
	 * Always recreate a new array. The write is an all or nothing
	 * operation. Always create a new array when adding new pids by
	 * the user. If the operation fails, then the current list is
	 * not modified.
	 */
	pid_list = kmalloc(sizeof(*pid_list), GFP_KERNEL);
	if (!pid_list)
		return -ENOMEM;

	pid_list->pid_max = READ_ONCE(pid_max);

	/* Only truncating will shrink pid_max */
	if (filtered_pids && filtered_pids->pid_max > pid_list->pid_max)
		pid_list->pid_max = filtered_pids->pid_max;

	pid_list->pids = vzalloc((pid_list->pid_max + 7) >> 3);
	if (!pid_list->pids) {
		kfree(pid_list);
		return -ENOMEM;
	}

	if (filtered_pids) {
		/* copy the current bits to the new max */
		for_each_set_bit(pid, filtered_pids->pids,
				 filtered_pids->pid_max) {
			set_bit(pid, pid_list->pids);
			nr_pids++;
		}
	}

	while (cnt > 0) {

		pos = 0;

		ret = trace_get_user(&parser, ubuf, cnt, &pos);
		if (ret < 0 || !trace_parser_loaded(&parser))
			break;

		read += ret;
		ubuf += ret;
		cnt -= ret;

		parser.buffer[parser.idx] = 0;

		ret = -EINVAL;
		if (kstrtoul(parser.buffer, 0, &val))
			break;
		if (val >= pid_list->pid_max)
			break;

		pid = (pid_t)val;

		set_bit(pid, pid_list->pids);
		nr_pids++;

		trace_parser_clear(&parser);
		ret = 0;
	}
	trace_parser_put(&parser);

	if (ret < 0) {
		trace_free_pid_list(pid_list);
		return ret;
	}

	if (!nr_pids) {
		/* Cleared the list of pids */
		trace_free_pid_list(pid_list);
		read = ret;
		pid_list = NULL;
	}

	*new_pid_list = pid_list;

	return read;
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

#define PID_BUF_SIZE		127

#define TRACE_BUF_SIZE_DEFAULT	1441792UL /* 16384 * 88 (sizeof(entry)) */

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);


static int instance_rmdir(const char *name)
{
	struct trace_array *tr;
	int found = 0;
	int ret;
	int i;

	mutex_lock(&event_mutex);
	mutex_lock(&trace_types_lock);

	ret = -ENODEV;
	list_for_each_entry(tr, &ftrace_trace_arrays, list) {
		if (tr->name && strcmp(tr->name, name) == 0) {
			found = 1;
			break;
		}
	}
	if (!found)
		goto out_unlock;

	ret = -EBUSY;
	if (tr->ref || (tr->current_trace && tr->current_trace->ref))
		goto out_unlock;

	list_del(&tr->list);

	/* Disable all the flags that were enabled coming in */
	for (i = 0; i < TRACE_FLAGS_MAX_SIZE; i++) {
		if ((1 << i) & ZEROED_TRACE_FLAGS)
			set_tracer_flag(tr, 1 << i, 0);
	}

	tracing_set_nop(tr);
	clear_ftrace_function_probes(tr);
	event_trace_del_tracer(tr);
	ftrace_clear_pids(tr);
	ftrace_destroy_function_files(tr);
	tracefs_remove_recursive(tr->dir);
	free_trace_buffers(tr);

	for (i = 0; i < tr->nr_topts; i++) {
		kfree(tr->topts[i].topts);
	}
	kfree(tr->topts);

	free_cpumask_var(tr->tracing_cpumask);
	kfree(tr->name);
	kfree(tr);

	ret = 0;

 out_unlock:
	mutex_unlock(&trace_types_lock);
	mutex_unlock(&event_mutex);

	return ret;
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

#define ZEROED_TRACE_FLAGS \
	(TRACE_ITER_EVENT_FORK | TRACE_ITER_FUNC_FORK)

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;


int tracing_update_buffers(void)
{
	int ret = 0;

	mutex_lock(&trace_types_lock);
	if (!ring_buffer_expanded)
		ret = __tracing_resize_ring_buffer(&global_trace, trace_buf_size,
						RING_BUFFER_ALL_CPUS);
	mutex_unlock(&trace_types_lock);

	return ret;
}

bool ring_buffer_expanded;

int tracepoint_printk;

static int tracing_disabled = 1;

int __disable_trace_on_warning;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static int trace_buffered_event_ref;

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static int buffers_allocated;

static void
create_trace_option_files(struct trace_array *tr, struct tracer *tracer);

struct ftrace_buffer_info {
	struct trace_iterator	iter;
	void			*spare;
	unsigned int		spare_cpu;
	unsigned int		read;
}

static int tracing_buffers_open(struct inode *inode, struct file *filp);

static int tracing_buffers_release(struct inode *inode, struct file *file);

static ssize_t tracing_buffers_splice_read(struct file *file, loff_t *ppos,
		   struct pipe_inode_info *pipe, size_t len, unsigned int flags);

struct buffer_ref {
	struct ring_buffer	*buffer;
	void			*page;
	int			cpu;
	int			ref;
}

static void
init_tracer_tracefs(struct trace_array *tr, struct dentry *d_tracer);


static void __update_tracer_options(struct trace_array *tr)
{
	struct tracer *t;

	for (t = trace_types; t; t = t->next)
		add_tracer_options(tr, t);
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static DEFINE_SPINLOCK(tracepoint_iter_lock);


void trace_buffered_event_enable(void)
{
	struct ring_buffer_event *event;
	struct page *page;
	int cpu;

	WARN_ON_ONCE(!mutex_is_locked(&event_mutex));

	if (trace_buffered_event_ref++)
		return;

	for_each_tracing_cpu(cpu) {
		page = alloc_pages_node(cpu_to_node(cpu),
					GFP_KERNEL | __GFP_NORETRY, 0);
		if (!page)
			goto failed;

		event = page_address(page);
		memset(event, 0, sizeof(*event));

		per_cpu(trace_buffered_event, cpu) = event;

		preempt_disable();
		if (cpu == smp_processor_id() &&
		    this_cpu_read(trace_buffered_event) !=
		    per_cpu(trace_buffered_event, cpu))
			WARN_ON_ONCE(1);
		preempt_enable();
	}

	return;
 failed:
	trace_buffered_event_disable();
}

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

#define TRACE_BUF_SIZE_DEFAULT	1441792UL /* 16384 * 88 (sizeof(entry)) */

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

static DEFINE_PER_CPU(int, ftrace_stack_reserve);

static DEFINE_PER_CPU(int, user_stack_count);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static int buffers_allocated;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};


void *trace_pid_next(struct trace_pid_list *pid_list, void *v, loff_t *pos)
{
	unsigned long pid = (unsigned long)v;

	(*pos)++;

	/* pid already is +1 of the actual prevous bit */
	pid = find_next_bit(pid_list->pids, pid_list->pid_max, pid);

	/* Return pid + 1 to allow zero to be represented */
	if (pid < pid_list->pid_max)
		return (void *)(pid + 1);

	return NULL;
}

struct trace_iterator *tracepoint_print_iter;

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static struct ring_buffer *temp_buffer;

static struct trace_export __rcu *ftrace_exports_list

#define FTRACE_STACK_MAX_ENTRIES (PAGE_SIZE / sizeof(unsigned long))

struct ftrace_stack {
	unsigned long		calls[FTRACE_STACK_MAX_ENTRIES];
}

static DEFINE_PER_CPU(struct ftrace_stack, ftrace_stack);

struct trace_buffer_struct {
	int nesting;
	char buffer[4][TRACE_BUF_SIZE];
}

static struct trace_buffer_struct *trace_percpu_buffer;

static const struct seq_operations tracer_seq_ops = {
	.start		= s_start,
	.next		= s_next,
	.stop		= s_stop,
	.show		= s_show,
};

static const struct seq_operations show_traces_seq_ops = {
	.start		= t_start,
	.next		= t_next,
	.stop		= t_stop,
	.show		= t_show,
};


static void *t_start(struct seq_file *m, loff_t *pos)
{
	struct trace_array *tr = m->private;
	struct tracer *t;
	loff_t l = 0;

	mutex_lock(&trace_types_lock);

	t = get_tracer_for_array(tr, trace_types);
	for (; t && l < *pos; t = t_next(m, t, &l))
			;

	return t;
}


static void trace_module_remove_evals(struct module *mod)
{
	union trace_eval_map_item *map;
	union trace_eval_map_item **last = &trace_eval_maps;

	if (!mod->num_trace_evals)
		return;

	mutex_lock(&trace_eval_mutex);

	map = trace_eval_maps;

	while (map) {
		if (map->head.mod == mod)
			break;
		map = trace_eval_jmp_to_tail(map);
		last = &map->tail.next;
		map = map->tail.next;
	}
	if (!map)
		goto out;

	*last = trace_eval_jmp_to_tail(map)->tail.next;
	kfree(map);
 out:
	mutex_unlock(&trace_eval_mutex);
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

union trace_eval_map_item

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static DEFINE_SPINLOCK(tracepoint_iter_lock);


static int trace_save_cmdline(struct task_struct *tsk)
{
	unsigned pid, idx;

	/* treat recording of idle task as a success */
	if (!tsk->pid)
		return 1;

	if (unlikely(tsk->pid > PID_MAX_DEFAULT))
		return 0;

	/*
	 * It's not the end of the world if we don't get
	 * the lock, but we also don't want to spin
	 * nor do we want to disable interrupts,
	 * so if we miss here, then better luck next time.
	 */
	if (!arch_spin_trylock(&trace_cmdline_lock))
		return 0;

	idx = savedcmd->map_pid_to_cmdline[tsk->pid];
	if (idx == NO_CMDLINE_MAP) {
		idx = (savedcmd->cmdline_idx + 1) % savedcmd->cmdline_num;

		/*
		 * Check whether the cmdline buffer at idx has a pid
		 * mapped. We are going to overwrite that entry so we
		 * need to clear the map_pid_to_cmdline. Otherwise we
		 * would read the new comm for the old pid.
		 */
		pid = savedcmd->map_cmdline_to_pid[idx];
		if (pid != NO_CMDLINE_MAP)
			savedcmd->map_pid_to_cmdline[pid] = NO_CMDLINE_MAP;

		savedcmd->map_cmdline_to_pid[idx] = tsk->pid;
		savedcmd->map_pid_to_cmdline[tsk->pid] = idx;

		savedcmd->cmdline_idx = idx;
	}

	set_cmdline(idx, tsk->comm);

	arch_spin_unlock(&trace_cmdline_lock);

	return 1;
}

static bool __read_mostly

struct trace_iterator *tracepoint_print_iter;

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

#define TRACE_BUF_SIZE_DEFAULT	1441792UL /* 16384 * 88 (sizeof(entry)) */

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

static bool selftests_can_run;

struct trace_selftests {
	struct list_head		list;
	struct tracer			*type;
}

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

#define NO_CMDLINE_MAP UINT_MAX

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;


ftrace_snapshot(unsigned long ip, unsigned long parent_ip,
		struct trace_array *tr, struct ftrace_probe_ops *ops,
		void *data)
{
	tracing_snapshot_instance(tr);
}


static __init void create_trace_instances(struct dentry *d_tracer)
{
	trace_instance_dir = tracefs_create_instance_dir("instances", d_tracer,
							 instance_mkdir,
							 instance_rmdir);
	if (WARN_ON(!trace_instance_dir))
		return;
}


static void set_buffer_entries(struct trace_buffer *buf, unsigned long val)
{
	int cpu;

	for_each_tracing_cpu(cpu)
		per_cpu_ptr(buf->data, cpu)->entries = val;
}


static void __trace_find_cmdline(int pid, char comm[])
{
	unsigned map;

	if (!pid) {
		strcpy(comm, "<idle>");
		return;
	}

	if (WARN_ON_ONCE(pid < 0)) {
		strcpy(comm, "<XXX>");
		return;
	}

	if (pid > PID_MAX_DEFAULT) {
		strcpy(comm, "<...>");
		return;
	}

	map = savedcmd->map_pid_to_cmdline[pid];
	if (map != NO_CMDLINE_MAP)
		strlcpy(comm, get_saved_cmdlines(map), TASK_COMM_LEN);
	else
		strcpy(comm, "<...>");
}

static bool __read_mostly

int tracepoint_printk;

static DEFINE_STATIC_KEY_FALSE(tracepoint_printk_key);

static struct tracer_opt dummy_tracer_opt[] = {
	{ }
};

static DEFINE_PER_CPU(bool, trace_taskinfo_save);

static int tracing_disabled = 1;

int __disable_trace_on_warning;

struct trace_eval_map_head {
	struct module			*mod;
	unsigned long			length;
}

struct trace_eval_map_tail {
	/*
	 * "end" is first and points to NULL as it must be different
	 * than "mod" or "eval_string"
	 */
	union trace_eval_map_item	*next;
	const char			*end;	/* points to NULL */
}

static DEFINE_MUTEX(trace_eval_mutex);

union trace_eval_map_item {
	struct trace_eval_map		map;
	struct trace_eval_map_head	head;
	struct trace_eval_map_tail	tail;
}

static union trace_eval_map_item *trace_eval_maps;

static int tracing_set_tracer(struct trace_array *tr, const char *buf);

static char bootup_tracer_buf[MAX_TRACER_SIZE]

static char *default_bootup_tracer;

static bool allocate_snapshot;

static char trace_boot_options_buf[MAX_TRACER_SIZE]

static char trace_boot_clock_buf[MAX_TRACER_SIZE]

static char *trace_boot_clock

static struct trace_array global_trace = {
	.trace_flags = TRACE_DEFAULT_FLAGS,
};

static unsigned long		trace_buf_size = TRACE_BUF_SIZE_DEFAULT;

static struct tracer		*trace_types

static DECLARE_RWSEM(all_cpu_access_lock);

static DEFINE_PER_CPU(struct mutex, cpu_access_lock);

static DEFINE_MUTEX(access_lock);

static void __ftrace_trace_stack(struct ring_buffer *buffer,
				 unsigned long flags,
				 int skip, int pc, struct pt_regs *regs);

static inline void ftrace_trace_stack(struct trace_array *tr,
				      struct ring_buffer *buffer,
				      unsigned long flags,
				      int skip, int pc, struct pt_regs *regs);

static __always_inline struct

static int resize_buffer_duplicate_size(struct trace_buffer *trace_buf,
					struct trace_buffer *size_buf, int cpu_id);

static void set_buffer_entries(struct trace_buffer *buf, unsigned long val);

static const char *trace_options[] = {
	TRACE_FLAGS
	NULL
};

static struct {
	u64 (*func)(void);
	const char *name;
	int in_ns;		/* is this clock in nanoseconds? */
} trace_clocks[] = {
	{ trace_clock_local,		"local",	1 },
	{ trace_clock_global,		"global",	1 },
	{ trace_clock_counter,		"counter",	0 },
	{ trace_clock_jiffies,		"uptime",	0 },
	{ trace_clock,			"perf",		1 },
	{ ktime_get_mono_fast_ns,	"mono",		1 },
	{ ktime_get_raw_fast_ns,	"mono_raw",	1 },
	{ ktime_get_boot_fast_ns,	"boot",		1 },
	ARCH_TRACE_CLOCKS
};

unsigned long __read_mostly	tracing_thresh;

static bool selftests_can_run;

static LIST_HEAD(postponed_selftests);

static void add_tracer_options(struct trace_array *tr, struct tracer *t);

static void __init apply_trace_boot_options(void);

static int *tgid_map;

#define NO_CMDLINE_MAP UINT_MAX

static arch_spinlock_t trace_cmdline_lock = __ARCH_SPIN_LOCK_UNLOCKED;

struct saved_cmdlines_buffer {
	unsigned map_pid_to_cmdline[PID_MAX_DEFAULT+1];
	unsigned *map_cmdline_to_pid;
	unsigned cmdline_num;
	int cmdline_idx;
	char *saved_cmdlines;
}

static struct saved_cmdlines_buffer *savedcmd;

static atomic_t trace_record_taskinfo_disabled

static int trace_buffered_event_ref;

static struct ring_buffer *temp_buffer;

static DEFINE_SPINLOCK(tracepoint_iter_lock);