Skip to content

Commit 4c17468

Browse files
committed
Merge tag 'trace-v4.12' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing updates from Steven Rostedt: "New features for this release: - Pretty much a full rewrite of the processing of function plugins. i.e. echo do_IRQ:stacktrace > set_ftrace_filter - The rewrite was needed to add plugins to be unique to tracing instances. i.e. mkdir instance/foo; cd instances/foo; echo do_IRQ:stacktrace > set_ftrace_filter The old way was written very hacky. This removes a lot of those hacks. - New "function-fork" tracing option. When set, pids in the set_ftrace_pid will have their children added when the processes with their pids listed in the set_ftrace_pid file forks. - Exposure of "maxactive" for kretprobe in kprobe_events - Allow for builtin init functions to be traced by the function tracer (via the kernel command line). Module init function tracing will come in the next release. - Added more selftests, and have selftests also test in an instance" * tag 'trace-v4.12' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (60 commits) ring-buffer: Return reader page back into existing ring buffer selftests: ftrace: Allow some event trigger tests to run in an instance selftests: ftrace: Have some basic tests run in a tracing instance too selftests: ftrace: Have event tests also run in an tracing instance selftests: ftrace: Make func_event_triggers and func_traceonoff_triggers tests do instances selftests: ftrace: Allow some tests to be run in a tracing instance tracing/ftrace: Allow for instances to trigger their own stacktrace probes tracing/ftrace: Allow for the traceonoff probe be unique to instances tracing/ftrace: Enable snapshot function trigger to work with instances tracing/ftrace: Allow instances to have their own function probes tracing/ftrace: Add a better way to pass data via the probe functions ftrace: Dynamically create the probe ftrace_ops for the trace_array tracing: Pass the trace_array into ftrace_probe_ops functions tracing: Have the trace_array hold the list of registered func probes ftrace: If the hash for a probe fails to update then free what was initialized ftrace: Have the function probes call their own function ftrace: Have each function probe use its own ftrace_ops ftrace: Have unregister_ftrace_function_probe_func() return a value ftrace: Add helper function ftrace_hash_move_and_update_ops() ftrace: Remove data field from ftrace_func_probe structure ...
2 parents 9c35baf + 73a757e commit 4c17468

40 files changed

Lines changed: 1902 additions & 656 deletions

‎Documentation/trace/kprobetrace.txt‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ current_tracer. Instead of that, add probe points via
2424
Synopsis of kprobe_events
2525
-------------------------
2626
p[:[GRP/]EVENT] [MOD:]SYM[+offs]|MEMADDR [FETCHARGS] : Set a probe
27-
r[:[GRP/]EVENT] [MOD:]SYM[+0] [FETCHARGS] : Set a return probe
27+
r[MAXACTIVE][:[GRP/]EVENT] [MOD:]SYM[+0] [FETCHARGS] : Set a return probe
2828
-:[GRP/]EVENT : Clear a probe
2929

3030
GRP : Group name. If omitted, use "kprobes" for it.
@@ -33,6 +33,9 @@ Synopsis of kprobe_events
3333
MOD : Module name which has given SYM.
3434
SYM[+offs] : Symbol+offset where the probe is inserted.
3535
MEMADDR : Address where the probe is inserted.
36+
MAXACTIVE : Maximum number of instances of the specified function that
37+
can be probed simultaneously, or 0 for the default value
38+
as defined in Documentation/kprobes.txt section 1.3.1.
3639

3740
FETCHARGS : Arguments. Each probe can have up to 128 args.
3841
%REG : Fetch register REG

‎arch/x86/kernel/ftrace.c‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -533,7 +533,13 @@ static void do_sync_core(void *data)
533533

