Skip to content

Commit 05daae0

Browse files
committed
Merge tag 'trace-v5.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing fixes from Steven Rostedt: - Fix deadloop in ring buffer because of using stale "read" variable - Fix synthetic event use of field_pos as boolean and not an index - Fixed histogram special var "cpu" overriding event fields called "cpu" - Cleaned up error prone logic in alloc_synth_event() - Removed call to synchronize_rcu_tasks_rude() when not needed - Removed redundant initialization of a local variable "ret" - Fixed kernel crash when updating tracepoint callbacks of different priorities. * tag 'trace-v5.14-rc2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: tracepoints: Update static_call before tp_funcs when adding a tracepoint ftrace: Remove redundant initialization of variable ret ftrace: Avoid synchronize_rcu_tasks_rude() call when not necessary tracing: Clean up alloc_synth_event() tracing/histogram: Rename "cpu" to "common_cpu" tracing: Synthetic event field_pos is an index not a boolean tracing: Fix bug in rb_per_cpu_empty() that might cause deadloop.
2 parents 1af09ed + 352384d commit 05daae0

File tree

8 files changed

+53
-20
lines changed

8 files changed

+53
-20
lines changed

Documentation/trace/histogram.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ Documentation written by Tom Zanussi
191191
with the event, in nanoseconds. May be
192192
modified by .usecs to have timestamps
193193
interpreted as microseconds.
194-
cpu int the cpu on which the event occurred.
194+
common_cpu int the cpu on which the event occurred.
195195
====================== ==== =======================================
196196

197197
Extended error information

kernel/trace/ftrace.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5985,7 +5985,8 @@ ftrace_graph_release(struct inode *inode, struct file *file)
59855985
* infrastructure to do the synchronization, thus we must do it
59865986
* ourselves.
59875987
*/
5988-
synchronize_rcu_tasks_rude();
5988+
if (old_hash != EMPTY_HASH)
5989+
synchronize_rcu_tasks_rude();
59895990

59905991
free_ftrace_hash(old_hash);
59915992
}
@@ -7544,7 +7545,7 @@ int ftrace_is_dead(void)
75447545
*/
75457546
int register_ftrace_function(struct ftrace_ops *ops)
75467547
{
7547-
int ret = -1;
7548+
int ret;
75487549

75497550
ftrace_ops_init(ops);
75507551

kernel/trace/ring_buffer.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3880,10 +3880,30 @@ static bool rb_per_cpu_empty(struct ring_buffer_per_cpu *cpu_buffer)
38803880
if (unlikely(!head))
38813881
return true;
38823882

3883-
return reader->read == rb_page_commit(reader) &&
3884-
(commit == reader ||
3885-
(commit == head &&
3886-
head->read == rb_page_commit(commit)));
3883+
/* Reader should exhaust content in reader page */
3884+
if (reader->read != rb_page_commit(reader))
3885+
return false;
3886+
3887+
/*
3888+
* If writers are committing on the reader page, knowing all
3889+
* committed content has been read, the ring buffer is empty.
3890+
*/
3891+
if (commit == reader)
3892+
return true;
3893+
3894+
/*
3895+
* If writers are committing on a page other than reader page
3896+
* and head page, there should always be content to read.
3897+
*/
3898+
if (commit != head)
3899+
return false;
3900+
3901+
/*
3902+
* Writers are committing on the head page, we just need
3903+
* to care about there're committed data, and the reader will
3904+
* swap reader page with head page when it is to read data.
3905+
*/
3906+
return rb_page_commit(commit) == 0;
38873907
}
38883908

