Skip to content

Commit c5eac6e

Browse files
Kalesh Singhrostedt
authored andcommitted
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/[email protected] Signed-off-by: Kalesh Singh <[email protected]> Suggested-by: Steven Rostedt <[email protected]> Signed-off-by: Steven Rostedt (VMware) <[email protected]>
1 parent 9710b2f commit c5eac6e

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
@@ -1672,10 +1671,6 @@ static int contains_operator(char *str, char **sep)
16721671
*/
16731672
minus_op = strrchr(str, '-');
16741673
if (minus_op) {
1675-
/* Unfortunately, the modifier ".sym-offset" can confuse things. */
1676-
if (minus_op - str >= 4 && !strncmp(minus_op - 4, ".sym-offset", 11))
1677-
goto out;
1678-
16791674
/*
16801675
* Unary minus is not supported in sub-expressions. If
16811676
* present, it is always the next root operator.
@@ -2138,7 +2133,11 @@ parse_field(struct hist_trigger_data *hist_data, struct trace_event_file *file,
21382133
*flags |= HIST_FIELD_FL_HEX;
21392134
else if (strcmp(modifier, "sym") == 0)
21402135
*flags |= HIST_FIELD_FL_SYM;
2141-
else if (strcmp(modifier, "sym-offset") == 0)
2136+
/*
2137+
* 'sym-offset' occurrences in the trigger string are modified
2138+
* to 'symXoffset' to simplify arithmetic expression parsing.
2139+
*/
2140+
else if (strcmp(modifier, "symXoffset") == 0)
21422141
*flags |= HIST_FIELD_FL_SYM_OFFSET;
21432142
else if ((strcmp(modifier, "execname") == 0) &&
21442143
(strcmp(field_name, "common_pid") == 0))
@@ -2463,24 +2462,6 @@ static struct hist_field *parse_expr(struct hist_trigger_data *hist_data,
24632462
return ERR_PTR(-EINVAL);
24642463
}
24652464

2466-
/*
2467-
* ".sym-offset" in expressions has no effect on their evaluation,
2468-
* but can confuse operator parsing.
2469-
*/
2470-
if (*n_subexprs == 0) {
2471-
sep = strstr(str, ".sym-offset");
2472-
if (sep) {
2473-
*sep = '\0';
2474-
if (strpbrk(str, "+-/*") || strpbrk(sep + 11, "+-/*")) {
2475-
*sep = '.';
2476-
hist_err(file->tr, HIST_ERR_SYM_OFFSET_SUBEXPR,
2477-
errpos(sep));
2478-
return ERR_PTR(-EINVAL);
2479-
}
2480-
*sep = '.';
2481-
}
2482-
}
2483-
24842465
field_op = contains_operator(str, &sep);
24852466

24862467
if (field_op == FIELD_OP_NONE)
@@ -5999,7 +5980,7 @@ static int event_hist_trigger_func(struct event_command *cmd_ops,
59995980
struct synth_event *se;
60005981
const char *se_name;
60015982
bool remove = false;
6002-
char *trigger, *p;
5983+
char *trigger, *p, *start;
60035984
int ret = 0;
60045985

60055986
lockdep_assert_held(&event_mutex);
@@ -6047,6 +6028,16 @@ static int event_hist_trigger_func(struct event_command *cmd_ops,
60476028
trigger = strstrip(trigger);
60486029
}
60496030

6031+
/*
6032+
* To simplify arithmetic expression parsing, replace occurrences of
6033+
* '.sym-offset' modifier with '.symXoffset'
6034+
*/
6035+
start = strstr(trigger, ".sym-offset");
6036+
while (start) {
6037+
*(start + 4) = 'X';
6038+
start = strstr(start + 11, ".sym-offset");
6039+
};
6040+
60506041
attrs = parse_hist_trigger_attrs(file->tr, trigger);
60516042
if (IS_ERR(attrs))
60526043
return PTR_ERR(attrs);

0 commit comments

Comments
 (0)