Skip to content

Commit d786f0f

Browse files
committed
Merge tag 'trace-v6.2-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace
Pull tracing fixes from Steven Rostedt: - Fix filter memory leak by calling ftrace_free_filter() - Initialize trace_printk() earlier so that ftrace_dump_on_oops shows data on early crashes. - Update the outdated instructions in scripts/tracing/ftrace-bisect.sh - Add lockdep_is_held() to fix lockdep warning - Add allocation failure check in create_hist_field() - Don't initialize pointer that gets set right away in enabled_monitors_write() - Update MAINTAINER entries - Fix help messages in Kconfigs - Fix kernel-doc header for update_preds() * tag 'trace-v6.2-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace: bootconfig: Update MAINTAINERS file to add tree and mailing list rv: remove redundant initialization of pointer ptr ftrace: Maintain samples/ftrace tracing/filter: fix kernel-doc warnings lib: Kconfig: fix spellos trace_events_hist: add check for return value of 'create_hist_field' tracing/osnoise: Use built-in RCU list checking tracing: Kconfig: Fix spelling/grammar/punctuation ftrace/scripts: Update the instructions for ftrace-bisect.sh tracing: Make sure trace_printk() can output as soon as it can be used ftrace: Export ftrace_free_filter() to modules
2 parents e6f2f6a + 7802023 commit d786f0f

File tree

15 files changed

+74
-25
lines changed

15 files changed

+74
-25
lines changed

MAINTAINERS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7893,7 +7893,11 @@ F: include/linux/extcon/
78937893

78947894
EXTRA BOOT CONFIG
78957895
M: Masami Hiramatsu <[email protected]>
7896+
7897+
7898+
Q: https://patchwork.kernel.org/project/linux-trace-kernel/list/
78967899
S: Maintained
7900+
T: git git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
78977901
F: Documentation/admin-guide/bootconfig.rst
78987902
F: fs/proc/bootconfig.c
78997903
F: include/linux/bootconfig.h
@@ -8569,6 +8573,7 @@ F: kernel/trace/fgraph.c
85698573
F: arch/*/*/*/*ftrace*
85708574
F: arch/*/*/*ftrace*
85718575
F: include/*/ftrace.h
8576+
F: samples/ftrace
85728577

85738578
FUNGIBLE ETHERNET DRIVERS
85748579
M: Dimitris Michailidis <[email protected]>

kernel/trace/Kconfig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -933,8 +933,8 @@ config RING_BUFFER_RECORD_RECURSION
933933
default y
934934
help
935935
The ring buffer has its own internal recursion. Although when
936-
recursion happens it wont cause harm because of the protection,
937-
but it does cause an unwanted overhead. Enabling this option will
936+
recursion happens it won't cause harm because of the protection,
937+
but it does cause unwanted overhead. Enabling this option will
938938
place where recursion was detected into the ftrace "recursed_functions"
939939
file.
940940

@@ -1017,8 +1017,8 @@ config RING_BUFFER_STARTUP_TEST
10171017
The test runs for 10 seconds. This will slow your boot time
10181018
by at least 10 more seconds.
10191019

1020-
At the end of the test, statics and more checks are done.
1021-
It will output the stats of each per cpu buffer. What
1020+
At the end of the test, statistics and more checks are done.
1021+
It will output the stats of each per cpu buffer: What
10221022
was written, the sizes, what was read, what was lost, and
10231023
other similar details.
10241024

kernel/trace/ftrace.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1248,12 +1248,17 @@ static void free_ftrace_hash_rcu(struct ftrace_hash *hash)
12481248
call_rcu(&hash->rcu, __free_ftrace_hash_rcu);
12491249
}
12501250

1251+
/**
1252+
* ftrace_free_filter - remove all filters for an ftrace_ops
1253+
* @ops - the ops to remove the filters from
1254+
*/
12511255
void ftrace_free_filter(struct ftrace_ops *ops)
12521256
{
12531257
ftrace_ops_init(ops);
12541258
free_ftrace_hash(ops->func_hash->filter_hash);
12551259
free_ftrace_hash(ops->func_hash->notrace_hash);
12561260
}
1261+
EXPORT_SYMBOL_GPL(ftrace_free_filter);
12571262