534534
static void run_sync(void)
535535
{
536-
int enable_irqs = irqs_disabled();
536+
int enable_irqs;
537+
538+
/* No need to sync if there's only one CPU */
539+
if (num_online_cpus() == 1)
540+
return;
541+
542+
enable_irqs = irqs_disabled();
537543

538544
/* We may be called with interrupts disabled (on bootup). */
539545
if (enable_irqs)

‎include/linux/ftrace.h‎

Lines changed: 47 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@
4242
/* Main tracing buffer and events set up */
4343
#ifdef CONFIG_TRACING
4444
void trace_init(void);
45+
void early_trace_init(void);
4546
#else
4647
static inline void trace_init(void) { }
48+
static inline void early_trace_init(void) { }
4749
#endif
4850

4951
struct module;
@@ -144,6 +146,10 @@ struct ftrace_ops_hash {
144146
struct ftrace_hash *filter_hash;
145147
struct mutex regex_lock;
146148
};
149+
150+
void ftrace_free_init_mem(void);
151+
#else
152+
static inline void ftrace_free_init_mem(void) { }
147153
#endif
148154

149155
/*
@@ -260,6 +266,7 @@ static inline int ftrace_nr_registered_ops(void)
260266
}
261267
static inline void clear_ftrace_function(void) { }
262268
static inline void ftrace_kill(void) { }
269+
static inline void ftrace_free_init_mem(void) { }
263270
#endif /* CONFIG_FUNCTION_TRACER */
264271

265272
#ifdef CONFIG_STACK_TRACER
@@ -279,15 +286,45 @@ int
279286
stack_trace_sysctl(struct ctl_table *table, int write,
280287
void __user *buffer, size_t *lenp,
281288
loff_t *ppos);
282-
#endif
283289

284-
struct ftrace_func_command {
285-
struct list_head list;
286-
char *name;
287-
int (*func)(struct ftrace_hash *hash,
288-
char *func, char *cmd,
289-
char *params, int enable);
290-
};
290+
/* DO NOT MODIFY THIS VARIABLE DIRECTLY! */
291+
DECLARE_PER_CPU(int, disable_stack_tracer);
292+
293+
/**
294+
* stack_tracer_disable - temporarily disable the stack tracer
295+
*
296+
* There's a few locations (namely in RCU) where stack tracing
297+
* cannot be executed. This function is used to disable stack
298+
* tracing during those critical sections.
299+
*
300+
* This function must be called with preemption or interrupts
301+
* disabled and stack_tracer_enable() must be called shortly after
302+
* while preemption or interrupts are still disabled.
303+
*/
304+
static inline void stack_tracer_disable(void)
305+
{
306+
/* Preemption or interupts must be disabled */
307+
if (IS_ENABLED(CONFIG_PREEMPT_DEBUG))
308+
WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
309+
this_cpu_inc(disable_stack_tracer);
310+
}
311+
312+
/**
313+
* stack_tracer_enable - re-enable the stack tracer
314+
*
315+
* After stack_tracer_disable() is called, stack_tracer_enable()
316+
* must be called shortly afterward.
317+
*/
318+
static inline void stack_tracer_enable(void)
319+
{
320+
if (IS_ENABLED(CONFIG_PREEMPT_DEBUG))
321+
WARN_ON_ONCE(!preempt_count() || !irqs_disabled());
322+
this_cpu_dec(disable_stack_tracer);
323+
}
324+
#else
325+
static inline void stack_tracer_disable(void) { }
326+
static inline void stack_tracer_enable(void) { }
327+
#endif
291328

292329
#ifdef CONFIG_DYNAMIC_FTRACE
293330

@@ -315,30 +352,6 @@ void ftrace_bug(int err, struct dyn_ftrace *rec);
315352

316353
struct seq_file;
317354

318-
struct ftrace_probe_ops {
319-
void (*func)(unsigned long ip,
320-
unsigned long parent_ip,
321-
void **data);
322-
int (*init)(struct ftrace_probe_ops *ops,
323-
unsigned long ip, void **data);
324-
void (*free)(struct ftrace_probe_ops *ops,
325-
unsigned long ip, void **data);
326-
int (*print)(struct seq_file *m,
327-
unsigned long ip,
328-
struct ftrace_probe_ops *ops,
329-
void *data);
330-
};
331-
332-
extern int
333-
register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
334-
void *data);
335-
extern void
336-
unregister_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
337-
void *data);
338-
extern void
339-
unregister_ftrace_function_probe_func(char *glob, struct ftrace_probe_ops *ops);
340-
extern void unregister_ftrace_function_probe_all(char *glob);
341-
342355
extern int ftrace_text_reserved(const void *start, const void *end);
343356

344357
extern int ftrace_nr_registered_ops(void);
@@ -400,9 +413,6 @@ void ftrace_set_global_notrace(unsigned char *buf, int len, int reset);
400413
void ftrace_free_filter(struct ftrace_ops *ops);
401414
void ftrace_ops_set_global_filter(struct ftrace_ops *ops);
402415

