Skip to content

Commit eff48dd

Browse files
committed
Merge tag 'trace-v5.9-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing fixes from Steven Rostedt: - Check kprobe is enabled before unregistering from ftrace as it isn't registered when disabled. - Remove kprobes enabled via command-line that is on init text when freed. - Add missing RCU synchronization for ftrace trampoline symbols removed from kallsyms. - Free trampoline on error path if ftrace_startup() fails. - Give more space for the longer PID numbers in trace output. - Fix a possible double free in the histogram code. - A couple of fixes that were discovered by sparse. * tag 'trace-v5.9-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: bootconfig: init: make xbc_namebuf static kprobes: tracing/kprobes: Fix to kill kprobes on initmem after boot tracing: fix double free ftrace: Let ftrace_enable_sysctl take a kernel pointer buffer tracing: Make the space reserved for the pid wider ftrace: Fix missing synchronize_rcu() removing trampoline from kallsyms ftrace: Free the trampoline when ftrace_startup() fails kprobes: Fix to check probe enabled before disarm_kprobe_ftrace()
2 parents 9847774 + a27026e commit eff48dd

7 files changed

Lines changed: 61 additions & 29 deletions

File tree

‎include/linux/kprobes.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,8 @@ void unregister_kretprobes(struct kretprobe **rps, int num);
373373
void kprobe_flush_task(struct task_struct *tk);
374374
void recycle_rp_inst(struct kretprobe_instance *ri, struct hlist_head *head);
375375

376+
void kprobe_free_init_mem(void);
377+
376378
int disable_kprobe(struct kprobe *kp);
377379
int enable_kprobe(struct kprobe *kp);
378380

@@ -435,6 +437,9 @@ static inline void unregister_kretprobes(struct kretprobe **rps, int num)
435437
static inline void kprobe_flush_task(struct task_struct *tk)
436438
{
437439
}
440+
static inline void kprobe_free_init_mem(void)
441+
{
442+
}
438443
static inline int disable_kprobe(struct kprobe *kp)
439444
{
440445
return -ENOSYS;

‎init/main.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/nmi.h>
3434
#include <linux/percpu.h>
3535
#include <linux/kmod.h>
36+
#include <linux/kprobes.h>
3637
#include <linux/vmalloc.h>
3738
#include <linux/kernel_stat.h>
3839
#include <linux/start_kernel.h>
@@ -303,7 +304,7 @@ static void * __init get_boot_config_from_initrd(u32 *_size, u32 *_csum)
303304

304305
#ifdef CONFIG_BOOT_CONFIG
305306

306-
char xbc_namebuf[XBC_KEYLEN_MAX] __initdata;
307+
static char xbc_namebuf[XBC_KEYLEN_MAX] __initdata;
307308

308309
#define rest(dst, end) ((end) > (dst) ? (end) - (dst) : 0)
309310

@@ -1402,6 +1403,7 @@ static int __ref kernel_init(void *unused)
14021403
kernel_init_freeable();
14031404
/* need to finish all async __init code before freeing the memory */
14041405
async_synchronize_full();
1406+
kprobe_free_init_mem();
14051407
ftrace_free_init_mem();
14061408
free_initmem();
14071409
mark_readonly();

‎kernel/kprobes.c‎

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2162,9 +2162,10 @@ static void kill_kprobe(struct kprobe *p)
21622162

21632163
/*
21642164
* The module is going away. We should disarm the kprobe which
2165-
* is using ftrace.
2165+
* is using ftrace, because ftrace framework is still available at
2166+
* MODULE_STATE_GOING notification.
21662167
*/
2167-
if (kprobe_ftrace(p))
2168+
if (kprobe_ftrace(p) && !kprobe_disabled(p) && !kprobes_all_disarmed)
21682169
disarm_kprobe_ftrace(p);
21692170
}
21702171

