Skip to content

Commit c17488d

Browse files
committed
Merge tag 'trace-v4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing updates from Steven Rostedt: "Not much new with tracing for this release. Mostly just clean ups and minor fixes. Here's what else is new: - A new TRACE_EVENT_FN_COND macro, combining both _FN and _COND for those that want both. - New selftest to test the instance create and delete - Better debug output when ftrace fails" * tag 'trace-v4.5' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (24 commits) ftrace: Fix the race between ftrace and insmod ftrace: Add infrastructure for delayed enabling of module functions x86: ftrace: Fix the comments for ftrace_modify_code_direct() tracing: Fix comment to use tracing_on over tracing_enable metag: ftrace: Fix the comments for ftrace_modify_code sh: ftrace: Fix the comments for ftrace_modify_code() ia64: ftrace: Fix the comments for ftrace_modify_code() ftrace: Clean up ftrace_module_init() code ftrace: Join functions ftrace_module_init() and ftrace_init_module() tracing: Introduce TRACE_EVENT_FN_COND macro tracing: Use seq_buf_used() in seq_buf_to_user() instead of len bpf: Constify bpf_verifier_ops structure ftrace: Have ftrace_ops_get_func() handle RCU and PER_CPU flags too ftrace: Remove use of control list and ops ftrace: Fix output of enabled_functions for showing tramp ftrace: Fix a typo in comment ftrace: Show all tramps registered to a record on ftrace_bug() ftrace: Add variable ftrace_expected for archs to show expected code ftrace: Add new type to distinguish what kind of ftrace_bug() tracing: Update cond flag when enabling or disabling a trigger ...
2 parents 34a9304 + 5156dca commit c17488d

File tree

16 files changed

+476
-276
lines changed

16 files changed

+476
-276
lines changed