403-
int register_ftrace_command(struct ftrace_func_command *cmd);
404-
int unregister_ftrace_command(struct ftrace_func_command *cmd);
405-
406416
enum {
407417
FTRACE_UPDATE_CALLS = (1 << 0),
408418
FTRACE_DISABLE_CALLS = (1 << 1),
@@ -433,8 +443,8 @@ enum {
433443
FTRACE_ITER_FILTER = (1 << 0),
434444
FTRACE_ITER_NOTRACE = (1 << 1),
435445
FTRACE_ITER_PRINTALL = (1 << 2),
436-
FTRACE_ITER_DO_HASH = (1 << 3),
437-
FTRACE_ITER_HASH = (1 << 4),
446+
FTRACE_ITER_DO_PROBES = (1 << 3),
447+
FTRACE_ITER_PROBE = (1 << 4),
438448
FTRACE_ITER_ENABLED = (1 << 5),
439449
};
440450

@@ -618,14 +628,6 @@ static inline void ftrace_enable_daemon(void) { }
618628
static inline void ftrace_module_init(struct module *mod) { }
619629
static inline void ftrace_module_enable(struct module *mod) { }
620630
static inline void ftrace_release_mod(struct module *mod) { }
621-
static inline __init int register_ftrace_command(struct ftrace_func_command *cmd)
622-
{
623-
return -EINVAL;
624-
}
625-
static inline __init int unregister_ftrace_command(char *cmd_name)
626-
{
627-
return -EINVAL;
628-
}
629631
static inline int ftrace_text_reserved(const void *start, const void *end)
630632
{
631633
return 0;

‎include/linux/init.h‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
/* These are for everybody (although not all archs will actually
4141
discard it in modules) */
42-
#define __init __section(.init.text) __cold notrace __latent_entropy
42+
#define __init __section(.init.text) __cold __inittrace __latent_entropy
4343
#define __initdata __section(.init.data)
4444
#define __initconst __section(.init.rodata)
4545
#define __exitdata __section(.exit.data)
@@ -68,8 +68,10 @@
6868

6969
#ifdef MODULE
7070
#define __exitused
71+
#define __inittrace notrace
7172
#else
7273
#define __exitused __used
74+
#define __inittrace
7375
#endif
7476

7577
#define __exit __section(.exit.text) __exitused __cold notrace

‎include/linux/rcupdate.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ void do_trace_rcu_torture_read(const char *rcutorturename,
9797
unsigned long secs,
9898
unsigned long c_old,
9999
unsigned long c);
100+
bool rcu_irq_enter_disabled(void);
100101
#else
101102
static inline void rcutorture_get_gp_data(enum rcutorture_type test_type,
102103
int *flags,
@@ -113,6 +114,10 @@ static inline void rcutorture_record_test_transition(void)
113114
static inline void rcutorture_record_progress(unsigned long vernum)
114115
{
115116
}
117+
static inline bool rcu_irq_enter_disabled(void)
118+
{
119+
return false;
120+
}
116121
#ifdef CONFIG_RCU_TRACE
117122
void do_trace_rcu_torture_read(const char *rcutorturename,
118123
struct rcu_head *rhp,

‎include/linux/ring_buffer.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ size_t ring_buffer_page_len(void *page);
185185

186186

187187
void *ring_buffer_alloc_read_page(struct ring_buffer *buffer, int cpu);
188-
void ring_buffer_free_read_page(struct ring_buffer *buffer, void *data);
188+
void ring_buffer_free_read_page(struct ring_buffer *buffer, int cpu, void *data);
189189
int ring_buffer_read_page(struct ring_buffer *buffer, void **data_page,
190190
size_t len, int cpu, int full);
191191

‎include/linux/trace_events.h‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,7 @@ enum print_line_t {
138138
TRACE_TYPE_NO_CONSUME = 3 /* Handled but ask to not consume */
139139
};
140140

141-
/*
142-
* Several functions return TRACE_TYPE_PARTIAL_LINE if the trace_seq
143-
* overflowed, and TRACE_TYPE_HANDLED otherwise. This helper function
144-
* simplifies those functions and keeps them in sync.
145-
*/
146-
static inline enum print_line_t trace_handle_return(struct trace_seq *s)
147-
{
148-
return trace_seq_has_overflowed(s) ?
149-
TRACE_TYPE_PARTIAL_LINE : TRACE_TYPE_HANDLED;
150-
}
141+
enum print_line_t trace_handle_return(struct trace_seq *s);
151142

152143
void tracing_generic_entry_update(struct trace_entry *entry,
153144
unsigned long flags,

‎include/linux/tracepoint.h‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,19 @@ extern void syscall_unregfunc(void);
128128
* as "(void *, void)". The DECLARE_TRACE_NOARGS() will pass in just
129129
* "void *data", where as the DECLARE_TRACE() will pass in "void *data, proto".
130130
*/
131-
#define __DO_TRACE(tp, proto, args, cond, prercu, postrcu) \
131+
#define __DO_TRACE(tp, proto, args, cond, rcucheck) \
132132
do { \
133133
struct tracepoint_func *it_func_ptr; \
134134
void *it_func; \
135135
void *__data; \
136136
\
137137
if (!(cond)) \
138138
return; \
139-
prercu; \
139+
if (rcucheck) { \
140+
if (WARN_ON_ONCE(rcu_irq_enter_disabled())) \
141+
return; \
142+
rcu_irq_enter_irqson(); \
143+
} \
140144
rcu_read_lock_sched_notrace(); \
141145
it_func_ptr = rcu_dereference_sched((tp)->funcs); \
142146
if (it_func_ptr) { \
@@ -147,20 +151,19 @@ extern void syscall_unregfunc(void);
147151
} while ((++it_func_ptr)->func); \
148152
} \
149153
rcu_read_unlock_sched_notrace(); \
150-
postrcu; \
154+
if (rcucheck) \
155+
rcu_irq_exit_irqson(); \
151156
} while (0)
152157

153158
#ifndef MODULE
154-
#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args) \
159+
#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args) \
155160
static inline void trace_##name##_rcuidle(proto) \
156161
{ \
157162
if (static_key_false(&__tracepoint_##name.key)) \
158163
__DO_TRACE(&__tracepoint_##name, \
159164
TP_PROTO(data_proto), \
160165
TP_ARGS(data_args), \
161-
TP_CONDITION(cond), \
162-
rcu_irq_enter_irqson(), \
163-
rcu_irq_exit_irqson()); \
166+
TP_CONDITION(cond), 1); \
164167
}
165168
#else
166169
#define __DECLARE_TRACE_RCU(name, proto, args, cond, data_proto, data_args)
@@ -186,7 +189,7 @@ extern void syscall_unregfunc(void);
186189
__DO_TRACE(&__tracepoint_##name, \
187190
TP_PROTO(data_proto), \
188191
TP_ARGS(data_args), \
189-
TP_CONDITION(cond),,); \
192+
TP_CONDITION(cond), 0); \
190193
if (IS_ENABLED(CONFIG_LOCKDEP) && (cond)) { \
191194
rcu_read_lock_sched_notrace(); \
192195
rcu_dereference_sched(__tracepoint_##name.funcs);\

‎init/main.c‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,11 @@ asmlinkage __visible void __init start_kernel(void)
545545
trap_init();
546546
mm_init();
547547

548+
ftrace_init();
549+
550+
/* trace_printk can be enabled here */
551+
early_trace_init();
552+
548553
/*
549554
* Set up the scheduler prior starting any interrupts (such as the
550555
* timer interrupt). Full topology setup happens at smp_init()
@@ -570,7 +575,7 @@ asmlinkage __visible void __init start_kernel(void)
570575

571576
rcu_init();
572577

573-
/* trace_printk() and trace points may be used after this */
578+
/* Trace events are available after this */
574579
trace_init();
575580

576581
context_tracking_init();
@@ -670,8 +675,6 @@ asmlinkage __visible void __init start_kernel(void)
670675
efi_free_boot_services();
671676
}
672677

673-
ftrace_init();
674-
675678
/* Do the rest non-__init'ed, we're now alive */
676679
rest_init();
677680
}
@@ -959,6 +962,7 @@ static int __ref kernel_init(void *unused)
959962
kernel_init_freeable();
960963
/* need to finish all async __init code before freeing the memory */
961964
async_synchronize_full();
965+
ftrace_free_init_mem();
962966
free_initmem();
963967
mark_readonly();
964968
system_state = SYSTEM_RUNNING;

0 commit comments

Comments
 (0)