Skip to content

Commit 65b7fbb

Browse files
tracing/histogram: Simplify handling of .sym-offset in expressions
JIRA: https://issues.redhat.com/browse/RHEL-67679 commit c5eac6e Author: Kalesh Singh <kaleshsingh@google.com> Date: Mon Oct 25 13:08:36 2021 -0700 tracing/histogram: Simplify handling of .sym-offset in expressions The '-' in .sym-offset can confuse the hist trigger arithmetic expression parsing. Simplify the handling of this by replacing the 'sym-offset' with 'symXoffset'. This allows us to correctly evaluate expressions where the user may have inadvertently added a .sym-offset modifier to one of the operands in an expression, instead of bailing out. In this case the .sym-offset has no effect on the evaluation of the expression. The only valid use of the .sym-offset is as a hist key modifier. Link: https://lkml.kernel.org/r/20211025200852.3002369-5-kaleshsingh@google.com Signed-off-by: Kalesh Singh <kaleshsingh@google.com> Suggested-by: Steven Rostedt <rostedt@goodmis.org> Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org> Signed-off-by: Tomas Glozar <tglozar@redhat.com>
1 parent c61b871 commit 65b7fbb

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

kernel/trace/trace_events_hist.c

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@
6868
C(INVALID_SORT_FIELD, "Sort field must be a key or a val"), \
6969
C(INVALID_STR_OPERAND, "String type can not be an operand in expression"), \
7070
C(EXPECT_NUMBER, "Expecting numeric literal"), \
71-
C(UNARY_MINUS_SUBEXPR, "Unary minus not supported in sub-expressions"), \
72-
C(SYM_OFFSET_SUBEXPR, ".sym-offset not supported in sub-expressions"),
71+
C(UNARY_MINUS_SUBEXPR, "Unary minus not supported in sub-expressions"),
7372

7473
#undef C
7574
#define C(a, b) HIST_ERR_##a
@@ -1662,10 +1661,6 @@ static int contains_operator(char *str, char **sep)
16621661
*/
16631662
minus_op = strrchr(str, '-');
16641663
if (minus_op) {
1665-
/* Unfortunately, the modifier ".sym-offset" can confuse things. */
1666-
if (minus_op - str >= 4 && !strncmp(minus_op - 4, ".sym-offset", 11))
1667-
goto out;
1668-
16691664
/*
16701665
* Unary minus is not supported in sub-expressions. If
16711666
* present, it is always the next root operator.
@@ -2132,7 +2127,11 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file,
21322127
*flags |= HIST_FIELD_FL_HEX;
21332128
else if (strcmp(modifier, "sym") == 0)
21342129
*flags |= HIST_FIELD_FL_SYM;
2135-
else if (strcmp(modifier, "sym-offset") == 0)
2130+
/*
2131+
* 'sym-offset' occurrences in the trigger string are modified
2132+
* to 'symXoffset' to simplify arithmetic expression parsing.
2133+
*/
2134+
else if (strcmp(modifier, "symXoffset") == 0)
21362135
*flags |= HIST_FIELD_FL_SYM_OFFSET;
21372136
else if ((strcmp(modifier, "execname") == 0) &&
21382137
(strcmp(field_name, "common_pid") == 0))
@@ -2457,24 +2456,6 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,
24572456
return ERR_PTR(-EINVAL);
24582457
}
24592458

2460-
/*
2461-
* ".sym-offset" in expressions has no effect on their evaluation,
2462-
* but can confuse operator parsing.
2463-
*/
2464-
if (*n_subexprs == 0) {
2465-
sep = strstr(str, ".sym-offset");
2466-
if (sep) {
2467-
*sep = '\0';
2468-
if (strpbrk(str, "+-/*") || strpbrk(sep + 11, "+-/*")) {
2469-
*sep = '.';
2470-
hist_err(file->tr, HIST_ERR_SYM_OFFSET_SUBEXPR,
2471-
errpos(sep));
2472-
return ERR_PTR(-EINVAL);
2473-
}
2474-
*sep = '.';
2475-
}
2476-
}
2477-
24782459
field_op = contains_operator(str, &sep);
24792460

24802461
if (field_op == FIELD_OP_NONE)
@@ -5965,7 +5946,7 @@ static int event_hist_trigger_func(struct event_command *cmd_ops,
59655946
struct synth_event *se;
59665947
const char *se_name;
59675948
bool remove = false;
5968-
char *trigger, *p;
5949+
char *trigger, *p, *start;
59695950
int ret = 0;
59705951

59715952
lockdep_assert_held(&event_mutex);
@@ -6013,6 +5994,16 @@ static int event_hist_trigger_func(struct event_command *cmd_ops,
60135994
trigger = strstrip(trigger);
60145995
}
60155996

5997+
/*
5998+
* To simplify arithmetic expression parsing, replace occurrences of
5999+
* '.sym-offset' modifier with '.symXoffset'
6000+
*/
6001+
start = strstr(trigger, ".sym-offset");
6002+
while (start) {
6003+
*(start + 4) = 'X';
6004+
start = strstr(start + 11, ".sym-offset");
6005+
};
6006+
60166007
attrs = parse_hist_trigger_attrs(file->tr, trigger);
60176008
if (IS_ERR(attrs))
60186009
return PTR_ERR(attrs);

0 commit comments

Comments
 (0)