arch/ia64/kernel/ftrace.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,13 +97,11 @@ ftrace_modify_code(unsigned long ip, unsigned char *old_code,
9797
unsigned char replaced[MCOUNT_INSN_SIZE];
9898

9999
/*
100-
* Note: Due to modules and __init, code can
101-
* disappear and change, we need to protect against faulting
102-
* as well as code changing. We do this by using the
103-
* probe_kernel_* functions.
104-
*
105-
* No real locking needed, this code is run through
106-
* kstop_machine, or before SMP starts.
100+
* Note:
101+
* We are paranoid about modifying text, as if a bug was to happen, it
102+
* could cause us to read or write to someplace that could cause harm.
103+
* Carefully read and modify the code with probe_kernel_*(), and make
104+
* sure what we read is what we expected it to be before modifying it.
107105
*/
108106

109107
if (!do_check)

arch/metag/kernel/ftrace.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ static int ftrace_modify_code(unsigned long pc, unsigned char *old_code,
5454
unsigned char replaced[MCOUNT_INSN_SIZE];
5555

5656
/*
57-
* Note: Due to modules and __init, code can
58-
* disappear and change, we need to protect against faulting
59-
* as well as code changing.
60-
*
61-
* No real locking needed, this code is run through
62-
* kstop_machine.
57+
* Note:
58+
* We are paranoid about modifying text, as if a bug was to happen, it
59+
* could cause us to read or write to someplace that could cause harm.
60+
* Carefully read and modify the code with probe_kernel_*(), and make
61+
* sure what we read is what we expected it to be before modifying it.
6362
*/
6463

6564
/* read the text we want to modify */

arch/sh/kernel/ftrace.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -212,13 +212,11 @@ static int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
212212
unsigned char replaced[MCOUNT_INSN_SIZE];
213213

214214
/*
215-
* Note: Due to modules and __init, code can
216-
* disappear and change, we need to protect against faulting
217-
* as well as code changing. We do this by using the
218-
* probe_kernel_* functions.
219-
*
220-
* No real locking needed, this code is run through
221-
* kstop_machine, or before SMP starts.
215+
* Note:
216+
* We are paranoid about modifying text, as if a bug was to happen, it
217+
* could cause us to read or write to someplace that could cause harm.
218+
* Carefully read and modify the code with probe_kernel_*(), and make
219+
* sure what we read is what we expected it to be before modifying it.
222220
*/
223221

224222
/* read the text we want to modify */

arch/x86/kernel/ftrace.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,14 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
105105
{
106106
unsigned char replaced[MCOUNT_INSN_SIZE];
107107

108+
ftrace_expected = old_code;
109+
108110
/*
109-
* Note: Due to modules and __init, code can
110-
* disappear and change, we need to protect against faulting
111-
* as well as code changing. We do this by using the
112-
* probe_kernel_* functions.
113-
*
114-
* No real locking needed, this code is run through
115-
* kstop_machine, or before SMP starts.
111+
* Note:
112+
* We are paranoid about modifying text, as if a bug was to happen, it
113+
* could cause us to read or write to someplace that could cause harm.
114+
* Carefully read and modify the code with probe_kernel_*(), and make
115+
* sure what we read is what we expected it to be before modifying it.
116116
*/
117117

118118
/* read the text we want to modify */
@@ -154,6 +154,8 @@ int ftrace_make_nop(struct module *mod,
154154
if (addr == MCOUNT_ADDR)
155155
return ftrace_modify_code_direct(rec->ip, old, new);
156156

157+
ftrace_expected = NULL;
158+
157159
/* Normal cases use add_brk_on_nop */
158160
WARN_ONCE(1, "invalid use of ftrace_make_nop");
159161
return -EINVAL;
@@ -220,6 +222,7 @@ int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr,
220222
unsigned long addr)
221223
{
222224
WARN_ON(1);
225+
ftrace_expected = NULL;
223226
return -EINVAL;
224227
}
225228

@@ -314,6 +317,8 @@ static int add_break(unsigned long ip, const char *old)
314317
if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
315318
return -EFAULT;
316319

320+
ftrace_expected = old;
321+
317322
/* Make sure it is what we expect it to be */
318323
if (memcmp(replaced, old, MCOUNT_INSN_SIZE) != 0)
319324
return -EINVAL;
@@ -413,6 +418,8 @@ static int remove_breakpoint(struct dyn_ftrace *rec)
413418
ftrace_addr = ftrace_get_addr_curr(rec);
414419
nop = ftrace_call_replace(ip, ftrace_addr);
415420

421+
ftrace_expected = nop;
422+
416423
if (memcmp(&ins[1], &nop[1], MCOUNT_INSN_SIZE - 1) != 0)
417424
return -EINVAL;
418425
}

include/linux/ftrace.h

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
7676
* ENABLED - set/unset when ftrace_ops is registered/unregistered
7777
* DYNAMIC - set when ftrace_ops is registered to denote dynamically
7878
* allocated ftrace_ops which need special care
79-
* CONTROL - set manualy by ftrace_ops user to denote the ftrace_ops
80-
* could be controled by following calls:
79+
* PER_CPU - set manualy by ftrace_ops user to denote the ftrace_ops
80+
* could be controlled by following calls:
8181
* ftrace_function_local_enable
8282
* ftrace_function_local_disable
8383
* SAVE_REGS - The ftrace_ops wants regs saved at each function called
@@ -121,7 +121,7 @@ ftrace_func_t ftrace_ops_get_func(struct ftrace_ops *ops);
121121
enum {
122122
FTRACE_OPS_FL_ENABLED = 1 << 0,
123123
FTRACE_OPS_FL_DYNAMIC = 1 << 1,
124-
FTRACE_OPS_FL_CONTROL = 1 << 2,
124+
FTRACE_OPS_FL_PER_CPU = 1 << 2,
125125
FTRACE_OPS_FL_SAVE_REGS = 1 << 3,
126126
FTRACE_OPS_FL_SAVE_REGS_IF_SUPPORTED = 1 << 4,
127127
FTRACE_OPS_FL_RECURSION_SAFE = 1 << 5,
@@ -134,6 +134,7 @@ enum {
134134
FTRACE_OPS_FL_ALLOC_TRAMP = 1 << 12,
135135
FTRACE_OPS_FL_IPMODIFY = 1 << 13,
136136
FTRACE_OPS_FL_PID = 1 << 14,
137+
FTRACE_OPS_FL_RCU = 1 << 15,
137138
};
138139

139140
#ifdef CONFIG_DYNAMIC_FTRACE
@@ -146,11 +147,11 @@ struct ftrace_ops_hash {
146147
#endif
147148

148149
/*
149-
* Note, ftrace_ops can be referenced outside of RCU protection.
150-
* (Although, for perf, the control ops prevent that). If ftrace_ops is
151-
* allocated and not part of kernel core data, the unregistering of it will
152-
* perform a scheduling on all CPUs to make sure that there are no more users.
153-
* Depending on the load of the system that may take a bit of time.
150+
* Note, ftrace_ops can be referenced outside of RCU protection, unless
151+
* the RCU flag is set. If ftrace_ops is allocated and not part of kernel
152+
* core data, the unregistering of it will perform a scheduling on all CPUs
153+
* to make sure that there are no more users. Depending on the load of the
154+
* system that may take a bit of time.
154155
*
155156
* Any private data added must also take care not to be freed and if private
156157
* data is added to a ftrace_ops that is in core code, the user of the
@@ -196,34 +197,34 @@ int unregister_ftrace_function(struct ftrace_ops *ops);
196197
void clear_ftrace_function(void);
197198

198199
/**
199-
* ftrace_function_local_enable - enable controlled ftrace_ops on current cpu
200+
* ftrace_function_local_enable - enable ftrace_ops on current cpu
200201
*
201202
* This function enables tracing on current cpu by decreasing
202203
* the per cpu control variable.
203204
* It must be called with preemption disabled and only on ftrace_ops
204-
* registered with FTRACE_OPS_FL_CONTROL. If called without preemption
205+
* registered with FTRACE_OPS_FL_PER_CPU. If called without preemption
205206
* disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
206207
*/
207208
static inline void ftrace_function_local_enable(struct ftrace_ops *ops)
208209
{
209-
if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
210+
if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_PER_CPU)))
210211
return;
211212

212213
(*this_cpu_ptr(ops->disabled))--;
213214
}
214215

215216
/**
216-
* ftrace_function_local_disable - enable controlled ftrace_ops on current cpu
217+
* ftrace_function_local_disable - disable ftrace_ops on current cpu
217218
*
218-
* This function enables tracing on current cpu by decreasing
219+
* This function disables tracing on current cpu by increasing
219220
* the per cpu control variable.
220221
* It must be called with preemption disabled and only on ftrace_ops
221-
* registered with FTRACE_OPS_FL_CONTROL. If called without preemption
222+
* registered with FTRACE_OPS_FL_PER_CPU. If called without preemption
222223
* disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
223224
*/
224225
static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
225226
{
226-
if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL)))
227+
if (WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_PER_CPU)))
227228
return;
228229

