Skip to content

Commit 32663c7

Browse files
committed
Merge tag 'trace-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing updates from Steven Rostedt: - The biggest news in that the tracing ring buffer can now time events that interrupted other ring buffer events. Before this change, if an interrupt came in while recording another event, and that interrupt also had an event, those events would all have the same time stamp as the event it interrupted. Now, with the new design, those events will have a unique time stamp and rightfully display the time for those events that were recorded while interrupting another event. - Bootconfig how has an "override" operator that lets the users have a default config, but then add options to override the default. - A fix was made to properly filter function graph tracing to the ftrace PIDs. This came in at the end of the -rc cycle, and needs to be backported. - Several clean ups, performance updates, and minor fixes as well. * tag 'trace-v5.9' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (39 commits) tracing: Add trace_array_init_printk() to initialize instance trace_printk() buffers kprobes: Fix compiler warning for !CONFIG_KPROBES_ON_FTRACE tracing: Use trace_sched_process_free() instead of exit() for pid tracing bootconfig: Fix to find the initargs correctly Documentation: bootconfig: Add bootconfig override operator tools/bootconfig: Add testcases for value override operator lib/bootconfig: Add override operator support kprobes: Remove show_registers() function prototype tracing/uprobe: Remove dead code in trace_uprobe_register() kprobes: Fix NULL pointer dereference at kprobe_ftrace_handler ftrace: Fix ftrace_trace_task return value tracepoint: Use __used attribute definitions from compiler_attributes.h tracepoint: Mark __tracepoint_string's __used trace : Have tracing buffer info use kvzalloc instead of kzalloc tracing: Remove outdated comment in stack handling ftrace: Do not let direct or IPMODIFY ftrace_ops be added to module and set trampolines ftrace: Setup correct FTRACE_FL_REGS flags for module tracing/hwlat: Honor the tracing_cpumask tracing/hwlat: Drop the duplicate assignment in start_kthread() tracing: Save one trace_event->type by using __TRACE_LAST_TYPE ...
2 parents 7b9de97 + 38ce2a9 commit 32663c7

File tree

23 files changed

+775
-250
lines changed

23 files changed

+775
-250
lines changed

Documentation/admin-guide/bootconfig.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,16 @@ For example,::
7171
foo = bar, baz
7272
foo = qux # !ERROR! we can not re-define same key
7373

74+
If you want to update the value, you must use the override operator
75+
``:=`` explicitly. For example::
76+
77+
foo = bar, baz
78+
foo := qux
79+
80+
then, the ``qux`` is assigned to ``foo`` key. This is useful for
81+
overriding the default value by adding (partial) custom bootconfigs
82+
without parsing the default bootconfig.
83+
7484
If you want to append the value to existing key as an array member,
7585
you can use ``+=`` operator. For example::
7686

@@ -84,6 +94,7 @@ For example, following config is NOT allowed.::
8494

8595
foo = value1
8696
foo.bar = value2 # !ERROR! subkey "bar" and value "value1" can NOT co-exist
97+
foo.bar := value2 # !ERROR! even with the override operator, this is NOT allowed.
8798

8899

89100
Comments

arch/x86/kernel/ftrace.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ extern void ftrace_regs_caller_ret(void);
286286
extern void ftrace_caller_end(void);
287287
extern void ftrace_caller_op_ptr(void);
288288
extern void ftrace_regs_caller_op_ptr(void);
289+
extern void ftrace_regs_caller_jmp(void);
289290

290291
/* movq function_trace_op(%rip), %rdx */
291292
/* 0x48 0x8b 0x15 <offset-to-ftrace_trace_op (4 bytes)> */
@@ -316,6 +317,7 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size)
316317
unsigned long end_offset;
317318
unsigned long op_offset;
318319
unsigned long call_offset;
320+
unsigned long jmp_offset;
319321
unsigned long offset;
320322
unsigned long npages;
321323
unsigned long size;
@@ -333,11 +335,13 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size)
333335
end_offset = (unsigned long)ftrace_regs_caller_end;
334336
op_offset = (unsigned long)ftrace_regs_caller_op_ptr;
335337
call_offset = (unsigned long)ftrace_regs_call;
338+
jmp_offset = (unsigned long)ftrace_regs_caller_jmp;
336339
} else {
337340
start_offset = (unsigned long)ftrace_caller;
338341
end_offset = (unsigned long)ftrace_caller_end;
339342
op_offset = (unsigned long)ftrace_caller_op_ptr;
340343
call_offset = (unsigned long)ftrace_call;
344+
jmp_offset = 0;
341345
}
342346

343347
size = end_offset - start_offset;
@@ -367,10 +371,14 @@ create_trampoline(struct ftrace_ops *ops, unsigned int *tramp_size)
367371
if (WARN_ON(ret < 0))
368372
goto fail;
369373