@@ -2459,6 +2460,28 @@ static struct notifier_block kprobe_module_nb = {
24592460
extern unsigned long __start_kprobe_blacklist[];
24602461
extern unsigned long __stop_kprobe_blacklist[];
24612462

2463+
void kprobe_free_init_mem(void)
2464+
{
2465+
void *start = (void *)(&__init_begin);
2466+
void *end = (void *)(&__init_end);
2467+
struct hlist_head *head;
2468+
struct kprobe *p;
2469+
int i;
2470+
2471+
mutex_lock(&kprobe_mutex);
2472+
2473+
/* Kill all kprobes on initmem */
2474+
for (i = 0; i < KPROBE_TABLE_SIZE; i++) {
2475+
head = &kprobe_table[i];
2476+
hlist_for_each_entry(p, head, hlist) {
2477+
if (start <= (void *)p->addr && (void *)p->addr < end)
2478+
kill_kprobe(p);
2479+
}
2480+
}
2481+
2482+
mutex_unlock(&kprobe_mutex);
2483+
}
2484+
24622485
static int __init init_kprobes(void)
24632486
{
24642487
int i, err = 0;

‎kernel/trace/ftrace.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2782,6 +2782,7 @@ static void ftrace_remove_trampoline_from_kallsyms(struct ftrace_ops *ops)
27822782
{
27832783
lockdep_assert_held(&ftrace_lock);
27842784
list_del_rcu(&ops->list);
2785+
synchronize_rcu();
27852786
}
27862787

27872788
/*
@@ -2862,6 +2863,8 @@ int ftrace_startup(struct ftrace_ops *ops, int command)
28622863
__unregister_ftrace_function(ops);
28632864
ftrace_start_up--;
28642865
ops->flags &= ~FTRACE_OPS_FL_ENABLED;
2866+
if (ops->flags & FTRACE_OPS_FL_DYNAMIC)
2867+
ftrace_trampoline_free(ops);
28652868
return ret;
28662869
}
28672870

‎kernel/trace/trace.c‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3782,14 +3782,14 @@ unsigned long trace_total_entries(struct trace_array *tr)
37823782

37833783
static void print_lat_help_header(struct seq_file *m)
37843784
{
3785-
seq_puts(m, "# _------=> CPU# \n"
3786-
"# / _-----=> irqs-off \n"
3787-
"# | / _----=> need-resched \n"
3788-
"# || / _---=> hardirq/softirq \n"
3789-
"# ||| / _--=> preempt-depth \n"
3790-
"# |||| / delay \n"
3791-
"# cmd pid ||||| time | caller \n"
3792-
"# \\ / ||||| \\ | / \n");
3785+
seq_puts(m, "# _------=> CPU# \n"
3786+
"# / _-----=> irqs-off \n"
3787+
"# | / _----=> need-resched \n"
3788+
"# || / _---=> hardirq/softirq \n"
3789+
"# ||| / _--=> preempt-depth \n"
3790+
"# |||| / delay \n"
3791+
"# cmd pid ||||| time | caller \n"
3792+
"# \\ / ||||| \\ | / \n");
37933793
}
37943794

37953795
static void print_event_info(struct array_buffer *buf, struct seq_file *m)
@@ -3810,26 +3810,26 @@ static void print_func_help_header(struct array_buffer *buf, struct seq_file *m,
38103810

38113811
print_event_info(buf, m);
38123812

3813-
seq_printf(m, "# TASK-PID %s CPU# TIMESTAMP FUNCTION\n", tgid ? "TGID " : "");
3814-
seq_printf(m, "# | | %s | | |\n", tgid ? " | " : "");
3813+
seq_printf(m, "# TASK-PID %s CPU# TIMESTAMP FUNCTION\n", tgid ? " TGID " : "");
3814+
seq_printf(m, "# | | %s | | |\n", tgid ? " | " : "");
38153815
}
38163816

38173817
static void print_func_help_header_irq(struct array_buffer *buf, struct seq_file *m,
38183818
unsigned int flags)
38193819
{
38203820
bool tgid = flags & TRACE_ITER_RECORD_TGID;
3821-
const char *space = " ";
3822-
int prec = tgid ? 10 : 2;
3821+
const char *space = " ";
3822+
int prec = tgid ? 12 : 2;
38233823

38243824
print_event_info(buf, m);
38253825

3826-
seq_printf(m, "# %.*s _-----=> irqs-off\n", prec, space);
3827-
seq_printf(m, "# %.*s / _----=> need-resched\n", prec, space);
3828-
seq_printf(m, "# %.*s| / _---=> hardirq/softirq\n", prec, space);
3829-
seq_printf(m, "# %.*s|| / _--=> preempt-depth\n", prec, space);
3830-
seq_printf(m, "# %.*s||| / delay\n", prec, space);
3831-
seq_printf(m, "# TASK-PID %.*sCPU# |||| TIMESTAMP FUNCTION\n", prec, " TGID ");
3832-
seq_printf(m, "# | | %.*s | |||| | |\n", prec, " | ");
3826+
seq_printf(m, "# %.*s _-----=> irqs-off\n", prec, space);
3827+
seq_printf(m, "# %.*s / _----=> need-resched\n", prec, space);
3828+
seq_printf(m, "# %.*s| / _---=> hardirq/softirq\n", prec, space);
3829+
seq_printf(m, "# %.*s|| / _--=> preempt-depth\n", prec, space);
3830+
seq_printf(m, "# %.*s||| / delay\n", prec, space);
3831+
seq_printf(m, "# TASK-PID %.*s CPU# |||| TIMESTAMP FUNCTION\n", prec, " TGID ");
3832+
seq_printf(m, "# | | %.*s | |||| | |\n", prec, " | ");
38333833
}
38343834

38353835
void

‎kernel/trace/trace_events_hist.c‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3865,7 +3865,6 @@ static int parse_var_defs(struct hist_trigger_data *hist_data)
38653865

38663866
s = kstrdup(field_str, GFP_KERNEL);
38673867
if (!s) {
3868-
kfree(hist_data->attrs->var_defs.name[n_vars]);
38693868
ret = -ENOMEM;
38703869
goto free;
38713870
}

‎kernel/trace/trace_output.c‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ lat_print_generic(struct trace_seq *s, struct trace_entry *entry, int cpu)
497497

498498
trace_find_cmdline(entry->pid, comm);
499499

500-
trace_seq_printf(s, "%8.8s-%-5d %3d",
500+
trace_seq_printf(s, "%8.8s-%-7d %3d",
501501
comm, entry->pid, cpu);
502502

503503
return trace_print_lat_fmt(s, entry);
@@ -588,15 +588,15 @@ int trace_print_context(struct trace_iterator *iter)
588588

589589
trace_find_cmdline(entry->pid, comm);
590590

591-
trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
591+
trace_seq_printf(s, "%16s-%-7d ", comm, entry->pid);
592592

593593
if (tr->trace_flags & TRACE_ITER_RECORD_TGID) {
594594
unsigned int tgid = trace_find_tgid(entry->pid);
595595

596596
if (!tgid)
597-
trace_seq_printf(s, "(-----) ");
597+
trace_seq_printf(s, "(-------) ");
598598
else
599-
trace_seq_printf(s, "(%5d) ", tgid);
599+
trace_seq_printf(s, "(%7d) ", tgid);
600600
}
601601

602602
trace_seq_printf(s, "[%03d] ", iter->cpu);
@@ -636,7 +636,7 @@ int trace_print_lat_context(struct trace_iterator *iter)
636636
trace_find_cmdline(entry->pid, comm);
637637

638638
trace_seq_printf(
639-
s, "%16s %5d %3d %d %08x %08lx ",
639+
s, "%16s %7d %3d %d %08x %08lx ",
640640
comm, entry->pid, iter->cpu, entry->flags,
641641
entry->preempt_count, iter->idx);
642642
} else {
@@ -917,7 +917,7 @@ static enum print_line_t trace_ctxwake_print(struct trace_iterator *iter,
917917
S = task_index_to_char(field->prev_state);
918918
trace_find_cmdline(field->next_pid, comm);
919919
trace_seq_printf(&iter->seq,
920-
" %5d:%3d:%c %s [%03d] %5d:%3d:%c %s\n",
920+
" %7d:%3d:%c %s [%03d] %7d:%3d:%c %s\n",
921921
field->prev_pid,
922922
field->prev_prio,
923923
S, delim,

0 commit comments

Comments
 (0)