12581263
static struct ftrace_hash *alloc_ftrace_hash(int size_bits)
12591264
{
@@ -5839,6 +5844,10 @@ EXPORT_SYMBOL_GPL(modify_ftrace_direct_multi);
58395844
*
58405845
* Filters denote which functions should be enabled when tracing is enabled
58415846
* If @ip is NULL, it fails to update filter.
5847+
*
5848+
* This can allocate memory which must be freed before @ops can be freed,
5849+
* either by removing each filtered addr or by using
5850+
* ftrace_free_filter(@ops).
58425851
*/
58435852
int ftrace_set_filter_ip(struct ftrace_ops *ops, unsigned long ip,
58445853
int remove, int reset)
@@ -5858,7 +5867,11 @@ EXPORT_SYMBOL_GPL(ftrace_set_filter_ip);
58585867
*
58595868
* Filters denote which functions should be enabled when tracing is enabled
58605869
* If @ips array or any ip specified within is NULL , it fails to update filter.
5861-
*/
5870+
*
5871+
* This can allocate memory which must be freed before @ops can be freed,
5872+
* either by removing each filtered addr or by using
5873+
* ftrace_free_filter(@ops).
5874+
*/
58625875
int ftrace_set_filter_ips(struct ftrace_ops *ops, unsigned long *ips,
58635876
unsigned int cnt, int remove, int reset)
58645877
{
@@ -5900,6 +5913,10 @@ ftrace_set_regex(struct ftrace_ops *ops, unsigned char *buf, int len,
59005913
*
59015914
* Filters denote which functions should be enabled when tracing is enabled.
59025915
* If @buf is NULL and reset is set, all functions will be enabled for tracing.
5916+
*
5917+
* This can allocate memory which must be freed before @ops can be freed,
5918+
* either by removing each filtered addr or by using
5919+
* ftrace_free_filter(@ops).
59035920
*/
59045921
int ftrace_set_filter(struct ftrace_ops *ops, unsigned char *buf,
59055922
int len, int reset)
@@ -5919,6 +5936,10 @@ EXPORT_SYMBOL_GPL(ftrace_set_filter);
59195936
* Notrace Filters denote which functions should not be enabled when tracing
59205937
* is enabled. If @buf is NULL and reset is set, all functions will be enabled
59215938
* for tracing.
5939+
*
5940+
* This can allocate memory which must be freed before @ops can be freed,
5941+
* either by removing each filtered addr or by using
5942+
* ftrace_free_filter(@ops).
59225943
*/
59235944
int ftrace_set_notrace(struct ftrace_ops *ops, unsigned char *buf,
59245945
int len, int reset)

kernel/trace/rv/rv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ static ssize_t enabled_monitors_write(struct file *filp, const char __user *user
516516
struct rv_monitor_def *mdef;
517517
int retval = -EINVAL;
518518
bool enable = true;
519-
char *ptr = buff;
519+
char *ptr;
520520
int len;
521521

522522
if (count < 1 || count > MAX_RV_MONITOR_NAME_SIZE + 1)

kernel/trace/trace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10295,6 +10295,8 @@ void __init early_trace_init(void)
1029510295
static_key_enable(&tracepoint_printk_key.key);
1029610296
}
1029710297
tracer_alloc_buffers();
10298+
10299+
init_events();
1029810300
}
1029910301

1030010302
void __init trace_init(void)

kernel/trace/trace.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,7 @@ extern void trace_event_enable_cmd_record(bool enable);
14901490
extern void trace_event_enable_tgid_record(bool enable);
14911491

14921492
extern int event_trace_init(void);
1493+
extern int init_events(void);
14931494
extern int event_trace_add_tracer(struct dentry *parent, struct trace_array *tr);
14941495
extern int event_trace_del_tracer(struct trace_array *tr);
14951496
extern void __trace_early_add_events(struct trace_array *tr);

kernel/trace/trace_events_filter.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ static bool is_not(const char *str)
128128
}
129129

130130
/**
131-
* prog_entry - a singe entry in the filter program
131+
* struct prog_entry - a singe entry in the filter program
132132
* @target: Index to jump to on a branch (actually one minus the index)
133133
* @when_to_branch: The value of the result of the predicate to do a branch
134134
* @pred: The predicate to execute.
@@ -140,16 +140,16 @@ struct prog_entry {
140140
};
141141

142142
/**
143-
* update_preds- assign a program entry a label target
143+
* update_preds - assign a program entry a label target
144144
* @prog: The program array
145145
* @N: The index of the current entry in @prog
146-
* @when_to_branch: What to assign a program entry for its branch condition
146+
* @invert: What to assign a program entry for its branch condition
147147
*
148148
* The program entry at @N has a target that points to the index of a program
149149
* entry that can have its target and when_to_branch fields updated.
150150
* Update the current program entry denoted by index @N target field to be
151151
* that of the updated entry. This will denote the entry to update if
152-
* we are processing an "||" after an "&&"
152+
* we are processing an "||" after an "&&".
153153
*/
154154
static void update_preds(struct prog_entry *prog, int N, int invert)
155155
{

kernel/trace/trace_events_hist.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1988,6 +1988,8 @@ static struct hist_field *create_hist_field(struct hist_trigger_data *hist_data,
19881988
hist_field->fn_num = flags & HIST_FIELD_FL_LOG2 ? HIST_FIELD_FN_LOG2 :
19891989
HIST_FIELD_FN_BUCKET;
19901990
hist_field->operands[0] = create_hist_field(hist_data, field, fl, NULL);
1991+
if (!hist_field->operands[0])
1992+
goto free;
19911993
hist_field->size = hist_field->operands[0]->size;
19921994
hist_field->type = kstrdup_const(hist_field->operands[0]->type, GFP_KERNEL);
19931995
if (!hist_field->type)

kernel/trace/trace_osnoise.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,8 @@ static void osnoise_unregister_instance(struct trace_array *tr)
147147
* register/unregister serialization is provided by trace's
148148
* trace_types_lock.
149149
*/
150-
lockdep_assert_held(&trace_types_lock);
151-
152-
list_for_each_entry_rcu(inst, &osnoise_instances, list) {
150+
list_for_each_entry_rcu(inst, &osnoise_instances, list,
151+
lockdep_is_held(&trace_types_lock)) {
153152
if (inst->tr == tr) {
154153
list_del_rcu(&inst->list);
155154
found = 1;

kernel/trace/trace_output.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1535,7 +1535,7 @@ static struct trace_event *events[] __initdata = {
15351535
NULL
15361536
};
15371537

1538-
__init static int init_events(void)
1538+
__init int init_events(void)
15391539
{
15401540
struct trace_event *event;
15411541
int i, ret;
@@ -1548,4 +1548,3 @@ __init static int init_events(void)
15481548

15491549
return 0;
15501550
}
1551-
early_initcall(init_events);

lib/Kconfig.debug

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1917,7 +1917,7 @@ config FUNCTION_ERROR_INJECTION
19171917
help
19181918
Add fault injections into various functions that are annotated with
19191919
ALLOW_ERROR_INJECTION() in the kernel. BPF may also modify the return
1920-
value of theses functions. This is useful to test error paths of code.
1920+
value of these functions. This is useful to test error paths of code.
19211921

19221922
If unsure, say N
19231923

lib/Kconfig.kcsan

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ config KCSAN_WEAK_MEMORY
194194
Enable support for modeling a subset of weak memory, which allows
195195
detecting a subset of data races due to missing memory barriers.
196196

197-
Depends on KCSAN_STRICT, because the options strenghtening certain
197+
Depends on KCSAN_STRICT, because the options strengthening certain
198198
plain accesses by default (depending on !KCSAN_STRICT) reduce the
199199
ability to detect any data races invoving reordered accesses, in
200200
particular reordered writes.

samples/ftrace/ftrace-direct-multi-modify.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ static void __exit ftrace_direct_multi_exit(void)
152152
{
153153
kthread_stop(simple_tsk);
154154
unregister_ftrace_direct_multi(&direct, my_tramp);
155+
ftrace_free_filter(&direct);
155156
}
156157

157158
module_init(ftrace_direct_multi_init);

samples/ftrace/ftrace-direct-multi.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ static int __init ftrace_direct_multi_init(void)
7979
static void __exit ftrace_direct_multi_exit(void)
8080
{
8181
unregister_ftrace_direct_multi(&direct, (unsigned long) my_tramp);
82+
ftrace_free_filter(&direct);
8283
}
8384

8485
module_init(ftrace_direct_multi_init);

scripts/tracing/ftrace-bisect.sh

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,48 @@
1212
# (note, if this is a problem with function_graph tracing, then simply
1313
# replace "function" with "function_graph" in the following steps).
1414
#
15-
# # cd /sys/kernel/debug/tracing
15+
# # cd /sys/kernel/tracing
1616
# # echo schedule > set_ftrace_filter
1717
# # echo function > current_tracer
1818
#
1919
# If this works, then we know that something is being traced that shouldn't be.
2020
#
2121
# # echo nop > current_tracer
2222
#
23-
# # cat available_filter_functions > ~/full-file
23+
# Starting with v5.1 this can be done with numbers, making it much faster:
24+
#
25+
# The old (slow) way, for kernels before v5.1.
26+
#
27+
# [old-way] # cat available_filter_functions > ~/full-file
28+
#
29+
# [old-way] *** Note *** this process will take several minutes to update the
30+
# [old-way] filters. Setting multiple functions is an O(n^2) operation, and we
31+
# [old-way] are dealing with thousands of functions. So go have coffee, talk
32+
# [old-way] with your coworkers, read facebook. And eventually, this operation
33+
# [old-way] will end.
34+
#
35+
# The new way (using numbers) is an O(n) operation, and usually takes less than a second.
36+
#
37+
# seq `wc -l available_filter_functions | cut -d' ' -f1` > ~/full-file
38+
#
39+
# This will create a sequence of numbers that match the functions in
40+
# available_filter_functions, and when echoing in a number into the
41+
# set_ftrace_filter file, it will enable the corresponding function in
42+
# O(1) time. Making enabling all functions O(n) where n is the number of
43+
# functions to enable.
44+
#
45+
# For either the new or old way, the rest of the operations remain the same.
46+
#
2447
# # ftrace-bisect ~/full-file ~/test-file ~/non-test-file
2548
# # cat ~/test-file > set_ftrace_filter
2649
#
27-
# *** Note *** this will take several minutes. Setting multiple functions is
28-
# an O(n^2) operation, and we are dealing with thousands of functions. So go
29-
# have coffee, talk with your coworkers, read facebook. And eventually, this
30-
# operation will end.
31-
#
3250
# # echo function > current_tracer
3351
#
3452
# If it crashes, we know that ~/test-file has a bad function.
3553
#
3654
# Reboot back to test kernel.
3755
#
38-
# # cd /sys/kernel/debug/tracing
56+
# # cd /sys/kernel/tracing
3957
# # mv ~/test-file ~/full-file
4058
#
4159
# If it didn't crash.

0 commit comments

Comments
 (0)