38893909
/**

kernel/trace/trace.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5609,6 +5609,10 @@ static const char readme_msg[] =
56095609
"\t [:name=histname1]\n"
56105610
"\t [:<handler>.<action>]\n"
56115611
"\t [if <filter>]\n\n"
5612+
"\t Note, special fields can be used as well:\n"
5613+
"\t common_timestamp - to record current timestamp\n"
5614+
"\t common_cpu - to record the CPU the event happened on\n"
5615+
"\n"
56125616
"\t When a matching event is hit, an entry is added to a hash\n"
56135617
"\t table using the key(s) and value(s) named, and the value of a\n"
56145618
"\t sum called 'hitcount' is incremented. Keys and values\n"

kernel/trace/trace_events_hist.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,7 +1111,7 @@ static const char *hist_field_name(struct hist_field *field,
11111111
field->flags & HIST_FIELD_FL_ALIAS)
11121112
field_name = hist_field_name(field->operands[0], ++level);
11131113
else if (field->flags & HIST_FIELD_FL_CPU)
1114-
field_name = "cpu";
1114+
field_name = "common_cpu";
11151115
else if (field->flags & HIST_FIELD_FL_EXPR ||
11161116
field->flags & HIST_FIELD_FL_VAR_REF) {
11171117
if (field->system) {
@@ -1991,14 +1991,24 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file,
19911991
hist_data->enable_timestamps = true;
19921992
if (*flags & HIST_FIELD_FL_TIMESTAMP_USECS)
19931993
hist_data->attrs->ts_in_usecs = true;
1994-
} else if (strcmp(field_name, "cpu") == 0)
1994+
} else if (strcmp(field_name, "common_cpu") == 0)
19951995
*flags |= HIST_FIELD_FL_CPU;
19961996
else {
19971997
field = trace_find_event_field(file->event_call, field_name);
19981998
if (!field || !field->size) {
1999-
hist_err(tr, HIST_ERR_FIELD_NOT_FOUND, errpos(field_name));
2000-
field = ERR_PTR(-EINVAL);
2001-
goto out;
1999+
/*
2000+
* For backward compatibility, if field_name
2001+
* was "cpu", then we treat this the same as
2002+
* common_cpu.
2003+
*/
2004+
if (strcmp(field_name, "cpu") == 0) {
2005+
*flags |= HIST_FIELD_FL_CPU;
2006+
} else {
2007+
hist_err(tr, HIST_ERR_FIELD_NOT_FOUND,
2008+
errpos(field_name));
2009+
field = ERR_PTR(-EINVAL);
2010+
goto out;
2011+
}
20022012
}
20032013
}
20042014
out:
@@ -5085,7 +5095,7 @@ static void hist_field_print(struct seq_file *m, struct hist_field *hist_field)
50855095
seq_printf(m, "%s=", hist_field->var.name);
50865096

50875097
if (hist_field->flags & HIST_FIELD_FL_CPU)
5088-
seq_puts(m, "cpu");
5098+
seq_puts(m, "common_cpu");
50895099
else if (field_name) {
50905100
if (hist_field->flags & HIST_FIELD_FL_VAR_REF ||
50915101
hist_field->flags & HIST_FIELD_FL_ALIAS)

kernel/trace/trace_events_synth.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -893,15 +893,13 @@ static struct synth_event *alloc_synth_event(const char *name, int n_fields,
893893
dyn_event_init(&event->devent, &synth_event_ops);
894894

895895
for (i = 0, j = 0; i < n_fields; i++) {
896+
fields[i]->field_pos = i;
896897
event->fields[i] = fields[i];
897898

898-
if (fields[i]->is_dynamic) {
899-
event->dynamic_fields[j] = fields[i];
900-
event->dynamic_fields[j]->field_pos = i;
899+
if (fields[i]->is_dynamic)
901900
event->dynamic_fields[j++] = fields[i];
902-
event->n_dynamic_fields++;
903-
}
904901
}
902+
event->n_dynamic_fields = j;
905903
event->n_fields = n_fields;
906904
out:
907905
return event;

kernel/trace/trace_synth.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ struct synth_field {
1414
char *name;
1515
size_t size;
1616
unsigned int offset;
17+
unsigned int field_pos;
1718
bool is_signed;
1819
bool is_string;
1920
bool is_dynamic;
20-
bool field_pos;
2121
};
2222

2323
struct synth_event {

kernel/tracepoint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ static int tracepoint_add_func(struct tracepoint *tp,
299299
* a pointer to it. This array is referenced by __DO_TRACE from
300300
* include/linux/tracepoint.h using rcu_dereference_sched().
301301
*/
302-
rcu_assign_pointer(tp->funcs, tp_funcs);
303302
tracepoint_update_call(tp, tp_funcs, false);
303+
rcu_assign_pointer(tp->funcs, tp_funcs);
304304
static_key_enable(&tp->key);
305305

306306
release_probes(old);

0 commit comments

Comments
 (0)