Skip to contentSkip to conversation

PATCH New Steven Rostedt 2 participants 34 messages Nov 20

Subsystems (5)
lore
Share & tools
lore
#1 lore raw

PATCH 1/32 ring-buffer: Do not WARN when trace_rb_cpu_prepare() fails to allocate

From: Christian Aurich Zanettini Martins <[email protected]>

Creating a tracing instance allocates the buffers of the other CPUs through trace_rb_cpu_prepare(), which WARNs if the allocation fails. But __rb_allocate_pages() bails out on purpose when si_mem_available() is too low or the task gets killed, so a mkdir in instances/ with a large trace_buf_size is enough to trigger it:

  WARNING: kernel/trace/ring_buffer.c:8094 at trace_rb_cpu_prepare+0xf1/0x100

The same failure for the current CPU, or in ring_buffer_resize(), just returns -ENOMEM. Use pr_warn() here instead.

---
 kernel/trace/ring_buffer.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
kernel/trace/ring_buffer.c +1 -2
index 75cd8df23c1b..ed267d628826 100644
@@ -8091,8 +8091,7 @@ int trace_rb_cpu_prepare(unsigned int cpu, struct hlist_node *node)
 	buffer->buffers[cpu] =
 		rb_allocate_cpu_buffer(buffer, nr_pages, cpu);
 	if (!buffer->buffers[cpu]) {
-		WARN(1, "failed to allocate ring buffer on CPU %u\n",
-		     cpu);
+		pr_warn("failed to allocate ring buffer on CPU %u\n", cpu);
 		return -ENOMEM;
 	}
 
Signature · 1 line
2.53.0
#2 lore raw

PATCH 2/32 tracing: Keep copying markers when one instance is stopped

In reply to Steven Rostedt

From: Jaewon Jung <[email protected]>

When several instances enable copy_trace_marker, stopping one instance can prevent the remaining buffers from receiving markers.

Continue copying text and raw markers even if one copy fails. Return the largest successful write length, or -ENODEV if no write succeeds.

Fixes 7b382efd5e8a ("tracing: Allow the top level trace_marker to write into another instances")
---
 kernel/trace/trace.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