229230
(*this_cpu_ptr(ops->disabled))++;
@@ -235,12 +236,12 @@ static inline void ftrace_function_local_disable(struct ftrace_ops *ops)
235236
*
236237
* This function returns value of ftrace_ops::disabled on current cpu.
237238
* It must be called with preemption disabled and only on ftrace_ops
238-
* registered with FTRACE_OPS_FL_CONTROL. If called without preemption
239+
* registered with FTRACE_OPS_FL_PER_CPU. If called without preemption
239240
* disabled, this_cpu_ptr will complain when CONFIG_DEBUG_PREEMPT is enabled.
240241
*/
241242
static inline int ftrace_function_local_disabled(struct ftrace_ops *ops)
242243
{
243-
WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_CONTROL));
244+
WARN_ON_ONCE(!(ops->flags & FTRACE_OPS_FL_PER_CPU));
244245
return *this_cpu_ptr(ops->disabled);
245246
}
246247

@@ -296,6 +297,21 @@ int ftrace_arch_code_modify_post_process(void);
296297

297298
struct dyn_ftrace;
298299

300+
enum ftrace_bug_type {
301+
FTRACE_BUG_UNKNOWN,
302+
FTRACE_BUG_INIT,
303+
FTRACE_BUG_NOP,
304+
FTRACE_BUG_CALL,
305+
FTRACE_BUG_UPDATE,
306+
};
307+
extern enum ftrace_bug_type ftrace_bug_type;
308+
309+
/*
310+
* Archs can set this to point to a variable that holds the value that was
311+
* expected at the call site before calling ftrace_bug().
312+
*/
313+
extern const void *ftrace_expected;
314+
299315
void ftrace_bug(int err, struct dyn_ftrace *rec);
300316