374+
/* No need to test direct calls on created trampolines */
370375
if (ops->flags & FTRACE_OPS_FL_SAVE_REGS) {
371-
ip = trampoline + (ftrace_regs_caller_ret - ftrace_regs_caller);
372-
ret = copy_from_kernel_nofault(ip, (void *)retq, RET_SIZE);
373-
if (WARN_ON(ret < 0))
376+
/* NOP the jnz 1f; but make sure it's a 2 byte jnz */
377+
ip = trampoline + (jmp_offset - start_offset);
378+
if (WARN_ON(*(char *)ip != 0x75))
379+
goto fail;
380+
ret = copy_from_kernel_nofault(ip, ideal_nops[2], 2);
381+
if (ret < 0)
374382
goto fail;
375383
}
376384

arch/x86/kernel/ftrace_64.S

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,10 @@ SYM_INNER_LABEL(ftrace_regs_call, SYM_L_GLOBAL)
241241
*/
242242
movq ORIG_RAX(%rsp), %rax
243243
testq %rax, %rax
244-
jz 1f
244+
SYM_INNER_LABEL(ftrace_regs_caller_jmp, SYM_L_GLOBAL)
245+
jnz 1f
245246

246-
/* Swap the flags with orig_rax */
247-
movq MCOUNT_REG_SIZE(%rsp), %rdi
248-
movq %rdi, MCOUNT_REG_SIZE-8(%rsp)
249-
movq %rax, MCOUNT_REG_SIZE(%rsp)
250-
251-
restore_mcount_regs 8
252-
/* Restore flags */
253-
popfq
254-
255-
SYM_INNER_LABEL(ftrace_regs_caller_ret, SYM_L_GLOBAL);
256-
UNWIND_HINT_RET_OFFSET
257-
jmp ftrace_epilogue
258-
259-
1: restore_mcount_regs
247+
restore_mcount_regs
260248
/* Restore flags */
261249
popfq
262250

@@ -269,6 +257,17 @@ SYM_INNER_LABEL(ftrace_regs_caller_ret, SYM_L_GLOBAL);
269257
SYM_INNER_LABEL(ftrace_regs_caller_end, SYM_L_GLOBAL)
270258
jmp ftrace_epilogue
271259

260+
/* Swap the flags with orig_rax */
261+
1: movq MCOUNT_REG_SIZE(%rsp), %rdi
262+
movq %rdi, MCOUNT_REG_SIZE-8(%rsp)
263+
movq %rax, MCOUNT_REG_SIZE(%rsp)
264+
265+
restore_mcount_regs 8
266+
/* Restore flags */
267+
popfq
268+
UNWIND_HINT_RET_OFFSET
269+
jmp ftrace_epilogue
270+
272271
SYM_FUNC_END(ftrace_regs_caller)
273272

274273

include/linux/kprobes.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ extern int arch_prepare_kprobe(struct kprobe *p);
227227
extern void arch_arm_kprobe(struct kprobe *p);
228228
extern void arch_disarm_kprobe(struct kprobe *p);
229229
extern int arch_init_kprobes(void);
230-
extern void show_registers(struct pt_regs *regs);
231230
extern void kprobes_inc_nmissed_count(struct kprobe *p);
232231
extern bool arch_within_kprobe_blacklist(unsigned long addr);
233232
extern int arch_populate_kprobe_blacklist(void);

include/linux/ring_buffer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ bool ring_buffer_iter_dropped(struct ring_buffer_iter *iter);
143143
unsigned long ring_buffer_size(struct trace_buffer *buffer, int cpu);
144144

145145
void ring_buffer_reset_cpu(struct trace_buffer *buffer, int cpu);
146+
void ring_buffer_reset_online_cpus(struct trace_buffer *buffer);
146147
void ring_buffer_reset(struct trace_buffer *buffer);
147148

148149
#ifdef CONFIG_RING_BUFFER_ALLOW_SWAP

include/linux/trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ struct trace_array;
2929
void trace_printk_init_buffers(void);
3030
int trace_array_printk(struct trace_array *tr, unsigned long ip,
3131
const char *fmt, ...);
32+
int trace_array_init_printk(struct trace_array *tr);
3233
void trace_array_put(struct trace_array *tr);
3334
struct trace_array *trace_array_get_by_name(const char *name);
3435
int trace_array_destroy(struct trace_array *tr);

include/linux/tracepoint.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
116116

117117
#define __TRACEPOINT_ENTRY(name) \
118118
static tracepoint_ptr_t __tracepoint_ptr_##name __used \
119-
__attribute__((section("__tracepoints_ptrs"))) = \
120-
&__tracepoint_##name
119+
__section(__tracepoints_ptrs) = &__tracepoint_##name
121120
#endif
122121