kernel/trace/trace.c +8 -6
index 4ccdefb5c3ef..527b16690acb 100644
@@ -6345,9 +6345,10 @@ tracing_mark_write(struct file *filp, const char __user *ubuf,
 	if (tr == &global_trace) {
 		guard(rcu)();
 		list_for_each_entry_rcu(tr, &marker_copies, marker_list) {
-			written = write_marker_to_buffer(tr, buf, cnt, ip);
-			if (written < 0)
-				break;
+			ssize_t w = write_marker_to_buffer(tr, buf, cnt, ip);
+
+			if (w >= 0 && w > written)
+				written = w;
 		}
 	} else {
 		written = write_marker_to_buffer(tr, buf, cnt, ip);
@@ -6424,9 +6425,10 @@ tracing_mark_raw_write(struct file *filp, const char __user *ubuf,
 	if (tr == &global_trace) {
 		guard(rcu)();
 		list_for_each_entry_rcu(tr, &marker_copies, marker_list) {
-			written = write_raw_marker_to_buffer(tr, buf, cnt);
-			if (written < 0)
-				break;
+			ssize_t w = write_raw_marker_to_buffer(tr, buf, cnt);
+
+			if (w >= 0 && w > written)
+				written = w;
 		}
 	} else {
 		written = write_raw_marker_to_buffer(tr, buf, cnt);
Signature · 1 line
2.53.0
#3 lore raw

PATCH 3/32 tracing: Restrict perf filters that read kernel strings

In reply to Steven Rostedt

From: Kyle Zeng <[email protected]>

A task-bound, counting-only syscall tracepoint can be opened without permission to read raw kernel tracepoint data. Setting exclude_kernel does not prevent its filter from running: perf_syscall_enter() submits the saved user-mode registers.

Pointer-string filters use FILTER_PRED_FN_PCHAR by default, which reads through strncpy_from_kernel_nofault(). For sys_enter_openat, for example, the filename field comes directly from a syscall argument. An unprivileged caller can pass a kernel address, install a filter such as 'filename ~ "Linux version*"', and use the event count to test the contents of kernel memory, even with perf_event_paranoid=2.

Check the compiled filter before installing it and require the same kernel and raw-tracepoint permissions as access to raw kernel tracepoint data for FILTER_PRED_FN_PCHAR. Inspect every predicate so that other events, operators, and boolean expressions cannot bypass the check. Return the permission error through the existing cleanup path before publishing the filter.

Keep user-pointer (.ustring) and record-local predicates available under the existing policy. This leaves tracefs filtering and authorized kernel string filtering unchanged.

Fixes 5967bd5c4239 ("tracing: Let filter_assign_type() detect FILTER_PTR_STRING")
Assisted-by Codex:gpt-6-astra
---
 kernel/trace/trace_events_filter.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
kernel/trace/trace_events_filter.c +26 -0
index c10951bcfc5f..cd0da148414d 100644
@@ -2749,6 +2749,28 @@ static int ftrace_function_set_filter(struct perf_event *event,
 }
 #endif /* CONFIG_FUNCTION_TRACER */
 
+static int ftrace_profile_filter_perm(struct event_filter *filter)
+{
+	struct prog_entry *prog = rcu_dereference_protected(filter->prog,
+						lockdep_is_held(&event_mutex));
+	int i, err;
+
+	for (i = 0; prog[i].pred; i++) {
+		if (prog[i].pred->fn_num != FILTER_PRED_FN_PCHAR)
+			continue;
+
+		/*
+		 * Even a counting filter can reveal kernel string data.
+		 * Require the same access as raw kernel tracepoints.
+		 */
+		err = perf_allow_kernel();
+		if (err)
+			return err;
+		return perf_allow_tracepoint();
+	}
+	return 0;
+}
+
 int ftrace_profile_set_filter(struct perf_event *event, int event_id,
 			      char *filter_str)
 {
@@ -2770,6 +2792,10 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
 	if (err)
 		goto free_filter;
 
+	err = ftrace_profile_filter_perm(filter);
+	if (err)
+		goto free_filter;
+
 	if (ftrace_event_is_function(call))
 		err = ftrace_function_set_filter(event, filter);
 	else
Signature · 1 line
2.53.0
#4 lore raw

PATCH 4/32 tracing/filters: Treat zero-length dynamic strings as empty

In reply to Steven Rostedt

From: Kyle Zeng <[email protected]>

The regex callbacks use a length of zero for NUL-terminated strings of unknown size, such as the trailing buffer in a trace_marker record. However, filter_pred_strloc() and filter_pred_strrelloc() pass the length from a data locator directly to those callbacks. A zero-length locator has no data and need not point at a NUL byte.

In particular, syscall entry events can contain an empty captured array or a failed user-string copy. Matching such a field with an equality, prefix, or substring filter can read beyond the record. The per-CPU perf trace buffer is reused, so an unprivileged counting syscall event can disclose bytes left by a previous kernel tracepoint even when raw sampling is denied and exclude_kernel prevents counting that tracepoint.

Handle both locator formats through a common helper. For a zero-length field, pass an empty string and its actual size to the regex callback. This gives all matching modes the empty-string semantics without reading the locator's target. Keep nonzero fields and the legacy trace_marker unknown-length convention unchanged.

Fixes 10f20e9f9da9 ("tracing: Have zero size length in filter logic be full string")
Assisted-by Codex:gpt-6-astra
---
 kernel/trace/trace_events_filter.c | 38 +++++++++++++++++++-----------
 1 file changed, 24 insertions(+), 14 deletions(-)
kernel/trace/trace_events_filter.c +24 -14
index cd0da148414d..62444db0f78b 100644
@@ -891,6 +891,25 @@ static int filter_pred_pchar_user(struct filter_pred *pred, void *event)
 	return filter_pchar(pred, str);
 }
 
+static __always_inline int filter_dyn_string(struct filter_pred *pred,
+					     char *str, int len)
+{
+	int cmp;
+
+	/*
+	 * The regex callbacks use zero for an unknown-length, NUL-terminated
+	 * string. A zero-length data_loc or rel_loc field has no bytes at all.
+	 * Match an empty string instead of reading past the end of the field.
+	 */
+	if (!len) {
+		str = "";
+		len = 1;
+	}
+
+	cmp = pred->regex->match(str, pred->regex, len);
+	return cmp ^ pred->not;
+}
+
 /*
  * Filter predicate for dynamic sized arrays of characters.
  * These are implemented through a list of strings at the end
@@ -907,13 +926,8 @@ static int filter_pred_strloc(struct filter_pred *pred, void *event)
 	int str_loc = str_item & 0xffff;
 	int str_len = str_item >> 16;
 	char *addr = (char *)(event + str_loc);
-	int cmp, match;
-
-	cmp = pred->regex->match(addr, pred->regex, str_len);
 
-	match = cmp ^ pred->not;
-
-	return match;
+	return filter_dyn_string(pred, addr, str_len);
 }
 
 /*
@@ -930,13 +944,8 @@ static int filter_pred_strrelloc(struct filter_pred *pred, void *event)
 	int str_loc = str_item & 0xffff;
 	int str_len = str_item >> 16;
 	char *addr = (char *)(&item[1]) + str_loc;
-	int cmp, match;
-
-	cmp = pred->regex->match(addr, pred->regex, str_len);
 
-	match = cmp ^ pred->not;
-
-	return match;
+	return filter_dyn_string(pred, addr, str_len);
 }
 
 /* Filter predicate for CPUs. */
@@ -1037,7 +1046,8 @@ static int filter_pred_within(struct filter_pred *pred, void *event)
  *
  * @str: the string to be searched
  * @r:   the regex structure containing the pattern string
- * @len: the length of the string to be searched (including '\0')
+ * @len: the length of the string to be searched (including '\0'), or zero
+ *       for a NUL-terminated string of unknown length
  *
  * Note:
  * - @str might not be NULL-terminated if it's of type DYN_STRING
@@ -1046,7 +1056,7 @@ static int filter_pred_within(struct filter_pred *pred, void *event)
 
 static int regex_match_full(char *str, struct regex *r, int len)
 {
-	/* len of zero means str is dynamic and ends with '\0' */
+	/* Zero is reserved for a NUL-terminated string of unknown length. */
 	if (!len)
 		return strcmp(str, r->pattern) == 0;
 
Signature · 1 line
2.53.0
#5 lore raw

PATCH 5/32 tracing: Define common event fields before enabling boot events

In reply to Steven Rostedt

From: David Carlier <[email protected]>

event_trace_enable() parses trace_event= filters before event_trace_init_fields() has defined the common and generic fields, so a filter on common_pid or comm fails and the event stays off until event_trace_enable_again().

Fixes 084100a1b579 ("tracing: Parse filter from boot event string")
---
 kernel/trace/trace_events.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events.c +1 -1
index 49d135bc2fbf..c9d31c9f3fca 100644
@@ -5026,8 +5026,8 @@ void __init trace_event_init(void)
 {
 	event_trace_memsetup();
 	init_ftrace_syscalls();
-	event_trace_enable();
 	event_trace_init_fields();
+	event_trace_enable();
 }
 
 #ifdef CONFIG_EVENT_TRACE_STARTUP_TEST
Signature · 1 line
2.53.0
#6 lore raw

PATCH 6/32 tracing: Drop the synthetic event ref when clearing hist triggers

In reply to Steven Rostedt

From: David Carlier <[email protected]>

clear_event_triggers() frees a hist trigger on a synthetic event without dropping the se->ref taken by event_hist_trigger_parse(). Removing an instance with such a trigger leaves the synthetic event busy forever.

Fixes 4b147936fa50 ("tracing: Add support for 'synthetic' events")
---
 kernel/trace/trace.h                |  2 ++
 kernel/trace/trace_events_hist.c    | 20 +++++++++++++-------
 kernel/trace/trace_events_trigger.c |  2 ++
 3 files changed, 17 insertions(+), 7 deletions(-)
kernel/trace/trace.h +2 -0
index 0635503a31dd..6b695a7f42c8 100644
@@ -1912,9 +1912,11 @@ extern const struct file_operations event_inject_fops;
 #ifdef CONFIG_HIST_TRIGGERS
 extern int register_trigger_hist_cmd(void);
 extern int register_trigger_hist_enable_disable_cmds(void);
+extern void hist_put_synth_event(struct trace_event_file *file);
 #else
 static inline int register_trigger_hist_cmd(void) { return 0; }
 static inline int register_trigger_hist_enable_disable_cmds(void) { return 0; }
+static inline void hist_put_synth_event(struct trace_event_file *file) { }
 #endif
 
 extern int register_trigger_cmds(void);
kernel/trace/trace_events_hist.c +13 -7
index 1aae7d7c6dc5..a87d626e40e8 100644
@@ -6761,6 +6761,17 @@ static bool hist_trigger_check_refs(struct event_trigger_data *data,
 	return false;
 }
 
+void hist_put_synth_event(struct trace_event_file *file)
+{
+	struct synth_event *se;
+
+	lockdep_assert_held(&event_mutex);
+
+	se = find_synth_event_call(file->event_call);
+	if (se)
+		se->ref--;
+}
+
 static void hist_unregister_trigger(char *glob,
 				    struct event_trigger_data *data,
 				    struct trace_event_file *file)
@@ -6816,7 +6827,6 @@ static void hist_unreg_all(struct trace_event_file *file)
 {
 	struct event_trigger_data *test, *n;
 	struct hist_trigger_data *hist_data;
-	struct synth_event *se;
 
 	lockdep_assert_held(&event_mutex);
 
@@ -6829,9 +6839,7 @@ static void hist_unreg_all(struct trace_event_file *file)
 			list_del_rcu(&test->list);
 			trace_event_trigger_enable_disable(file, 0);
 
-			se = find_synth_event_call(file->event_call);
-			if (se)
-				se->ref--;
+			hist_put_synth_event(file);
 
 			update_cond_flag(file);
 			if (hist_data->enable_timestamps)
@@ -6946,9 +6954,7 @@ static int event_hist_trigger_parse(struct event_command *cmd_ops,
 		}
 
 		event_trigger_unregister(cmd_ops, file, glob+1, trigger_data);
-		se = find_synth_event_call(file->event_call);
-		if (se)
-			se->ref--;
+		hist_put_synth_event(file);
 		ret = 0;
 		goto out_free;
 	}
kernel/trace/trace_events_trigger.c +2 -0
index 4d2fde996c0f..a2487ad7fef8 100644
@@ -643,6 +643,8 @@ clear_event_triggers(struct trace_array *tr)
 		list_for_each_entry_safe(data, n, &file->triggers, list) {
 			trace_event_trigger_enable_disable(file, 0);
 			list_del_rcu(&data->list);
+			if (data->cmd_ops->trigger_type == ETT_EVENT_HIST)
+				hist_put_synth_event(file);
 			if (data->cmd_ops->free)
 				data->cmd_ops->free(data);
 		}
Signature · 1 line
2.53.0
#7 lore raw

PATCH 7/32 tracing: Avoid undefined shifts for zero histogram map size

In reply to Steven Rostedt

From: Jaewon Jung <[email protected]>

Reject size=0 before calling roundup_pow_of_two().

include/linux/log2.h documents roundup_pow_of_two() as:

- the result is undefined when n == 0

With CONFIG_UBSAN_SHIFT=y, a size=0 histogram trigger reports:

  UBSAN: shift-out-of-bounds in include/linux/log2.h
  shift exponent 64 is too large for 64-bit type 'long unsigned int'

Tested on x86_64 QEMU: size=0 is rejected without UBSAN warnings, and the histogram modifier and parser tests pass.

Fixes 7ef224d1d0e3 ("tracing: Add 'hist' event trigger command")
---
 kernel/trace/trace_events_hist.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/trace/trace_events_hist.c +5 -0
index a87d626e40e8..d4702ad4e003 100644
@@ -1430,6 +1430,11 @@ static int parse_map_size(char *str)
 	if (ret)
 		goto out;
 
+	if (!size) {
+		ret = -EINVAL;
+		goto out;
+	}
+
 	map_bits = ilog2(roundup_pow_of_two(size));
 	if (map_bits < TRACING_MAP_BITS_MIN ||
 	    map_bits > TRACING_MAP_BITS_MAX)
Signature · 1 line
2.53.0
#8 lore raw

PATCH 8/32 tracing/filters: Fix MATCH_END_ONLY regex matching for fixed-size strings

In reply to Steven Rostedt

From: "Masami Hiramatsu (Google)" <[email protected]>

regex_match_end() calculates string length as "len - 1", assuming @len is the string length including trailing '\0'. For dynamic strings (filter_pred_strloc) and pointer strings (filter_pchar), this assumption holds and allows O(1) constant-time suffix matching.

However, for fixed-size string fields (FILTER_STATIC_STRING) and "comm" (FILTER_COMM), the callers pass the buffer capacity rather than the actual string length (field->size for filter_pred_string, and TASK_COMM_LEN for filter_pred_comm). Because these buffers hold null-terminated strings (e.g. prev_comm in sched_switch holding "bash" in a 16-byte buffer), regex_match_end() tests against the tail of the buffer capacity (typically trailing '\0' padding at offset 13) rather than the actual string end. Consequently, suffix matching like comm ~ "*sh" or prev_comm ~ "*sh" fails for all strings shorter than the buffer capacity.

Furthermore, for trace events like ftrace/print (trace_marker), the "buf" field is defined with size 0, denoting an unbounded NUL-terminated string. regex_match_end() and regex_match_end_str() return 0 when len is 0, causing suffix matching to fail on ftrace/print events as well.

To fix this without penalizing dynamic and pointer strings with an unnecessary scan on every event:
- Introduce regex_match_end_str() using strnlen(str, len) for fixed-size buffers (FILTER_COMM and FILTER_STATIC_STRING with field->size > 0).
- Introduce regex_match_end_dynstr() using strlen(str) for unbounded strings (FILTER_STATIC_STRING with field->size == 0).

Assign these match callbacks in parse_pred() when MATCH_END_ONLY is requested.

Fixes a3291c14ecf0 ("tracing/filters: Fix MATCH_END_ONLY filter matching")
Fixes 10f20e9f9da9 ("tracing: Have zero size length in filter logic be full string")
---
 kernel/trace/trace_events_filter.c | 32 ++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
kernel/trace/trace_events_filter.c +32 -0
index 62444db0f78b..d2069ef554d6 100644
@@ -1092,6 +1092,30 @@ static int regex_match_end(char *str, struct regex *r, int len)
 	return 0;
 }
 
+static int regex_match_end_str(char *str, struct regex *r, int len)
+{
+	int slen;
+
+	if (len < r->len)
+		return 0;
+
+	slen = strnlen(str, len);
+	if (slen >= r->len &&
+	    memcmp(str + slen - r->len, r->pattern, r->len) == 0)
+		return 1;
+	return 0;
+}
+
+static int regex_match_end_dynstr(char *str, struct regex *r, int len)
+{
+	int slen = strlen(str);
+
+	if (slen >= r->len &&
+	    memcmp(str + slen - r->len, r->pattern, r->len) == 0)
+		return 1;
+	return 0;
+}
+
 static int regex_match_glob(char *str, struct regex *r, int len)
 {
 	return glob_match_len(r->pattern, str, len) ? 1 : 0;
@@ -2031,10 +2055,18 @@ static int parse_pred(const char *str, void *data,
 
 		if (field->filter_type == FILTER_COMM) {
 			pred->fn_num = FILTER_PRED_FN_COMM;
+			if (pred->regex->match == regex_match_end)
+				pred->regex->match = regex_match_end_str;
 
 		} else if (field->filter_type == FILTER_STATIC_STRING) {
 			pred->fn_num = FILTER_PRED_FN_STRING;
 			pred->regex->field_len = field->size;
+			if (pred->regex->match == regex_match_end) {
+				if (!field->size)
+					pred->regex->match = regex_match_end_dynstr;
+				else
+					pred->regex->match = regex_match_end_str;
+			}
 
 		} else if (field->filter_type == FILTER_DYN_STRING) {
 			pred->fn_num = FILTER_PRED_FN_STRLOC;
Signature · 1 line
2.53.0
#9 lore raw

PATCH 9/32 tracing/filters: Handle out-of-range CPU for OP_NE in cpumask comparison

In reply to Steven Rostedt

From: "Masami Hiramatsu (Google)" <[email protected]>

In filter_pred_##size##_cpumask(), if the event's scalar CPU value is out of range (cpu >= nr_cpu_ids), it unconditionally returns 0.

However, if the predicate operation is OP_NE (e.g., field != CPUS{0,1}), an out-of-range CPU cannot match any valid CPU in the user-provided cpumask and the condition is satisfied. Returning 0 produces a false negative.

Return "pred->op == OP_NE" instead of 0 when cpu >= nr_cpu_ids.

---
 kernel/trace/trace_events_filter.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace_events_filter.c +1 -1
index d2069ef554d6..1b960cfdc69d 100644
@@ -758,7 +758,7 @@ static int filter_pred_##size##_cpumask(struct filter_pred *pred, void *event)	\
 	unsigned int cpu = *addr;						\
 										\
 	if (cpu >= nr_cpu_ids)							\
-		return 0;							\
+		return pred->op == OP_NE;					\
 										\
 	return do_filter_scalar_cpumask(pred->op, cpu, pred->mask);		\
 }
Signature · 1 line
2.53.0
#10 lore raw

PATCH 10/32 tracing/filters: Check for missing operand after operator in parse_pred()

In reply to Steven Rostedt

From: "Masami Hiramatsu (Google)" <[email protected]>

In parse_pred(), after matching the operator and skipping whitespace, the filter string may terminate (str[i] == '\0') if the operand is missing (e.g. "ip ==" or "common_pid ==").

For function events, the loop 'for (i++; str[i]; i++)' unconditionally increments 'i' past the NUL terminator, causing an out-of-bounds read. For other event types, allocating a predicate only to fail later during value parsing is wasteful.

Check if 'str[i]' is NUL immediately after skipping whitespace after the operator, and report FILT_ERR_INVALID_FILTER.

---
 kernel/trace/trace_events_filter.c | 5 +++++
 1 file changed, 5 insertions(+)
kernel/trace/trace_events_filter.c +5 -0
index 1b960cfdc69d..32fcc6215d24 100644
@@ -1766,6 +1766,11 @@ static int parse_pred(const char *str, void *data,
 	while (isspace(str[i]))
 		i++;
 
+	if (!str[i]) {
+		parse_error(pe, FILT_ERR_INVALID_FILTER, pos + i);
+		goto err_free;
+	}
+
 	s = i;
 
 	pred = kzalloc_obj(*pred);
Signature · 1 line
2.53.0
#11 lore raw

PATCH 11/32 tracing/filters: Fix false success return in process_system_preds()

In reply to Steven Rostedt

From: "Masami Hiramatsu (Google)" <[email protected]>

In process_system_preds(), "fail" was initialized to true to indicate whether any event in the subsystem successfully applied the filter. However, "fail = false;" was placed at the end of the event loop outside the error check, unconditionally clearing "fail" on every iteration even when process_preds() returned an error.

As a result, if every event in the subsystem fails to match the filter (e.g., an invalid field), process_system_preds() returns 0 (success) instead of -EINVAL. Consequently, create_system_filter() considers the operation successful and silently resets the subsystem filter display to the default global filter message instead of reporting the parse error.

Fix this by clearing "fail" only when at least one event filter succeeds. Consolidate the cleanup logic in fail and fail_mem by using ret initialized to -ENOMEM, setting ret to -EINVAL in fail, and falling through to fail_mem, freeing any replaced filters via delay_free_filter() if !list_empty(&filter_list->list).

---
 kernel/trace/trace_events_filter.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
kernel/trace/trace_events_filter.c +8 -9
index 32fcc6215d24..a1c298210059 100644
@@ -2352,6 +2352,7 @@ static int process_system_preds(struct trace_subsystem_dir *dir,
 	struct event_filter *filter = NULL;
 	struct filter_head *filter_list;
 	bool fail = true;
+	int ret = -ENOMEM;
 	int err;
 
 	filter_list = kmalloc_obj(*filter_list);
@@ -2378,9 +2379,10 @@ static int process_system_preds(struct trace_subsystem_dir *dir,
 			filter_disable(file);
 			parse_error(pe, FILT_ERR_BAD_SUBSYS_FILTER, 0);
 			append_filter_err(tr, pe, filter);
-		} else
+		} else {
 			event_set_filtered_flag(file);
-
+			fail = false;
+		}
 
 		filter_item = kzalloc_obj(*filter_item);
 		if (!filter_item)
@@ -2394,8 +2396,6 @@ static int process_system_preds(struct trace_subsystem_dir *dir,
 		filter_item->filter = event_filter(file);
 		event_set_filter(file, filter);
 		filter = NULL;
-
-		fail = false;
 	}
 
 	if (fail)
@@ -2410,19 +2410,18 @@ static int process_system_preds(struct trace_subsystem_dir *dir,
 	return 0;
  fail:
 	/* No call succeeded */
-	free_filter_list(filter_list);
 	parse_error(pe, FILT_ERR_BAD_SUBSYS_FILTER, 0);
-	return -EINVAL;
+	ret = -EINVAL;
  fail_mem:
 	__free_filter(filter);
 
-	/* If any call succeeded, we still need to sync */
-	if (!fail)
+	/* If any filter was replaced, we still need to sync */
+	if (!list_empty(&filter_list->list))
 		delay_free_filter(filter_list);
 	else
 		free_filter_list(filter_list);
 
-	return -ENOMEM;
+	return ret;
 }
 
 static int create_filter_start(char *filter_string, bool set_str,
Signature · 1 line
2.53.0
#12 lore raw

PATCH 12/32 tracing: Free tracer resources on instance creation failure

In reply to Steven Rostedt

From: "Baek Kyu, Kim" <[email protected]>

Creating a tracefs instance can allocate private tracer nodes, copied flags and option arrays before trace_array_create_dir() returns. If a later allocation fails, trace_array_create_systems() frees the trace_array without releasing those private allocations. The failed instance is never registered, so normal removal cannot reclaim them.

Free the tracer nodes and option arrays when trace_array_create_dir() fails, then continue through the existing trace_array cleanup. Share the option array cleanup with normal instance removal. Earlier failures still use out_free_tr because the tracer list is not yet initialized there.

Fixes 428add559b69 ("tracing: Have tracer option be instance specific")
---
 kernel/trace/trace.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)
kernel/trace/trace.c +12 -5
index 527b16690acb..b11ec4d3cfb8 100644
@@ -1456,6 +1456,13 @@ static void free_tracers(struct trace_array *tr)
 	}
 }
 
+static void free_tracer_options(struct trace_array *tr)
+{
+	for (int i = 0; i < tr->nr_topts; i++)
+		kfree(tr->topts[i].topts);
+	kfree(tr->topts);
+}
+
 /**
  * register_tracer - register a tracer with the ftrace system.
  * @type: the plugin for the tracer
@@ -8763,7 +8770,7 @@ trace_array_create_systems(const char *name, const char *systems,
 	if (trace_instance_dir) {
 		ret = trace_array_create_dir(tr);
 		if (ret)
-			goto out_free_tr;
+			goto out_free_tracers;
 	} else
 		__trace_early_add_events(tr);
 
@@ -8773,6 +8780,9 @@ trace_array_create_systems(const char *name, const char *systems,
 
 	return tr;
 
+ out_free_tracers:
+	free_tracers(tr);
+	free_tracer_options(tr);
  out_free_tr:
 	ftrace_free_ftrace_ops(tr);
 	free_trace_buffers(tr);
@@ -8926,10 +8936,7 @@ static int __remove_instance(struct trace_array *tr)
 	if (tr->flags & TRACE_ARRAY_FL_VMALLOC)
 		vfree((void *)tr->range_addr_start);
 
-	for (i = 0; i < tr->nr_topts; i++) {
-		kfree(tr->topts[i].topts);
-	}
-	kfree(tr->topts);
+	free_tracer_options(tr);
 
 	free_cpumask_var(tr->pipe_cpumask);
 	free_cpumask_var(tr->tracing_cpumask);
Signature · 1 line
2.53.0
#13 lore raw

PATCH 13/32 fgraph: Allocate shadow stacks inline with GFP_NOWAIT

In reply to Steven Rostedt

From: Vineet Gupta <[email protected]>

When ftrace graphing is turned on, all tasks in the system missing return stack page are assigned one. This is done in a simplistic multi-sweep loop of FTRACE_RETSTACK_ALLOC_SIZE (currently 32) tasks at a time as follows:

start_graph_tracing()

	do {
		alloc_retstack_tasklist
	} while (-EAGAIN);

alloc_retstack_tasklist()
alloc x32 # GFP_KERNEL, may sleep
rcu_read_lock() # preempt off
for_each_process_thread walk N_total, no cond_resched
t->ret_stack = new_page
rcu_read_unlock() # preempt enable but no explicit yield

Each successive iteration of loop invokes for_each_process_thread() which doesn't support cursor based resume and always restarts from the init_task. Thus each successive loop needs to skip the tasks assigned ret_stack in prior sweeps and thus take longer and longer to find the candidate 32 tasks. And while the loop end calls rcu unlock, and re-enables preemption briefly, there is no explicit yield.

The total number of iterations turn out to be

N_total * N_null / (2 * FTRACE_RETSTACK_ALLOC_SIZE)

where N_total is the number of threads on the system and N_null the number of those whose ret_stack is still NULL. After boot with no fgraph user that is every thread.

This is not a tracing-only path. Since commit 4346ba160409 ("fprobe:
Rewrite fprobe on function-graph tracer") fprobe is built on fgraph, so an ordinary kprobe_multi BPF attach that flips ftrace_graph_active from 0 to 1 pays the whole cost inside one bpf() syscall. Commit 2c67dc457bc6 ("tracing: fprobe: optimization for entry only case") narrows that to return and session probes but does not remove it.

A host running hundreds of thousands of threads, with the current batch size of 32, turns the ftrace_graph_active 0 -> 1 transition into a multi-second, and eventually multi-minute, operation which showed up as RCU stall and softlockup_panic on heavily loaded Meta Fleet machines with preemption disabled.

    rcu: INFO: rcu_sched self-detected stall on CPU
    rcu: 0-....: (20718 ticks this GP) (t=21000 jiffies g=913 q=8 ncpus=8)
    CPU: 0 UID: 0 PID: 160141 Comm: bpftrace
     ___slab_alloc+0x549/0xa20
     kmem_cache_alloc_noprof+0x16c/0x340
     register_ftrace_graph+0x3d7/0x6c0
     register_fprobe_ips+0x2d5/0x310
     bpf_kprobe_multi_link_attach+0x218/0x7e0
     __sys_bpf+0x267a/0x27a0

Fix this by allocating inline with GFP_NOWAIT instead of pre-allocating a fixed batch. GFP_NOWAIT does not sleep, so it is legal inside the RCU read-side critical section.

A single sweep now serves every task, so the walk becomes O(N) rather than O(N_total * N_null), and the retry loop is no longer the normal path.

The pre-allocated array remains as the fallback when GFP_NOWAIT fails. The runs below never needed it, so it was exercised with failslab
injection: at a 100% failure rate every task falls back and -EAGAIN retries ~1560 times for 50000 threads, with no stall or splat.

smp_store_release() is a drop-in replacement for the smp_wmb() and plain store it replaces.

Measured on a 60-core Sapphire Rapids machine running a PREEMPT_LAZY kernel (CONFIG_PREEMPT_DYNAMIC=y, mode lazy), timing the write that drives the ftrace_graph_active 0 -> 1 transition. Threads are spawned while fgraph is inactive so every one of them has ret_stack == NULL, and the loop was instrumented to count sweeps:

	threads   before              after
	          sweeps   time       sweeps   time
	100000     3126     15.3 s      1       0.019 s
	200000     6253     59.1 s      1       0.047 s
	400000    12503    227.8 s      1       0.092 s

The sweep count is 1 throughout. Time now scales linearly with the thread count at roughly 230 ns per task, which is the allocation and initialisation of one shadow stack.

Fixes f201ae2356c7 ("tracing/function-return-tracer: store return stack into task_struct and allocate it dynamically")
---
 kernel/trace/fgraph.c | 39 ++++++++++++++++++++++++---------------
 1 file changed, 24 insertions(+), 15 deletions(-)
kernel/trace/fgraph.c +24 -15
index 6d87143b3ddb..59c217b06695 100644
@@ -1033,13 +1033,16 @@ void ftrace_stub_graph(struct ftrace_graph_ret *trace, struct fgraph_ops *gops,
 trace_func_graph_ret_t ftrace_graph_return = ftrace_stub_graph;
 trace_func_graph_ent_t ftrace_graph_entry = ftrace_graph_entry_stub;
 
-/* Try to assign a return stack array on FTRACE_RETSTACK_ALLOC_SIZE tasks. */
+/*
+ * Loop thru all the tasks in the system and assign ret_stack.
+ * The @ret_stack_list is a small pre-allocated fallback, in case
+ * the GFP_NOWAIT allocations here fail.
+ */
 static int alloc_retstack_tasklist(unsigned long **ret_stack_list)
 {
-	int i;
-	int ret = 0;
 	int start = 0, end = FTRACE_RETSTACK_ALLOC_SIZE;
 	struct task_struct *g, *t;
+	int i, ret = 0;
 
 	if (WARN_ON_ONCE(!fgraph_stack_cachep))
 		return -ENOMEM;
@@ -1056,20 +1059,26 @@ static int alloc_retstack_tasklist(unsigned long **ret_stack_list)
 
 	rcu_read_lock();
 	for_each_process_thread(g, t) {
-		if (start == end) {
-			ret = -EAGAIN;
-			goto unlock;
-		}
+		unsigned long *rs;
 
-		if (t->ret_stack == NULL) {
-			atomic_set(&t->trace_overrun, 0);
-			ret_stack_init_task_vars(ret_stack_list[start]);
-			t->curr_ret_stack = 0;
-			t->curr_ret_depth = -1;
-			/* Make sure the tasks see the 0 first: */
-			smp_wmb();
-			t->ret_stack = ret_stack_list[start++];
+		if (t->ret_stack)
+			continue;
+
+		rs = kmem_cache_alloc(fgraph_stack_cachep, GFP_NOWAIT);
+		if (!rs) {
+			if (start == end) {
+				ret = -EAGAIN;
+				goto unlock;
+			}
+			rs = ret_stack_list[start++];
 		}
+
+		atomic_set(&t->trace_overrun, 0);
+		ret_stack_init_task_vars(rs);
+		t->curr_ret_stack = 0;
+		t->curr_ret_depth = -1;
+		/* Make sure the tasks see the 0 first: */
+		smp_store_release(&t->ret_stack, rs);
 	}
 
 unlock:
Signature · 1 line
2.53.0
#14 lore raw

PATCH 14/32 fgraph: Use scoped_guard() for the task list walk

In reply to Steven Rostedt

From: Vineet Gupta <[email protected]>

alloc_retstack_tasklist() open-codes rcu_read_lock() and unwinds it through an unlock label. Use scoped_guard(rcu) instead and let the compiler emit the unlock on every exit path.

The -EAGAIN case now jumps straight to the free label rather than to unlock; leaving the guard's scope releases the RCU read lock on the way, so the unlock label has no remaining users and is removed.

No functional change: objdump of fgraph.o shows identical call targets and counts, including the three __rcu_read_unlock() sites the compiler emits for the exits from the read-side section. A PROVE_RCU + DEBUG_ATOMIC_SLEEP build with the -EAGAIN path forced several thousand times is clean.

---
 kernel/trace/fgraph.c | 39 +++++++++++++++++++--------------------
 1 file changed, 19 insertions(+), 20 deletions(-)
kernel/trace/fgraph.c +19 -20
index 59c217b06695..8a6709959b62 100644
@@ -1057,32 +1057,31 @@ static int alloc_retstack_tasklist(unsigned long **ret_stack_list)
 		}
 	}
 
-	rcu_read_lock();
-	for_each_process_thread(g, t) {
-		unsigned long *rs;
+	scoped_guard (rcu) {
+		for_each_process_thread(g, t) {
+			unsigned long *rs;
 
-		if (t->ret_stack)
-			continue;
+			if (t->ret_stack)
+				continue;
 
-		rs = kmem_cache_alloc(fgraph_stack_cachep, GFP_NOWAIT);
-		if (!rs) {
-			if (start == end) {
-				ret = -EAGAIN;
-				goto unlock;
+			rs = kmem_cache_alloc(fgraph_stack_cachep, GFP_NOWAIT);
+			if (!rs) {
+				if (start == end) {
+					ret = -EAGAIN;
+					goto free;
+				}
+				rs = ret_stack_list[start++];
 			}
-			rs = ret_stack_list[start++];
-		}
 
-		atomic_set(&t->trace_overrun, 0);
-		ret_stack_init_task_vars(rs);
-		t->curr_ret_stack = 0;
-		t->curr_ret_depth = -1;
-		/* Make sure the tasks see the 0 first: */
-		smp_store_release(&t->ret_stack, rs);
+			atomic_set(&t->trace_overrun, 0);
+			ret_stack_init_task_vars(rs);
+			t->curr_ret_stack = 0;
+			t->curr_ret_depth = -1;
+			/* Make sure the tasks see the 0 first: */
+			smp_store_release(&t->ret_stack, rs);
+		}
 	}
 
-unlock:
-	rcu_read_unlock();
 free:
 	for (i = start; i < end; i++)
 		kmem_cache_free(fgraph_stack_cachep, ret_stack_list[i]);
Signature · 1 line
2.53.0
#15 lore raw

PATCH 15/32 fgraph: Read the task->ret_stack with a smp_load_acquire()

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

The setting of task->ret_stack was switched from a smp_wmb() and the update to the variable with a smp_store_release(). Match the reading of the task->ret_stack with a smp_load_acquire() to replace the read and smp_rmb().

Also update graph_init_task() to use smp_store_release().

---
 kernel/trace/fgraph.c | 15 ++++++---------
 1 file changed, 6 insertions(+), 9 deletions(-)
kernel/trace/fgraph.c +6 -9
index 8a6709959b62..1d900445d23a 100644
@@ -568,7 +568,11 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
 	if (unlikely(ftrace_graph_is_dead()))
 		return -EBUSY;
 
-	if (!current->ret_stack)
+	/*
+	 * We must make sure the ret_stack is tested before we read
+	 * anything else (See alloc_retstack_tasklist()).
+	 */
+	if (!smp_load_acquire(&current->ret_stack))
 		return -EBUSY;
 
 	BUILD_BUG_ON(SHADOW_STACK_SIZE % sizeof(long));
@@ -576,12 +580,6 @@ ftrace_push_return_trace(unsigned long ret, unsigned long func,
 	/* Set val to "reserved" with the delta to the new fgraph frame */
 	val = (FGRAPH_TYPE_RESERVED << FGRAPH_TYPE_SHIFT) | FGRAPH_FRAME_OFFSET;
 
-	/*
-	 * We must make sure the ret_stack is tested before we read
-	 * anything else.
-	 */
-	smp_rmb();
-
 	/*
 	 * Check if there's room on the shadow stack to fit a fraph frame
 	 * and a bitmap word.
@@ -1125,8 +1123,7 @@ graph_init_task(struct task_struct *t, unsigned long *ret_stack)
 	t->curr_ret_stack = 0;
 	t->curr_ret_depth = -1;
 	/* make curr_ret_stack visible before we add the ret_stack */
-	smp_wmb();
-	t->ret_stack = ret_stack;
+	smp_store_release(&t->ret_stack, ret_stack);
 }
 
 /*
Signature · 1 line
2.53.0
#16 lore raw

PATCH 16/32 tracing/osnoise: Dont start a kthread in timerlat user-space mode

In reply to Steven Rostedt

From: Chaosheng Qu <[email protected]>

In timerlat user-space mode (NO_OSNOISE_WORKLOAD) the workload is a user task reading timerlat_fd, so there is no per-CPU kernel thread to run. start_kthread() only checks for that in the osnoise branch:

	if (timerlat_enabled()) {
		snprintf(comm, 24, "timerlat/%d", cpu);
		main = timerlat_main;
	} else {
		/* if no workload, just return */
		if (!test_bit(OSN_WORKLOAD, &osnoise_options)) {
			...
			return 0;
		}
		...
	}

start_per_cpu_kthreads() guards against this mode itself, but osnoise_hotplug_workfn() calls start_kthread() directly. Bringing a CPU online in user-space mode therefore starts a timerlat/N thread and sets its bit in kthread_cpumask while OSN_WORKLOAD is clear.

stop_kthread() uses that bit to decide what the recorded task is:

	if (cpumask_test_and_clear_cpu(cpu, &kthread_cpumask) &&
	    !WARN_ON(!test_bit(OSN_WORKLOAD, &osnoise_options))) {
		kthread_stop(kthread);
	} else if (!WARN_ON(test_bit(OSN_WORKLOAD, &osnoise_options))) {
		kill_pid(kthread->thread_pid, SIGKILL, 1);
		put_task_struct(kthread);
	}

The bit is set but OSN_WORKLOAD is not, so the first WARN_ON() fires and the && short-circuits into the user-task branch. A running kernel thread is SIGKILLed and its task_struct is put without ever being stopped, so it keeps executing until it is freed underneath itself.

Any write to osnoise/options reaches this: osnoise_options_write() stops the per-CPU threads before applying the new value, so stop_kthread() still sees OSN_WORKLOAD clear. Re-writing the value that is already set triggers it just as well as changing it.

echo NO_OSNOISE_WORKLOAD > osnoise/options
echo timerlat > current_tracer
echo 0 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu1/online
echo NO_OSNOISE_WORKLOAD > osnoise/options

The offline/online pair is required, otherwise no kthread is recorded and no bit is set. Running this on 7.3-rc7 with KASAN gives a WARNING in stop_kthread() followed by a slab-use-after-free in update_se(); leaving out the hotplug step produces neither.

Keep the check in start_kthread(), where the related hotplug bug was fixed in 0bb0a5c12ecf, instead of adding another copy to the callback.

Fixes e88ed227f639 ("tracing/timerlat: Add user-space interface")
---
 kernel/trace/trace_osnoise.c | 8 ++++++++
 1 file changed, 8 insertions(+)
kernel/trace/trace_osnoise.c +8 -0
index 995da9e0b548..fbba42286747 100644
@@ -2039,6 +2039,14 @@ static int start_kthread(unsigned int cpu)
 		return 0;
 
 	if (timerlat_enabled()) {
+		/*
+		 * In timerlat user-space mode the workload is the user task
+		 * reading timerlat_fd, so there is no kernel thread to start.
+		 * One started here would set its kthread_cpumask bit, which
+		 * stop_kthread() reads as "osnoise workload kthread".
+		 */
+		if (!test_bit(OSN_WORKLOAD, &osnoise_options))
+			return 0;
 		snprintf(comm, 24, "timerlat/%d", cpu);
 		main = timerlat_main;
 	} else {
Signature · 1 line
2.53.0
#17 lore raw

PATCH 17/32 tracing/user_events: Dont free an event that a dynamic event still references

In reply to Steven Rostedt

From: David Carlier <[email protected]>

An eprobe takes a reference on the call of the event it attaches to, and kprobe, uprobe, fprobe and synth events all refuse to go away while trace_event_dyn_busy() says such a reference exists. user_events never checks it, so a user event can be freed under an eprobe:

echo 'u:test u32 a' >> dynamic_events
echo 'e:ep user_events/test a=$a' >> dynamic_events echo '-:user_events/test u32 a' >> dynamic_events echo '-:eprobes/ep' >> dynamic_events

The last write drops the reference on the freed call.

If the last fd of a non-persistent event closes while such a reference is held, the delayed destroy now fails. Mark the event persistent then, so it can still be deleted once the reference is gone instead of being leaked.

Return -EBUSY from destroy_user_event() in that case.

Fixes 7f5a08c79df3 ("user_events: Add minimal support for trace_event into ftrace")
---
 kernel/trace/trace_events_user.c | 9 +++++++++
 1 file changed, 9 insertions(+)
kernel/trace/trace_events_user.c +9 -0
index f658c3a77aa7..ea6a20a30cf5 100644
@@ -256,6 +256,11 @@ static void delayed_destroy_user_event(struct work_struct *work)
 		 * attempt to delete it later.
 		 */
 		pr_warn("user_events: Unable to delete event\n");
+		/*
+		 * Keep it as persistent so it can be still deleted
+		 * since nobody own this event
+		 */
+		user->reg_flags |= USER_EVENT_REG_PERSIST;
 		refcount_set(&user->refcnt, 1);
 	}
 out:
@@ -1506,6 +1511,10 @@ static int destroy_user_event(struct user_event *user)
 
 	lockdep_assert_held(&event_mutex);
 
+	/* If there is a reference to a dynamic event */
+	if (trace_event_dyn_busy(&user->call))
+		return -EBUSY;
+
 	/*
 	 * Detach the fields before removing the call. Removing the event
 	 * frees the field list memory (trace_destroy_fields() is run on
Signature · 1 line
2.53.0
#18 lore raw

PATCH 18/32 tracing: Wait for marker writers when copy_trace_marker is cleared

In reply to Steven Rostedt

From: Pengfei Li <[email protected]>

Clearing copy_trace_marker removes the instance from marker_copies without waiting for trace_marker writers still walking the list. If the option is set again right away, a writer on that entry can revisit instances and write the same marker twice.

Assisted-by LLM
Fixes 7b382efd5e8a ("tracing: Allow the top level trace_marker to write into another instances")
---
 kernel/trace/trace.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/trace.c +3 -1
index b11ec4d3cfb8..bffba5e27086 100644
@@ -4035,7 +4035,9 @@ int set_tracer_flag(struct trace_array *tr, u64 mask, int enabled)
 		break;
 
 	case TRACE_ITER(COPY_MARKER):
-		update_marker_trace(tr, enabled);
+		/* Writers of the top level trace_marker may still be on this instance */
+		if (update_marker_trace(tr, enabled) && !enabled)
+			synchronize_rcu();
 		/* update_marker_trace updates the tr->trace_flags */
 		return 0;
 	}
Signature · 1 line
2.53.0
#19 lore raw

PATCH 19/32 tracing: Validate user addresses in faultable buffer copies

In reply to Steven Rostedt

From: Kyle Zeng <[email protected]>

trace_user_fault_read() uses __copy_from_user() when no custom copy function is supplied. That primitive assumes the source address has already been validated, but the helper only checks the destination buffer size. A caller that passes an unchecked kernel address can therefore cause mapped kernel memory to be copied into the tracing buffer. The original syscall-array tracing implementation exposed this path to syscall arguments before the syscall validated them.

Use copy_from_user() for the default copy as documented. Non-user addresses then fail the copy and follow the existing NULL-return path. Successful user copies, buffer bounds, and preemption and migration retry rules are unchanged.

Fixes 64cf7d058a005 ("tracing: Have trace_marker use per-cpu data to read user space")
---
 kernel/trace/trace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
kernel/trace/trace.c +1 -1
index bffba5e27086..70b3c11ac166 100644
@@ -6298,7 +6298,7 @@ char *trace_user_fault_read(struct trace_user_buf_info *tinfo,
 		if (copy_func) {
 			ret = copy_func(buffer, ptr, size, data);
 		} else {
-			ret = __copy_from_user(buffer, ptr, size);
+			ret = copy_from_user(buffer, ptr, size);
 		}
 
 		preempt_disable_notrace();
Signature · 1 line
2.53.0
#20 lore raw

PATCH 20/32 fgraph: Do not mark index 0 in every shadow stack frame

In reply to Steven Rostedt

From: Breno Leitao <[email protected]>

We are seeing this warning on an arm64 host:

  WARNING: kernel/trace/fprobe.c:676 at fprobe_return+0x260/0x2c8, CPU#16: FuncSched/3281330
  Call trace:
   fprobe_return+0x260/0x2c8 (P)
   ftrace_return_to_handler+0x2bc/0x5a8
   return_to_handler+0x20/0x48
   futex_wait+0xa4/0x218
   do_futex+0xb4/0x1d0
   __arm64_sys_futex+0x15c/0x278

The theory is that function_graph_enter_regs() sets BIT(0) in the bitmap of every frame, a leftover of an old tail-call check, while the return path calls the retfunc of every set bit.

A reproducer on linux-next supports the theory. On a fresh boot, with no other fgraph user yet:

cd /sys/kernel/tracing
echo 'f:fpexit vfs_read%return' >> dynamic_events
echo 1 > events/fprobes/fpexit/enable # fprobe_graph_ops: index 0
echo vfs_write > set_ftrace_filter
echo function_graph > current_tracer # function_graph: index 1
echo x > /dev/null # WARN on vfs_write return

Removing the bit was agreed in the review of the series that added it [0], but the line stayed. Drop it now.

[0] https://lore.kernel.org/all/[email protected]/

Fixes 7aa1eaef9f42 ("function_graph: Allow multiple users to attach to function graph")
---
 kernel/trace/fgraph.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)
kernel/trace/fgraph.c +1 -5
index 1d900445d23a..d1f79a85ed2e 100644
@@ -698,11 +698,7 @@ int function_graph_enter_regs(unsigned long ret, unsigned long func,
 	if (!bitmap)
 		goto out_ret;
 
-	/*
-	 * Since this function uses fgraph_idx = 0 as a tail-call checking
-	 * flag, set that bit always.
-	 */
-	set_bitmap(current, offset, bitmap | BIT(0));
+	set_bitmap(current, offset, bitmap);
 	ftrace_test_recursion_unlock(bit);
 	return 0;
  out_ret:
Signature · 1 line
2.53.0
#21 lore raw

PATCH 21/32 ring-buffer: Skip remote reader page swap when on tail

In reply to Steven Rostedt

From: Vincent Donnefort <[email protected]>

When the reader page is also the tail, swap should not be permitted or it would insert the tail behind the head, breaking the integrity of the ring buffer. While __rb_get_reader_page() does correctly prevent this situation, the simple_ring_buffer implementation misses it.

Once the reader catches up with the tail, make simple_ring_buffer_swap_reader_page() return 0. The remote reader now can expect an unchanged reader. When it is the case, there's nothing more to read.

Also, when the simple_ring_buffer writer moves the tail to a new page, it resets the new tail counters and more specifically page::commit. As moving the tail unblocks page swap, order the page reset before the tail_page update. This ensures the reader can't swap the reader page with the new tail and observe a stale commit value.

Fixes 2e67fabd8b77 ("ring-buffer: Introduce ring-buffer remotes")
Fixes 34e5b958bdad ("tracing: Introduce simple_ring_buffer")
---
 kernel/trace/ring_buffer.c        |  3 ++-
 kernel/trace/simple_ring_buffer.c | 15 ++++++++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
kernel/trace/ring_buffer.c +2 -1
index ed267d628826..15ccb65de35b 100644
@@ -5848,7 +5848,8 @@ __rb_get_reader_page_from_remote(struct ring_buffer_per_cpu *cpu_buffer)
 
 	new_reader = cpu_buffer->subbuf_ids[cpu_buffer->meta_page->reader.id];
 
-	WARN_ON_ONCE(prev_reader == new_reader);
+	if (prev_reader == new_reader)
+		return NULL;
 
 	prev_head = new_reader;  /* New reader was also the previous head */
 	new_head = prev_head;
kernel/trace/simple_ring_buffer.c +14 -1
index abfaf9bee12e..d5c84af01925 100644
@@ -139,6 +139,13 @@ int simple_ring_buffer_swap_reader_page(struct simple_rb_per_cpu *cpu_buffer)
 
 	reader = cpu_buffer->reader_page;
 
+	/*
+	 * The reader is already the tail page. See simple_rb_move_tail() for
+	 * memory ordering.
+	 */
+	if (reader == smp_load_acquire(&cpu_buffer->tail_page))
+		return 0;
+
 	do {
 		/* Run after the writer to find the head */
 		ret = simple_rb_find_head(cpu_buffer);
@@ -196,7 +203,13 @@ static struct simple_buffer_page *simple_rb_move_tail(struct simple_rb_per_cpu *
 	}
 
 	simple_bpage_reset(new_tail);
-	cpu_buffer->tail_page = new_tail;
+
+	/*
+	 * Setting a new tail may unblock the swap in
+	 * simple_ring_buffer_swap_reader_page(). Ensure the reader observes the
+	 * page::commit reset.
+	 */
+	smp_store_release(&cpu_buffer->tail_page, new_tail);
 
 	simple_rb_meta_inc(cpu_buffer->meta->pages_touched, 1);
 
Signature · 1 line
2.53.0
#22 lore raw

PATCH 22/32 ring-buffer: Check remote reader page commit before meta entries

In reply to Steven Rostedt

From: Vincent Donnefort <[email protected]>

__rb_get_reader_page_from_remote() bails out when rb_num_of_entries() is zero before verifying if there is more data committed on the current reader_page (rb_page_size()), while simple_ring_buffer updates page::commit before meta::entries. As a consequence, a race between the writer and reader could lead to __rb_get_reader_page_from_remote() returning NULL, while more data is available for reading on the ring buffer.

  CPU0 (writer)                       CPU1 (reader)
  -------------                       -------------
  local_set(&page->commit, write);
                                      __rb_get_reader_page_from_remote()
                                        !rb_read_remote_meta_page()
                                          return NULL;
  simple_rb_meta_inc(meta->entries, 1);

This is an issue for rb_advance_reader() which always expects rb_get_reader_page() to return a page.

Fix this issue by swapping the checks in __rb_get_reader_page_from_remote(): first it verifies if there is more to read in the current reader page, then it verifies if there's anything at all in the ring buffer.

Also, if the reader observes the meta::entries update before page::commit while the writer moves tail_page, it could swap reader_page out and drop unread events. Order page::commit before meta::entries on the writer and rb_read_remote_meta_page() before rb_page_size() on the reader size.

Fixes 2e67fabd8b77 ("ring-buffer: Introduce ring-buffer remotes")
Fixes 34e5b958bdad ("tracing: Introduce simple_ring_buffer")
---
 kernel/trace/ring_buffer.c        | 19 +++++++++++++------
 kernel/trace/simple_ring_buffer.c |  6 ++++++
 2 files changed, 19 insertions(+), 6 deletions(-)
kernel/trace/ring_buffer.c +13 -6
index 15ccb65de35b..f728ee82cf54 100644
@@ -5615,14 +5615,12 @@ unsigned long ring_buffer_overruns(struct trace_buffer *buffer)
 }
 EXPORT_SYMBOL_GPL(ring_buffer_overruns);
 
-static bool rb_read_remote_meta_page(struct ring_buffer_per_cpu *cpu_buffer)
+static void rb_read_remote_meta_page(struct ring_buffer_per_cpu *cpu_buffer)
 {
 	local_set(&cpu_buffer->entries, READ_ONCE(cpu_buffer->meta_page->entries));
 	local_set(&cpu_buffer->overrun, READ_ONCE(cpu_buffer->meta_page->overrun));
 	local_set(&cpu_buffer->pages_touched, READ_ONCE(cpu_buffer->meta_page->pages_touched));
 	local_set(&cpu_buffer->pages_lost, READ_ONCE(cpu_buffer->meta_page->pages_lost));
-
-	return rb_num_of_entries(cpu_buffer);
 }
 
 static void rb_update_remote_head(struct ring_buffer_per_cpu *cpu_buffer)
@@ -5825,8 +5823,13 @@ __rb_get_reader_page_from_remote(struct ring_buffer_per_cpu *cpu_buffer)
 {
 	struct buffer_page *new_reader, *prev_reader, *prev_head, *new_head, *last;
 
-	if (!rb_read_remote_meta_page(cpu_buffer))
-		return NULL;
+	rb_read_remote_meta_page(cpu_buffer);
+
+	/*
+	 * Order meta::entries read before page::commit, most likely paired with
+	 * simple_ring_buffer_commit().
+	 */
+	smp_rmb();
 
 	/* More to read on the reader page */
 	if (cpu_buffer->reader_page->read < rb_page_size(cpu_buffer->reader_page)) {
@@ -5835,6 +5838,9 @@ __rb_get_reader_page_from_remote(struct ring_buffer_per_cpu *cpu_buffer)
 		return cpu_buffer->reader_page;
 	}
 
+	if (!rb_num_of_entries(cpu_buffer))
+		return NULL;
+
 	prev_reader = cpu_buffer->subbuf_ids[cpu_buffer->meta_page->reader.id];
 
 	if (cpu_buffer->remote->swap_reader_page(cpu_buffer->cpu,
@@ -6909,7 +6915,8 @@ int ring_buffer_poll_remote(struct trace_buffer *buffer, int cpu)
 		cpu_buffer = buffer->buffers[cpu];
 
 		guard(raw_spinlock)(&cpu_buffer->reader_lock);
-		if (rb_read_remote_meta_page(cpu_buffer))
+		rb_read_remote_meta_page(cpu_buffer);
+		if (rb_num_of_entries(cpu_buffer))
 			rb_wakeups(buffer, cpu_buffer);
 
 		return 0;
kernel/trace/simple_ring_buffer.c +6 -0
index d5c84af01925..5f14ba152fba 100644
@@ -309,6 +309,12 @@ void simple_ring_buffer_commit(struct simple_rb_per_cpu *cpu_buffer)
 {
 	local_set(&cpu_buffer->tail_page->page->commit,
 		  cpu_buffer->tail_page->write);
+
+	/*
+	 * Order page::commit before meta::entries. Paired with
+	 * __rb_get_reader_page_from_remote().
+	 */
+	smp_wmb();
 	simple_rb_meta_inc(cpu_buffer->meta->entries, 1);
 
 	/*
Signature · 1 line
2.53.0
#23 lore raw

PATCH 23/32 ring-buffer: Order remote page commit with data and timestamp

In reply to Steven Rostedt

From: Vincent Donnefort <[email protected]>

__rb_get_reader_page_from_remote() uses page::commit to check if more data is available for consumption. However, it needs to make sure that data and page::time_stamp are not stale. Enforce page::commit order with page::data and page::time_stamp, and defer updating read_stamp on page swap until rb_page_size() confirms committed data is present.

Fixes 2e67fabd8b77 ("ring-buffer: Introduce ring-buffer remotes")
Fixes 34e5b958bdad ("tracing: Introduce simple_ring_buffer")
---
 kernel/trace/ring_buffer.c        | 23 ++++++++++++++++-------
 kernel/trace/simple_ring_buffer.c |  5 +++++
 2 files changed, 21 insertions(+), 7 deletions(-)
kernel/trace/ring_buffer.c +16 -7
index f728ee82cf54..158c7c75688b 100644
@@ -5832,11 +5832,8 @@ __rb_get_reader_page_from_remote(struct ring_buffer_per_cpu *cpu_buffer)
 	smp_rmb();
 
 	/* More to read on the reader page */
-	if (cpu_buffer->reader_page->read < rb_page_size(cpu_buffer->reader_page)) {
-		if (!cpu_buffer->reader_page->read)
-			cpu_buffer->read_stamp = cpu_buffer->reader_page->page->time_stamp;
-		return cpu_buffer->reader_page;
-	}
+	if (cpu_buffer->reader_page->read < rb_page_size(cpu_buffer->reader_page))
+		goto out;
 
 	if (!rb_num_of_entries(cpu_buffer))
 		return NULL;
@@ -5883,10 +5880,22 @@ __rb_get_reader_page_from_remote(struct ring_buffer_per_cpu *cpu_buffer)
 	cpu_buffer->reader_page = new_reader;
 	cpu_buffer->reader_page->read = 0;
 	cpu_buffer->pages = &new_head->list;
-	cpu_buffer->read_stamp = new_reader->page->time_stamp;
 	cpu_buffer->lost_events = cpu_buffer->meta_page->reader.lost_events;
 
-	return rb_page_size(cpu_buffer->reader_page) ? cpu_buffer->reader_page : NULL;
+	if (!rb_page_size(cpu_buffer->reader_page))
+		return NULL;
+
+out:
+	/*
+	 * Order page::commit read before page::data and page::time_stamp, most
+	 * likely paired with simple_ring_buffer_commit().
+	 */
+	smp_rmb();
+
+	if (!cpu_buffer->reader_page->read)
+		cpu_buffer->read_stamp = cpu_buffer->reader_page->page->time_stamp;
+
+	return cpu_buffer->reader_page;
 }
 
 static struct buffer_page *
kernel/trace/simple_ring_buffer.c +5 -0
index 5f14ba152fba..2dddaef638dc 100644
@@ -307,6 +307,11 @@ EXPORT_SYMBOL_GPL(simple_ring_buffer_reserve);
  */
 void simple_ring_buffer_commit(struct simple_rb_per_cpu *cpu_buffer)
 {
+	/*
+	 * Order page::data and page::time_stamp before page::commit. Paired
+	 * with __rb_get_reader_page_from_remote().
+	 */
+	smp_wmb();
 	local_set(&cpu_buffer->tail_page->page->commit,
 		  cpu_buffer->tail_page->write);
 
Signature · 1 line
2.53.0
#24 lore raw

PATCH 24/32 ring-buffer: Increment pages_read on remote ring buffer page swap

In reply to Steven Rostedt

From: Vincent Donnefort <[email protected]>

__rb_get_reader_page_from_remote() swaps in a new reader page without incrementing cpu_buffer->pages_read. While this isn't an issue now as trace remotes do not use buffer_percent, add this missing increment for consistency.

---
 kernel/trace/ring_buffer.c | 1 +
 1 file changed, 1 insertion(+)
kernel/trace/ring_buffer.c +1 -0
index 158c7c75688b..0a1c7f98159e 100644
@@ -5881,6 +5881,7 @@ __rb_get_reader_page_from_remote(struct ring_buffer_per_cpu *cpu_buffer)
 	cpu_buffer->reader_page->read = 0;
 	cpu_buffer->pages = &new_head->list;
 	cpu_buffer->lost_events = cpu_buffer->meta_page->reader.lost_events;
+	local_inc(&cpu_buffer->pages_read);
 
 	if (!rb_page_size(cpu_buffer->reader_page))
 		return NULL;
Signature · 1 line
2.53.0
#25 lore raw

PATCH 25/32 tracing/hwlat: Do the latency calculations in nanoseconds

In reply to Steven Rostedt

From: Wenwu Hou <[email protected]>

tr->max_latency is expected to hold nanoseconds: tracing_max_lat_read() converts it with nsecs_to_usecs() to print the usecs documented in hwlat_detector.rst, and the other latency tracers store nanoseconds there too.

Do all the latency calculations in nanoseconds instead, and only convert the durations to microseconds when recording the hwlat event.

This also makes the backward-clock error paths reachable. Previously, time_to_us() passed the delta through unsigned div_u64(), so a negative delta became a positive value after division. These error paths jumped to out without clearing trace_hwlat_callback_enabled. Fix this as well.

Fixes e7c15cd8a1133 ("tracing: Added hardware latency tracer")
Fixes 7b2c86250122d ("tracing: Add NMI tracing in hwlat detector")
---
 kernel/trace/trace_hwlat.c | 41 +++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 21 deletions(-)
kernel/trace/trace_hwlat.c +20 -21
index 3fe274b84f1c..5be9031f1ffe 100644
@@ -203,14 +203,12 @@ static int get_sample(void)
 	time_type start, t1, t2, last_t2;
 	s64 diff, outer_diff, total, last_total = 0;
 	u64 sample = 0;
-	u64 sample_width = READ_ONCE(hwlat_data.sample_width);
+	u64 sample_width = READ_ONCE(hwlat_data.sample_width) * NSEC_PER_USEC;
 	u64 thresh = tracing_thresh;
 	u64 outer_sample = 0;
-	int ret = -1;
+	int ret = 0;
 	unsigned int count = 0;
 
-	do_div(thresh, NSEC_PER_USEC); /* modifies interval value */
-
 	kdata->nmi_total_ts = 0;
 	kdata->nmi_count = 0;
 	/* Make sure NMIs see this first */
@@ -229,28 +227,37 @@ static int get_sample(void)
 
 		if (time_u64(last_t2)) {
 			/* Check the delta from outer loop (t2 to next t1) */
-			outer_diff = time_to_us(time_sub(t1, last_t2));
+			outer_diff = time_sub(t1, last_t2);
 			/* This shouldn't happen */
 			if (outer_diff < 0) {
 				hwlat_err(BANNER "time running backwards\n");
-				goto out;
+				ret = -1;
+				break;
 			}
 			if (outer_diff > outer_sample)
 				outer_sample = outer_diff;
 		}
 		last_t2 = t2;
 
-		total = time_to_us(time_sub(t2, start)); /* sample width */
+		total = time_sub(t2, start); /* sample width */
 
 		/* Check for possible overflows */
 		if (total < last_total) {
 			hwlat_err("Time total overflowed\n");
+			/* Keep ret == 0 to preserve any latencies already detected */
 			break;
 		}
 		last_total = total;
 
 		/* This checks the inner loop (t1 to t2) */
-		diff = time_to_us(time_sub(t2, t1));     /* current diff */
+		diff = time_sub(t2, t1);     /* current diff */
+
+		/* This shouldn't happen: time went backwards between t1 and t2 */
+		if (diff < 0) {
+			hwlat_err(BANNER "time running backwards\n");
+			ret = -1;
+			break;
+		}
 
 		if (diff > thresh || outer_diff > thresh) {
 			if (!count)
@@ -258,12 +265,6 @@ static int get_sample(void)
 			count++;
 		}
 
-		/* This shouldn't happen */
-		if (diff < 0) {
-			hwlat_err(BANNER "time running backwards\n");
-			goto out;
-		}
-
 		if (diff > sample)
 			sample = diff; /* only want highest value */
 
@@ -273,10 +274,11 @@ static int get_sample(void)
 	trace_hwlat_callback_enabled = false;
 	barrier(); /* Make sure nmi_total_ts is no longer updated */
 
-	ret = 0;
+	if (ret)
+		return ret;
 
 	/* If we exceed the threshold value, we have found a hardware latency */
-	if (sample > thresh || outer_sample > thresh) {
+	if (count) {
 		u64 latency;
 
 		ret = 1;
@@ -286,8 +288,8 @@ static int get_sample(void)
 			do_div(kdata->nmi_total_ts, NSEC_PER_USEC);
 
 		s.seqnum = atomic64_inc_return(&hwlat_data.count);
-		s.duration = sample;
-		s.outer_duration = outer_sample;
+		s.duration = time_to_us(sample);
+		s.outer_duration = time_to_us(outer_sample);
 		s.nmi_total_ts = kdata->nmi_total_ts;
 		s.nmi_count = kdata->nmi_count;
 		s.count = count;
@@ -301,8 +303,6 @@ static int get_sample(void)
 			latency_fsnotify(tr);
 		}
 	}
-
-out:
 	return ret;
 }
 
@@ -835,7 +835,6 @@ static int hwlat_tracer_init(struct trace_array *tr)
 	tr->max_latency = 0;
 	save_tracing_thresh = tracing_thresh;
 
-	/* tracing_thresh is in nsecs, we speak in usecs */
 	if (!tracing_thresh)
 		tracing_thresh = last_tracing_thresh;
 
Signature · 1 line
2.53.0
#26 lore raw

PATCH 26/32 tracing: Properly match strings that start with numbers

In reply to Steven Rostedt

From: Brian Norris <[email protected]>

As an optimization, set_ftrace_filter supports writing indices (numbers) instead of function names. This support was added to the generic glob (fake regex) function, which breaks the ability to filter string patterns that start with a number. For example, PCI device names tend to look like '0001:01:00.0', and a reasonable filter might be:

echo 'name ~ "0001:*"' > /sys/kernel/tracing/events/rpm/rpm_resume/filter

Move the MATCH_INDEX code out to the only place it actually was intended to work -- ftrace match_records(), with a 'func' and no 'mod'.

As a side effect, this also fixes :mod:<module> function filtering for modules whose names start with a digit.

Fixes f79b3f338564 ("ftrace: Allow enabling of filters via index of available_filter_functions")
---
 kernel/trace/ftrace.c              | 3 ++-
 kernel/trace/trace.h               | 1 -
 kernel/trace/trace_events_filter.c | 5 -----
 3 files changed, 2 insertions(+), 7 deletions(-)
kernel/trace/ftrace.c +2 -1
index c7d74b33d36d..6654da9d1bbf 100644
@@ -5029,7 +5029,8 @@ match_records(struct ftrace_hash *hash, char *func, int len, char *mod)
 	if (unlikely(ftrace_disabled))
 		return 0;
 
-	if (func_g.type == MATCH_INDEX)
+	if (func_g.type == MATCH_FULL && !mod &&
+	    func_g.search && isdigit(func_g.search[0]))
 		return add_rec_by_index(hash, &func_g, clear_filter);
 
 	do_for_each_ftrace_rec(pg, rec) {
kernel/trace/trace.h +0 -1
index 6b695a7f42c8..1fec567e789e 100644
@@ -1807,7 +1807,6 @@ enum regex_type {
 	MATCH_MIDDLE_ONLY,
 	MATCH_END_ONLY,
 	MATCH_GLOB,
-	MATCH_INDEX,
 };
 
 struct regex {
kernel/trace/trace_events_filter.c +0 -5
index a1c298210059..6704ef3d9520 100644
@@ -1152,9 +1152,6 @@ enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not)
 
 	*search = buff;
 
-	if (isdigit(buff[0]))
-		return MATCH_INDEX;
-
 	for (i = 0; i < len; i++) {
 		if (buff[i] == '*') {
 			if (!i) {
@@ -1192,8 +1189,6 @@ static void filter_build_regex(struct filter_pred *pred)
 	}
 
 	switch (type) {
-	/* MATCH_INDEX should not happen, but if it does, match full */
-	case MATCH_INDEX:
 	case MATCH_FULL:
 		r->match = regex_match_full;
 		break;
Signature · 1 line
2.53.0
#27 lore raw

PATCH 27/32 tracing: Add tests for globbing number-based strings

In reply to Steven Rostedt

From: Brian Norris <[email protected]>

In "tracing: Properly match strings that start with numbers", we fixed bugs related to string fields that start with a number and also use globs instead of full matches.

Add some additional startup test cases for this.

For easy reproducible testing, I abused the kunit.py script to boot a minimal kernel with FTRACE_STARTUP_TEST enabled:

  ./tools/testing/kunit/kunit.py run --arch=x86_64 \
      --kconfig_add=CONFIG_FTRACE=y \
      --kconfig_add=CONFIG_FUNCTION_TRACER=y \
      --kconfig_add=CONFIG_DYNAMIC_FTRACE=y \
      --kconfig_add=CONFIG_FTRACE_STARTUP_TEST=y \
      --kconfig_add=CONFIG_EVENT_TRACE_STARTUP_TEST=n \
      --raw_output=all deadbeef

Relevant line:

Testing ftrace filter: OK

Without "tracing: Properly match strings that start with numbers", the test fails with:

Testing ftrace filter:
Failed to match filter 'str ~ "0001:*"', expected 1

---
 kernel/trace/trace_events_filter.c      | 74 ++++++++++++++++++++++++-
 kernel/trace/trace_events_filter_test.h | 12 ++--
 2 files changed, 80 insertions(+), 6 deletions(-)
kernel/trace/trace_events_filter.c +72 -2
index 6704ef3d9520..7018964c94fc 100644
@@ -2856,6 +2856,8 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
 #include <linux/types.h>
 #include <linux/tracepoint.h>
 
+#include "trace_probe.h"
+
 #define CREATE_TRACE_POINTS
 #include "trace_events_filter_test.h"
 
@@ -2867,12 +2869,22 @@ int ftrace_profile_set_filter(struct perf_event *event, int event_id,
 	.match  = m, \
 	.not_visited = nvisit, \
 }
+
+#define DATA_STR(m, s) \
+{ \
+	.filter = FILTER, \
+	.str    = s, \
+	.match  = m, \
+	.not_visited = "", \
+}
+
 #define YES 1
 #define NO  0
 
 static struct test_filter_data_t {
 	char *filter;
 	struct trace_event_raw_ftrace_test_filter rec;
+	const char *str;
 	int match;
 	char *not_visited;
 } test_filter_data[] = {
@@ -2924,9 +2936,46 @@ static struct test_filter_data_t {
 	DATA_REC(YES, 1, 1, 1, 1, 1, 1, 1, 1, "bdfh"),
 	DATA_REC(YES, 0, 1, 0, 1, 0, 1, 0, 1, ""),
 	DATA_REC(YES, 1, 0, 1, 0, 1, 0, 1, 0, "bdfh"),
+#undef FILTER
+#define FILTER "str ~ \"0001:*\""
+	DATA_STR(YES, "0001:01:00.0"),
+	DATA_STR(YES, "0001:"),
+	DATA_STR(NO,  "0002:01:00.0"),
+	DATA_STR(NO,  "pci:0001:01:00.0"),
+	DATA_STR(NO,  "0001"),
+#undef FILTER
+#define FILTER "str ~ \"!0001:*\""
+	DATA_STR(NO,  "0001:01:00.0"),
+	DATA_STR(YES, "0002:01:00.0"),
+#undef FILTER
+#define FILTER "str ~ \"0001:*:00.[0-9]\""
+	DATA_STR(YES, "0001:01:00.0"),
+	DATA_STR(YES, "0001:ff:00.7"),
+	DATA_STR(NO,  "0001:01:00.a"),
+	DATA_STR(NO,  "0002:01:00.0"),
+#undef FILTER
+#define FILTER "str ~ \"0001:01:00.0\""
+	DATA_STR(YES, "0001:01:00.0"),
+	DATA_STR(NO,  "0001:01:00.1"),
+	DATA_STR(NO,  "0001:01:00.00"),
+	DATA_STR(NO,  "0001:01:00"),
+#undef FILTER
+#define FILTER "str == \"0001:01:00.0\""
+	DATA_STR(YES, "0001:01:00.0"),
+	DATA_STR(NO,  "0001:01:00.1"),
+#undef FILTER
+#define FILTER "str ~ \"*0001:*\""
+	DATA_STR(YES, "0001:01:00.0"),
+	DATA_STR(YES, "pci:0001:01:00.0"),
+	DATA_STR(NO,  "0002:01:00.0"),
+#undef FILTER
+#define FILTER "str ~ \"*:00.0\""
+	DATA_STR(YES, "0001:01:00.0"),
+	DATA_STR(NO,  "0001:01:00.1"),
 };
 
 #undef DATA_REC
+#undef DATA_STR
 #undef FILTER
 #undef YES
 #undef NO
@@ -2977,8 +3026,29 @@ static __init int ftrace_test_event_filter(void)
 	for (i = 0; i < DATA_CNT; i++) {
 		struct event_filter *filter = NULL;
 		struct test_filter_data_t *d = &test_filter_data[i];
+		union {
+			struct trace_event_raw_ftrace_test_filter rec;
+			/* Add some spare, to append the string contents. */
+			char buf[sizeof(struct trace_event_raw_ftrace_test_filter) + 32];
+		} event = { .rec = d->rec };
 		int err;
 
+		if (d->str) {
+			struct ftrace_event_field *field;
+			u32 offset = offsetof(typeof(event.rec), __data);
+			u32 len = strlen(d->str) + 1;
+			u32 *str_item;
+
+			field = trace_find_event_field(&event_ftrace_test_filter, "str");
+			if (WARN_ON_ONCE(!field))
+				break;
+			if (WARN_ON_ONCE(offset + len > sizeof(event.buf)))
+				break;
+			str_item = (u32 *)&event.buf[field->offset];
+			*str_item = make_data_loc(len, offset);
+			memcpy(&event.buf[offset], d->str, len);
+		}
+
 		err = create_filter(NULL, &event_ftrace_test_filter,
 				    d->filter, false, &filter);
 		if (err) {
@@ -3000,7 +3070,7 @@ static __init int ftrace_test_event_filter(void)
 			update_pred_fn(filter, d->not_visited);
 
 		test_pred_visited = 0;
-		err = filter_match_preds(filter, &d->rec);
+		err = filter_match_preds(filter, &event.rec);
 		preempt_enable();
 
 		mutex_unlock(&event_mutex);
@@ -3027,7 +3097,7 @@ static __init int ftrace_test_event_filter(void)
 
 	/* Need to call ftrace_test_filter to prevent a warning */
 	if (!trace_ftrace_test_filter_enabled())
-		trace_ftrace_test_filter(1, 2, 3, 4, 5, 6, 7, 8);
+		trace_ftrace_test_filter(1, 2, 3, 4, 5, 6, 7, 8, "");
 
 	return 0;
 }
kernel/trace/trace_events_filter_test.h +8 -4
index e651dfbd345e..74a9dba91545 100644
@@ -9,9 +9,10 @@
 
 TRACE_EVENT(ftrace_test_filter,
 
-	TP_PROTO(int a, int b, int c, int d, int e, int f, int g, int h),
+	TP_PROTO(int a, int b, int c, int d, int e, int f, int g, int h,
+		 const char *str),
 
-	TP_ARGS(a, b, c, d, e, f, g, h),
+	TP_ARGS(a, b, c, d, e, f, g, h, str),
 
 	TP_STRUCT__entry(
 		__field(int, a)
@@ -22,6 +23,7 @@ TRACE_EVENT(ftrace_test_filter,
 		__field(int, f)
 		__field(int, g)
 		__field(int, h)
+		__string(str, str)
 	),
 
 	TP_fast_assign(
@@ -33,11 +35,13 @@ TRACE_EVENT(ftrace_test_filter,
 		__entry->f = f;
 		__entry->g = g;
 		__entry->h = h;
+		__assign_str(str);
 	),
 
-	TP_printk("a %d, b %d, c %d, d %d, e %d, f %d, g %d, h %d",
+	TP_printk("a %d, b %d, c %d, d %d, e %d, f %d, g %d, h %d, str %s",
 		  __entry->a, __entry->b, __entry->c, __entry->d,
-		  __entry->e, __entry->f, __entry->g, __entry->h)
+		  __entry->e, __entry->f, __entry->g, __entry->h,
+		  __get_str(str))
 );
 
 #endif /* _TRACE_TEST_H || TRACE_HEADER_MULTI_READ */
Signature · 1 line
2.53.0
#28 lore raw

PATCH 28/32 tracing: Take trace_access_lock() in tracing_buffers_ioctl()

In reply to Steven Rostedt

From: Vincent Donnefort <[email protected]>

tracing_buffers_ioctl() calls ring_buffer_map_get_reader() without trace_access_lock, breaking concurrent readers. Take trace_access_lock() around ring_buffer_map_get_reader(), matching the other consuming readers.

---
 kernel/trace/trace.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
kernel/trace/trace.c +6 -2
index 70b3c11ac166..65b9d67647e5 100644
@@ -7415,8 +7415,12 @@ static long tracing_buffers_ioctl(struct file *file, unsigned int cmd, unsigned
 				return err;
 		}
 
-		return ring_buffer_map_get_reader(iter->array_buffer->buffer,
-						  iter->cpu_file);
+		trace_access_lock(iter->cpu_file);
+		err = ring_buffer_map_get_reader(iter->array_buffer->buffer,
+						 iter->cpu_file);
+		trace_access_unlock(iter->cpu_file);
+
+		return err;
 	} else if (cmd) {
 		return -ENOTTY;
 	}
Signature · 1 line
2.53.0
#29 lore raw

PATCH 29/32 tracing: Do not allow user events to add a system name

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

User events currently do not support the addition of a system name, but the parsing does not check to see if one is specified.

A kprobe can add its own system name with the following command:

~# echo 'p:mysystem/kprobe_event schedule a=%ax' >> dynamic_events ~# ls events/mysystem
enable filter kprobe_event

But if one tries to do the same with user events:

~# echo 'u:user_events/test u32 a' >> dynamic_events ~# ls events/user_events
ls: reading directory 'events/user_events/': Invalid argument enable filter

It corrupts the file system as the event added had a '/' in the name.

Until user events support specifying system names, just return -EINVAL to prevent the corrupted file system from happening:

~# echo 'u:user_events/test u32 a' >> dynamic_events -bash: echo: write error: Invalid argument

Fixes 7f5a08c79df35 ("user_events: Add minimal support for trace_event into ftrace")
---
 kernel/trace/trace_events_user.c | 3 +++
 1 file changed, 3 insertions(+)
kernel/trace/trace_events_user.c +3 -0
index ea6a20a30cf5..e29e1c772aa7 100644
@@ -1040,6 +1040,9 @@ static int user_event_parse_cmd(struct user_event_group *group,
 	if (flags)
 		*flags++ = '\0';
 
+	if (strstr(name, "/") != NULL)
+		return -EINVAL;
+
 	return user_event_parse(group, name, args, flags, newuser, reg_flags);
 }
 
Signature · 1 line
2.53.0
#30 lore raw

PATCH 30/32 ring-buffer: Do not check si_mem_available() before deferred init completes

In reply to Steven Rostedt

From: Amit Machhiwal <[email protected]>

With CONFIG_DEFERRED_STRUCT_PAGE_INIT=y, only about one memory section per node is initialized early in boot (16 MiB on powerpc). The rest is initialized on demand by deferred_grow_zone() when an allocation would otherwise fail, or later by page_alloc_init_late().

Until then NR_FREE_PAGES can be close to zero, because early allocations (SLUB, vmalloc, ftrace records) use up the first section. si_mem_available() is derived from NR_FREE_PAGES, so it under-reports.

__rb_allocate_pages() returns -ENOMEM when si_mem_available() is below the requested size. This check wrongly fails the buffers allocated for the boot CPU in early_trace_init() and for secondary CPUs in smp_init(), both of which run before page_alloc_init_late(). The resulting boot log shows:

ERROR: Failed to allocate trace buffer
ERROR: tracer: failed to allocate ring buffer!

Skip the check until SYSTEM_FREEING_INITMEM on CONFIG_DEFERRED_STRUCT_PAGE_INIT kernels. The allocation itself still fails if memory really is short.

This is the second half of the fix for the early boot crash reported on ppc64le KVM guests. Commit b3b974008388 ("tracing: Do not initialize tracefs work if tracing is disabled") stopped the NULL pointer dereference in __find_event_file() that followed the failed allocation. This patch fixes the allocation failure itself.

---
 kernel/trace/ring_buffer.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)
kernel/trace/ring_buffer.c +10 -1
index 0a1c7f98159e..a5a0adc934fa 100644
@@ -2468,8 +2468,17 @@ static int __rb_allocate_pages(struct ring_buffer_per_cpu *cpu_buffer,
 		 * memory. It may not be accurate. But we don't care, we just want
 		 * to prevent doing any allocation when it is obvious that it is
 		 * not going to succeed.
+		 *
+		 * With CONFIG_DEFERRED_STRUCT_PAGE_INIT, si_mem_available()
+		 * will reflect the actual available memory only after
+		 * SYSTEM_FREEING_INITMEM.
 		 */
-		i = si_mem_available();
+		if (IS_ENABLED(CONFIG_DEFERRED_STRUCT_PAGE_INIT) &&
+		    unlikely(system_state < SYSTEM_FREEING_INITMEM))
+			i = LONG_MAX;
+		else
+			i = si_mem_available();
+
 		if (i < (nr_pages << subbuf_order))
 			return -ENOMEM;
 
Signature · 1 line
2.53.0
#31 lore raw

PATCH 31/32 tracing: Add notrace to event functions that hook to ftrace

In reply to Steven Rostedt

From: Steven Rostedt <[email protected]>

A few functions in trace_events.c are used to hook to the ftrace function hooks. Before CONFIG_FUNCTION_SELF_TRACING was added, these functions were not marked for tracing because the entire directory was set to "notrace". But now that certain files can be traced by ftrace when the CONFIG_FUNCTION_SELF_TRACING config is set, individual functions that use ftrace must be annotated with "notrace" otherwise they can trigger a triple fault when called.

Annotate the trace_events.c functions that are attached to ftrace with "notrace.

Fixes f93a7d0caccd6 ("ftrace: Allow tracing of some of the tracing code")
---
 kernel/trace/trace_events.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
kernel/trace/trace_events.c +3 -3
index c9d31c9f3fca..7f89160aeff3 100644
@@ -4317,7 +4317,7 @@ static void update_event_probe(struct event_probe_data *data)
 		set_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT, &data->file->flags);
 }
 
-static void
+static void notrace
 event_enable_probe(unsigned long ip, unsigned long parent_ip,
 		   struct trace_array *tr, struct ftrace_probe_ops *ops,
 		   void *data)
@@ -4334,7 +4334,7 @@ event_enable_probe(unsigned long ip, unsigned long parent_ip,
 	update_event_probe(edata);
 }
 
-static void
+static void notrace
 event_enable_count_probe(unsigned long ip, unsigned long parent_ip,
 			 struct trace_array *tr, struct ftrace_probe_ops *ops,
 			 void *data)
@@ -5205,7 +5205,7 @@ static DEFINE_PER_CPU(atomic_t, ftrace_test_event_disable);
 
 static struct trace_event_file event_trace_file __initdata;
 
-static void __init
+static void notrace __init
 function_test_events_call(unsigned long ip, unsigned long parent_ip,
 			  struct ftrace_ops *op, struct ftrace_regs *regs)
 {
Signature · 1 line
2.53.0
#32 lore raw

PATCH 32/32 tracing: Ignore .function on the function trace event

In reply to Steven Rostedt

From: David Carlier <[email protected]>

For the function event, parse_pred() handles the .function suffix before the ftrace_event_is_function() case, so "ip.function == schedule" builds a predicate with no regex. Setting it through perf then dereferences the NULL pred->regex in ftrace_function_set_filter_pred().

The "ip" field of that event already takes a function name, so ignore the suffix there and let the function event case handle it.

Fixes cfb58e278c6a ("tracing/filters: Dynamically allocate filter_pred.regex")
---
 kernel/trace/trace_events_filter.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
kernel/trace/trace_events_filter.c +3 -1
index 7018964c94fc..a9d77df3e19a 100644
@@ -1737,7 +1737,9 @@ static int parse_pred(const char *str, void *data,
 
 	/* See if the field is a kernel function name */
 	if ((len = str_has_prefix(str + i, ".function"))) {
-		function = true;
+		/* Ignore if event is already a function */
+		if (!ftrace_event_is_function(call))
+			function = true;
 		i += len;
 	}
 
Signature · 1 line
2.53.0
maintainer
#33 lore raw

cover tracing: Fixes for v7.4

In reply to Steven Rostedt

[
Hmm, looks like my script died on the cover letter (an email had an extra comma in it :-p) Here's what it was supposed to be.
]

tracing fixes for v7.4:

- Do not WARN when trace_rb_cpu_prepare() fails to allocate on CPU startup

The per CPU ring buffers are allocated when a new CPU comes online. If the system is under memory pressure it shouldn't trigger a WARN_ON if the buffer fails to allocate. Switch the WARN to a pr_warn() message.

- Copy trace_marker to all instances even if one fails

Each instance can set a flag that it wants what is written into the trace_marker file to be copied to its ring buffer. Currently, if one of the instances has tracing disabled, the copy will fail. The loop that copies to each ring buffer detects this failure and stops copying to the rest of the instances. This is not what is expected as the copy should be tried to all instances even if it fails on one.

- Prevent perf from using filter logic to read kernel memory

Perf can use filtering on addresses supplied by user space system calls to look at kernel address space and depending on the result of the filter determine what was in that address. Prevent perf from this type of filter.

- Fix filter logic on zero length dynamic strings

The string filter match expects the length passed to it to include the nul terminating byte. Dynamic strings may be zero in length and have no nul byte. Have the filter logic for this strings pass in an empty string ("") instead.

- Fix boot filtering on common fields of events

The common fields (like the CPU or PID of the event) are initialized after boot filtering is processed. This prevents boot filters from using them. Initialized the common fields before processing the boot filters.

- Fix ref counting of synthetic events

When an instance is removed, it calls clear_event_triggers() on its events. This function does not properly release the synthetic event ref counters keeping them "busy" indefinitely. Fix the function to properly release the reference of the synthetic events they contain.

- Reject the size of zero for histograms

Make it an error if the user tries to create a histogram of size zero. Not only does it not make sense, it is invalid to call to roundup_pow_of_two() as it is undefined.

- Fix tail matching of filtering fixed size strings

The filtering of the end of string (*end) does not work properly for fixed sized string fields. This is because it matches the end of the fixed size and not the string itself. That is, if a fixed string field of 16 bytes has "abcd" and the match is to be "cd" the compare is done to the last three bytes of the 16 (including '\0'), which will likely not be the "cd".

- Fix the filter match of not-equal for out of range CPU masks.

When a compare of a cpumask is out of range, the test returns nr_cpus and the match function will return zero (not matched) on that. But if the filter has a negative value (!=) then it should be a match. Fix this by returning "pred->op == OP_NE" which would return true if it should be a negative match and false otherwise.

- Fix out-of-bounds read in unfinished filter match

If the filter passed in is "ip ==" without a value after the conditional, the parsing logic will increment one passed the nul byte and read the memory after it, possibly reading out-of-bounds memory. Detect this case and return an error immediately.

- Fix false success when failing on filtering of system groups

A filter may be placed on a system group where the filter is then applied to each event. This returns success if at least one event succeeds. But the logic in the loop of all events reset the failure condition at the end of each iteration meaning that it would always return success even if no event was successful at applying it. The only way it would fail is if the first event failed on a memory issue.

- Free created option descriptors on instance creation failure

If an instance were to fail to be created after creating its options, it would then leak them. Clean them up on failure.

- Allocate shadow stacks inline when enabling function graph hooks

The current method of allocating the shadow stacks used by function graph (and which is now the backend of kretprobes), allocates 32 stacks, iterates over all tasks under an RCU lock and adds the stacks to the tasks that do not have them yet. After it has depleted and assigned all 32 stacks, it would break out of the loop, allocate another 32 stacks and repeat. Unfortunately, this meant that it would iterate all the tasks it had already assigned stacks to before assigning new stacks. For machines running 1000s of tasks, this would take an exponential time to complete.

This logic was created when the loop of all tasks required more locking and allocating during the loop wasn't recommended. Instead, still allocate the 32 stacks outside the RCU atomic but only use them if the allocation of a stack with GFP_NOWAIT fails. This brings down the time to enable a kretprobe from over 200 seconds down to 0.92 seconds on a machine with 400,000 tasks.

- Do not start kthread in timerlat user space mode

Timerlat has a mode that you can assign a user space task to it. Normally the code would not start a kernel thread in this case, but if a CPU comes online, it does not check if its in user space mode and starts a kernel thread regardless. This triggers a WARN_ON on clean up as timerlat is not expecting to have a kernel thread running. Prevent kernel thread start up when a CPU comes on line while timerlat is in user space mode.

- Do not free user events when an event probe is attached to it

Event probes can attach to any other event. User events are events created that can be controlled by user space. Event probes can attach to these events, but they currently do not add a reference to them when they do. This means that the user event can be destroyed leaving the event probe attached to a stale event which can cause a use-after-free bug.

On destruction of the user event, return -EBUSY if there's a dynamic event attached to it. Also make it persistent so that the event can be destroyed once the last fd is closed for it.

- Synchronize the clearing of the copy marker flag

The marker_copies link list contains all the instances that are to copy the trace_marker writes. When the flag is cleared, and the instance is removed from the list, wait an RCU synchronization, otherwise if the flag is set again, it can cause the same write to be written twice as the instance would be added to the end of the list and a current copy walk of the list would hit the same instance again.

- Use copy_from_user() and not __copy_from_user() when reading user addresses

When a system call event reads the user space address (like reading the path string of an openat system call), it users __copy_from_user() which assumes the address has been verified. Use the copy_from_user() function instead to verify that the address is OK for user space to read. Note, this has no security concern as this data read is only visible by the tracing system which in turn is only visible by admins.

- Fix shadow stack marking of the function graph infrastructure

An old implementation of the shadow stack set bit zero of the shadow stack frame to denote tail function calls. This is no longer the case and the setting of the bit can trigger a WARN_ON in some cases.

- Do not do a reader-page swap when head is on tail

The remote ring buffer does not handle swapping the buffer when the head is on the tail page. Prevent it from happening.

- Fix race between reader and writer of remote ring buffer reader page

When there's data in the buffer, the reader first checks the meta page counter and then reads the data on the page. But because the writer updates the content of the pages before updating the meta data, the reader receives NULL unexpectedly. Swap the checks around so that the reader still returns the data if there is some before checking the meta data.

Also fix the data ordering of remote buffer page time accounting.

- Fix wrong unit used in hwlat tracer accounting

The tr->max_latency stores nanoseconds (even though its updated from user space in microseconds, but its converted over). The hwlat tracer assumes that the tr->max_latency is in microseconds and updates it accordingly. This causes the output to user space to be off by 1000. Do all calculations in the hwlat in nanoseconds.

- Properly match filter strings that start with numbers

The set_ftrace_fiter file can take numbers to set functions via an index into the file instead of having to search all tens of thousands of files for a match. This code is shared with the event filtering logic as well. But this caused some of the event filters to get confused by strings matching numbers and turning it into an index which did not apply to events.

Have the function tracing handle indexes directly and remove that logic from the event filtering so that the indexing only affects the set_ftrace_filter file and nothing else.

- Protect the ring_buffer ioctl from concurrent readers

The ring_buffer ioctl call that maps the ring buffer can race with concurrent readers. Have it take the trace_access_lock().

- Prevent user events from defining a system name

Currently, user events is the one dynamic event that does not allow the API from defining its own system (all user events go into the "user_events" system). But nothing prevents the user from trying to create one. As systems are denoted with '/' to separate the system from the event name, the API simply takes the entire string (the '/' and all) as the event name and tries to create a file with it. This causes the tracefs file system to be corrupted.

Have the system call fail with -EINVAL if '/' is used.

- Do not use si_mem_available() in early boot for ring_buffer allocation

When allocating the ring buffer, the amount allocated is compared to the amount of memory available so that it doesn't allocate too much and cause a system failure. It uses si_mem_available() to get an approximate amount of memory it can allocate. On systems with CONFIG_DEFERRED_STRUCT_PAGE_INIT and on early boot up, the value returned by si_mem_available() is derived by NR_FREE_PAGES and can under report the amount of free memory. This makes it nearly impossible to allocate the ring buffer and do early boot tracing on these systems.

For this case, use LONG_MAX as the maximum amount available. If it allocates too much and crashes the system, that's on the sysadmin that asked for too much memory for the ring buffer on the kernel command line.

- Add notrace to event functions that use function hooks

A few options in the event code hooks into the ftrace function hook mechanism. These functions must be marked with notrace. When CONFIG_FUNCTION_SELF_TRACING is enabled, event functions can be traced by ftrace and because these functions are not marked as notrace when they are traced, it causes an infinite loop and the system triple faults. Normally this wasn't a problem because without the SELF_TRACING set, all files in the tracing directory are marked as notrace.

Mark the individual functions that are used in the event code with ftrace as notrace so that the rest of the code can still be traced by ftrace.

- Ignore .function field modifier if the event is already a function event

Perf can hook to the ftrace function event which is special and is marked as a "function" event where its fields can be filtered against function names. If the perf uses adds a filter to the ftrace event and adds the ".function" modifier (which converts the field to a function field to be searched with function names), the double conversion confuses the logic as the code for the ".function" does not work with function events (only normal events with unsigned long fields). This can end up with a NULL pointer dereference.

If the ".function" modifier is used on a function event, simply ignore it, as the processing will work the same.

git://git.kernel.org/pub/scm/linux/kernel/git/trace/linux-trace.git
trace/fixes

Head SHA1: 56ce4ed6316cae9536ea891d6686b92f1d930c00

Amit Machhiwal (1):
ring-buffer: Do not check si_mem_available() before deferred init completes

Baek Kyu, Kim (1):
tracing: Free tracer resources on instance creation failure

Breno Leitao (1):
fgraph: Do not mark index 0 in every shadow stack frame

Brian Norris (2):
tracing: Properly match strings that start with numbers
tracing: Add tests for globbing number-based strings

Chaosheng Qu (1):
tracing/osnoise: Don't start a kthread in timerlat user-space mode

Christian Aurich Zanettini Martins (1):
ring-buffer: Do not WARN when trace_rb_cpu_prepare() fails to allocate

David Carlier (4):
tracing: Define common event fields before enabling boot events
tracing: Drop the synthetic event ref when clearing hist triggers tracing/user_events: Don't free an event that a dynamic event still references
tracing: Ignore .function on the function trace event

Jaewon Jung (2):
tracing: Keep copying markers when one instance is stopped
tracing: Avoid undefined shifts for zero histogram map size

Kyle Zeng (3):
tracing: Restrict perf filters that read kernel strings tracing/filters: Treat zero-length dynamic strings as empty
tracing: Validate user addresses in faultable buffer copies

Masami Hiramatsu (Google) (4):
tracing/filters: Fix MATCH_END_ONLY regex matching for fixed-size strings tracing/filters: Handle out-of-range CPU for OP_NE in cpumask comparison tracing/filters: Check for missing operand after operator in parse_pred() tracing/filters: Fix false success return in process_system_preds()

Pengfei Li (1):
tracing: Wait for marker writers when copy_trace_marker is cleared

Steven Rostedt (3):
fgraph: Read the task->ret_stack with a smp_load_acquire()
tracing: Do not allow user events to add a system name
tracing: Add notrace to event functions that hook to ftrace

Vincent Donnefort (5):
ring-buffer: Skip remote reader page swap when on tail
ring-buffer: Check remote reader page commit before meta entries
ring-buffer: Order remote page commit with data and timestamp
ring-buffer: Increment pages_read on remote ring buffer page swap
tracing: Take trace_access_lock() in tracing_buffers_ioctl()

Vineet Gupta (2):
fgraph: Allocate shadow stacks inline with GFP_NOWAIT
fgraph: Use scoped_guard() for the task list walk

Wenwu Hou (1):
tracing/hwlat: Do the latency calculations in nanoseconds

----

 kernel/trace/fgraph.c                   |  59 +++++-----
 kernel/trace/ftrace.c                   |   3 +-
 kernel/trace/ring_buffer.c              |  60 +++++++---
 kernel/trace/simple_ring_buffer.c       |  26 +++-
 kernel/trace/trace.c                    |  45 ++++---
 kernel/trace/trace.h                    |   3 +-
 kernel/trace/trace_events.c             |   8 +-
 kernel/trace/trace_events_filter.c      | 203 +++++++++++++++++++++++++++-----
 kernel/trace/trace_events_filter_test.h |  12 +-
 kernel/trace/trace_events_hist.c        |  25 ++--
 kernel/trace/trace_events_trigger.c     |   2 +
 kernel/trace/trace_events_user.c        |  12 ++
 kernel/trace/trace_hwlat.c              |  41 ++++---
 kernel/trace/trace_osnoise.c            |   8 ++
 14 files changed, 375 insertions(+), 132 deletions(-)