public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@kernel.org>,
	Andrew Morton <akpm@linux-foundation.org>,
	Tom Zanussi <zanussi@kernel.org>
Subject: [for-linus][PATCH 04/15] tracing: Save normal string variables
Date: Tue, 06 Oct 2020 10:34:50 -0400	[thread overview]
Message-ID: <20201006143511.159147822@goodmis.org> (raw)
In-Reply-To: 20201006143446.182666356@goodmis.org

From: Tom Zanussi <zanussi@kernel.org>

String variables created as field variables and save variables are
already handled properly by having their values copied when set.  The
same isn't done for normal variables, but needs to be - simply saving
a pointer to a string contained in an old event isn't sufficient,
since that event's data may quickly become overwritten and therefore a
string pointer to it could yield garbage.

This change uses the same mechanism as field variables and simply
appends the new strings to the existing per-element field_var_str[]
array allocated for that purpose.

Link: https://lkml.kernel.org/r/1c1a03798b02e67307412a0c719d1bfb69b13007.1601848695.git.zanussi@kernel.org

Fixes: 02205a6752f2 (tracing: Add support for 'field variables')
Signed-off-by: Tom Zanussi <zanussi@kernel.org>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 kernel/trace/trace_events_hist.c | 34 ++++++++++++++++++++++++++++++--
 1 file changed, 32 insertions(+), 2 deletions(-)

diff --git a/kernel/trace/trace_events_hist.c b/kernel/trace/trace_events_hist.c
index 3b22e2122d1a..812bc5f94b5c 100644
--- a/kernel/trace/trace_events_hist.c
+++ b/kernel/trace/trace_events_hist.c
@@ -147,6 +147,8 @@ struct hist_field {
 	 */
 	unsigned int			var_ref_idx;
 	bool                            read_once;
+
+	unsigned int			var_str_idx;
 };
 
 static u64 hist_field_none(struct hist_field *field,
@@ -349,6 +351,7 @@ struct hist_trigger_data {
 	unsigned int			n_keys;
 	unsigned int			n_fields;
 	unsigned int			n_vars;
+	unsigned int			n_var_str;
 	unsigned int			key_size;
 	struct tracing_map_sort_key	sort_keys[TRACING_MAP_SORT_KEYS_MAX];
 	unsigned int			n_sort_keys;
@@ -1396,7 +1399,12 @@ static int hist_trigger_elt_data_alloc(struct tracing_map_elt *elt)
 		}
 	}
 
-	n_str = hist_data->n_field_var_str + hist_data->n_save_var_str;
+	n_str = hist_data->n_field_var_str + hist_data->n_save_var_str +
+		hist_data->n_var_str;
+	if (n_str > SYNTH_FIELDS_MAX) {
+		hist_elt_data_free(elt_data);
+		return -EINVAL;
+	}
 
 	BUILD_BUG_ON(STR_VAR_LEN_MAX & (sizeof(u64) - 1));
 
@@ -3653,6 +3661,7 @@ static int create_var_field(struct hist_trigger_data *hist_data,
 {
 	struct trace_array *tr = hist_data->event_file->tr;
 	unsigned long flags = 0;
+	int ret;
 
 	if (WARN_ON(val_idx >= TRACING_MAP_VALS_MAX + TRACING_MAP_VARS_MAX))
 		return -EINVAL;
@@ -3667,7 +3676,12 @@ static int create_var_field(struct hist_trigger_data *hist_data,
 	if (WARN_ON(hist_data->n_vars > TRACING_MAP_VARS_MAX))
 		return -EINVAL;
 
-	return __create_val_field(hist_data, val_idx, file, var_name, expr_str, flags);
+	ret = __create_val_field(hist_data, val_idx, file, var_name, expr_str, flags);
+
+	if (hist_data->fields[val_idx]->flags & HIST_FIELD_FL_STRING)
+		hist_data->fields[val_idx]->var_str_idx = hist_data->n_var_str++;
+
+	return ret;
 }
 
 static int create_val_fields(struct hist_trigger_data *hist_data,
@@ -4394,6 +4408,22 @@ static void hist_trigger_elt_update(struct hist_trigger_data *hist_data,
 		hist_val = hist_field->fn(hist_field, elt, rbe, rec);
 		if (hist_field->flags & HIST_FIELD_FL_VAR) {
 			var_idx = hist_field->var.idx;
+
+			if (hist_field->flags & HIST_FIELD_FL_STRING) {
+				unsigned int str_start, var_str_idx, idx;
+				char *str, *val_str;
+
+				str_start = hist_data->n_field_var_str +
+					hist_data->n_save_var_str;
+				var_str_idx = hist_field->var_str_idx;
+				idx = str_start + var_str_idx;
+
+				str = elt_data->field_var_str[idx];
+				val_str = (char *)(uintptr_t)hist_val;
+				strscpy(str, val_str, STR_VAR_LEN_MAX);
+
+				hist_val = (u64)(uintptr_t)str;
+			}
 			tracing_map_set_var(elt, var_idx, hist_val);
 			continue;
 		}
-- 
2.28.0



  parent reply	other threads:[~2020-10-06 14:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-06 14:34 [for-linus][PATCH 00/15] tracing: Some final updates for 5.10 Steven Rostedt
2020-10-06 14:34 ` [for-linus][PATCH 01/15] ftrace: Fix some typos in comment Steven Rostedt
2020-10-06 14:34 ` [for-linus][PATCH 02/15] tracing: Change STR_VAR_MAX_LEN Steven Rostedt
2020-10-06 14:34 ` [for-linus][PATCH 03/15] tracing: Fix parse_synth_field() error handling Steven Rostedt
2020-10-06 14:34 ` Steven Rostedt [this message]
2020-10-06 14:34 ` [for-linus][PATCH 05/15] tracing: Add support for dynamic strings to synthetic events Steven Rostedt
2020-10-06 14:34 ` [for-linus][PATCH 06/15] tracing: Add README information for synthetic_events file Steven Rostedt
2020-10-06 14:34 ` [for-linus][PATCH 07/15] selftests/ftrace: Add test case for synthetic event dynamic strings Steven Rostedt
2020-10-06 14:34 ` [for-linus][PATCH 08/15] tracing: Change synthetic event string format to limit printed length Steven Rostedt
2020-10-06 14:34 ` [for-linus][PATCH 09/15] ftrace: Use fls() to get the bits for dup_hash() Steven Rostedt
2020-10-06 14:34 ` [for-linus][PATCH 10/15] ftrace: Simplify the hash calculation Steven Rostedt
2020-10-06 14:34 ` [for-linus][PATCH 11/15] ftrace: Simplify the dyn_ftrace->flags macro Steven Rostedt
2020-10-06 14:34 ` [for-linus][PATCH 12/15] ftrace: Simplify the calculation of page number for ftrace_page->records Steven Rostedt
2020-10-06 14:34 ` [for-linus][PATCH 13/15] ftrace: Format variable declarations of ftrace_allocate_records Steven Rostedt
2020-10-06 14:35 ` [for-linus][PATCH 14/15] ftrace: ftrace_global_list is renamed to ftrace_ops_list Steven Rostedt
2020-10-06 14:35 ` [for-linus][PATCH 15/15] tracing: Remove a pointless assignment Steven Rostedt
2020-10-06 15:01 ` [for-linus][PATCH 00/15] tracing: Some final updates for 5.10 Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201006143511.159147822@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=zanussi@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox