2018-08-16 15:23:53 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2009-03-22 08:31:04 +00:00
|
|
|
/*
|
|
|
|
* trace_events_filter - generic event filtering
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Tom Zanussi <tzanussi@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/ctype.h>
|
2009-04-17 05:27:08 +00:00
|
|
|
#include <linux/mutex.h>
|
2009-10-15 03:21:42 +00:00
|
|
|
#include <linux/perf_event.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2009-03-22 08:31:04 +00:00
|
|
|
|
|
|
|
#include "trace.h"
|
2009-03-24 07:14:31 +00:00
|
|
|
#include "trace_output.h"
|
2009-03-22 08:31:04 +00:00
|
|
|
|
2011-11-02 20:46:46 +00:00
|
|
|
#define DEFAULT_SYS_FILTER_MESSAGE \
|
|
|
|
"### global filter ###\n" \
|
|
|
|
"# Use this to set filters for multiple events.\n" \
|
|
|
|
"# Only events with the given fields will be affected.\n" \
|
|
|
|
"# If no events are modified, an error message will be displayed here"
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* Due to token parsing '<=' must be before '<' and '>=' must be before '>' */
|
2018-03-08 20:32:50 +00:00
|
|
|
#define OPS \
|
2018-03-09 18:19:28 +00:00
|
|
|
C( OP_GLOB, "~" ), \
|
|
|
|
C( OP_NE, "!=" ), \
|
|
|
|
C( OP_EQ, "==" ), \
|
|
|
|
C( OP_LE, "<=" ), \
|
|
|
|
C( OP_LT, "<" ), \
|
|
|
|
C( OP_GE, ">=" ), \
|
|
|
|
C( OP_GT, ">" ), \
|
|
|
|
C( OP_BAND, "&" ), \
|
|
|
|
C( OP_MAX, NULL )
|
2018-03-08 20:32:50 +00:00
|
|
|
|
|
|
|
#undef C
|
2018-03-09 18:19:28 +00:00
|
|
|
#define C(a, b) a
|
2018-03-08 20:32:50 +00:00
|
|
|
|
|
|
|
enum filter_op_ids { OPS };
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-08 20:32:50 +00:00
|
|
|
#undef C
|
2018-03-09 18:19:28 +00:00
|
|
|
#define C(a, b) b
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
static const char * ops[] = { OPS };
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-08 22:53:20 +00:00
|
|
|
/*
|
2018-03-09 18:19:28 +00:00
|
|
|
* pred functions are OP_LE, OP_LT, OP_GE, OP_GT, and OP_BAND
|
2018-03-08 22:53:20 +00:00
|
|
|
* pred_funcs_##type below must match the order of them above.
|
|
|
|
*/
|
2018-03-09 18:19:28 +00:00
|
|
|
#define PRED_FUNC_START OP_LE
|
2018-03-08 22:53:20 +00:00
|
|
|
#define PRED_FUNC_MAX (OP_BAND - PRED_FUNC_START)
|
|
|
|
|
2018-03-08 20:32:50 +00:00
|
|
|
#define ERRORS \
|
2018-03-09 18:19:28 +00:00
|
|
|
C(NONE, "No error"), \
|
|
|
|
C(INVALID_OP, "Invalid operator"), \
|
|
|
|
C(TOO_MANY_OPEN, "Too many '('"), \
|
|
|
|
C(TOO_MANY_CLOSE, "Too few '('"), \
|
|
|
|
C(MISSING_QUOTE, "Missing matching quote"), \
|
|
|
|
C(OPERAND_TOO_LONG, "Operand too long"), \
|
|
|
|
C(EXPECT_STRING, "Expecting string field"), \
|
|
|
|
C(EXPECT_DIGIT, "Expecting numeric field"), \
|
|
|
|
C(ILLEGAL_FIELD_OP, "Illegal operation for field type"), \
|
|
|
|
C(FIELD_NOT_FOUND, "Field not found"), \
|
|
|
|
C(ILLEGAL_INTVAL, "Illegal integer value"), \
|
|
|
|
C(BAD_SUBSYS_FILTER, "Couldn't find or set field in one of a subsystem's events"), \
|
|
|
|
C(TOO_MANY_PREDS, "Too many terms in predicate expression"), \
|
|
|
|
C(INVALID_FILTER, "Meaningless filter expression"), \
|
|
|
|
C(IP_FIELD_ONLY, "Only 'ip' field is supported for function trace"), \
|
2018-06-21 17:20:53 +00:00
|
|
|
C(INVALID_VALUE, "Invalid value (did you forget quotes)?"), \
|
2019-03-31 23:48:18 +00:00
|
|
|
C(ERRNO, "Error"), \
|
|
|
|
C(NO_FILTER, "No filter found")
|
2018-03-08 20:32:50 +00:00
|
|
|
|
|
|
|
#undef C
|
|
|
|
#define C(a, b) FILT_ERR_##a
|
|
|
|
|
|
|
|
enum { ERRORS };
|
|
|
|
|
|
|
|
#undef C
|
|
|
|
#define C(a, b) b
|
|
|
|
|
2019-03-31 23:48:18 +00:00
|
|
|
static const char *err_text[] = { ERRORS };
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* Called after a '!' character but "!=" and "!~" are not "not"s */
|
|
|
|
static bool is_not(const char *str)
|
|
|
|
{
|
|
|
|
switch (str[1]) {
|
|
|
|
case '=':
|
|
|
|
case '~':
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/**
|
|
|
|
* prog_entry - a singe entry in the filter program
|
|
|
|
* @target: Index to jump to on a branch (actually one minus the index)
|
|
|
|
* @when_to_branch: The value of the result of the predicate to do a branch
|
|
|
|
* @pred: The predicate to execute.
|
|
|
|
*/
|
|
|
|
struct prog_entry {
|
|
|
|
int target;
|
|
|
|
int when_to_branch;
|
|
|
|
struct filter_pred *pred;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
};
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/**
|
|
|
|
* update_preds- assign a program entry a label target
|
|
|
|
* @prog: The program array
|
|
|
|
* @N: The index of the current entry in @prog
|
|
|
|
* @when_to_branch: What to assign a program entry for its branch condition
|
|
|
|
*
|
|
|
|
* The program entry at @N has a target that points to the index of a program
|
|
|
|
* entry that can have its target and when_to_branch fields updated.
|
|
|
|
* Update the current program entry denoted by index @N target field to be
|
|
|
|
* that of the updated entry. This will denote the entry to update if
|
|
|
|
* we are processing an "||" after an "&&"
|
|
|
|
*/
|
|
|
|
static void update_preds(struct prog_entry *prog, int N, int invert)
|
|
|
|
{
|
|
|
|
int t, s;
|
|
|
|
|
|
|
|
t = prog[N].target;
|
|
|
|
s = prog[t].target;
|
|
|
|
prog[t].when_to_branch = invert;
|
|
|
|
prog[t].target = N;
|
|
|
|
prog[N].target = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct filter_parse_error {
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
int lasterr;
|
|
|
|
int lasterr_pos;
|
|
|
|
};
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
static void parse_error(struct filter_parse_error *pe, int err, int pos)
|
|
|
|
{
|
|
|
|
pe->lasterr = err;
|
|
|
|
pe->lasterr_pos = pos;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef int (*parse_pred_fn)(const char *str, void *data, int pos,
|
|
|
|
struct filter_parse_error *pe,
|
|
|
|
struct filter_pred **pred);
|
|
|
|
|
|
|
|
enum {
|
|
|
|
INVERT = 1,
|
|
|
|
PROCESS_AND = 2,
|
|
|
|
PROCESS_OR = 4,
|
2011-01-28 03:54:33 +00:00
|
|
|
};
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/*
|
|
|
|
* Without going into a formal proof, this explains the method that is used in
|
|
|
|
* parsing the logical expressions.
|
|
|
|
*
|
|
|
|
* For example, if we have: "a && !(!b || (c && g)) || d || e && !f"
|
|
|
|
* The first pass will convert it into the following program:
|
|
|
|
*
|
|
|
|
* n1: r=a; l1: if (!r) goto l4;
|
|
|
|
* n2: r=b; l2: if (!r) goto l4;
|
|
|
|
* n3: r=c; r=!r; l3: if (r) goto l4;
|
|
|
|
* n4: r=g; r=!r; l4: if (r) goto l5;
|
|
|
|
* n5: r=d; l5: if (r) goto T
|
|
|
|
* n6: r=e; l6: if (!r) goto l7;
|
|
|
|
* n7: r=f; r=!r; l7: if (!r) goto F
|
|
|
|
* T: return TRUE
|
|
|
|
* F: return FALSE
|
|
|
|
*
|
|
|
|
* To do this, we use a data structure to represent each of the above
|
|
|
|
* predicate and conditions that has:
|
|
|
|
*
|
|
|
|
* predicate, when_to_branch, invert, target
|
|
|
|
*
|
|
|
|
* The "predicate" will hold the function to determine the result "r".
|
|
|
|
* The "when_to_branch" denotes what "r" should be if a branch is to be taken
|
|
|
|
* "&&" would contain "!r" or (0) and "||" would contain "r" or (1).
|
|
|
|
* The "invert" holds whether the value should be reversed before testing.
|
|
|
|
* The "target" contains the label "l#" to jump to.
|
|
|
|
*
|
|
|
|
* A stack is created to hold values when parentheses are used.
|
|
|
|
*
|
|
|
|
* To simplify the logic, the labels will start at 0 and not 1.
|
|
|
|
*
|
|
|
|
* The possible invert values are 1 and 0. The number of "!"s that are in scope
|
|
|
|
* before the predicate determines the invert value, if the number is odd then
|
|
|
|
* the invert value is 1 and 0 otherwise. This means the invert value only
|
|
|
|
* needs to be toggled when a new "!" is introduced compared to what is stored
|
|
|
|
* on the stack, where parentheses were used.
|
|
|
|
*
|
|
|
|
* The top of the stack and "invert" are initialized to zero.
|
|
|
|
*
|
|
|
|
* ** FIRST PASS **
|
|
|
|
*
|
|
|
|
* #1 A loop through all the tokens is done:
|
|
|
|
*
|
|
|
|
* #2 If the token is an "(", the stack is push, and the current stack value
|
|
|
|
* gets the current invert value, and the loop continues to the next token.
|
|
|
|
* The top of the stack saves the "invert" value to keep track of what
|
|
|
|
* the current inversion is. As "!(a && !b || c)" would require all
|
|
|
|
* predicates being affected separately by the "!" before the parentheses.
|
|
|
|
* And that would end up being equivalent to "(!a || b) && !c"
|
|
|
|
*
|
|
|
|
* #3 If the token is an "!", the current "invert" value gets inverted, and
|
|
|
|
* the loop continues. Note, if the next token is a predicate, then
|
|
|
|
* this "invert" value is only valid for the current program entry,
|
|
|
|
* and does not affect other predicates later on.
|
|
|
|
*
|
|
|
|
* The only other acceptable token is the predicate string.
|
|
|
|
*
|
|
|
|
* #4 A new entry into the program is added saving: the predicate and the
|
|
|
|
* current value of "invert". The target is currently assigned to the
|
|
|
|
* previous program index (this will not be its final value).
|
|
|
|
*
|
|
|
|
* #5 We now enter another loop and look at the next token. The only valid
|
|
|
|
* tokens are ")", "&&", "||" or end of the input string "\0".
|
|
|
|
*
|
|
|
|
* #6 The invert variable is reset to the current value saved on the top of
|
|
|
|
* the stack.
|
|
|
|
*
|
|
|
|
* #7 The top of the stack holds not only the current invert value, but also
|
|
|
|
* if a "&&" or "||" needs to be processed. Note, the "&&" takes higher
|
|
|
|
* precedence than "||". That is "a && b || c && d" is equivalent to
|
|
|
|
* "(a && b) || (c && d)". Thus the first thing to do is to see if "&&" needs
|
|
|
|
* to be processed. This is the case if an "&&" was the last token. If it was
|
|
|
|
* then we call update_preds(). This takes the program, the current index in
|
|
|
|
* the program, and the current value of "invert". More will be described
|
|
|
|
* below about this function.
|
|
|
|
*
|
|
|
|
* #8 If the next token is "&&" then we set a flag in the top of the stack
|
|
|
|
* that denotes that "&&" needs to be processed, break out of this loop
|
|
|
|
* and continue with the outer loop.
|
|
|
|
*
|
|
|
|
* #9 Otherwise, if a "||" needs to be processed then update_preds() is called.
|
|
|
|
* This is called with the program, the current index in the program, but
|
|
|
|
* this time with an inverted value of "invert" (that is !invert). This is
|
|
|
|
* because the value taken will become the "when_to_branch" value of the
|
|
|
|
* program.
|
|
|
|
* Note, this is called when the next token is not an "&&". As stated before,
|
|
|
|
* "&&" takes higher precedence, and "||" should not be processed yet if the
|
|
|
|
* next logical operation is "&&".
|
|
|
|
*
|
|
|
|
* #10 If the next token is "||" then we set a flag in the top of the stack
|
|
|
|
* that denotes that "||" needs to be processed, break out of this loop
|
|
|
|
* and continue with the outer loop.
|
|
|
|
*
|
|
|
|
* #11 If this is the end of the input string "\0" then we break out of both
|
|
|
|
* loops.
|
|
|
|
*
|
|
|
|
* #12 Otherwise, the next token is ")", where we pop the stack and continue
|
|
|
|
* this inner loop.
|
|
|
|
*
|
|
|
|
* Now to discuss the update_pred() function, as that is key to the setting up
|
|
|
|
* of the program. Remember the "target" of the program is initialized to the
|
|
|
|
* previous index and not the "l" label. The target holds the index into the
|
|
|
|
* program that gets affected by the operand. Thus if we have something like
|
|
|
|
* "a || b && c", when we process "a" the target will be "-1" (undefined).
|
|
|
|
* When we process "b", its target is "0", which is the index of "a", as that's
|
|
|
|
* the predicate that is affected by "||". But because the next token after "b"
|
|
|
|
* is "&&" we don't call update_preds(). Instead continue to "c". As the
|
|
|
|
* next token after "c" is not "&&" but the end of input, we first process the
|
|
|
|
* "&&" by calling update_preds() for the "&&" then we process the "||" by
|
|
|
|
* callin updates_preds() with the values for processing "||".
|
|
|
|
*
|
|
|
|
* What does that mean? What update_preds() does is to first save the "target"
|
|
|
|
* of the program entry indexed by the current program entry's "target"
|
|
|
|
* (remember the "target" is initialized to previous program entry), and then
|
|
|
|
* sets that "target" to the current index which represents the label "l#".
|
|
|
|
* That entry's "when_to_branch" is set to the value passed in (the "invert"
|
|
|
|
* or "!invert"). Then it sets the current program entry's target to the saved
|
|
|
|
* "target" value (the old value of the program that had its "target" updated
|
|
|
|
* to the label).
|
|
|
|
*
|
|
|
|
* Looking back at "a || b && c", we have the following steps:
|
|
|
|
* "a" - prog[0] = { "a", X, -1 } // pred, when_to_branch, target
|
|
|
|
* "||" - flag that we need to process "||"; continue outer loop
|
|
|
|
* "b" - prog[1] = { "b", X, 0 }
|
|
|
|
* "&&" - flag that we need to process "&&"; continue outer loop
|
|
|
|
* (Notice we did not process "||")
|
|
|
|
* "c" - prog[2] = { "c", X, 1 }
|
|
|
|
* update_preds(prog, 2, 0); // invert = 0 as we are processing "&&"
|
|
|
|
* t = prog[2].target; // t = 1
|
|
|
|
* s = prog[t].target; // s = 0
|
|
|
|
* prog[t].target = 2; // Set target to "l2"
|
|
|
|
* prog[t].when_to_branch = 0;
|
|
|
|
* prog[2].target = s;
|
|
|
|
* update_preds(prog, 2, 1); // invert = 1 as we are now processing "||"
|
|
|
|
* t = prog[2].target; // t = 0
|
|
|
|
* s = prog[t].target; // s = -1
|
|
|
|
* prog[t].target = 2; // Set target to "l2"
|
|
|
|
* prog[t].when_to_branch = 1;
|
|
|
|
* prog[2].target = s;
|
|
|
|
*
|
|
|
|
* #13 Which brings us to the final step of the first pass, which is to set
|
|
|
|
* the last program entry's when_to_branch and target, which will be
|
|
|
|
* when_to_branch = 0; target = N; ( the label after the program entry after
|
|
|
|
* the last program entry processed above).
|
|
|
|
*
|
|
|
|
* If we denote "TRUE" to be the entry after the last program entry processed,
|
|
|
|
* and "FALSE" the program entry after that, we are now done with the first
|
|
|
|
* pass.
|
|
|
|
*
|
|
|
|
* Making the above "a || b && c" have a progam of:
|
|
|
|
* prog[0] = { "a", 1, 2 }
|
|
|
|
* prog[1] = { "b", 0, 2 }
|
|
|
|
* prog[2] = { "c", 0, 3 }
|
|
|
|
*
|
|
|
|
* Which translates into:
|
|
|
|
* n0: r = a; l0: if (r) goto l2;
|
|
|
|
* n1: r = b; l1: if (!r) goto l2;
|
|
|
|
* n2: r = c; l2: if (!r) goto l3; // Which is the same as "goto F;"
|
|
|
|
* T: return TRUE; l3:
|
|
|
|
* F: return FALSE
|
|
|
|
*
|
|
|
|
* Although, after the first pass, the program is correct, it is
|
|
|
|
* inefficient. The simple sample of "a || b && c" could be easily been
|
|
|
|
* converted into:
|
|
|
|
* n0: r = a; if (r) goto T
|
|
|
|
* n1: r = b; if (!r) goto F
|
|
|
|
* n2: r = c; if (!r) goto F
|
|
|
|
* T: return TRUE;
|
|
|
|
* F: return FALSE;
|
|
|
|
*
|
|
|
|
* The First Pass is over the input string. The next too passes are over
|
|
|
|
* the program itself.
|
|
|
|
*
|
|
|
|
* ** SECOND PASS **
|
|
|
|
*
|
|
|
|
* Which brings us to the second pass. If a jump to a label has the
|
|
|
|
* same condition as that label, it can instead jump to its target.
|
|
|
|
* The original example of "a && !(!b || (c && g)) || d || e && !f"
|
|
|
|
* where the first pass gives us:
|
|
|
|
*
|
|
|
|
* n1: r=a; l1: if (!r) goto l4;
|
|
|
|
* n2: r=b; l2: if (!r) goto l4;
|
|
|
|
* n3: r=c; r=!r; l3: if (r) goto l4;
|
|
|
|
* n4: r=g; r=!r; l4: if (r) goto l5;
|
|
|
|
* n5: r=d; l5: if (r) goto T
|
|
|
|
* n6: r=e; l6: if (!r) goto l7;
|
|
|
|
* n7: r=f; r=!r; l7: if (!r) goto F:
|
|
|
|
* T: return TRUE;
|
|
|
|
* F: return FALSE
|
|
|
|
*
|
|
|
|
* We can see that "l3: if (r) goto l4;" and at l4, we have "if (r) goto l5;".
|
|
|
|
* And "l5: if (r) goto T", we could optimize this by converting l3 and l4
|
|
|
|
* to go directly to T. To accomplish this, we start from the last
|
|
|
|
* entry in the program and work our way back. If the target of the entry
|
|
|
|
* has the same "when_to_branch" then we could use that entry's target.
|
|
|
|
* Doing this, the above would end up as:
|
|
|
|
*
|
|
|
|
* n1: r=a; l1: if (!r) goto l4;
|
|
|
|
* n2: r=b; l2: if (!r) goto l4;
|
|
|
|
* n3: r=c; r=!r; l3: if (r) goto T;
|
|
|
|
* n4: r=g; r=!r; l4: if (r) goto T;
|
|
|
|
* n5: r=d; l5: if (r) goto T;
|
|
|
|
* n6: r=e; l6: if (!r) goto F;
|
|
|
|
* n7: r=f; r=!r; l7: if (!r) goto F;
|
|
|
|
* T: return TRUE
|
|
|
|
* F: return FALSE
|
|
|
|
*
|
|
|
|
* In that same pass, if the "when_to_branch" doesn't match, we can simply
|
|
|
|
* go to the program entry after the label. That is, "l2: if (!r) goto l4;"
|
|
|
|
* where "l4: if (r) goto T;", then we can convert l2 to be:
|
|
|
|
* "l2: if (!r) goto n5;".
|
|
|
|
*
|
|
|
|
* This will have the second pass give us:
|
|
|
|
* n1: r=a; l1: if (!r) goto n5;
|
|
|
|
* n2: r=b; l2: if (!r) goto n5;
|
|
|
|
* n3: r=c; r=!r; l3: if (r) goto T;
|
|
|
|
* n4: r=g; r=!r; l4: if (r) goto T;
|
|
|
|
* n5: r=d; l5: if (r) goto T
|
|
|
|
* n6: r=e; l6: if (!r) goto F;
|
|
|
|
* n7: r=f; r=!r; l7: if (!r) goto F
|
|
|
|
* T: return TRUE
|
|
|
|
* F: return FALSE
|
|
|
|
*
|
|
|
|
* Notice, all the "l#" labels are no longer used, and they can now
|
|
|
|
* be discarded.
|
|
|
|
*
|
|
|
|
* ** THIRD PASS **
|
|
|
|
*
|
|
|
|
* For the third pass we deal with the inverts. As they simply just
|
|
|
|
* make the "when_to_branch" get inverted, a simple loop over the
|
|
|
|
* program to that does: "when_to_branch ^= invert;" will do the
|
|
|
|
* job, leaving us with:
|
|
|
|
* n1: r=a; if (!r) goto n5;
|
|
|
|
* n2: r=b; if (!r) goto n5;
|
|
|
|
* n3: r=c: if (!r) goto T;
|
|
|
|
* n4: r=g; if (!r) goto T;
|
|
|
|
* n5: r=d; if (r) goto T
|
|
|
|
* n6: r=e; if (!r) goto F;
|
|
|
|
* n7: r=f; if (r) goto F
|
|
|
|
* T: return TRUE
|
|
|
|
* F: return FALSE
|
|
|
|
*
|
|
|
|
* As "r = a; if (!r) goto n5;" is obviously the same as
|
|
|
|
* "if (!a) goto n5;" without doing anything we can interperate the
|
|
|
|
* program as:
|
|
|
|
* n1: if (!a) goto n5;
|
|
|
|
* n2: if (!b) goto n5;
|
|
|
|
* n3: if (!c) goto T;
|
|
|
|
* n4: if (!g) goto T;
|
|
|
|
* n5: if (d) goto T
|
|
|
|
* n6: if (!e) goto F;
|
|
|
|
* n7: if (f) goto F
|
|
|
|
* T: return TRUE
|
|
|
|
* F: return FALSE
|
|
|
|
*
|
|
|
|
* Since the inverts are discarded at the end, there's no reason to store
|
|
|
|
* them in the program array (and waste memory). A separate array to hold
|
|
|
|
* the inverts is used and freed at the end.
|
|
|
|
*/
|
|
|
|
static struct prog_entry *
|
|
|
|
predicate_parse(const char *str, int nr_parens, int nr_preds,
|
|
|
|
parse_pred_fn parse_pred, void *data,
|
|
|
|
struct filter_parse_error *pe)
|
|
|
|
{
|
|
|
|
struct prog_entry *prog_stack;
|
|
|
|
struct prog_entry *prog;
|
|
|
|
const char *ptr = str;
|
|
|
|
char *inverts = NULL;
|
|
|
|
int *op_stack;
|
|
|
|
int *top;
|
|
|
|
int invert = 0;
|
|
|
|
int ret = -ENOMEM;
|
|
|
|
int len;
|
|
|
|
int N = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
nr_preds += 2; /* For TRUE and FALSE */
|
|
|
|
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 20:55:00 +00:00
|
|
|
op_stack = kmalloc_array(nr_parens, sizeof(*op_stack), GFP_KERNEL);
|
2018-03-09 18:19:28 +00:00
|
|
|
if (!op_stack)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
2019-05-28 15:43:38 +00:00
|
|
|
prog_stack = kcalloc(nr_preds, sizeof(*prog_stack), GFP_KERNEL);
|
2018-03-09 18:19:28 +00:00
|
|
|
if (!prog_stack) {
|
|
|
|
parse_error(pe, -ENOMEM, 0);
|
|
|
|
goto out_free;
|
|
|
|
}
|
treewide: kmalloc() -> kmalloc_array()
The kmalloc() function has a 2-factor argument form, kmalloc_array(). This
patch replaces cases of:
kmalloc(a * b, gfp)
with:
kmalloc_array(a * b, gfp)
as well as handling cases of:
kmalloc(a * b * c, gfp)
with:
kmalloc(array3_size(a, b, c), gfp)
as it's slightly less ugly than:
kmalloc_array(array_size(a, b), c, gfp)
This does, however, attempt to ignore constant size factors like:
kmalloc(4 * 1024, gfp)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The tools/ directory was manually excluded, since it has its own
implementation of kmalloc().
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
kmalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
kmalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
kmalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
kmalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
kmalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_ID)
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_ID
+ COUNT_ID, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (COUNT_CONST)
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * COUNT_CONST
+ COUNT_CONST, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_ID)
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_ID
+ COUNT_ID, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (COUNT_CONST)
+ COUNT_CONST, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * COUNT_CONST
+ COUNT_CONST, sizeof(THING)
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
- kmalloc
+ kmalloc_array
(
- SIZE * COUNT
+ COUNT, SIZE
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
kmalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
kmalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
kmalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
kmalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
kmalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
kmalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products,
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(
- (E1) * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * E3
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- (E1) * (E2) * (E3)
+ array3_size(E1, E2, E3)
, ...)
|
kmalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants,
// keeping sizeof() as the second factor argument.
@@
expression THING, E1, E2;
type TYPE;
constant C1, C2, C3;
@@
(
kmalloc(sizeof(THING) * C2, ...)
|
kmalloc(sizeof(TYPE) * C2, ...)
|
kmalloc(C1 * C2 * C3, ...)
|
kmalloc(C1 * C2, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * (E2)
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(TYPE) * E2
+ E2, sizeof(TYPE)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * (E2)
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- sizeof(THING) * E2
+ E2, sizeof(THING)
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * E2
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- (E1) * (E2)
+ E1, E2
, ...)
|
- kmalloc
+ kmalloc_array
(
- E1 * E2
+ E1, E2
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-12 20:55:00 +00:00
|
|
|
inverts = kmalloc_array(nr_preds, sizeof(*inverts), GFP_KERNEL);
|
2018-03-09 18:19:28 +00:00
|
|
|
if (!inverts) {
|
|
|
|
parse_error(pe, -ENOMEM, 0);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
top = op_stack;
|
|
|
|
prog = prog_stack;
|
|
|
|
*top = 0;
|
|
|
|
|
|
|
|
/* First pass */
|
|
|
|
while (*ptr) { /* #1 */
|
|
|
|
const char *next = ptr++;
|
|
|
|
|
|
|
|
if (isspace(*next))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (*next) {
|
|
|
|
case '(': /* #2 */
|
2019-09-20 22:57:59 +00:00
|
|
|
if (top - op_stack > nr_parens) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out_free;
|
|
|
|
}
|
2018-03-09 18:19:28 +00:00
|
|
|
*(++top) = invert;
|
|
|
|
continue;
|
|
|
|
case '!': /* #3 */
|
|
|
|
if (!is_not(next))
|
|
|
|
break;
|
|
|
|
invert = !invert;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (N >= nr_preds) {
|
|
|
|
parse_error(pe, FILT_ERR_TOO_MANY_PREDS, next - str);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
inverts[N] = invert; /* #4 */
|
|
|
|
prog[N].target = N-1;
|
|
|
|
|
|
|
|
len = parse_pred(next, data, ptr - str, pe, &prog[N].pred);
|
|
|
|
if (len < 0) {
|
|
|
|
ret = len;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
ptr = next + len;
|
|
|
|
|
|
|
|
N++;
|
|
|
|
|
|
|
|
ret = -1;
|
|
|
|
while (1) { /* #5 */
|
|
|
|
next = ptr++;
|
|
|
|
if (isspace(*next))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
switch (*next) {
|
|
|
|
case ')':
|
|
|
|
case '\0':
|
|
|
|
break;
|
|
|
|
case '&':
|
|
|
|
case '|':
|
2019-01-14 21:37:53 +00:00
|
|
|
/* accepting only "&&" or "||" */
|
2018-03-09 18:19:28 +00:00
|
|
|
if (next[1] == next[0]) {
|
|
|
|
ptr++;
|
|
|
|
break;
|
|
|
|
}
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2018-03-09 18:19:28 +00:00
|
|
|
default:
|
|
|
|
parse_error(pe, FILT_ERR_TOO_MANY_PREDS,
|
|
|
|
next - str);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
|
|
|
invert = *top & INVERT;
|
|
|
|
|
|
|
|
if (*top & PROCESS_AND) { /* #7 */
|
|
|
|
update_preds(prog, N - 1, invert);
|
|
|
|
*top &= ~PROCESS_AND;
|
|
|
|
}
|
|
|
|
if (*next == '&') { /* #8 */
|
|
|
|
*top |= PROCESS_AND;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*top & PROCESS_OR) { /* #9 */
|
|
|
|
update_preds(prog, N - 1, !invert);
|
|
|
|
*top &= ~PROCESS_OR;
|
|
|
|
}
|
|
|
|
if (*next == '|') { /* #10 */
|
|
|
|
*top |= PROCESS_OR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!*next) /* #11 */
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
if (top == op_stack) {
|
|
|
|
ret = -1;
|
|
|
|
/* Too few '(' */
|
|
|
|
parse_error(pe, FILT_ERR_TOO_MANY_CLOSE, ptr - str);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
top--; /* #12 */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
out:
|
|
|
|
if (top != op_stack) {
|
|
|
|
/* Too many '(' */
|
|
|
|
parse_error(pe, FILT_ERR_TOO_MANY_OPEN, ptr - str);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
2018-06-21 17:20:53 +00:00
|
|
|
if (!N) {
|
|
|
|
/* No program? */
|
|
|
|
ret = -EINVAL;
|
|
|
|
parse_error(pe, FILT_ERR_NO_FILTER, ptr - str);
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
prog[N].pred = NULL; /* #13 */
|
|
|
|
prog[N].target = 1; /* TRUE */
|
|
|
|
prog[N+1].pred = NULL;
|
|
|
|
prog[N+1].target = 0; /* FALSE */
|
|
|
|
prog[N-1].target = N;
|
|
|
|
prog[N-1].when_to_branch = false;
|
|
|
|
|
|
|
|
/* Second Pass */
|
|
|
|
for (i = N-1 ; i--; ) {
|
|
|
|
int target = prog[i].target;
|
|
|
|
if (prog[i].when_to_branch == prog[target].when_to_branch)
|
|
|
|
prog[i].target = prog[target].target;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Third Pass */
|
|
|
|
for (i = 0; i < N; i++) {
|
|
|
|
invert = inverts[i] ^ prog[i].when_to_branch;
|
|
|
|
prog[i].when_to_branch = invert;
|
|
|
|
/* Make sure the program always moves forward */
|
|
|
|
if (WARN_ON(prog[i].target <= i)) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto out_free;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-09 02:10:04 +00:00
|
|
|
kfree(op_stack);
|
|
|
|
kfree(inverts);
|
2018-03-09 18:19:28 +00:00
|
|
|
return prog;
|
|
|
|
out_free:
|
|
|
|
kfree(op_stack);
|
|
|
|
kfree(inverts);
|
2019-05-28 15:43:38 +00:00
|
|
|
if (prog_stack) {
|
|
|
|
for (i = 0; prog_stack[i].pred; i++)
|
|
|
|
kfree(prog_stack[i].pred);
|
|
|
|
kfree(prog_stack);
|
|
|
|
}
|
2018-03-09 18:19:28 +00:00
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
2009-09-10 01:34:19 +00:00
|
|
|
#define DEFINE_COMPARISON_PRED(type) \
|
2016-10-25 20:14:28 +00:00
|
|
|
static int filter_pred_LT_##type(struct filter_pred *pred, void *event) \
|
2009-09-10 01:34:19 +00:00
|
|
|
{ \
|
|
|
|
type *addr = (type *)(event + pred->offset); \
|
|
|
|
type val = (type)pred->val; \
|
2018-03-09 18:19:28 +00:00
|
|
|
return *addr < val; \
|
2016-10-25 20:14:28 +00:00
|
|
|
} \
|
|
|
|
static int filter_pred_LE_##type(struct filter_pred *pred, void *event) \
|
|
|
|
{ \
|
|
|
|
type *addr = (type *)(event + pred->offset); \
|
|
|
|
type val = (type)pred->val; \
|
2018-03-09 18:19:28 +00:00
|
|
|
return *addr <= val; \
|
2016-10-25 20:14:28 +00:00
|
|
|
} \
|
|
|
|
static int filter_pred_GT_##type(struct filter_pred *pred, void *event) \
|
|
|
|
{ \
|
|
|
|
type *addr = (type *)(event + pred->offset); \
|
|
|
|
type val = (type)pred->val; \
|
2018-03-09 18:19:28 +00:00
|
|
|
return *addr > val; \
|
2016-10-25 20:14:28 +00:00
|
|
|
} \
|
|
|
|
static int filter_pred_GE_##type(struct filter_pred *pred, void *event) \
|
|
|
|
{ \
|
|
|
|
type *addr = (type *)(event + pred->offset); \
|
|
|
|
type val = (type)pred->val; \
|
2018-03-09 18:19:28 +00:00
|
|
|
return *addr >= val; \
|
2016-10-25 20:14:28 +00:00
|
|
|
} \
|
|
|
|
static int filter_pred_BAND_##type(struct filter_pred *pred, void *event) \
|
|
|
|
{ \
|
|
|
|
type *addr = (type *)(event + pred->offset); \
|
|
|
|
type val = (type)pred->val; \
|
2018-03-09 18:19:28 +00:00
|
|
|
return !!(*addr & val); \
|
2016-10-25 20:14:28 +00:00
|
|
|
} \
|
|
|
|
static const filter_pred_fn_t pred_funcs_##type[] = { \
|
|
|
|
filter_pred_LE_##type, \
|
2018-03-09 18:19:28 +00:00
|
|
|
filter_pred_LT_##type, \
|
2016-10-25 20:14:28 +00:00
|
|
|
filter_pred_GE_##type, \
|
2018-03-09 18:19:28 +00:00
|
|
|
filter_pred_GT_##type, \
|
2016-10-25 20:14:28 +00:00
|
|
|
filter_pred_BAND_##type, \
|
|
|
|
};
|
|
|
|
|
2009-09-10 01:34:19 +00:00
|
|
|
#define DEFINE_EQUALITY_PRED(size) \
|
2011-01-28 03:37:09 +00:00
|
|
|
static int filter_pred_##size(struct filter_pred *pred, void *event) \
|
2009-09-10 01:34:19 +00:00
|
|
|
{ \
|
|
|
|
u##size *addr = (u##size *)(event + pred->offset); \
|
|
|
|
u##size val = (u##size)pred->val; \
|
|
|
|
int match; \
|
|
|
|
\
|
|
|
|
match = (val == *addr) ^ pred->not; \
|
|
|
|
\
|
|
|
|
return match; \
|
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
DEFINE_COMPARISON_PRED(s64);
|
|
|
|
DEFINE_COMPARISON_PRED(u64);
|
|
|
|
DEFINE_COMPARISON_PRED(s32);
|
|
|
|
DEFINE_COMPARISON_PRED(u32);
|
|
|
|
DEFINE_COMPARISON_PRED(s16);
|
|
|
|
DEFINE_COMPARISON_PRED(u16);
|
|
|
|
DEFINE_COMPARISON_PRED(s8);
|
|
|
|
DEFINE_COMPARISON_PRED(u8);
|
|
|
|
|
|
|
|
DEFINE_EQUALITY_PRED(64);
|
|
|
|
DEFINE_EQUALITY_PRED(32);
|
|
|
|
DEFINE_EQUALITY_PRED(16);
|
|
|
|
DEFINE_EQUALITY_PRED(8);
|
|
|
|
|
2009-05-03 00:48:52 +00:00
|
|
|
/* Filter predicate for fixed sized arrays of characters */
|
2011-01-28 03:37:09 +00:00
|
|
|
static int filter_pred_string(struct filter_pred *pred, void *event)
|
2009-03-22 08:31:04 +00:00
|
|
|
{
|
|
|
|
char *addr = (char *)(event + pred->offset);
|
|
|
|
int cmp, match;
|
|
|
|
|
2009-09-24 19:10:44 +00:00
|
|
|
cmp = pred->regex.match(addr, &pred->regex, pred->regex.field_len);
|
2009-03-22 08:31:04 +00:00
|
|
|
|
2009-09-24 19:10:44 +00:00
|
|
|
match = cmp ^ pred->not;
|
2009-03-22 08:31:04 +00:00
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2009-08-07 02:33:43 +00:00
|
|
|
/* Filter predicate for char * pointers */
|
2011-01-28 03:37:09 +00:00
|
|
|
static int filter_pred_pchar(struct filter_pred *pred, void *event)
|
2009-08-07 02:33:43 +00:00
|
|
|
{
|
|
|
|
char **addr = (char **)(event + pred->offset);
|
|
|
|
int cmp, match;
|
2010-01-14 02:54:27 +00:00
|
|
|
int len = strlen(*addr) + 1; /* including tailing '\0' */
|
2009-08-07 02:33:43 +00:00
|
|
|
|
2010-01-14 02:54:27 +00:00
|
|
|
cmp = pred->regex.match(*addr, &pred->regex, len);
|
2009-08-07 02:33:43 +00:00
|
|
|
|
2009-09-24 19:10:44 +00:00
|
|
|
match = cmp ^ pred->not;
|
2009-08-07 02:33:43 +00:00
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2009-05-03 00:48:52 +00:00
|
|
|
/*
|
|
|
|
* Filter predicate for dynamic sized arrays of characters.
|
|
|
|
* These are implemented through a list of strings at the end
|
|
|
|
* of the entry.
|
|
|
|
* Also each of these strings have a field in the entry which
|
|
|
|
* contains its offset from the beginning of the entry.
|
|
|
|
* We have then first to get this field, dereference it
|
|
|
|
* and add it to the address of the entry, and at last we have
|
|
|
|
* the address of the string.
|
|
|
|
*/
|
2011-01-28 03:37:09 +00:00
|
|
|
static int filter_pred_strloc(struct filter_pred *pred, void *event)
|
2009-05-03 00:48:52 +00:00
|
|
|
{
|
2009-07-16 02:54:02 +00:00
|
|
|
u32 str_item = *(u32 *)(event + pred->offset);
|
|
|
|
int str_loc = str_item & 0xffff;
|
|
|
|
int str_len = str_item >> 16;
|
2009-05-03 00:48:52 +00:00
|
|
|
char *addr = (char *)(event + str_loc);
|
|
|
|
int cmp, match;
|
|
|
|
|
2009-09-24 19:10:44 +00:00
|
|
|
cmp = pred->regex.match(addr, &pred->regex, str_len);
|
2009-05-03 00:48:52 +00:00
|
|
|
|
2009-09-24 19:10:44 +00:00
|
|
|
match = cmp ^ pred->not;
|
2009-05-03 00:48:52 +00:00
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2015-08-10 12:35:46 +00:00
|
|
|
/* Filter predicate for CPUs. */
|
|
|
|
static int filter_pred_cpu(struct filter_pred *pred, void *event)
|
|
|
|
{
|
|
|
|
int cpu, cmp;
|
|
|
|
|
|
|
|
cpu = raw_smp_processor_id();
|
|
|
|
cmp = pred->val;
|
|
|
|
|
|
|
|
switch (pred->op) {
|
|
|
|
case OP_EQ:
|
2018-03-09 18:19:28 +00:00
|
|
|
return cpu == cmp;
|
|
|
|
case OP_NE:
|
|
|
|
return cpu != cmp;
|
2015-08-10 12:35:46 +00:00
|
|
|
case OP_LT:
|
2018-03-09 18:19:28 +00:00
|
|
|
return cpu < cmp;
|
2015-08-10 12:35:46 +00:00
|
|
|
case OP_LE:
|
2018-03-09 18:19:28 +00:00
|
|
|
return cpu <= cmp;
|
2015-08-10 12:35:46 +00:00
|
|
|
case OP_GT:
|
2018-03-09 18:19:28 +00:00
|
|
|
return cpu > cmp;
|
2015-08-10 12:35:46 +00:00
|
|
|
case OP_GE:
|
2018-03-09 18:19:28 +00:00
|
|
|
return cpu >= cmp;
|
2015-08-10 12:35:46 +00:00
|
|
|
default:
|
2018-03-09 18:19:28 +00:00
|
|
|
return 0;
|
2015-08-10 12:35:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Filter predicate for COMM. */
|
|
|
|
static int filter_pred_comm(struct filter_pred *pred, void *event)
|
|
|
|
{
|
2018-03-09 18:19:28 +00:00
|
|
|
int cmp;
|
2015-08-10 12:35:46 +00:00
|
|
|
|
|
|
|
cmp = pred->regex.match(current->comm, &pred->regex,
|
2018-03-09 18:19:28 +00:00
|
|
|
TASK_COMM_LEN);
|
|
|
|
return cmp ^ pred->not;
|
2015-08-10 12:35:46 +00:00
|
|
|
}
|
|
|
|
|
2011-01-28 03:37:09 +00:00
|
|
|
static int filter_pred_none(struct filter_pred *pred, void *event)
|
tracing/filters: allow on-the-fly filter switching
This patch allows event filters to be safely removed or switched
on-the-fly while avoiding the use of rcu or the suspension of tracing of
previous versions.
It does it by adding a new filter_pred_none() predicate function which
does nothing and by never deallocating either the predicates or any of
the filter_pred members used in matching; the predicate lists are
allocated and initialized during ftrace_event_calls initialization.
Whenever a filter is removed or replaced, the filter_pred_* functions
currently in use by the affected ftrace_event_call are immediately
switched over to to the filter_pred_none() function, while the rest of
the filter_pred members are left intact, allowing any currently
executing filter_pred_* functions to finish up, using the values they're
currently using.
In the case of filter replacement, the new predicate values are copied
into the old predicates after the above step, and the filter_pred_none()
functions are replaced by the filter_pred_* functions for the new
filter. In this case, it is possible though very unlikely that a
previous filter_pred_* is still running even after the
filter_pred_none() switch and the switch to the new filter_pred_*. In
that case, however, because nothing has been deallocated in the
filter_pred, the worst that can happen is that the old filter_pred_*
function sees the new values and as a result produces either a false
positive or a false negative, depending on the values it finds.
So one downside to this method is that rarely, it can produce a bad
match during the filter switch, but it should be possible to live with
that, IMHO.
The other downside is that at least in this patch the predicate lists
are always pre-allocated, taking up memory from the start. They could
probably be allocated on first-use, and de-allocated when tracing is
completely stopped - if this patch makes sense, I could create another
one to do that later on.
Oh, and it also places a restriction on the size of __arrays in events,
currently set to 128, since they can't be larger than the now embedded
str_val arrays in the filter_pred struct.
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: paulmck@linux.vnet.ibm.com
LKML-Reference: <1239610670.6660.49.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-13 08:17:50 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-01-14 02:54:40 +00:00
|
|
|
/*
|
|
|
|
* regex_match_foo - Basic regex callbacks
|
|
|
|
*
|
|
|
|
* @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')
|
|
|
|
*
|
|
|
|
* Note:
|
|
|
|
* - @str might not be NULL-terminated if it's of type DYN_STRING
|
2018-05-09 18:22:06 +00:00
|
|
|
* or STATIC_STRING, unless @len is zero.
|
2010-01-14 02:54:40 +00:00
|
|
|
*/
|
|
|
|
|
2009-09-24 19:10:44 +00:00
|
|
|
static int regex_match_full(char *str, struct regex *r, int len)
|
|
|
|
{
|
2018-05-09 18:22:06 +00:00
|
|
|
/* len of zero means str is dynamic and ends with '\0' */
|
|
|
|
if (!len)
|
|
|
|
return strcmp(str, r->pattern) == 0;
|
|
|
|
|
|
|
|
return strncmp(str, r->pattern, len) == 0;
|
2009-09-24 19:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int regex_match_front(char *str, struct regex *r, int len)
|
|
|
|
{
|
2018-05-09 18:22:06 +00:00
|
|
|
if (len && len < r->len)
|
2018-05-09 15:59:32 +00:00
|
|
|
return 0;
|
|
|
|
|
2018-05-09 18:22:06 +00:00
|
|
|
return strncmp(str, r->pattern, r->len) == 0;
|
2009-09-24 19:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int regex_match_middle(char *str, struct regex *r, int len)
|
|
|
|
{
|
2018-05-09 18:22:06 +00:00
|
|
|
if (!len)
|
|
|
|
return strstr(str, r->pattern) != NULL;
|
|
|
|
|
|
|
|
return strnstr(str, r->pattern, len) != NULL;
|
2009-09-24 19:10:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int regex_match_end(char *str, struct regex *r, int len)
|
|
|
|
{
|
2010-01-14 02:53:41 +00:00
|
|
|
int strlen = len - 1;
|
2009-09-24 19:10:44 +00:00
|
|
|
|
2010-01-14 02:53:41 +00:00
|
|
|
if (strlen >= r->len &&
|
|
|
|
memcmp(str + strlen - r->len, r->pattern, r->len) == 0)
|
2009-09-24 19:10:44 +00:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-05 11:58:15 +00:00
|
|
|
static int regex_match_glob(char *str, struct regex *r, int len __maybe_unused)
|
|
|
|
{
|
|
|
|
if (glob_match(r->pattern, str))
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
2018-03-09 18:19:28 +00:00
|
|
|
|
2009-09-24 19:31:51 +00:00
|
|
|
/**
|
|
|
|
* filter_parse_regex - parse a basic regex
|
|
|
|
* @buff: the raw regex
|
|
|
|
* @len: length of the regex
|
|
|
|
* @search: will point to the beginning of the string to compare
|
|
|
|
* @not: tell whether the match will have to be inverted
|
|
|
|
*
|
|
|
|
* This passes in a buffer containing a regex and this function will
|
2009-09-24 19:10:44 +00:00
|
|
|
* set search to point to the search part of the buffer and
|
|
|
|
* return the type of search it is (see enum above).
|
|
|
|
* This does modify buff.
|
|
|
|
*
|
|
|
|
* Returns enum type.
|
|
|
|
* search returns the pointer to use for comparison.
|
|
|
|
* not returns 1 if buff started with a '!'
|
|
|
|
* 0 otherwise.
|
|
|
|
*/
|
2009-09-24 19:31:51 +00:00
|
|
|
enum regex_type filter_parse_regex(char *buff, int len, char **search, int *not)
|
2009-09-24 19:10:44 +00:00
|
|
|
{
|
|
|
|
int type = MATCH_FULL;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (buff[0] == '!') {
|
|
|
|
*not = 1;
|
|
|
|
buff++;
|
|
|
|
len--;
|
|
|
|
} else
|
|
|
|
*not = 0;
|
|
|
|
|
|
|
|
*search = buff;
|
|
|
|
|
ftrace: Allow enabling of filters via index of available_filter_functions
Enabling of large number of functions by echoing in a large subset of the
functions in available_filter_functions can take a very long time. The
process requires testing all functions registered by the function tracer
(which is in the 10s of thousands), and doing a kallsyms lookup to convert
the ip address into a name, then comparing that name with the string passed
in.
When a function causes the function tracer to crash the system, a binary
bisect of the available_filter_functions can be done to find the culprit.
But this requires passing in half of the functions in
available_filter_functions over and over again, which makes it basically a
O(n^2) operation. With 40,000 functions, that ends up bing 1,600,000,000
opertions! And enabling this can take over 20 minutes.
As a quick speed up, if a number is passed into one of the filter files,
instead of doing a search, it just enables the function at the corresponding
line of the available_filter_functions file. That is:
# echo 50 > set_ftrace_filter
# cat set_ftrace_filter
x86_pmu_commit_txn
# head -50 available_filter_functions | tail -1
x86_pmu_commit_txn
This allows setting of half the available_filter_functions to take place in
less than a second!
# time seq 20000 > set_ftrace_filter
real 0m0.042s
user 0m0.005s
sys 0m0.015s
# wc -l set_ftrace_filter
20000 set_ftrace_filter
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
2019-02-11 20:00:48 +00:00
|
|
|
if (isdigit(buff[0]))
|
|
|
|
return MATCH_INDEX;
|
|
|
|
|
2009-09-24 19:10:44 +00:00
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (buff[i] == '*') {
|
|
|
|
if (!i) {
|
|
|
|
type = MATCH_END_ONLY;
|
2016-10-05 11:58:15 +00:00
|
|
|
} else if (i == len - 1) {
|
2009-09-24 19:10:44 +00:00
|
|
|
if (type == MATCH_END_ONLY)
|
|
|
|
type = MATCH_MIDDLE_ONLY;
|
|
|
|
else
|
|
|
|
type = MATCH_FRONT_ONLY;
|
|
|
|
buff[i] = 0;
|
|
|
|
break;
|
2016-10-05 11:58:15 +00:00
|
|
|
} else { /* pattern continues, use full glob */
|
2018-02-06 03:18:11 +00:00
|
|
|
return MATCH_GLOB;
|
2009-09-24 19:10:44 +00:00
|
|
|
}
|
2016-10-05 11:58:15 +00:00
|
|
|
} else if (strchr("[?\\", buff[i])) {
|
2018-02-06 03:18:11 +00:00
|
|
|
return MATCH_GLOB;
|
2009-09-24 19:10:44 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-06 03:18:11 +00:00
|
|
|
if (buff[0] == '*')
|
|
|
|
*search = buff + 1;
|
2009-09-24 19:10:44 +00:00
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2009-10-15 03:21:12 +00:00
|
|
|
static void filter_build_regex(struct filter_pred *pred)
|
2009-09-24 19:10:44 +00:00
|
|
|
{
|
|
|
|
struct regex *r = &pred->regex;
|
2009-10-15 03:21:12 +00:00
|
|
|
char *search;
|
|
|
|
enum regex_type type = MATCH_FULL;
|
|
|
|
|
|
|
|
if (pred->op == OP_GLOB) {
|
2018-03-09 18:19:28 +00:00
|
|
|
type = filter_parse_regex(r->pattern, r->len, &search, &pred->not);
|
2009-10-15 03:21:12 +00:00
|
|
|
r->len = strlen(search);
|
|
|
|
memmove(r->pattern, search, r->len+1);
|
|
|
|
}
|
2009-09-24 19:10:44 +00:00
|
|
|
|
|
|
|
switch (type) {
|
ftrace: Allow enabling of filters via index of available_filter_functions
Enabling of large number of functions by echoing in a large subset of the
functions in available_filter_functions can take a very long time. The
process requires testing all functions registered by the function tracer
(which is in the 10s of thousands), and doing a kallsyms lookup to convert
the ip address into a name, then comparing that name with the string passed
in.
When a function causes the function tracer to crash the system, a binary
bisect of the available_filter_functions can be done to find the culprit.
But this requires passing in half of the functions in
available_filter_functions over and over again, which makes it basically a
O(n^2) operation. With 40,000 functions, that ends up bing 1,600,000,000
opertions! And enabling this can take over 20 minutes.
As a quick speed up, if a number is passed into one of the filter files,
instead of doing a search, it just enables the function at the corresponding
line of the available_filter_functions file. That is:
# echo 50 > set_ftrace_filter
# cat set_ftrace_filter
x86_pmu_commit_txn
# head -50 available_filter_functions | tail -1
x86_pmu_commit_txn
This allows setting of half the available_filter_functions to take place in
less than a second!
# time seq 20000 > set_ftrace_filter
real 0m0.042s
user 0m0.005s
sys 0m0.015s
# wc -l set_ftrace_filter
20000 set_ftrace_filter
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
2019-02-11 20:00:48 +00:00
|
|
|
/* MATCH_INDEX should not happen, but if it does, match full */
|
|
|
|
case MATCH_INDEX:
|
2009-09-24 19:10:44 +00:00
|
|
|
case MATCH_FULL:
|
|
|
|
r->match = regex_match_full;
|
|
|
|
break;
|
|
|
|
case MATCH_FRONT_ONLY:
|
|
|
|
r->match = regex_match_front;
|
|
|
|
break;
|
|
|
|
case MATCH_MIDDLE_ONLY:
|
|
|
|
r->match = regex_match_middle;
|
|
|
|
break;
|
|
|
|
case MATCH_END_ONLY:
|
|
|
|
r->match = regex_match_end;
|
|
|
|
break;
|
2016-10-05 11:58:15 +00:00
|
|
|
case MATCH_GLOB:
|
|
|
|
r->match = regex_match_glob;
|
|
|
|
break;
|
2009-09-24 19:10:44 +00:00
|
|
|
}
|
2011-08-11 14:25:53 +00:00
|
|
|
}
|
|
|
|
|
2009-03-22 08:31:04 +00:00
|
|
|
/* return 1 if event matches, 0 otherwise (discard) */
|
2009-10-15 03:21:42 +00:00
|
|
|
int filter_match_preds(struct event_filter *filter, void *rec)
|
2009-03-22 08:31:04 +00:00
|
|
|
{
|
2018-03-09 18:19:28 +00:00
|
|
|
struct prog_entry *prog;
|
|
|
|
int i;
|
2009-03-22 08:31:04 +00:00
|
|
|
|
2011-01-28 03:33:26 +00:00
|
|
|
/* no filter is considered a match */
|
2011-02-04 04:25:46 +00:00
|
|
|
if (!filter)
|
|
|
|
return 1;
|
|
|
|
|
2018-08-09 19:31:48 +00:00
|
|
|
/* Protected by either SRCU(tracepoint_srcu) or preempt_disable */
|
|
|
|
prog = rcu_dereference_raw(filter->prog);
|
2018-03-09 18:19:28 +00:00
|
|
|
if (!prog)
|
2011-01-28 03:33:26 +00:00
|
|
|
return 1;
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
for (i = 0; prog[i].pred; i++) {
|
|
|
|
struct filter_pred *pred = prog[i].pred;
|
|
|
|
int match = pred->fn(pred, rec);
|
|
|
|
if (match == prog[i].when_to_branch)
|
|
|
|
i = prog[i].target;
|
|
|
|
}
|
|
|
|
return prog[i].target;
|
2009-03-22 08:31:04 +00:00
|
|
|
}
|
2009-04-10 22:12:50 +00:00
|
|
|
EXPORT_SYMBOL_GPL(filter_match_preds);
|
2009-03-22 08:31:04 +00:00
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
static void remove_filter_string(struct event_filter *filter)
|
|
|
|
{
|
2011-02-04 04:25:46 +00:00
|
|
|
if (!filter)
|
|
|
|
return;
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
kfree(filter->filter_string);
|
|
|
|
filter->filter_string = NULL;
|
|
|
|
}
|
|
|
|
|
2019-04-01 20:07:48 +00:00
|
|
|
static void append_filter_err(struct trace_array *tr,
|
|
|
|
struct filter_parse_error *pe,
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
struct event_filter *filter)
|
|
|
|
{
|
2018-02-23 04:14:04 +00:00
|
|
|
struct trace_seq *s;
|
2018-03-09 18:19:28 +00:00
|
|
|
int pos = pe->lasterr_pos;
|
2018-02-23 04:14:04 +00:00
|
|
|
char *buf;
|
|
|
|
int len;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-02-23 04:14:04 +00:00
|
|
|
if (WARN_ON(!filter->filter_string))
|
2009-03-24 07:14:31 +00:00
|
|
|
return;
|
2009-03-22 08:31:04 +00:00
|
|
|
|
2018-02-23 04:14:04 +00:00
|
|
|
s = kmalloc(sizeof(*s), GFP_KERNEL);
|
|
|
|
if (!s)
|
|
|
|
return;
|
|
|
|
trace_seq_init(s);
|
|
|
|
|
|
|
|
len = strlen(filter->filter_string);
|
|
|
|
if (pos > len)
|
2018-03-09 18:19:28 +00:00
|
|
|
pos = len;
|
|
|
|
|
|
|
|
/* indexing is off by one */
|
|
|
|
if (pos)
|
|
|
|
pos++;
|
2018-02-23 04:14:04 +00:00
|
|
|
|
|
|
|
trace_seq_puts(s, filter->filter_string);
|
2018-03-09 18:19:28 +00:00
|
|
|
if (pe->lasterr > 0) {
|
|
|
|
trace_seq_printf(s, "\n%*s", pos, "^");
|
|
|
|
trace_seq_printf(s, "\nparse_error: %s\n", err_text[pe->lasterr]);
|
2019-04-02 02:52:21 +00:00
|
|
|
tracing_log_err(tr, "event filter parse error",
|
2019-03-31 23:48:18 +00:00
|
|
|
filter->filter_string, err_text,
|
|
|
|
pe->lasterr, pe->lasterr_pos);
|
2018-03-09 18:19:28 +00:00
|
|
|
} else {
|
|
|
|
trace_seq_printf(s, "\nError: (%d)\n", pe->lasterr);
|
2019-04-02 02:52:21 +00:00
|
|
|
tracing_log_err(tr, "event filter parse error",
|
2019-03-31 23:48:18 +00:00
|
|
|
filter->filter_string, err_text,
|
|
|
|
FILT_ERR_ERRNO, 0);
|
2018-03-09 18:19:28 +00:00
|
|
|
}
|
2018-02-23 04:14:04 +00:00
|
|
|
trace_seq_putc(s, 0);
|
|
|
|
buf = kmemdup_nul(s->buffer, s->seq.len, GFP_KERNEL);
|
|
|
|
if (buf) {
|
|
|
|
kfree(filter->filter_string);
|
|
|
|
filter->filter_string = buf;
|
|
|
|
}
|
|
|
|
kfree(s);
|
2009-03-22 08:31:04 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 14:09:53 +00:00
|
|
|
static inline struct event_filter *event_filter(struct trace_event_file *file)
|
2013-10-24 13:34:17 +00:00
|
|
|
{
|
2016-05-03 01:30:04 +00:00
|
|
|
return file->filter;
|
2013-10-24 13:34:17 +00:00
|
|
|
}
|
|
|
|
|
2013-07-26 17:25:40 +00:00
|
|
|
/* caller must hold event_mutex */
|
2015-05-05 14:09:53 +00:00
|
|
|
void print_event_filter(struct trace_event_file *file, struct trace_seq *s)
|
2009-04-17 05:27:08 +00:00
|
|
|
{
|
2013-10-24 13:34:17 +00:00
|
|
|
struct event_filter *filter = event_filter(file);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2009-08-31 08:49:41 +00:00
|
|
|
if (filter && filter->filter_string)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
trace_seq_printf(s, "%s\n", filter->filter_string);
|
|
|
|
else
|
2013-07-15 08:32:44 +00:00
|
|
|
trace_seq_puts(s, "none\n");
|
2009-04-17 05:27:08 +00:00
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
void print_subsystem_event_filter(struct event_subsystem *system,
|
2009-04-17 05:27:08 +00:00
|
|
|
struct trace_seq *s)
|
|
|
|
{
|
2011-02-04 04:25:46 +00:00
|
|
|
struct event_filter *filter;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2009-06-16 08:39:41 +00:00
|
|
|
mutex_lock(&event_mutex);
|
2011-02-04 04:25:46 +00:00
|
|
|
filter = system->filter;
|
2009-08-31 08:49:41 +00:00
|
|
|
if (filter && filter->filter_string)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
trace_seq_printf(s, "%s\n", filter->filter_string);
|
|
|
|
else
|
2013-07-15 08:32:44 +00:00
|
|
|
trace_seq_puts(s, DEFAULT_SYS_FILTER_MESSAGE "\n");
|
2009-06-16 08:39:41 +00:00
|
|
|
mutex_unlock(&event_mutex);
|
2009-04-17 05:27:08 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
static void free_prog(struct event_filter *filter)
|
2011-01-28 03:42:43 +00:00
|
|
|
{
|
2018-03-09 18:19:28 +00:00
|
|
|
struct prog_entry *prog;
|
2013-05-14 19:40:48 +00:00
|
|
|
int i;
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
prog = rcu_access_pointer(filter->prog);
|
|
|
|
if (!prog)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; prog[i].pred; i++)
|
|
|
|
kfree(prog[i].pred);
|
|
|
|
kfree(prog);
|
2011-01-28 03:42:43 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 14:09:53 +00:00
|
|
|
static void filter_disable(struct trace_event_file *file)
|
2013-10-24 13:34:17 +00:00
|
|
|
{
|
2016-05-03 21:15:43 +00:00
|
|
|
unsigned long old_flags = file->flags;
|
|
|
|
|
2016-05-03 01:30:04 +00:00
|
|
|
file->flags &= ~EVENT_FILE_FL_FILTERED;
|
2016-05-03 21:15:43 +00:00
|
|
|
|
|
|
|
if (old_flags != file->flags)
|
|
|
|
trace_buffered_event_disable();
|
2013-10-24 13:34:17 +00:00
|
|
|
}
|
|
|
|
|
2011-01-28 03:42:43 +00:00
|
|
|
static void __free_filter(struct event_filter *filter)
|
2009-05-06 02:33:04 +00:00
|
|
|
{
|
2009-08-31 08:49:41 +00:00
|
|
|
if (!filter)
|
|
|
|
return;
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
free_prog(filter);
|
2009-06-16 08:39:12 +00:00
|
|
|
kfree(filter->filter_string);
|
2009-05-06 02:33:04 +00:00
|
|
|
kfree(filter);
|
2009-10-15 03:21:42 +00:00
|
|
|
}
|
|
|
|
|
tracing: Add and use generic set_trigger_filter() implementation
Add a generic event_command.set_trigger_filter() op implementation and
have the current set of trigger commands use it - this essentially
gives them all support for filters.
Syntactically, filters are supported by adding 'if <filter>' just
after the command, in which case only events matching the filter will
invoke the trigger. For example, to add a filter to an
enable/disable_event command:
echo 'enable_event:system:event if common_pid == 999' > \
.../othersys/otherevent/trigger
The above command will only enable the system:event event if the
common_pid field in the othersys:otherevent event is 999.
As another example, to add a filter to a stacktrace command:
echo 'stacktrace if common_pid == 999' > \
.../somesys/someevent/trigger
The above command will only trigger a stacktrace if the common_pid
field in the event is 999.
The filter syntax is the same as that described in the 'Event
filtering' section of Documentation/trace/events.txt.
Because triggers can now use filters, the trigger-invoking logic needs
to be moved in those cases - e.g. for ftrace_raw_event_calls, if a
trigger has a filter associated with it, the trigger invocation now
needs to happen after the { assign; } part of the call, in order for
the trigger condition to be tested.
There's still a SOFT_DISABLED-only check at the top of e.g. the
ftrace_raw_events function, so when an event is soft disabled but not
because of the presence of a trigger, the original SOFT_DISABLED
behavior remains unchanged.
There's also a bit of trickiness in that some triggers need to avoid
being invoked while an event is currently in the process of being
logged, since the trigger may itself log data into the trace buffer.
Thus we make sure the current event is committed before invoking those
triggers. To do that, we split the trigger invocation in two - the
first part (event_triggers_call()) checks the filter using the current
trace record; if a command has the post_trigger flag set, it sets a
bit for itself in the return value, otherwise it directly invoks the
trigger. Once all commands have been either invoked or set their
return flag, event_triggers_call() returns. The current record is
then either committed or discarded; if any commands have deferred
their triggers, those commands are finally invoked following the close
of the current event by event_triggers_post_call().
To simplify the above and make it more efficient, the TRIGGER_COND bit
is introduced, which is set only if a soft-disabled trigger needs to
use the log record for filter testing or needs to wait until the
current log record is closed.
The syscall event invocation code is also changed in analogous ways.
Because event triggers need to be able to create and free filters,
this also adds a couple external wrappers for the existing
create_filter and free_filter functions, which are too generic to be
made extern functions themselves.
Link: http://lkml.kernel.org/r/7164930759d8719ef460357f143d995406e4eead.1382622043.git.tom.zanussi@linux.intel.com
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-10-24 13:59:29 +00:00
|
|
|
void free_event_filter(struct event_filter *filter)
|
|
|
|
{
|
|
|
|
__free_filter(filter);
|
|
|
|
}
|
|
|
|
|
2015-05-05 14:09:53 +00:00
|
|
|
static inline void __remove_filter(struct trace_event_file *file)
|
2009-08-31 08:49:41 +00:00
|
|
|
{
|
2013-10-24 13:34:17 +00:00
|
|
|
filter_disable(file);
|
2016-05-03 01:30:04 +00:00
|
|
|
remove_filter_string(file->filter);
|
2013-10-24 13:34:17 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 18:59:40 +00:00
|
|
|
static void filter_free_subsystem_preds(struct trace_subsystem_dir *dir,
|
2013-10-24 13:34:17 +00:00
|
|
|
struct trace_array *tr)
|
|
|
|
{
|
2015-05-05 14:09:53 +00:00
|
|
|
struct trace_event_file *file;
|
2009-08-31 08:49:41 +00:00
|
|
|
|
2013-10-24 13:34:17 +00:00
|
|
|
list_for_each_entry(file, &tr->events, list) {
|
2014-07-15 18:48:29 +00:00
|
|
|
if (file->system != dir)
|
2009-08-31 08:49:41 +00:00
|
|
|
continue;
|
2013-10-24 13:34:17 +00:00
|
|
|
__remove_filter(file);
|
2009-08-31 08:49:41 +00:00
|
|
|
}
|
|
|
|
}
|
2009-03-22 08:31:04 +00:00
|
|
|
|
2015-05-05 14:09:53 +00:00
|
|
|
static inline void __free_subsystem_filter(struct trace_event_file *file)
|
2009-03-22 08:31:17 +00:00
|
|
|
{
|
2016-05-03 01:30:04 +00:00
|
|
|
__free_filter(file->filter);
|
|
|
|
file->filter = NULL;
|
2013-10-24 13:34:17 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 18:59:40 +00:00
|
|
|
static void filter_free_subsystem_filters(struct trace_subsystem_dir *dir,
|
2013-10-24 13:34:17 +00:00
|
|
|
struct trace_array *tr)
|
|
|
|
{
|
2015-05-05 14:09:53 +00:00
|
|
|
struct trace_event_file *file;
|
2009-03-22 08:31:17 +00:00
|
|
|
|
2013-10-24 13:34:17 +00:00
|
|
|
list_for_each_entry(file, &tr->events, list) {
|
2018-03-09 18:19:28 +00:00
|
|
|
if (file->system != dir)
|
2009-03-22 08:31:04 +00:00
|
|
|
continue;
|
2018-03-09 18:19:28 +00:00
|
|
|
__free_subsystem_filter(file);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
}
|
2018-03-09 18:19:28 +00:00
|
|
|
}
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
int filter_assign_type(const char *type)
|
|
|
|
{
|
|
|
|
if (strstr(type, "__data_loc") && strstr(type, "char"))
|
|
|
|
return FILTER_DYN_STRING;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
if (strchr(type, '[') && strstr(type, "char"))
|
|
|
|
return FILTER_STATIC_STRING;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2019-05-25 16:58:00 +00:00
|
|
|
if (strcmp(type, "char *") == 0 || strcmp(type, "const char *") == 0)
|
|
|
|
return FILTER_PTR_STRING;
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
return FILTER_OTHER;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
static filter_pred_fn_t select_comparison_fn(enum filter_op_ids op,
|
|
|
|
int field_size, int field_is_signed)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
{
|
2018-03-09 18:19:28 +00:00
|
|
|
filter_pred_fn_t fn = NULL;
|
|
|
|
int pred_func_index = -1;
|
2011-08-11 14:25:45 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
switch (op) {
|
|
|
|
case OP_EQ:
|
|
|
|
case OP_NE:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (WARN_ON_ONCE(op < PRED_FUNC_START))
|
|
|
|
return NULL;
|
|
|
|
pred_func_index = op - PRED_FUNC_START;
|
|
|
|
if (WARN_ON_ONCE(pred_func_index > PRED_FUNC_MAX))
|
|
|
|
return NULL;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
switch (field_size) {
|
|
|
|
case 8:
|
|
|
|
if (pred_func_index < 0)
|
|
|
|
fn = filter_pred_64;
|
|
|
|
else if (field_is_signed)
|
|
|
|
fn = pred_funcs_s64[pred_func_index];
|
|
|
|
else
|
|
|
|
fn = pred_funcs_u64[pred_func_index];
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
if (pred_func_index < 0)
|
|
|
|
fn = filter_pred_32;
|
|
|
|
else if (field_is_signed)
|
|
|
|
fn = pred_funcs_s32[pred_func_index];
|
|
|
|
else
|
|
|
|
fn = pred_funcs_u32[pred_func_index];
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
if (pred_func_index < 0)
|
|
|
|
fn = filter_pred_16;
|
|
|
|
else if (field_is_signed)
|
|
|
|
fn = pred_funcs_s16[pred_func_index];
|
|
|
|
else
|
|
|
|
fn = pred_funcs_u16[pred_func_index];
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (pred_func_index < 0)
|
|
|
|
fn = filter_pred_8;
|
|
|
|
else if (field_is_signed)
|
|
|
|
fn = pred_funcs_s8[pred_func_index];
|
|
|
|
else
|
|
|
|
fn = pred_funcs_u8[pred_func_index];
|
|
|
|
break;
|
2011-08-11 14:25:47 +00:00
|
|
|
}
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
return fn;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* Called when a predicate is encountered by predicate_parse() */
|
|
|
|
static int parse_pred(const char *str, void *data,
|
|
|
|
int pos, struct filter_parse_error *pe,
|
|
|
|
struct filter_pred **pred_ptr)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
{
|
2018-03-09 18:19:28 +00:00
|
|
|
struct trace_event_call *call = data;
|
|
|
|
struct ftrace_event_field *field;
|
|
|
|
struct filter_pred *pred = NULL;
|
|
|
|
char num_buf[24]; /* Big enough to hold an address */
|
|
|
|
char *field_name;
|
|
|
|
char q;
|
|
|
|
u64 val;
|
|
|
|
int len;
|
|
|
|
int ret;
|
|
|
|
int op;
|
|
|
|
int s;
|
|
|
|
int i = 0;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* First find the field to associate to */
|
|
|
|
while (isspace(str[i]))
|
|
|
|
i++;
|
|
|
|
s = i;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
while (isalnum(str[i]) || str[i] == '_')
|
|
|
|
i++;
|
|
|
|
|
|
|
|
len = i - s;
|
|
|
|
|
|
|
|
if (!len)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
field_name = kmemdup_nul(str + s, len, GFP_KERNEL);
|
|
|
|
if (!field_name)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
/* Make sure that the field exists */
|
2009-03-22 08:31:04 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
field = trace_find_event_field(call, field_name);
|
|
|
|
kfree(field_name);
|
|
|
|
if (!field) {
|
|
|
|
parse_error(pe, FILT_ERR_FIELD_NOT_FOUND, pos + i);
|
2009-04-11 07:52:35 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
while (isspace(str[i]))
|
|
|
|
i++;
|
2009-04-21 09:12:11 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* Make sure this op is supported */
|
|
|
|
for (op = 0; ops[op]; op++) {
|
|
|
|
/* This is why '<=' must come before '<' in ops[] */
|
|
|
|
if (strncmp(str + i, ops[op], strlen(ops[op])) == 0)
|
|
|
|
break;
|
|
|
|
}
|
2011-01-28 03:42:43 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
if (!ops[op]) {
|
|
|
|
parse_error(pe, FILT_ERR_INVALID_OP, pos + i);
|
|
|
|
goto err_free;
|
2011-01-28 03:42:43 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
i += strlen(ops[op]);
|
2011-01-28 03:42:43 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
while (isspace(str[i]))
|
|
|
|
i++;
|
2011-08-11 14:25:49 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
s = i;
|
2011-08-11 14:25:49 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
pred = kzalloc(sizeof(*pred), GFP_KERNEL);
|
|
|
|
if (!pred)
|
|
|
|
return -ENOMEM;
|
2011-08-11 14:25:49 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
pred->field = field;
|
|
|
|
pred->offset = field->offset;
|
|
|
|
pred->op = op;
|
|
|
|
|
|
|
|
if (ftrace_event_is_function(call)) {
|
2011-08-11 14:25:49 +00:00
|
|
|
/*
|
2018-03-09 18:19:28 +00:00
|
|
|
* Perf does things different with function events.
|
|
|
|
* It only allows an "ip" field, and expects a string.
|
|
|
|
* But the string does not need to be surrounded by quotes.
|
|
|
|
* If it is a string, the assigned function as a nop,
|
|
|
|
* (perf doesn't use it) and grab everything.
|
2011-08-11 14:25:49 +00:00
|
|
|
*/
|
2018-03-09 18:19:28 +00:00
|
|
|
if (strcmp(field->name, "ip") != 0) {
|
2018-11-09 13:23:12 +00:00
|
|
|
parse_error(pe, FILT_ERR_IP_FIELD_ONLY, pos + i);
|
|
|
|
goto err_free;
|
|
|
|
}
|
|
|
|
pred->fn = filter_pred_none;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Quotes are not required, but if they exist then we need
|
|
|
|
* to read them till we hit a matching one.
|
|
|
|
*/
|
|
|
|
if (str[i] == '\'' || str[i] == '"')
|
|
|
|
q = str[i];
|
|
|
|
else
|
|
|
|
q = 0;
|
|
|
|
|
|
|
|
for (i++; str[i]; i++) {
|
|
|
|
if (q && str[i] == q)
|
|
|
|
break;
|
|
|
|
if (!q && (str[i] == ')' || str[i] == '&' ||
|
|
|
|
str[i] == '|'))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Skip quotes */
|
|
|
|
if (q)
|
|
|
|
s++;
|
2018-03-09 18:19:28 +00:00
|
|
|
len = i - s;
|
|
|
|
if (len >= MAX_FILTER_STR_VAL) {
|
|
|
|
parse_error(pe, FILT_ERR_OPERAND_TOO_LONG, pos + i);
|
|
|
|
goto err_free;
|
|
|
|
}
|
2011-01-28 04:14:25 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
pred->regex.len = len;
|
|
|
|
strncpy(pred->regex.pattern, str + s, len);
|
|
|
|
pred->regex.pattern[len] = 0;
|
|
|
|
|
|
|
|
/* This is either a string, or an integer */
|
|
|
|
} else if (str[i] == '\'' || str[i] == '"') {
|
|
|
|
char q = str[i];
|
|
|
|
|
|
|
|
/* Make sure the op is OK for strings */
|
|
|
|
switch (op) {
|
|
|
|
case OP_NE:
|
|
|
|
pred->not = 1;
|
2020-08-23 22:36:59 +00:00
|
|
|
fallthrough;
|
2018-03-09 18:19:28 +00:00
|
|
|
case OP_GLOB:
|
|
|
|
case OP_EQ:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
parse_error(pe, FILT_ERR_ILLEGAL_FIELD_OP, pos + i);
|
|
|
|
goto err_free;
|
|
|
|
}
|
2011-01-28 04:14:25 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* Make sure the field is OK for strings */
|
|
|
|
if (!is_string_field(field)) {
|
|
|
|
parse_error(pe, FILT_ERR_EXPECT_DIGIT, pos + i);
|
|
|
|
goto err_free;
|
|
|
|
}
|
2011-01-28 04:16:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
for (i++; str[i]; i++) {
|
|
|
|
if (str[i] == q)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (!str[i]) {
|
|
|
|
parse_error(pe, FILT_ERR_MISSING_QUOTE, pos + i);
|
|
|
|
goto err_free;
|
|
|
|
}
|
2011-01-28 04:16:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* Skip quotes */
|
|
|
|
s++;
|
|
|
|
len = i - s;
|
|
|
|
if (len >= MAX_FILTER_STR_VAL) {
|
|
|
|
parse_error(pe, FILT_ERR_OPERAND_TOO_LONG, pos + i);
|
|
|
|
goto err_free;
|
|
|
|
}
|
2011-08-11 14:25:50 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
pred->regex.len = len;
|
|
|
|
strncpy(pred->regex.pattern, str + s, len);
|
|
|
|
pred->regex.pattern[len] = 0;
|
2011-01-28 04:16:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
filter_build_regex(pred);
|
2011-01-28 04:16:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
if (field->filter_type == FILTER_COMM) {
|
|
|
|
pred->fn = filter_pred_comm;
|
2011-08-11 14:25:52 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
} else if (field->filter_type == FILTER_STATIC_STRING) {
|
|
|
|
pred->fn = filter_pred_string;
|
|
|
|
pred->regex.field_len = field->size;
|
2011-08-11 14:25:52 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
} else if (field->filter_type == FILTER_DYN_STRING)
|
|
|
|
pred->fn = filter_pred_strloc;
|
|
|
|
else
|
|
|
|
pred->fn = filter_pred_pchar;
|
|
|
|
/* go past the last quote */
|
|
|
|
i++;
|
2011-08-11 14:25:52 +00:00
|
|
|
|
2018-08-23 10:25:34 +00:00
|
|
|
} else if (isdigit(str[i]) || str[i] == '-') {
|
2011-08-11 14:25:52 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* Make sure the field is not a string */
|
|
|
|
if (is_string_field(field)) {
|
|
|
|
parse_error(pe, FILT_ERR_EXPECT_STRING, pos + i);
|
|
|
|
goto err_free;
|
|
|
|
}
|
2011-08-11 14:25:52 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
if (op == OP_GLOB) {
|
|
|
|
parse_error(pe, FILT_ERR_ILLEGAL_FIELD_OP, pos + i);
|
|
|
|
goto err_free;
|
|
|
|
}
|
2011-01-28 04:16:51 +00:00
|
|
|
|
2018-08-23 10:25:34 +00:00
|
|
|
if (str[i] == '-')
|
|
|
|
i++;
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* We allow 0xDEADBEEF */
|
|
|
|
while (isalnum(str[i]))
|
|
|
|
i++;
|
2011-01-28 04:16:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
len = i - s;
|
|
|
|
/* 0xfeedfacedeadbeef is 18 chars max */
|
|
|
|
if (len >= sizeof(num_buf)) {
|
|
|
|
parse_error(pe, FILT_ERR_OPERAND_TOO_LONG, pos + i);
|
|
|
|
goto err_free;
|
|
|
|
}
|
2011-01-28 04:16:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
strncpy(num_buf, str + s, len);
|
|
|
|
num_buf[len] = 0;
|
2011-01-28 04:16:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* Make sure it is a value */
|
|
|
|
if (field->is_signed)
|
|
|
|
ret = kstrtoll(num_buf, 0, &val);
|
|
|
|
else
|
|
|
|
ret = kstrtoull(num_buf, 0, &val);
|
|
|
|
if (ret) {
|
|
|
|
parse_error(pe, FILT_ERR_ILLEGAL_INTVAL, pos + s);
|
|
|
|
goto err_free;
|
|
|
|
}
|
2011-01-28 04:16:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
pred->val = val;
|
2011-01-28 04:16:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
if (field->filter_type == FILTER_CPU)
|
|
|
|
pred->fn = filter_pred_cpu;
|
|
|
|
else {
|
|
|
|
pred->fn = select_comparison_fn(pred->op, field->size,
|
|
|
|
field->is_signed);
|
|
|
|
if (pred->op == OP_NE)
|
|
|
|
pred->not = 1;
|
|
|
|
}
|
2011-08-11 14:25:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
} else {
|
|
|
|
parse_error(pe, FILT_ERR_INVALID_VALUE, pos + i);
|
|
|
|
goto err_free;
|
|
|
|
}
|
2011-08-11 14:25:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
*pred_ptr = pred;
|
|
|
|
return i;
|
2011-08-11 14:25:51 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
err_free:
|
|
|
|
kfree(pred);
|
|
|
|
return -EINVAL;
|
2011-08-11 14:25:51 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
enum {
|
|
|
|
TOO_MANY_CLOSE = -1,
|
|
|
|
TOO_MANY_OPEN = -2,
|
|
|
|
MISSING_QUOTE = -3,
|
|
|
|
};
|
|
|
|
|
2011-01-28 04:16:51 +00:00
|
|
|
/*
|
2018-03-09 18:19:28 +00:00
|
|
|
* Read the filter string once to calculate the number of predicates
|
|
|
|
* as well as how deep the parentheses go.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* 0 - everything is fine (err is undefined)
|
|
|
|
* -1 - too many ')'
|
|
|
|
* -2 - too many '('
|
|
|
|
* -3 - No matching quote
|
2011-01-28 04:16:51 +00:00
|
|
|
*/
|
2018-03-09 18:19:28 +00:00
|
|
|
static int calc_stack(const char *str, int *parens, int *preds, int *err)
|
|
|
|
{
|
|
|
|
bool is_pred = false;
|
|
|
|
int nr_preds = 0;
|
|
|
|
int open = 1; /* Count the expression as "(E)" */
|
|
|
|
int last_quote = 0;
|
|
|
|
int max_open = 1;
|
|
|
|
int quote = 0;
|
|
|
|
int i;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
*err = 0;
|
2011-01-28 03:42:43 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
for (i = 0; str[i]; i++) {
|
|
|
|
if (isspace(str[i]))
|
|
|
|
continue;
|
|
|
|
if (quote) {
|
|
|
|
if (str[i] == quote)
|
|
|
|
quote = 0;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
switch (str[i]) {
|
|
|
|
case '\'':
|
|
|
|
case '"':
|
|
|
|
quote = str[i];
|
|
|
|
last_quote = i;
|
|
|
|
break;
|
|
|
|
case '|':
|
|
|
|
case '&':
|
|
|
|
if (str[i+1] != str[i])
|
|
|
|
break;
|
|
|
|
is_pred = false;
|
|
|
|
continue;
|
|
|
|
case '(':
|
|
|
|
is_pred = false;
|
|
|
|
open++;
|
|
|
|
if (open > max_open)
|
|
|
|
max_open = open;
|
|
|
|
continue;
|
|
|
|
case ')':
|
|
|
|
is_pred = false;
|
|
|
|
if (open == 1) {
|
|
|
|
*err = i;
|
|
|
|
return TOO_MANY_CLOSE;
|
2014-12-02 16:55:36 +00:00
|
|
|
}
|
2018-03-09 18:19:28 +00:00
|
|
|
open--;
|
2014-12-02 16:55:36 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-03-09 18:19:28 +00:00
|
|
|
if (!is_pred) {
|
|
|
|
nr_preds++;
|
|
|
|
is_pred = true;
|
2009-07-20 02:20:53 +00:00
|
|
|
}
|
2018-03-09 18:19:28 +00:00
|
|
|
}
|
2009-07-20 02:20:53 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
if (quote) {
|
|
|
|
*err = last_quote;
|
|
|
|
return MISSING_QUOTE;
|
|
|
|
}
|
2011-08-11 14:25:47 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
if (open != 1) {
|
|
|
|
int level = open;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* find the bad open */
|
|
|
|
for (i--; i; i--) {
|
|
|
|
if (quote) {
|
|
|
|
if (str[i] == quote)
|
|
|
|
quote = 0;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
switch (str[i]) {
|
|
|
|
case '(':
|
|
|
|
if (level == open) {
|
|
|
|
*err = i;
|
|
|
|
return TOO_MANY_OPEN;
|
|
|
|
}
|
|
|
|
level--;
|
|
|
|
break;
|
|
|
|
case ')':
|
|
|
|
level++;
|
|
|
|
break;
|
|
|
|
case '\'':
|
|
|
|
case '"':
|
|
|
|
quote = str[i];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* First character is the '(' with missing ')' */
|
|
|
|
*err = 0;
|
|
|
|
return TOO_MANY_OPEN;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
}
|
2009-03-22 08:31:04 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/* Set the size of the required stacks */
|
|
|
|
*parens = max_open;
|
|
|
|
*preds = nr_preds;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int process_preds(struct trace_event_call *call,
|
|
|
|
const char *filter_string,
|
|
|
|
struct event_filter *filter,
|
|
|
|
struct filter_parse_error *pe)
|
|
|
|
{
|
|
|
|
struct prog_entry *prog;
|
|
|
|
int nr_parens;
|
|
|
|
int nr_preds;
|
|
|
|
int index;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = calc_stack(filter_string, &nr_parens, &nr_preds, &index);
|
|
|
|
if (ret < 0) {
|
|
|
|
switch (ret) {
|
|
|
|
case MISSING_QUOTE:
|
|
|
|
parse_error(pe, FILT_ERR_MISSING_QUOTE, index);
|
|
|
|
break;
|
|
|
|
case TOO_MANY_OPEN:
|
|
|
|
parse_error(pe, FILT_ERR_TOO_MANY_OPEN, index);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
parse_error(pe, FILT_ERR_TOO_MANY_CLOSE, index);
|
2011-01-28 03:54:33 +00:00
|
|
|
}
|
2018-03-09 18:19:28 +00:00
|
|
|
return ret;
|
2011-01-28 03:54:33 +00:00
|
|
|
}
|
|
|
|
|
2018-04-20 15:07:58 +00:00
|
|
|
if (!nr_preds)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
prog = predicate_parse(filter_string, nr_parens, nr_preds,
|
2018-03-09 18:19:28 +00:00
|
|
|
parse_pred, call, pe);
|
2018-04-20 15:07:58 +00:00
|
|
|
if (IS_ERR(prog))
|
|
|
|
return PTR_ERR(prog);
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
rcu_assign_pointer(filter->prog, prog);
|
|
|
|
return 0;
|
2009-03-22 08:31:04 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 14:09:53 +00:00
|
|
|
static inline void event_set_filtered_flag(struct trace_event_file *file)
|
2013-10-24 13:34:17 +00:00
|
|
|
{
|
2016-05-03 21:15:43 +00:00
|
|
|
unsigned long old_flags = file->flags;
|
|
|
|
|
2016-05-03 01:30:04 +00:00
|
|
|
file->flags |= EVENT_FILE_FL_FILTERED;
|
2016-05-03 21:15:43 +00:00
|
|
|
|
|
|
|
if (old_flags != file->flags)
|
|
|
|
trace_buffered_event_enable();
|
2013-10-24 13:34:17 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 14:09:53 +00:00
|
|
|
static inline void event_set_filter(struct trace_event_file *file,
|
2013-10-24 13:34:17 +00:00
|
|
|
struct event_filter *filter)
|
|
|
|
{
|
2016-05-03 01:30:04 +00:00
|
|
|
rcu_assign_pointer(file->filter, filter);
|
2013-10-24 13:34:17 +00:00
|
|
|
}
|
|
|
|
|
2015-05-05 14:09:53 +00:00
|
|
|
static inline void event_clear_filter(struct trace_event_file *file)
|
2013-10-24 13:34:17 +00:00
|
|
|
{
|
2016-05-03 01:30:04 +00:00
|
|
|
RCU_INIT_POINTER(file->filter, NULL);
|
2013-10-24 13:34:17 +00:00
|
|
|
}
|
|
|
|
|
2011-02-04 04:25:46 +00:00
|
|
|
struct filter_list {
|
|
|
|
struct list_head list;
|
|
|
|
struct event_filter *filter;
|
|
|
|
};
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
static int process_system_preds(struct trace_subsystem_dir *dir,
|
2013-10-24 13:34:17 +00:00
|
|
|
struct trace_array *tr,
|
2018-03-09 18:19:28 +00:00
|
|
|
struct filter_parse_error *pe,
|
2009-10-15 03:20:34 +00:00
|
|
|
char *filter_string)
|
|
|
|
{
|
2015-05-05 14:09:53 +00:00
|
|
|
struct trace_event_file *file;
|
2011-02-04 04:25:46 +00:00
|
|
|
struct filter_list *filter_item;
|
2018-02-23 04:26:11 +00:00
|
|
|
struct event_filter *filter = NULL;
|
2011-02-04 04:25:46 +00:00
|
|
|
struct filter_list *tmp;
|
|
|
|
LIST_HEAD(filter_list);
|
2009-10-15 03:20:34 +00:00
|
|
|
bool fail = true;
|
2009-10-15 10:24:04 +00:00
|
|
|
int err;
|
2009-10-15 03:20:34 +00:00
|
|
|
|
2013-10-24 13:34:17 +00:00
|
|
|
list_for_each_entry(file, &tr->events, list) {
|
2011-01-28 03:46:46 +00:00
|
|
|
|
2014-07-15 18:48:29 +00:00
|
|
|
if (file->system != dir)
|
2011-01-28 03:46:46 +00:00
|
|
|
continue;
|
|
|
|
|
2018-02-23 04:26:11 +00:00
|
|
|
filter = kzalloc(sizeof(*filter), GFP_KERNEL);
|
|
|
|
if (!filter)
|
2011-02-04 04:25:46 +00:00
|
|
|
goto fail_mem;
|
2011-01-28 03:46:46 +00:00
|
|
|
|
2018-02-23 14:45:27 +00:00
|
|
|
filter->filter_string = kstrdup(filter_string, GFP_KERNEL);
|
|
|
|
if (!filter->filter_string)
|
2011-02-04 04:25:46 +00:00
|
|
|
goto fail_mem;
|
2009-10-15 03:20:34 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
err = process_preds(file->event_call, filter_string, filter, pe);
|
2011-02-04 04:25:46 +00:00
|
|
|
if (err) {
|
2013-10-24 13:34:17 +00:00
|
|
|
filter_disable(file);
|
2018-03-09 18:19:28 +00:00
|
|
|
parse_error(pe, FILT_ERR_BAD_SUBSYS_FILTER, 0);
|
2019-04-01 20:07:48 +00:00
|
|
|
append_filter_err(tr, pe, filter);
|
2011-02-04 04:25:46 +00:00
|
|
|
} else
|
2013-10-24 13:34:17 +00:00
|
|
|
event_set_filtered_flag(file);
|
2018-02-23 04:26:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
filter_item = kzalloc(sizeof(*filter_item), GFP_KERNEL);
|
|
|
|
if (!filter_item)
|
|
|
|
goto fail_mem;
|
|
|
|
|
|
|
|
list_add_tail(&filter_item->list, &filter_list);
|
2011-02-04 04:25:46 +00:00
|
|
|
/*
|
|
|
|
* Regardless of if this returned an error, we still
|
|
|
|
* replace the filter for the call.
|
|
|
|
*/
|
2018-02-23 04:26:11 +00:00
|
|
|
filter_item->filter = event_filter(file);
|
|
|
|
event_set_filter(file, filter);
|
|
|
|
filter = NULL;
|
2011-02-04 04:25:46 +00:00
|
|
|
|
2009-10-15 03:20:34 +00:00
|
|
|
fail = false;
|
|
|
|
}
|
|
|
|
|
2011-01-28 03:46:46 +00:00
|
|
|
if (fail)
|
|
|
|
goto fail;
|
|
|
|
|
2011-02-04 04:25:46 +00:00
|
|
|
/*
|
|
|
|
* The calls can still be using the old filters.
|
2018-11-07 02:44:52 +00:00
|
|
|
* Do a synchronize_rcu() and to ensure all calls are
|
2011-02-04 04:25:46 +00:00
|
|
|
* done with them before we free them.
|
|
|
|
*/
|
2018-08-09 19:31:48 +00:00
|
|
|
tracepoint_synchronize_unregister();
|
2011-02-04 04:25:46 +00:00
|
|
|
list_for_each_entry_safe(filter_item, tmp, &filter_list, list) {
|
|
|
|
__free_filter(filter_item->filter);
|
|
|
|
list_del(&filter_item->list);
|
|
|
|
kfree(filter_item);
|
|
|
|
}
|
2009-10-15 03:20:34 +00:00
|
|
|
return 0;
|
2011-01-28 03:46:46 +00:00
|
|
|
fail:
|
2011-02-04 04:25:46 +00:00
|
|
|
/* No call succeeded */
|
|
|
|
list_for_each_entry_safe(filter_item, tmp, &filter_list, list) {
|
|
|
|
list_del(&filter_item->list);
|
|
|
|
kfree(filter_item);
|
|
|
|
}
|
2018-03-09 18:19:28 +00:00
|
|
|
parse_error(pe, FILT_ERR_BAD_SUBSYS_FILTER, 0);
|
2011-01-28 03:46:46 +00:00
|
|
|
return -EINVAL;
|
2011-02-04 04:25:46 +00:00
|
|
|
fail_mem:
|
tracing: Avoid memory leak in process_system_preds()
When failing in the allocation of filter_item, process_system_preds()
goes to fail_mem, where the allocated filter is freed.
However, this leads to memory leak of filter->filter_string and
filter->prog, which is allocated before and in process_preds().
This bug has been detected by kmemleak as well.
Fix this by changing kfree to __free_fiter.
unreferenced object 0xffff8880658007c0 (size 32):
comm "bash", pid 579, jiffies 4295096372 (age 17.752s)
hex dump (first 32 bytes):
63 6f 6d 6d 6f 6e 5f 70 69 64 20 20 3e 20 31 30 common_pid > 10
00 00 00 00 00 00 00 00 65 73 00 00 00 00 00 00 ........es......
backtrace:
[<0000000067441602>] kstrdup+0x2d/0x60
[<00000000141cf7b7>] apply_subsystem_event_filter+0x378/0x932
[<000000009ca32334>] subsystem_filter_write+0x5a/0x90
[<0000000072da2bee>] vfs_write+0xe1/0x240
[<000000004f14f473>] ksys_write+0xb4/0x150
[<00000000a968b4a0>] do_syscall_64+0x6d/0x1e0
[<000000001a189f40>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
unreferenced object 0xffff888060c22d00 (size 64):
comm "bash", pid 579, jiffies 4295096372 (age 17.752s)
hex dump (first 32 bytes):
01 00 00 00 00 00 00 00 00 e8 d7 41 80 88 ff ff ...........A....
01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<00000000b8c1b109>] process_preds+0x243/0x1820
[<000000003972c7f0>] apply_subsystem_event_filter+0x3be/0x932
[<000000009ca32334>] subsystem_filter_write+0x5a/0x90
[<0000000072da2bee>] vfs_write+0xe1/0x240
[<000000004f14f473>] ksys_write+0xb4/0x150
[<00000000a968b4a0>] do_syscall_64+0x6d/0x1e0
[<000000001a189f40>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
unreferenced object 0xffff888041d7e800 (size 512):
comm "bash", pid 579, jiffies 4295096372 (age 17.752s)
hex dump (first 32 bytes):
70 bc 85 97 ff ff ff ff 0a 00 00 00 00 00 00 00 p...............
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
backtrace:
[<000000001e04af34>] process_preds+0x71a/0x1820
[<000000003972c7f0>] apply_subsystem_event_filter+0x3be/0x932
[<000000009ca32334>] subsystem_filter_write+0x5a/0x90
[<0000000072da2bee>] vfs_write+0xe1/0x240
[<000000004f14f473>] ksys_write+0xb4/0x150
[<00000000a968b4a0>] do_syscall_64+0x6d/0x1e0
[<000000001a189f40>] entry_SYSCALL_64_after_hwframe+0x44/0xa9
Link: http://lkml.kernel.org/r/20191211091258.11310-1-keitasuzuki.park@sslab.ics.keio.ac.jp
Cc: Ingo Molnar <mingo@redhat.com>
Cc: stable@vger.kernel.org
Fixes: 404a3add43c9c ("tracing: Only add filter list when needed")
Signed-off-by: Keita Suzuki <keitasuzuki.park@sslab.ics.keio.ac.jp>
Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
2019-12-11 09:12:58 +00:00
|
|
|
__free_filter(filter);
|
2011-02-04 04:25:46 +00:00
|
|
|
/* If any call succeeded, we still need to sync */
|
|
|
|
if (!fail)
|
2018-08-09 19:31:48 +00:00
|
|
|
tracepoint_synchronize_unregister();
|
2011-02-04 04:25:46 +00:00
|
|
|
list_for_each_entry_safe(filter_item, tmp, &filter_list, list) {
|
|
|
|
__free_filter(filter_item->filter);
|
|
|
|
list_del(&filter_item->list);
|
|
|
|
kfree(filter_item);
|
|
|
|
}
|
|
|
|
return -ENOMEM;
|
2009-10-15 03:20:34 +00:00
|
|
|
}
|
|
|
|
|
2018-02-23 14:45:27 +00:00
|
|
|
static int create_filter_start(char *filter_string, bool set_str,
|
2018-03-09 18:19:28 +00:00
|
|
|
struct filter_parse_error **pse,
|
2011-12-15 22:31:35 +00:00
|
|
|
struct event_filter **filterp)
|
|
|
|
{
|
|
|
|
struct event_filter *filter;
|
2018-03-09 18:19:28 +00:00
|
|
|
struct filter_parse_error *pe = NULL;
|
2011-12-15 22:31:35 +00:00
|
|
|
int err = 0;
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
if (WARN_ON_ONCE(*pse || *filterp))
|
|
|
|
return -EINVAL;
|
2011-12-15 22:31:35 +00:00
|
|
|
|
2018-02-23 04:17:54 +00:00
|
|
|
filter = kzalloc(sizeof(*filter), GFP_KERNEL);
|
2018-02-23 14:45:27 +00:00
|
|
|
if (filter && set_str) {
|
|
|
|
filter->filter_string = kstrdup(filter_string, GFP_KERNEL);
|
|
|
|
if (!filter->filter_string)
|
|
|
|
err = -ENOMEM;
|
|
|
|
}
|
2011-12-15 22:31:35 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
pe = kzalloc(sizeof(*pe), GFP_KERNEL);
|
2011-12-15 22:31:35 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
if (!filter || !pe || err) {
|
|
|
|
kfree(pe);
|
2011-12-15 22:31:35 +00:00
|
|
|
__free_filter(filter);
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we're committed to creating a new filter */
|
|
|
|
*filterp = filter;
|
2018-03-09 18:19:28 +00:00
|
|
|
*pse = pe;
|
2011-12-15 22:31:35 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
return 0;
|
2011-12-15 22:31:35 +00:00
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
static void create_filter_finish(struct filter_parse_error *pe)
|
2011-12-15 22:31:35 +00:00
|
|
|
{
|
2018-03-09 18:19:28 +00:00
|
|
|
kfree(pe);
|
2011-12-15 22:31:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-05-05 15:45:27 +00:00
|
|
|
* create_filter - create a filter for a trace_event_call
|
|
|
|
* @call: trace_event_call to create a filter for
|
2011-12-15 22:31:35 +00:00
|
|
|
* @filter_str: filter string
|
|
|
|
* @set_str: remember @filter_str and enable detailed error in filter
|
|
|
|
* @filterp: out param for created filter (always updated on return)
|
2018-07-02 15:41:38 +00:00
|
|
|
* Must be a pointer that references a NULL pointer.
|
2011-12-15 22:31:35 +00:00
|
|
|
*
|
|
|
|
* Creates a filter for @call with @filter_str. If @set_str is %true,
|
|
|
|
* @filter_str is copied and recorded in the new filter.
|
|
|
|
*
|
|
|
|
* On success, returns 0 and *@filterp points to the new filter. On
|
|
|
|
* failure, returns -errno and *@filterp may point to %NULL or to a new
|
|
|
|
* filter. In the latter case, the returned filter contains error
|
|
|
|
* information if @set_str is %true and the caller is responsible for
|
|
|
|
* freeing it.
|
|
|
|
*/
|
2019-04-01 20:07:48 +00:00
|
|
|
static int create_filter(struct trace_array *tr,
|
|
|
|
struct trace_event_call *call,
|
2018-03-09 18:19:28 +00:00
|
|
|
char *filter_string, bool set_str,
|
2011-12-15 22:31:35 +00:00
|
|
|
struct event_filter **filterp)
|
|
|
|
{
|
2018-03-09 18:19:28 +00:00
|
|
|
struct filter_parse_error *pe = NULL;
|
2011-12-15 22:31:35 +00:00
|
|
|
int err;
|
|
|
|
|
2018-07-02 15:41:38 +00:00
|
|
|
/* filterp must point to NULL */
|
|
|
|
if (WARN_ON(*filterp))
|
|
|
|
*filterp = NULL;
|
|
|
|
|
2018-04-11 14:59:46 +00:00
|
|
|
err = create_filter_start(filter_string, set_str, &pe, filterp);
|
2018-03-09 18:19:28 +00:00
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-04-11 14:59:46 +00:00
|
|
|
err = process_preds(call, filter_string, *filterp, pe);
|
2018-03-09 18:19:28 +00:00
|
|
|
if (err && set_str)
|
2019-04-01 20:07:48 +00:00
|
|
|
append_filter_err(tr, pe, *filterp);
|
2018-12-09 02:10:04 +00:00
|
|
|
create_filter_finish(pe);
|
2011-12-15 22:31:35 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-04-01 20:07:48 +00:00
|
|
|
int create_event_filter(struct trace_array *tr,
|
|
|
|
struct trace_event_call *call,
|
tracing: Add and use generic set_trigger_filter() implementation
Add a generic event_command.set_trigger_filter() op implementation and
have the current set of trigger commands use it - this essentially
gives them all support for filters.
Syntactically, filters are supported by adding 'if <filter>' just
after the command, in which case only events matching the filter will
invoke the trigger. For example, to add a filter to an
enable/disable_event command:
echo 'enable_event:system:event if common_pid == 999' > \
.../othersys/otherevent/trigger
The above command will only enable the system:event event if the
common_pid field in the othersys:otherevent event is 999.
As another example, to add a filter to a stacktrace command:
echo 'stacktrace if common_pid == 999' > \
.../somesys/someevent/trigger
The above command will only trigger a stacktrace if the common_pid
field in the event is 999.
The filter syntax is the same as that described in the 'Event
filtering' section of Documentation/trace/events.txt.
Because triggers can now use filters, the trigger-invoking logic needs
to be moved in those cases - e.g. for ftrace_raw_event_calls, if a
trigger has a filter associated with it, the trigger invocation now
needs to happen after the { assign; } part of the call, in order for
the trigger condition to be tested.
There's still a SOFT_DISABLED-only check at the top of e.g. the
ftrace_raw_events function, so when an event is soft disabled but not
because of the presence of a trigger, the original SOFT_DISABLED
behavior remains unchanged.
There's also a bit of trickiness in that some triggers need to avoid
being invoked while an event is currently in the process of being
logged, since the trigger may itself log data into the trace buffer.
Thus we make sure the current event is committed before invoking those
triggers. To do that, we split the trigger invocation in two - the
first part (event_triggers_call()) checks the filter using the current
trace record; if a command has the post_trigger flag set, it sets a
bit for itself in the return value, otherwise it directly invoks the
trigger. Once all commands have been either invoked or set their
return flag, event_triggers_call() returns. The current record is
then either committed or discarded; if any commands have deferred
their triggers, those commands are finally invoked following the close
of the current event by event_triggers_post_call().
To simplify the above and make it more efficient, the TRIGGER_COND bit
is introduced, which is set only if a soft-disabled trigger needs to
use the log record for filter testing or needs to wait until the
current log record is closed.
The syscall event invocation code is also changed in analogous ways.
Because event triggers need to be able to create and free filters,
this also adds a couple external wrappers for the existing
create_filter and free_filter functions, which are too generic to be
made extern functions themselves.
Link: http://lkml.kernel.org/r/7164930759d8719ef460357f143d995406e4eead.1382622043.git.tom.zanussi@linux.intel.com
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-10-24 13:59:29 +00:00
|
|
|
char *filter_str, bool set_str,
|
|
|
|
struct event_filter **filterp)
|
|
|
|
{
|
2019-04-01 20:07:48 +00:00
|
|
|
return create_filter(tr, call, filter_str, set_str, filterp);
|
tracing: Add and use generic set_trigger_filter() implementation
Add a generic event_command.set_trigger_filter() op implementation and
have the current set of trigger commands use it - this essentially
gives them all support for filters.
Syntactically, filters are supported by adding 'if <filter>' just
after the command, in which case only events matching the filter will
invoke the trigger. For example, to add a filter to an
enable/disable_event command:
echo 'enable_event:system:event if common_pid == 999' > \
.../othersys/otherevent/trigger
The above command will only enable the system:event event if the
common_pid field in the othersys:otherevent event is 999.
As another example, to add a filter to a stacktrace command:
echo 'stacktrace if common_pid == 999' > \
.../somesys/someevent/trigger
The above command will only trigger a stacktrace if the common_pid
field in the event is 999.
The filter syntax is the same as that described in the 'Event
filtering' section of Documentation/trace/events.txt.
Because triggers can now use filters, the trigger-invoking logic needs
to be moved in those cases - e.g. for ftrace_raw_event_calls, if a
trigger has a filter associated with it, the trigger invocation now
needs to happen after the { assign; } part of the call, in order for
the trigger condition to be tested.
There's still a SOFT_DISABLED-only check at the top of e.g. the
ftrace_raw_events function, so when an event is soft disabled but not
because of the presence of a trigger, the original SOFT_DISABLED
behavior remains unchanged.
There's also a bit of trickiness in that some triggers need to avoid
being invoked while an event is currently in the process of being
logged, since the trigger may itself log data into the trace buffer.
Thus we make sure the current event is committed before invoking those
triggers. To do that, we split the trigger invocation in two - the
first part (event_triggers_call()) checks the filter using the current
trace record; if a command has the post_trigger flag set, it sets a
bit for itself in the return value, otherwise it directly invoks the
trigger. Once all commands have been either invoked or set their
return flag, event_triggers_call() returns. The current record is
then either committed or discarded; if any commands have deferred
their triggers, those commands are finally invoked following the close
of the current event by event_triggers_post_call().
To simplify the above and make it more efficient, the TRIGGER_COND bit
is introduced, which is set only if a soft-disabled trigger needs to
use the log record for filter testing or needs to wait until the
current log record is closed.
The syscall event invocation code is also changed in analogous ways.
Because event triggers need to be able to create and free filters,
this also adds a couple external wrappers for the existing
create_filter and free_filter functions, which are too generic to be
made extern functions themselves.
Link: http://lkml.kernel.org/r/7164930759d8719ef460357f143d995406e4eead.1382622043.git.tom.zanussi@linux.intel.com
Signed-off-by: Tom Zanussi <tom.zanussi@linux.intel.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2013-10-24 13:59:29 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 22:31:35 +00:00
|
|
|
/**
|
|
|
|
* create_system_filter - create a filter for an event_subsystem
|
|
|
|
* @system: event_subsystem to create a filter for
|
|
|
|
* @filter_str: filter string
|
|
|
|
* @filterp: out param for created filter (always updated on return)
|
|
|
|
*
|
|
|
|
* Identical to create_filter() except that it creates a subsystem filter
|
|
|
|
* and always remembers @filter_str.
|
|
|
|
*/
|
2015-05-13 18:59:40 +00:00
|
|
|
static int create_system_filter(struct trace_subsystem_dir *dir,
|
2013-10-24 13:34:17 +00:00
|
|
|
struct trace_array *tr,
|
2011-12-15 22:31:35 +00:00
|
|
|
char *filter_str, struct event_filter **filterp)
|
|
|
|
{
|
2018-03-09 18:19:28 +00:00
|
|
|
struct filter_parse_error *pe = NULL;
|
2011-12-15 22:31:35 +00:00
|
|
|
int err;
|
|
|
|
|
2018-04-11 14:59:46 +00:00
|
|
|
err = create_filter_start(filter_str, true, &pe, filterp);
|
2011-12-15 22:31:35 +00:00
|
|
|
if (!err) {
|
2018-03-09 18:19:28 +00:00
|
|
|
err = process_system_preds(dir, tr, pe, filter_str);
|
2011-12-15 22:31:35 +00:00
|
|
|
if (!err) {
|
|
|
|
/* System filters just show a default message */
|
2018-04-11 14:59:46 +00:00
|
|
|
kfree((*filterp)->filter_string);
|
|
|
|
(*filterp)->filter_string = NULL;
|
2011-12-15 22:31:35 +00:00
|
|
|
} else {
|
2019-04-01 20:07:48 +00:00
|
|
|
append_filter_err(tr, pe, *filterp);
|
2011-12-15 22:31:35 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-09 18:19:28 +00:00
|
|
|
create_filter_finish(pe);
|
2011-12-15 22:31:35 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2013-07-26 17:25:40 +00:00
|
|
|
/* caller must hold event_mutex */
|
2015-05-05 14:09:53 +00:00
|
|
|
int apply_event_filter(struct trace_event_file *file, char *filter_string)
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
{
|
2015-05-05 15:45:27 +00:00
|
|
|
struct trace_event_call *call = file->event_call;
|
2018-04-11 14:59:46 +00:00
|
|
|
struct event_filter *filter = NULL;
|
2013-07-26 17:25:40 +00:00
|
|
|
int err;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
|
|
|
if (!strcmp(strstrip(filter_string), "0")) {
|
2013-10-24 13:34:17 +00:00
|
|
|
filter_disable(file);
|
|
|
|
filter = event_filter(file);
|
|
|
|
|
2011-02-04 04:25:46 +00:00
|
|
|
if (!filter)
|
2013-07-26 17:25:40 +00:00
|
|
|
return 0;
|
2013-10-24 13:34:17 +00:00
|
|
|
|
|
|
|
event_clear_filter(file);
|
|
|
|
|
2011-01-28 03:53:06 +00:00
|
|
|
/* Make sure the filter is not being used */
|
2018-08-09 19:31:48 +00:00
|
|
|
tracepoint_synchronize_unregister();
|
2011-02-04 04:25:46 +00:00
|
|
|
__free_filter(filter);
|
2013-10-24 13:34:17 +00:00
|
|
|
|
2013-07-26 17:25:40 +00:00
|
|
|
return 0;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 20:07:48 +00:00
|
|
|
err = create_filter(file->tr, call, filter_string, true, &filter);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2011-02-04 04:25:46 +00:00
|
|
|
/*
|
|
|
|
* Always swap the call filter with the new filter
|
|
|
|
* even if there was an error. If there was an error
|
|
|
|
* in the filter, we disable the filter and show the error
|
|
|
|
* string
|
|
|
|
*/
|
2011-12-15 22:31:35 +00:00
|
|
|
if (filter) {
|
2013-10-24 13:34:17 +00:00
|
|
|
struct event_filter *tmp;
|
2011-12-15 22:31:35 +00:00
|
|
|
|
2013-10-24 13:34:17 +00:00
|
|
|
tmp = event_filter(file);
|
2011-12-15 22:31:35 +00:00
|
|
|
if (!err)
|
2013-10-24 13:34:17 +00:00
|
|
|
event_set_filtered_flag(file);
|
2011-12-15 22:31:35 +00:00
|
|
|
else
|
2013-10-24 13:34:17 +00:00
|
|
|
filter_disable(file);
|
2011-12-15 22:31:35 +00:00
|
|
|
|
2013-10-24 13:34:17 +00:00
|
|
|
event_set_filter(file, filter);
|
2011-12-15 22:31:35 +00:00
|
|
|
|
|
|
|
if (tmp) {
|
|
|
|
/* Make sure the call is done with the filter */
|
2018-08-09 19:31:48 +00:00
|
|
|
tracepoint_synchronize_unregister();
|
2011-12-15 22:31:35 +00:00
|
|
|
__free_filter(tmp);
|
|
|
|
}
|
2011-02-04 04:25:46 +00:00
|
|
|
}
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2015-05-13 18:59:40 +00:00
|
|
|
int apply_subsystem_event_filter(struct trace_subsystem_dir *dir,
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
char *filter_string)
|
|
|
|
{
|
2012-05-04 03:09:03 +00:00
|
|
|
struct event_subsystem *system = dir->subsystem;
|
2013-10-24 13:34:17 +00:00
|
|
|
struct trace_array *tr = dir->tr;
|
2018-04-11 14:59:46 +00:00
|
|
|
struct event_filter *filter = NULL;
|
2011-02-04 04:25:46 +00:00
|
|
|
int err = 0;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2009-06-16 08:39:41 +00:00
|
|
|
mutex_lock(&event_mutex);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
2011-07-05 15:36:06 +00:00
|
|
|
/* Make sure the system still has events */
|
2012-05-04 03:09:03 +00:00
|
|
|
if (!dir->nr_events) {
|
2011-07-05 15:36:06 +00:00
|
|
|
err = -ENODEV;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
if (!strcmp(strstrip(filter_string), "0")) {
|
2014-07-15 18:48:29 +00:00
|
|
|
filter_free_subsystem_preds(dir, tr);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
remove_filter_string(system->filter);
|
2011-02-04 04:25:46 +00:00
|
|
|
filter = system->filter;
|
|
|
|
system->filter = NULL;
|
|
|
|
/* Ensure all filters are no longer used */
|
2018-08-09 19:31:48 +00:00
|
|
|
tracepoint_synchronize_unregister();
|
2014-07-15 18:48:29 +00:00
|
|
|
filter_free_subsystem_filters(dir, tr);
|
2011-02-04 04:25:46 +00:00
|
|
|
__free_filter(filter);
|
2009-10-15 10:24:04 +00:00
|
|
|
goto out_unlock;
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
}
|
|
|
|
|
2014-07-15 18:48:29 +00:00
|
|
|
err = create_system_filter(dir, tr, filter_string, &filter);
|
2011-12-15 22:31:35 +00:00
|
|
|
if (filter) {
|
|
|
|
/*
|
|
|
|
* No event actually uses the system filter
|
2018-11-07 02:44:52 +00:00
|
|
|
* we can free it without synchronize_rcu().
|
2011-12-15 22:31:35 +00:00
|
|
|
*/
|
|
|
|
__free_filter(system->filter);
|
|
|
|
system->filter = filter;
|
|
|
|
}
|
2009-05-15 03:07:27 +00:00
|
|
|
out_unlock:
|
2009-06-16 08:39:41 +00:00
|
|
|
mutex_unlock(&event_mutex);
|
tracing/filters: a better event parser
Replace the current event parser hack with a better one. Filters are
no longer specified predicate by predicate, but all at once and can
use parens and any of the following operators:
numeric fields:
==, !=, <, <=, >, >=
string fields:
==, !=
predicates can be combined with the logical operators:
&&, ||
examples:
"common_preempt_count > 4" > filter
"((sig >= 10 && sig < 15) || sig == 17) && comm != bash" > filter
If there was an error, the erroneous string along with an error
message can be seen by looking at the filter e.g.:
((sig >= 10 && sig < 15) || dsig == 17) && comm != bash
^
parse_error: Field not found
Currently the caret for an error always appears at the beginning of
the filter; a real position should be used, but the error message
should be useful even without it.
To clear a filter, '0' can be written to the filter file.
Filters can also be set or cleared for a complete subsystem by writing
the same filter as would be written to an individual event to the
filter file at the root of the subsytem. Note however, that if any
event in the subsystem lacks a field specified in the filter being
set, the set will fail and all filters in the subsytem are
automatically cleared. This change from the previous version was made
because using only the fields that happen to exist for a given event
would most likely result in a meaningless filter.
Because the logical operators are now implemented as predicates, the
maximum number of predicates in a filter was increased from 8 to 16.
[ Impact: add new, extended trace-filter implementation ]
Signed-off-by: Tom Zanussi <tzanussi@gmail.com>
Acked-by: Steven Rostedt <rostedt@goodmis.org>
Cc: fweisbec@gmail.com
Cc: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <1240905899.6416.121.camel@tropicana>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-04-28 08:04:59 +00:00
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
2009-03-22 08:31:04 +00:00
|
|
|
|
2009-12-21 06:27:35 +00:00
|
|
|
#ifdef CONFIG_PERF_EVENTS
|
2009-10-15 03:21:42 +00:00
|
|
|
|
|
|
|
void ftrace_profile_free_filter(struct perf_event *event)
|
|
|
|
{
|
|
|
|
struct event_filter *filter = event->filter;
|
|
|
|
|
|
|
|
event->filter = NULL;
|
2011-01-28 03:42:43 +00:00
|
|
|
__free_filter(filter);
|
2009-10-15 03:21:42 +00:00
|
|
|
}
|
|
|
|
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
struct function_filter_data {
|
|
|
|
struct ftrace_ops *ops;
|
|
|
|
int first_filter;
|
|
|
|
int first_notrace;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_FUNCTION_TRACER
|
|
|
|
static char **
|
|
|
|
ftrace_function_filter_re(char *buf, int len, int *count)
|
|
|
|
{
|
2015-06-25 22:02:25 +00:00
|
|
|
char *str, **re;
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
|
|
|
|
str = kstrndup(buf, len, GFP_KERNEL);
|
|
|
|
if (!str)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The argv_split function takes white space
|
|
|
|
* as a separator, so convert ',' into spaces.
|
|
|
|
*/
|
2015-06-25 22:02:25 +00:00
|
|
|
strreplace(str, ',', ' ');
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
|
|
|
|
re = argv_split(GFP_KERNEL, str, count);
|
|
|
|
kfree(str);
|
|
|
|
return re;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int ftrace_function_set_regexp(struct ftrace_ops *ops, int filter,
|
|
|
|
int reset, char *re, int len)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (filter)
|
|
|
|
ret = ftrace_set_filter(ops, re, len, reset);
|
|
|
|
else
|
|
|
|
ret = ftrace_set_notrace(ops, re, len, reset);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __ftrace_function_set_filter(int filter, char *buf, int len,
|
|
|
|
struct function_filter_data *data)
|
|
|
|
{
|
2012-06-19 15:47:52 +00:00
|
|
|
int i, re_cnt, ret = -EINVAL;
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
int *reset;
|
|
|
|
char **re;
|
|
|
|
|
|
|
|
reset = filter ? &data->first_filter : &data->first_notrace;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The 'ip' field could have multiple filters set, separated
|
|
|
|
* either by space or comma. We first cut the filter and apply
|
2020-10-29 15:05:54 +00:00
|
|
|
* all pieces separately.
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
*/
|
|
|
|
re = ftrace_function_filter_re(buf, len, &re_cnt);
|
|
|
|
if (!re)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
for (i = 0; i < re_cnt; i++) {
|
|
|
|
ret = ftrace_function_set_regexp(data->ops, filter, *reset,
|
|
|
|
re[i], strlen(re[i]));
|
|
|
|
if (ret)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (*reset)
|
|
|
|
*reset = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
argv_free(re);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
static int ftrace_function_check_pred(struct filter_pred *pred)
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
{
|
|
|
|
struct ftrace_event_field *field = pred->field;
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/*
|
|
|
|
* Check the predicate for function trace, verify:
|
|
|
|
* - only '==' and '!=' is used
|
|
|
|
* - the 'ip' field is used
|
|
|
|
*/
|
|
|
|
if ((pred->op != OP_EQ) && (pred->op != OP_NE))
|
|
|
|
return -EINVAL;
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
if (strcmp(field->name, "ip"))
|
|
|
|
return -EINVAL;
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
static int ftrace_function_set_filter_pred(struct filter_pred *pred,
|
|
|
|
struct function_filter_data *data)
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
{
|
2018-03-09 18:19:28 +00:00
|
|
|
int ret;
|
|
|
|
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
/* Checking the node is valid for function trace. */
|
2018-03-09 18:19:28 +00:00
|
|
|
ret = ftrace_function_check_pred(pred);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return __ftrace_function_set_filter(pred->op == OP_EQ,
|
|
|
|
pred->regex.pattern,
|
|
|
|
pred->regex.len,
|
|
|
|
data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool is_or(struct prog_entry *prog, int i)
|
|
|
|
{
|
|
|
|
int target;
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
/*
|
|
|
|
* Only "||" is allowed for function events, thus,
|
|
|
|
* all true branches should jump to true, and any
|
|
|
|
* false branch should jump to false.
|
|
|
|
*/
|
|
|
|
target = prog[i].target + 1;
|
|
|
|
/* True and false have NULL preds (all prog entries should jump to one */
|
|
|
|
if (prog[target].pred)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* prog[target].target is 1 for TRUE, 0 for FALSE */
|
|
|
|
return prog[i].when_to_branch == prog[target].target;
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int ftrace_function_set_filter(struct perf_event *event,
|
|
|
|
struct event_filter *filter)
|
|
|
|
{
|
2018-04-05 17:39:36 +00:00
|
|
|
struct prog_entry *prog = rcu_dereference_protected(filter->prog,
|
|
|
|
lockdep_is_held(&event_mutex));
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
struct function_filter_data data = {
|
|
|
|
.first_filter = 1,
|
|
|
|
.first_notrace = 1,
|
|
|
|
.ops = &event->ftrace_ops,
|
|
|
|
};
|
2018-03-09 18:19:28 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; prog[i].pred; i++) {
|
|
|
|
struct filter_pred *pred = prog[i].pred;
|
|
|
|
|
|
|
|
if (!is_or(prog, i))
|
|
|
|
return -EINVAL;
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
if (ftrace_function_set_filter_pred(pred, &data) < 0)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
static int ftrace_function_set_filter(struct perf_event *event,
|
|
|
|
struct event_filter *filter)
|
|
|
|
{
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_FUNCTION_TRACER */
|
|
|
|
|
2009-10-15 03:21:42 +00:00
|
|
|
int ftrace_profile_set_filter(struct perf_event *event, int event_id,
|
|
|
|
char *filter_str)
|
|
|
|
{
|
|
|
|
int err;
|
2018-04-11 14:59:46 +00:00
|
|
|
struct event_filter *filter = NULL;
|
2015-05-05 15:45:27 +00:00
|
|
|
struct trace_event_call *call;
|
2009-10-15 03:21:42 +00:00
|
|
|
|
|
|
|
mutex_lock(&event_mutex);
|
|
|
|
|
2011-08-11 14:25:48 +00:00
|
|
|
call = event->tp_event;
|
2009-10-15 10:24:04 +00:00
|
|
|
|
|
|
|
err = -EINVAL;
|
2011-08-11 14:25:48 +00:00
|
|
|
if (!call)
|
2009-10-15 10:24:04 +00:00
|
|
|
goto out_unlock;
|
2009-10-15 03:21:42 +00:00
|
|
|
|
2009-10-15 10:24:04 +00:00
|
|
|
err = -EEXIST;
|
2009-10-15 03:21:42 +00:00
|
|
|
if (event->filter)
|
2009-10-15 10:24:04 +00:00
|
|
|
goto out_unlock;
|
2009-10-15 03:21:42 +00:00
|
|
|
|
2019-04-01 20:07:48 +00:00
|
|
|
err = create_filter(NULL, call, filter_str, false, &filter);
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
if (err)
|
|
|
|
goto free_filter;
|
|
|
|
|
|
|
|
if (ftrace_event_is_function(call))
|
|
|
|
err = ftrace_function_set_filter(event, filter);
|
2011-12-15 22:31:35 +00:00
|
|
|
else
|
ftrace, perf: Add filter support for function trace event
Adding support to filter function trace event via perf
interface. It is now possible to use filter interface
in the perf tool like:
perf record -e ftrace:function --filter="(ip == mm_*)" ls
The filter syntax is restricted to the the 'ip' field only,
and following operators are accepted '==' '!=' '||', ending
up with the filter strings like:
ip == f1[, ]f2 ... || ip != f3[, ]f4 ...
with comma ',' or space ' ' as a function separator. If the
space ' ' is used as a separator, the right side of the
assignment needs to be enclosed in double quotes '"', e.g.:
perf record -e ftrace:function --filter '(ip == do_execve,sys_*,ext*)' ls
perf record -e ftrace:function --filter '(ip == "do_execve,sys_*,ext*")' ls
perf record -e ftrace:function --filter '(ip == "do_execve sys_* ext*")' ls
The '==' operator adds trace filter with same effect as would
be added via set_ftrace_filter file.
The '!=' operator adds trace filter with same effect as would
be added via set_ftrace_notrace file.
The right side of the '!=', '==' operators is list of functions
or regexp. to be added to filter separated by space.
The '||' operator is used for connecting multiple filter definitions
together. It is possible to have more than one '==' and '!='
operators within one filter string.
Link: http://lkml.kernel.org/r/1329317514-8131-8-git-send-email-jolsa@redhat.com
Signed-off-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2012-02-15 14:51:54 +00:00
|
|
|
event->filter = filter;
|
|
|
|
|
|
|
|
free_filter:
|
|
|
|
if (err || ftrace_event_is_function(call))
|
2011-01-28 03:42:43 +00:00
|
|
|
__free_filter(filter);
|
2009-10-15 03:21:42 +00:00
|
|
|
|
2009-10-15 10:24:04 +00:00
|
|
|
out_unlock:
|
2009-10-15 03:21:42 +00:00
|
|
|
mutex_unlock(&event_mutex);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2009-12-21 06:27:35 +00:00
|
|
|
#endif /* CONFIG_PERF_EVENTS */
|
2009-10-15 03:21:42 +00:00
|
|
|
|
2011-08-11 14:25:54 +00:00
|
|
|
#ifdef CONFIG_FTRACE_STARTUP_TEST
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/tracepoint.h>
|
|
|
|
|
|
|
|
#define CREATE_TRACE_POINTS
|
|
|
|
#include "trace_events_filter_test.h"
|
|
|
|
|
|
|
|
#define DATA_REC(m, va, vb, vc, vd, ve, vf, vg, vh, nvisit) \
|
|
|
|
{ \
|
|
|
|
.filter = FILTER, \
|
|
|
|
.rec = { .a = va, .b = vb, .c = vc, .d = vd, \
|
|
|
|
.e = ve, .f = vf, .g = vg, .h = vh }, \
|
|
|
|
.match = m, \
|
|
|
|
.not_visited = nvisit, \
|
|
|
|
}
|
|
|
|
#define YES 1
|
|
|
|
#define NO 0
|
|
|
|
|
|
|
|
static struct test_filter_data_t {
|
|
|
|
char *filter;
|
2015-05-13 19:27:47 +00:00
|
|
|
struct trace_event_raw_ftrace_test_filter rec;
|
2011-08-11 14:25:54 +00:00
|
|
|
int match;
|
|
|
|
char *not_visited;
|
|
|
|
} test_filter_data[] = {
|
|
|
|
#define FILTER "a == 1 && b == 1 && c == 1 && d == 1 && " \
|
|
|
|
"e == 1 && f == 1 && g == 1 && h == 1"
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 1, 1, 1, ""),
|
|
|
|
DATA_REC(NO, 0, 1, 1, 1, 1, 1, 1, 1, "bcdefgh"),
|
|
|
|
DATA_REC(NO, 1, 1, 1, 1, 1, 1, 1, 0, ""),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "a == 1 || b == 1 || c == 1 || d == 1 || " \
|
|
|
|
"e == 1 || f == 1 || g == 1 || h == 1"
|
|
|
|
DATA_REC(NO, 0, 0, 0, 0, 0, 0, 0, 0, ""),
|
|
|
|
DATA_REC(YES, 0, 0, 0, 0, 0, 0, 0, 1, ""),
|
|
|
|
DATA_REC(YES, 1, 0, 0, 0, 0, 0, 0, 0, "bcdefgh"),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "(a == 1 || b == 1) && (c == 1 || d == 1) && " \
|
|
|
|
"(e == 1 || f == 1) && (g == 1 || h == 1)"
|
|
|
|
DATA_REC(NO, 0, 0, 1, 1, 1, 1, 1, 1, "dfh"),
|
|
|
|
DATA_REC(YES, 0, 1, 0, 1, 0, 1, 0, 1, ""),
|
|
|
|
DATA_REC(YES, 1, 0, 1, 0, 0, 1, 0, 1, "bd"),
|
|
|
|
DATA_REC(NO, 1, 0, 1, 0, 0, 1, 0, 0, "bd"),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "(a == 1 && b == 1) || (c == 1 && d == 1) || " \
|
|
|
|
"(e == 1 && f == 1) || (g == 1 && h == 1)"
|
|
|
|
DATA_REC(YES, 1, 0, 1, 1, 1, 1, 1, 1, "efgh"),
|
|
|
|
DATA_REC(YES, 0, 0, 0, 0, 0, 0, 1, 1, ""),
|
|
|
|
DATA_REC(NO, 0, 0, 0, 0, 0, 0, 0, 1, ""),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "(a == 1 && b == 1) && (c == 1 && d == 1) && " \
|
|
|
|
"(e == 1 && f == 1) || (g == 1 && h == 1)"
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 1, 0, 0, "gh"),
|
|
|
|
DATA_REC(NO, 0, 0, 0, 0, 0, 0, 0, 1, ""),
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 0, 1, 1, ""),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "((a == 1 || b == 1) || (c == 1 || d == 1) || " \
|
|
|
|
"(e == 1 || f == 1)) && (g == 1 || h == 1)"
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 1, 0, 1, "bcdef"),
|
|
|
|
DATA_REC(NO, 0, 0, 0, 0, 0, 0, 0, 0, ""),
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 0, 1, 1, "h"),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "((((((((a == 1) && (b == 1)) || (c == 1)) && (d == 1)) || " \
|
|
|
|
"(e == 1)) && (f == 1)) || (g == 1)) && (h == 1))"
|
|
|
|
DATA_REC(YES, 1, 1, 1, 1, 1, 1, 1, 1, "ceg"),
|
|
|
|
DATA_REC(NO, 0, 1, 0, 1, 0, 1, 0, 1, ""),
|
|
|
|
DATA_REC(NO, 1, 0, 1, 0, 1, 0, 1, 0, ""),
|
|
|
|
#undef FILTER
|
|
|
|
#define FILTER "((((((((a == 1) || (b == 1)) && (c == 1)) || (d == 1)) && " \
|
|
|
|
"(e == 1)) || (f == 1)) && (g == 1)) || (h == 1))"
|
|
|
|
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 DATA_REC
|
|
|
|
#undef FILTER
|
|
|
|
#undef YES
|
|
|
|
#undef NO
|
|
|
|
|
2017-10-16 01:22:49 +00:00
|
|
|
#define DATA_CNT ARRAY_SIZE(test_filter_data)
|
2011-08-11 14:25:54 +00:00
|
|
|
|
|
|
|
static int test_pred_visited;
|
|
|
|
|
|
|
|
static int test_pred_visited_fn(struct filter_pred *pred, void *event)
|
|
|
|
{
|
|
|
|
struct ftrace_event_field *field = pred->field;
|
|
|
|
|
|
|
|
test_pred_visited = 1;
|
|
|
|
printk(KERN_INFO "\npred visited %s\n", field->name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
static void update_pred_fn(struct event_filter *filter, char *fields)
|
2011-08-11 14:25:54 +00:00
|
|
|
{
|
2018-04-05 19:20:26 +00:00
|
|
|
struct prog_entry *prog = rcu_dereference_protected(filter->prog,
|
|
|
|
lockdep_is_held(&event_mutex));
|
2018-03-09 18:19:28 +00:00
|
|
|
int i;
|
2011-08-11 14:25:54 +00:00
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
for (i = 0; prog[i].pred; i++) {
|
|
|
|
struct filter_pred *pred = prog[i].pred;
|
2011-08-11 14:25:54 +00:00
|
|
|
struct ftrace_event_field *field = pred->field;
|
|
|
|
|
2018-03-09 18:19:28 +00:00
|
|
|
WARN_ON_ONCE(!pred->fn);
|
|
|
|
|
2011-08-11 14:25:54 +00:00
|
|
|
if (!field) {
|
2018-03-09 18:19:28 +00:00
|
|
|
WARN_ONCE(1, "all leafs should have field defined %d", i);
|
|
|
|
continue;
|
2011-08-11 14:25:54 +00:00
|
|
|
}
|
2018-03-09 18:19:28 +00:00
|
|
|
|
2011-08-11 14:25:54 +00:00
|
|
|
if (!strchr(fields, *field->name))
|
2018-03-09 18:19:28 +00:00
|
|
|
continue;
|
2011-08-11 14:25:54 +00:00
|
|
|
|
|
|
|
pred->fn = test_pred_visited_fn;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static __init int ftrace_test_event_filter(void)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printk(KERN_INFO "Testing ftrace filter: ");
|
|
|
|
|
|
|
|
for (i = 0; i < DATA_CNT; i++) {
|
|
|
|
struct event_filter *filter = NULL;
|
|
|
|
struct test_filter_data_t *d = &test_filter_data[i];
|
|
|
|
int err;
|
|
|
|
|
2019-04-01 20:07:48 +00:00
|
|
|
err = create_filter(NULL, &event_ftrace_test_filter,
|
|
|
|
d->filter, false, &filter);
|
2011-08-11 14:25:54 +00:00
|
|
|
if (err) {
|
|
|
|
printk(KERN_INFO
|
|
|
|
"Failed to get filter for '%s', err %d\n",
|
|
|
|
d->filter, err);
|
2011-12-15 22:31:35 +00:00
|
|
|
__free_filter(filter);
|
2011-08-11 14:25:54 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-04-05 19:20:26 +00:00
|
|
|
/* Needed to dereference filter->prog */
|
|
|
|
mutex_lock(&event_mutex);
|
2011-08-22 13:41:46 +00:00
|
|
|
/*
|
|
|
|
* The preemption disabling is not really needed for self
|
|
|
|
* tests, but the rcu dereference will complain without it.
|
|
|
|
*/
|
|
|
|
preempt_disable();
|
2011-08-11 14:25:54 +00:00
|
|
|
if (*d->not_visited)
|
2018-03-09 18:19:28 +00:00
|
|
|
update_pred_fn(filter, d->not_visited);
|
2011-08-11 14:25:54 +00:00
|
|
|
|
|
|
|
test_pred_visited = 0;
|
|
|
|
err = filter_match_preds(filter, &d->rec);
|
2011-08-22 13:41:46 +00:00
|
|
|
preempt_enable();
|
2011-08-11 14:25:54 +00:00
|
|
|
|
2018-04-05 19:20:26 +00:00
|
|
|
mutex_unlock(&event_mutex);
|
|
|
|
|
2011-08-11 14:25:54 +00:00
|
|
|
__free_filter(filter);
|
|
|
|
|
|
|
|
if (test_pred_visited) {
|
|
|
|
printk(KERN_INFO
|
|
|
|
"Failed, unwanted pred visited for filter %s\n",
|
|
|
|
d->filter);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err != d->match) {
|
|
|
|
printk(KERN_INFO
|
|
|
|
"Failed to match filter '%s', expected %d\n",
|
|
|
|
d->filter, d->match);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (i == DATA_CNT)
|
|
|
|
printk(KERN_CONT "OK\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
late_initcall(ftrace_test_event_filter);
|
|
|
|
|
|
|
|
#endif /* CONFIG_FTRACE_STARTUP_TEST */
|