123122
#endif /* _LINUX_TRACEPOINT_H */
@@ -280,9 +279,9 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
280279
*/
281280
#define DEFINE_TRACE_FN(name, reg, unreg) \
282281
static const char __tpstrtab_##name[] \
283-
__attribute__((section("__tracepoints_strings"))) = #name; \
284-
struct tracepoint __tracepoint_##name \
285-
__attribute__((section("__tracepoints"), used)) = \
282+
__section(__tracepoints_strings) = #name; \
283+
struct tracepoint __tracepoint_##name __used \
284+
__section(__tracepoints) = \
286285
{ __tpstrtab_##name, STATIC_KEY_INIT_FALSE, reg, unreg, NULL };\
287286
__TRACEPOINT_ENTRY(name);
288287

@@ -361,7 +360,7 @@ static inline struct tracepoint *tracepoint_ptr_deref(tracepoint_ptr_t *p)
361360
static const char *___tp_str __tracepoint_string = str; \
362361
___tp_str; \
363362
})
364-
#define __tracepoint_string __attribute__((section("__tracepoint_str")))
363+
#define __tracepoint_string __used __section(__tracepoint_str)
365364
#else
366365
/*
367366
* tracepoint_string() is used to save the string address for userspace

include/trace/trace_events.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,7 @@ TRACE_MAKE_SYSTEM_STR();
210210
#define DEFINE_EVENT(template, name, proto, args)
211211

212212
#undef DEFINE_EVENT_PRINT
213-
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
214-
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
213+
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
215214

216215
#undef TRACE_EVENT_FLAGS
217216
#define TRACE_EVENT_FLAGS(event, flag)
@@ -443,12 +442,8 @@ static struct trace_event_fields trace_event_fields_##call[] = { \
443442
tstruct \
444443
{} };
445444

446-
#undef DEFINE_EVENT
447-
#define DEFINE_EVENT(template, name, proto, args)
448-
449445
#undef DEFINE_EVENT_PRINT
450-
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
451-
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
446+
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
452447

453448
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
454449

@@ -523,13 +518,6 @@ static inline notrace int trace_event_get_offsets_##call( \
523518
return __data_size; \
524519
}
525520

526-
#undef DEFINE_EVENT
527-
#define DEFINE_EVENT(template, name, proto, args)
528-
529-
#undef DEFINE_EVENT_PRINT
530-
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
531-
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
532-
533521
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
534522

535523
/*
@@ -721,9 +709,6 @@ static inline void ftrace_test_probe_##call(void) \
721709
check_trace_callback_type_##call(trace_event_raw_event_##template); \
722710
}
723711

724-
#undef DEFINE_EVENT_PRINT
725-
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
726-
727712
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
728713

729714
#undef __entry

init/main.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,6 @@ static int __init bootconfig_params(char *param, char *val,
388388
{
389389
if (strcmp(param, "bootconfig") == 0) {
390390
bootconfig_found = true;
391-
} else if (strcmp(param, "--") == 0) {
392-
initargs_found = true;
393391
}
394392
return 0;
395393
}
@@ -400,19 +398,23 @@ static void __init setup_boot_config(const char *cmdline)
400398
const char *msg;
401399
int pos;
402400
u32 size, csum;
403-
char *data, *copy;
401+
char *data, *copy, *err;
404402
int ret;
405403

406404
/* Cut out the bootconfig data even if we have no bootconfig option */
407405
data = get_boot_config_from_initrd(&size, &csum);
408406

409407
strlcpy(tmp_cmdline, boot_command_line, COMMAND_LINE_SIZE);
410-
parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
411-
bootconfig_params);
408+
err = parse_args("bootconfig", tmp_cmdline, NULL, 0, 0, 0, NULL,
409+
bootconfig_params);
412410

413-
if (!bootconfig_found)
411+
if (IS_ERR(err) || !bootconfig_found)
414412
return;
415413

414+
/* parse_args() stops at '--' and returns an address */
415+
if (err)
416+
initargs_found = true;
417+
416418
if (!data) {
417419
pr_err("'bootconfig' found on command line, but no bootconfig found\n");
418420
return;

kernel/kprobes.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,9 +1111,20 @@ static int disarm_kprobe_ftrace(struct kprobe *p)
11111111
ipmodify ? &kprobe_ipmodify_enabled : &kprobe_ftrace_enabled);
11121112
}
11131113
#else /* !CONFIG_KPROBES_ON_FTRACE */
1114-
#define prepare_kprobe(p) arch_prepare_kprobe(p)
1115-
#define arm_kprobe_ftrace(p) (-ENODEV)
1116-
#define disarm_kprobe_ftrace(p) (-ENODEV)
1114+
static inline int prepare_kprobe(struct kprobe *p)
1115+
{
1116+
return arch_prepare_kprobe(p);
1117+
}
1118+
1119+
static inline int arm_kprobe_ftrace(struct kprobe *p)
1120+
{
1121+
return -ENODEV;
1122+
}
1123+
1124+
static inline int disarm_kprobe_ftrace(struct kprobe *p)
1125+
{
1126+
return -ENODEV;
1127+
}
11171128
#endif
11181129

11191130
/* Arm a kprobe with text_mutex */
@@ -2145,6 +2156,13 @@ static void kill_kprobe(struct kprobe *p)
21452156
* the original probed function (which will be freed soon) any more.
21462157
*/
21472158
arch_remove_kprobe(p);
2159+
2160+
/*
2161+
* The module is going away. We should disarm the kprobe which
2162+
* is using ftrace.
2163+
*/
2164+
if (kprobe_ftrace(p))
2165+
disarm_kprobe_ftrace(p);
21482166
}
21492167

21502168
/* Disable one kprobe */

0 commit comments

Comments
 (0)