301317
struct seq_file;
@@ -341,6 +357,7 @@ bool is_ftrace_trampoline(unsigned long addr);
341357
* REGS - the record wants the function to save regs
342358
* REGS_EN - the function is set up to save regs.
343359
* IPMODIFY - the record allows for the IP address to be changed.
360+
* DISABLED - the record is not ready to be touched yet
344361
*
345362
* When a new ftrace_ops is registered and wants a function to save
346363
* pt_regs, the rec->flag REGS is set. When the function has been
@@ -355,10 +372,11 @@ enum {
355372
FTRACE_FL_TRAMP = (1UL << 28),
356373
FTRACE_FL_TRAMP_EN = (1UL << 27),
357374
FTRACE_FL_IPMODIFY = (1UL << 26),
375+
FTRACE_FL_DISABLED = (1UL << 25),
358376
};
359377

360-
#define FTRACE_REF_MAX_SHIFT 26
361-
#define FTRACE_FL_BITS 6
378+
#define FTRACE_REF_MAX_SHIFT 25
379+
#define FTRACE_FL_BITS 7
362380
#define FTRACE_FL_MASKED_BITS ((1UL << FTRACE_FL_BITS) - 1)
363381
#define FTRACE_FL_MASK (FTRACE_FL_MASKED_BITS << FTRACE_REF_MAX_SHIFT)
364382
#define FTRACE_REF_MAX ((1UL << FTRACE_REF_MAX_SHIFT) - 1)

include/linux/tracepoint.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,10 @@ extern void syscall_unregfunc(void);
479479
#define TRACE_EVENT_FN(name, proto, args, struct, \
480480
assign, print, reg, unreg) \
481481
DECLARE_TRACE(name, PARAMS(proto), PARAMS(args))
482+
#define TRACE_EVENT_FN_COND(name, proto, args, cond, struct, \
483+
assign, print, reg, unreg) \
484+
DECLARE_TRACE_CONDITION(name, PARAMS(proto), \
485+
PARAMS(args), PARAMS(cond))
482486
#define TRACE_EVENT_CONDITION(name, proto, args, cond, \
483487
struct, assign, print) \
484488
DECLARE_TRACE_CONDITION(name, PARAMS(proto), \

include/trace/define_trace.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@
4040
assign, print, reg, unreg) \
4141
DEFINE_TRACE_FN(name, reg, unreg)
4242

43+
#undef TRACE_EVENT_FN_COND
44+
#define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \
45+
assign, print, reg, unreg) \
46+
DEFINE_TRACE_FN(name, reg, unreg)
47+
4348
#undef DEFINE_EVENT
4449
#define DEFINE_EVENT(template, name, proto, args) \
4550
DEFINE_TRACE(name)
@@ -93,6 +98,7 @@
9398

9499
#undef TRACE_EVENT
95100
#undef TRACE_EVENT_FN
101+
#undef TRACE_EVENT_FN_COND
96102
#undef TRACE_EVENT_CONDITION
97103
#undef DECLARE_EVENT_CLASS
98104
#undef DEFINE_EVENT

include/trace/trace_events.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ TRACE_MAKE_SYSTEM_STR();
123123
TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
124124
PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
125125

126+
#undef TRACE_EVENT_FN_COND
127+
#define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \
128+
assign, print, reg, unreg) \
129+
TRACE_EVENT_CONDITION(name, PARAMS(proto), PARAMS(args), PARAMS(cond), \
130+
PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
131+
126132
#undef TRACE_EVENT_FLAGS
127133
#define TRACE_EVENT_FLAGS(name, value) \
128134
__TRACE_EVENT_FLAGS(name, value)

kernel/trace/bpf_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ static bool kprobe_prog_is_valid_access(int off, int size, enum bpf_access_type
316316
return true;
317317
}
318318

319-
static struct bpf_verifier_ops kprobe_prog_ops = {
319+
static const struct bpf_verifier_ops kprobe_prog_ops = {
320320
.get_func_proto = kprobe_prog_func_proto,
321321
.is_valid_access = kprobe_prog_is_valid_access,
322322
};

0 commit comments

Comments
 (0)