2 * trace_events_filter - generic event filtering
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 * Copyright (C) 2009 Tom Zanussi <tzanussi@gmail.com>
21 #include <linux/debugfs.h>
22 #include <linux/uaccess.h>
23 #include <linux/module.h>
24 #include <linux/ctype.h>
25 #include <linux/mutex.h>
28 #include "trace_output.h"
50 static struct filter_op filter_ops
[] = {
59 { OP_NONE
, "OP_NONE", 0 },
60 { OP_OPEN_PAREN
, "(", 0 },
66 FILT_ERR_UNBALANCED_PAREN
,
67 FILT_ERR_TOO_MANY_OPERANDS
,
68 FILT_ERR_OPERAND_TOO_LONG
,
69 FILT_ERR_FIELD_NOT_FOUND
,
70 FILT_ERR_ILLEGAL_FIELD_OP
,
71 FILT_ERR_ILLEGAL_INTVAL
,
72 FILT_ERR_BAD_SUBSYS_FILTER
,
73 FILT_ERR_TOO_MANY_PREDS
,
74 FILT_ERR_MISSING_FIELD
,
75 FILT_ERR_INVALID_FILTER
,
78 static char *err_text
[] = {
85 "Illegal operation for field type",
86 "Illegal integer value",
87 "Couldn't find or set field in one of a subsystem's events",
88 "Too many terms in predicate expression",
89 "Missing field name and/or value",
90 "Meaningless filter expression",
95 struct list_head list
;
101 struct list_head list
;
104 struct filter_parse_state
{
105 struct filter_op
*ops
;
106 struct list_head opstack
;
107 struct list_head postfix
;
118 char string
[MAX_FILTER_STR_VAL
];
124 #define DEFINE_COMPARISON_PRED(type) \
125 static int filter_pred_##type(struct filter_pred *pred, void *event, \
126 int val1, int val2) \
128 type *addr = (type *)(event + pred->offset); \
129 type val = (type)pred->val; \
132 switch (pred->op) { \
134 match = (*addr < val); \
137 match = (*addr <= val); \
140 match = (*addr > val); \
143 match = (*addr >= val); \
152 #define DEFINE_EQUALITY_PRED(size) \
153 static int filter_pred_##size(struct filter_pred *pred, void *event, \
154 int val1, int val2) \
156 u##size *addr = (u##size *)(event + pred->offset); \
157 u##size val = (u##size)pred->val; \
160 match = (val == *addr) ^ pred->not; \
165 DEFINE_COMPARISON_PRED(s64
);
166 DEFINE_COMPARISON_PRED(u64
);
167 DEFINE_COMPARISON_PRED(s32
);
168 DEFINE_COMPARISON_PRED(u32
);
169 DEFINE_COMPARISON_PRED(s16
);
170 DEFINE_COMPARISON_PRED(u16
);
171 DEFINE_COMPARISON_PRED(s8
);
172 DEFINE_COMPARISON_PRED(u8
);
174 DEFINE_EQUALITY_PRED(64);
175 DEFINE_EQUALITY_PRED(32);
176 DEFINE_EQUALITY_PRED(16);
177 DEFINE_EQUALITY_PRED(8);
179 static int filter_pred_and(struct filter_pred
*pred
__attribute((unused
)),
180 void *event
__attribute((unused
)),
186 static int filter_pred_or(struct filter_pred
*pred
__attribute((unused
)),
187 void *event
__attribute((unused
)),
193 /* Filter predicate for fixed sized arrays of characters */
194 static int filter_pred_string(struct filter_pred
*pred
, void *event
,
197 char *addr
= (char *)(event
+ pred
->offset
);
200 cmp
= strncmp(addr
, pred
->str_val
, pred
->str_len
);
202 match
= (!cmp
) ^ pred
->not;
207 /* Filter predicate for char * pointers */
208 static int filter_pred_pchar(struct filter_pred
*pred
, void *event
,
211 char **addr
= (char **)(event
+ pred
->offset
);
214 cmp
= strncmp(*addr
, pred
->str_val
, pred
->str_len
);
216 match
= (!cmp
) ^ pred
->not;
222 * Filter predicate for dynamic sized arrays of characters.
223 * These are implemented through a list of strings at the end
225 * Also each of these strings have a field in the entry which
226 * contains its offset from the beginning of the entry.
227 * We have then first to get this field, dereference it
228 * and add it to the address of the entry, and at last we have
229 * the address of the string.
231 static int filter_pred_strloc(struct filter_pred
*pred
, void *event
,
234 u32 str_item
= *(u32
*)(event
+ pred
->offset
);
235 int str_loc
= str_item
& 0xffff;
236 int str_len
= str_item
>> 16;
237 char *addr
= (char *)(event
+ str_loc
);
240 cmp
= strncmp(addr
, pred
->str_val
, str_len
);
242 match
= (!cmp
) ^ pred
->not;
247 static int filter_pred_none(struct filter_pred
*pred
, void *event
,
253 /* return 1 if event matches, 0 otherwise (discard) */
254 int filter_match_preds(struct ftrace_event_call
*call
, void *rec
)
256 struct event_filter
*filter
= call
->filter
;
257 int match
, top
= 0, val1
= 0, val2
= 0;
258 int stack
[MAX_FILTER_PRED
];
259 struct filter_pred
*pred
;
262 for (i
= 0; i
< filter
->n_preds
; i
++) {
263 pred
= filter
->preds
[i
];
265 match
= pred
->fn(pred
, rec
, val1
, val2
);
266 stack
[top
++] = match
;
269 if (pred
->pop_n
> top
) {
275 match
= pred
->fn(pred
, rec
, val1
, val2
);
276 stack
[top
++] = match
;
281 EXPORT_SYMBOL_GPL(filter_match_preds
);
283 static void parse_error(struct filter_parse_state
*ps
, int err
, int pos
)
286 ps
->lasterr_pos
= pos
;
289 static void remove_filter_string(struct event_filter
*filter
)
291 kfree(filter
->filter_string
);
292 filter
->filter_string
= NULL
;
295 static int replace_filter_string(struct event_filter
*filter
,
298 kfree(filter
->filter_string
);
299 filter
->filter_string
= kstrdup(filter_string
, GFP_KERNEL
);
300 if (!filter
->filter_string
)
306 static int append_filter_string(struct event_filter
*filter
,
310 char *new_filter_string
;
312 BUG_ON(!filter
->filter_string
);
313 newlen
= strlen(filter
->filter_string
) + strlen(string
) + 1;
314 new_filter_string
= kmalloc(newlen
, GFP_KERNEL
);
315 if (!new_filter_string
)
318 strcpy(new_filter_string
, filter
->filter_string
);
319 strcat(new_filter_string
, string
);
320 kfree(filter
->filter_string
);
321 filter
->filter_string
= new_filter_string
;
326 static void append_filter_err(struct filter_parse_state
*ps
,
327 struct event_filter
*filter
)
329 int pos
= ps
->lasterr_pos
;
332 buf
= (char *)__get_free_page(GFP_TEMPORARY
);
336 append_filter_string(filter
, "\n");
337 memset(buf
, ' ', PAGE_SIZE
);
338 if (pos
> PAGE_SIZE
- 128)
341 pbuf
= &buf
[pos
] + 1;
343 sprintf(pbuf
, "\nparse_error: %s\n", err_text
[ps
->lasterr
]);
344 append_filter_string(filter
, buf
);
345 free_page((unsigned long) buf
);
348 void print_event_filter(struct ftrace_event_call
*call
, struct trace_seq
*s
)
350 struct event_filter
*filter
= call
->filter
;
352 mutex_lock(&event_mutex
);
353 if (filter
&& filter
->filter_string
)
354 trace_seq_printf(s
, "%s\n", filter
->filter_string
);
356 trace_seq_printf(s
, "none\n");
357 mutex_unlock(&event_mutex
);
360 void print_subsystem_event_filter(struct event_subsystem
*system
,
363 struct event_filter
*filter
= system
->filter
;
365 mutex_lock(&event_mutex
);
366 if (filter
&& filter
->filter_string
)
367 trace_seq_printf(s
, "%s\n", filter
->filter_string
);
369 trace_seq_printf(s
, "none\n");
370 mutex_unlock(&event_mutex
);
373 static struct ftrace_event_field
*
374 find_event_field(struct ftrace_event_call
*call
, char *name
)
376 struct ftrace_event_field
*field
;
378 list_for_each_entry(field
, &call
->fields
, link
) {
379 if (!strcmp(field
->name
, name
))
386 static void filter_free_pred(struct filter_pred
*pred
)
391 kfree(pred
->field_name
);
395 static void filter_clear_pred(struct filter_pred
*pred
)
397 kfree(pred
->field_name
);
398 pred
->field_name
= NULL
;
402 static int filter_set_pred(struct filter_pred
*dest
,
403 struct filter_pred
*src
,
407 if (src
->field_name
) {
408 dest
->field_name
= kstrdup(src
->field_name
, GFP_KERNEL
);
409 if (!dest
->field_name
)
417 static void filter_disable_preds(struct ftrace_event_call
*call
)
419 struct event_filter
*filter
= call
->filter
;
422 call
->filter_active
= 0;
425 for (i
= 0; i
< MAX_FILTER_PRED
; i
++)
426 filter
->preds
[i
]->fn
= filter_pred_none
;
429 void destroy_preds(struct ftrace_event_call
*call
)
431 struct event_filter
*filter
= call
->filter
;
437 for (i
= 0; i
< MAX_FILTER_PRED
; i
++) {
438 if (filter
->preds
[i
])
439 filter_free_pred(filter
->preds
[i
]);
441 kfree(filter
->preds
);
442 kfree(filter
->filter_string
);
447 static int init_preds(struct ftrace_event_call
*call
)
449 struct event_filter
*filter
;
450 struct filter_pred
*pred
;
456 filter
= call
->filter
= kzalloc(sizeof(*filter
), GFP_KERNEL
);
462 filter
->preds
= kzalloc(MAX_FILTER_PRED
* sizeof(pred
), GFP_KERNEL
);
466 for (i
= 0; i
< MAX_FILTER_PRED
; i
++) {
467 pred
= kzalloc(sizeof(*pred
), GFP_KERNEL
);
470 pred
->fn
= filter_pred_none
;
471 filter
->preds
[i
] = pred
;
482 static int init_subsystem_preds(struct event_subsystem
*system
)
484 struct ftrace_event_call
*call
;
487 list_for_each_entry(call
, &ftrace_events
, list
) {
488 if (!call
->define_fields
)
491 if (strcmp(call
->system
, system
->name
) != 0)
494 err
= init_preds(call
);
504 FILTER_INIT_NO_RESET
,
505 FILTER_SKIP_NO_RESET
,
508 static void filter_free_subsystem_preds(struct event_subsystem
*system
,
511 struct ftrace_event_call
*call
;
513 list_for_each_entry(call
, &ftrace_events
, list
) {
514 if (!call
->define_fields
)
517 if (strcmp(call
->system
, system
->name
) != 0)
520 if (flag
== FILTER_INIT_NO_RESET
) {
521 call
->filter
->no_reset
= false;
525 if (flag
== FILTER_SKIP_NO_RESET
&& call
->filter
->no_reset
)
528 filter_disable_preds(call
);
529 remove_filter_string(call
->filter
);
533 static int filter_add_pred_fn(struct filter_parse_state
*ps
,
534 struct ftrace_event_call
*call
,
535 struct filter_pred
*pred
,
538 struct event_filter
*filter
= call
->filter
;
541 if (filter
->n_preds
== MAX_FILTER_PRED
) {
542 parse_error(ps
, FILT_ERR_TOO_MANY_PREDS
, 0);
546 idx
= filter
->n_preds
;
547 filter_clear_pred(filter
->preds
[idx
]);
548 err
= filter_set_pred(filter
->preds
[idx
], pred
, fn
);
553 call
->filter_active
= 1;
558 int filter_assign_type(const char *type
)
560 if (strstr(type
, "__data_loc") && strstr(type
, "char"))
561 return FILTER_DYN_STRING
;
563 if (strchr(type
, '[') && strstr(type
, "char"))
564 return FILTER_STATIC_STRING
;
569 static bool is_string_field(struct ftrace_event_field
*field
)
571 return field
->filter_type
== FILTER_DYN_STRING
||
572 field
->filter_type
== FILTER_STATIC_STRING
||
573 field
->filter_type
== FILTER_PTR_STRING
;
576 static int is_legal_op(struct ftrace_event_field
*field
, int op
)
578 if (is_string_field(field
) && (op
!= OP_EQ
&& op
!= OP_NE
))
584 static filter_pred_fn_t
select_comparison_fn(int op
, int field_size
,
587 filter_pred_fn_t fn
= NULL
;
589 switch (field_size
) {
591 if (op
== OP_EQ
|| op
== OP_NE
)
593 else if (field_is_signed
)
594 fn
= filter_pred_s64
;
596 fn
= filter_pred_u64
;
599 if (op
== OP_EQ
|| op
== OP_NE
)
601 else if (field_is_signed
)
602 fn
= filter_pred_s32
;
604 fn
= filter_pred_u32
;
607 if (op
== OP_EQ
|| op
== OP_NE
)
609 else if (field_is_signed
)
610 fn
= filter_pred_s16
;
612 fn
= filter_pred_u16
;
615 if (op
== OP_EQ
|| op
== OP_NE
)
617 else if (field_is_signed
)
627 static int filter_add_pred(struct filter_parse_state
*ps
,
628 struct ftrace_event_call
*call
,
629 struct filter_pred
*pred
,
632 struct ftrace_event_field
*field
;
634 unsigned long long val
;
637 pred
->fn
= filter_pred_none
;
639 if (pred
->op
== OP_AND
) {
641 fn
= filter_pred_and
;
643 } else if (pred
->op
== OP_OR
) {
649 field
= find_event_field(call
, pred
->field_name
);
651 parse_error(ps
, FILT_ERR_FIELD_NOT_FOUND
, 0);
655 pred
->offset
= field
->offset
;
657 if (!is_legal_op(field
, pred
->op
)) {
658 parse_error(ps
, FILT_ERR_ILLEGAL_FIELD_OP
, 0);
662 if (is_string_field(field
)) {
663 pred
->str_len
= field
->size
;
665 if (field
->filter_type
== FILTER_STATIC_STRING
)
666 fn
= filter_pred_string
;
667 else if (field
->filter_type
== FILTER_DYN_STRING
)
668 fn
= filter_pred_strloc
;
670 fn
= filter_pred_pchar
;
671 pred
->str_len
= strlen(pred
->str_val
);
674 if (field
->is_signed
)
675 ret
= strict_strtoll(pred
->str_val
, 0, &val
);
677 ret
= strict_strtoull(pred
->str_val
, 0, &val
);
679 parse_error(ps
, FILT_ERR_ILLEGAL_INTVAL
, 0);
684 fn
= select_comparison_fn(pred
->op
, field
->size
,
687 parse_error(ps
, FILT_ERR_INVALID_OP
, 0);
692 if (pred
->op
== OP_NE
)
697 return filter_add_pred_fn(ps
, call
, pred
, fn
);
701 static int filter_add_subsystem_pred(struct filter_parse_state
*ps
,
702 struct event_subsystem
*system
,
703 struct filter_pred
*pred
,
707 struct ftrace_event_call
*call
;
711 list_for_each_entry(call
, &ftrace_events
, list
) {
713 if (!call
->define_fields
)
716 if (strcmp(call
->system
, system
->name
))
719 if (call
->filter
->no_reset
)
722 err
= filter_add_pred(ps
, call
, pred
, dry_run
);
724 call
->filter
->no_reset
= true;
729 replace_filter_string(call
->filter
, filter_string
);
733 parse_error(ps
, FILT_ERR_BAD_SUBSYS_FILTER
, 0);
739 static void parse_init(struct filter_parse_state
*ps
,
740 struct filter_op
*ops
,
743 memset(ps
, '\0', sizeof(*ps
));
745 ps
->infix
.string
= infix_string
;
746 ps
->infix
.cnt
= strlen(infix_string
);
749 INIT_LIST_HEAD(&ps
->opstack
);
750 INIT_LIST_HEAD(&ps
->postfix
);
753 static char infix_next(struct filter_parse_state
*ps
)
757 return ps
->infix
.string
[ps
->infix
.tail
++];
760 static char infix_peek(struct filter_parse_state
*ps
)
762 if (ps
->infix
.tail
== strlen(ps
->infix
.string
))
765 return ps
->infix
.string
[ps
->infix
.tail
];
768 static void infix_advance(struct filter_parse_state
*ps
)
774 static inline int is_precedence_lower(struct filter_parse_state
*ps
,
777 return ps
->ops
[a
].precedence
< ps
->ops
[b
].precedence
;
780 static inline int is_op_char(struct filter_parse_state
*ps
, char c
)
784 for (i
= 0; strcmp(ps
->ops
[i
].string
, "OP_NONE"); i
++) {
785 if (ps
->ops
[i
].string
[0] == c
)
792 static int infix_get_op(struct filter_parse_state
*ps
, char firstc
)
794 char nextc
= infix_peek(ps
);
802 for (i
= 0; strcmp(ps
->ops
[i
].string
, "OP_NONE"); i
++) {
803 if (!strcmp(opstr
, ps
->ops
[i
].string
)) {
805 return ps
->ops
[i
].id
;
811 for (i
= 0; strcmp(ps
->ops
[i
].string
, "OP_NONE"); i
++) {
812 if (!strcmp(opstr
, ps
->ops
[i
].string
))
813 return ps
->ops
[i
].id
;
819 static inline void clear_operand_string(struct filter_parse_state
*ps
)
821 memset(ps
->operand
.string
, '\0', MAX_FILTER_STR_VAL
);
822 ps
->operand
.tail
= 0;
825 static inline int append_operand_char(struct filter_parse_state
*ps
, char c
)
827 if (ps
->operand
.tail
== MAX_FILTER_STR_VAL
- 1)
830 ps
->operand
.string
[ps
->operand
.tail
++] = c
;
835 static int filter_opstack_push(struct filter_parse_state
*ps
, int op
)
837 struct opstack_op
*opstack_op
;
839 opstack_op
= kmalloc(sizeof(*opstack_op
), GFP_KERNEL
);
844 list_add(&opstack_op
->list
, &ps
->opstack
);
849 static int filter_opstack_empty(struct filter_parse_state
*ps
)
851 return list_empty(&ps
->opstack
);
854 static int filter_opstack_top(struct filter_parse_state
*ps
)
856 struct opstack_op
*opstack_op
;
858 if (filter_opstack_empty(ps
))
861 opstack_op
= list_first_entry(&ps
->opstack
, struct opstack_op
, list
);
863 return opstack_op
->op
;
866 static int filter_opstack_pop(struct filter_parse_state
*ps
)
868 struct opstack_op
*opstack_op
;
871 if (filter_opstack_empty(ps
))
874 opstack_op
= list_first_entry(&ps
->opstack
, struct opstack_op
, list
);
876 list_del(&opstack_op
->list
);
883 static void filter_opstack_clear(struct filter_parse_state
*ps
)
885 while (!filter_opstack_empty(ps
))
886 filter_opstack_pop(ps
);
889 static char *curr_operand(struct filter_parse_state
*ps
)
891 return ps
->operand
.string
;
894 static int postfix_append_operand(struct filter_parse_state
*ps
, char *operand
)
896 struct postfix_elt
*elt
;
898 elt
= kmalloc(sizeof(*elt
), GFP_KERNEL
);
903 elt
->operand
= kstrdup(operand
, GFP_KERNEL
);
909 list_add_tail(&elt
->list
, &ps
->postfix
);
914 static int postfix_append_op(struct filter_parse_state
*ps
, int op
)
916 struct postfix_elt
*elt
;
918 elt
= kmalloc(sizeof(*elt
), GFP_KERNEL
);
925 list_add_tail(&elt
->list
, &ps
->postfix
);
930 static void postfix_clear(struct filter_parse_state
*ps
)
932 struct postfix_elt
*elt
;
934 while (!list_empty(&ps
->postfix
)) {
935 elt
= list_first_entry(&ps
->postfix
, struct postfix_elt
, list
);
937 list_del(&elt
->list
);
941 static int filter_parse(struct filter_parse_state
*ps
)
947 while ((ch
= infix_next(ps
))) {
959 if (is_op_char(ps
, ch
)) {
960 op
= infix_get_op(ps
, ch
);
962 parse_error(ps
, FILT_ERR_INVALID_OP
, 0);
966 if (strlen(curr_operand(ps
))) {
967 postfix_append_operand(ps
, curr_operand(ps
));
968 clear_operand_string(ps
);
971 while (!filter_opstack_empty(ps
)) {
972 top_op
= filter_opstack_top(ps
);
973 if (!is_precedence_lower(ps
, top_op
, op
)) {
974 top_op
= filter_opstack_pop(ps
);
975 postfix_append_op(ps
, top_op
);
981 filter_opstack_push(ps
, op
);
986 filter_opstack_push(ps
, OP_OPEN_PAREN
);
991 if (strlen(curr_operand(ps
))) {
992 postfix_append_operand(ps
, curr_operand(ps
));
993 clear_operand_string(ps
);
996 top_op
= filter_opstack_pop(ps
);
997 while (top_op
!= OP_NONE
) {
998 if (top_op
== OP_OPEN_PAREN
)
1000 postfix_append_op(ps
, top_op
);
1001 top_op
= filter_opstack_pop(ps
);
1003 if (top_op
== OP_NONE
) {
1004 parse_error(ps
, FILT_ERR_UNBALANCED_PAREN
, 0);
1010 if (append_operand_char(ps
, ch
)) {
1011 parse_error(ps
, FILT_ERR_OPERAND_TOO_LONG
, 0);
1016 if (strlen(curr_operand(ps
)))
1017 postfix_append_operand(ps
, curr_operand(ps
));
1019 while (!filter_opstack_empty(ps
)) {
1020 top_op
= filter_opstack_pop(ps
);
1021 if (top_op
== OP_NONE
)
1023 if (top_op
== OP_OPEN_PAREN
) {
1024 parse_error(ps
, FILT_ERR_UNBALANCED_PAREN
, 0);
1027 postfix_append_op(ps
, top_op
);
1033 static struct filter_pred
*create_pred(int op
, char *operand1
, char *operand2
)
1035 struct filter_pred
*pred
;
1037 pred
= kzalloc(sizeof(*pred
), GFP_KERNEL
);
1041 pred
->field_name
= kstrdup(operand1
, GFP_KERNEL
);
1042 if (!pred
->field_name
) {
1047 strcpy(pred
->str_val
, operand2
);
1048 pred
->str_len
= strlen(operand2
);
1055 static struct filter_pred
*create_logical_pred(int op
)
1057 struct filter_pred
*pred
;
1059 pred
= kzalloc(sizeof(*pred
), GFP_KERNEL
);
1068 static int check_preds(struct filter_parse_state
*ps
)
1070 int n_normal_preds
= 0, n_logical_preds
= 0;
1071 struct postfix_elt
*elt
;
1073 list_for_each_entry(elt
, &ps
->postfix
, list
) {
1074 if (elt
->op
== OP_NONE
)
1077 if (elt
->op
== OP_AND
|| elt
->op
== OP_OR
) {
1084 if (!n_normal_preds
|| n_logical_preds
>= n_normal_preds
) {
1085 parse_error(ps
, FILT_ERR_INVALID_FILTER
, 0);
1092 static int replace_preds(struct event_subsystem
*system
,
1093 struct ftrace_event_call
*call
,
1094 struct filter_parse_state
*ps
,
1095 char *filter_string
,
1098 char *operand1
= NULL
, *operand2
= NULL
;
1099 struct filter_pred
*pred
;
1100 struct postfix_elt
*elt
;
1104 err
= check_preds(ps
);
1108 list_for_each_entry(elt
, &ps
->postfix
, list
) {
1109 if (elt
->op
== OP_NONE
) {
1111 operand1
= elt
->operand
;
1113 operand2
= elt
->operand
;
1115 parse_error(ps
, FILT_ERR_TOO_MANY_OPERANDS
, 0);
1121 if (n_preds
++ == MAX_FILTER_PRED
) {
1122 parse_error(ps
, FILT_ERR_TOO_MANY_PREDS
, 0);
1126 if (elt
->op
== OP_AND
|| elt
->op
== OP_OR
) {
1127 pred
= create_logical_pred(elt
->op
);
1131 if (!operand1
|| !operand2
) {
1132 parse_error(ps
, FILT_ERR_MISSING_FIELD
, 0);
1136 pred
= create_pred(elt
->op
, operand1
, operand2
);
1141 err
= filter_add_pred(ps
, call
, pred
, false);
1143 err
= filter_add_subsystem_pred(ps
, system
, pred
,
1144 filter_string
, dry_run
);
1145 filter_free_pred(pred
);
1149 operand1
= operand2
= NULL
;
1155 int apply_event_filter(struct ftrace_event_call
*call
, char *filter_string
)
1159 struct filter_parse_state
*ps
;
1161 mutex_lock(&event_mutex
);
1163 err
= init_preds(call
);
1167 if (!strcmp(strstrip(filter_string
), "0")) {
1168 filter_disable_preds(call
);
1169 remove_filter_string(call
->filter
);
1170 mutex_unlock(&event_mutex
);
1175 ps
= kzalloc(sizeof(*ps
), GFP_KERNEL
);
1179 filter_disable_preds(call
);
1180 replace_filter_string(call
->filter
, filter_string
);
1182 parse_init(ps
, filter_ops
, filter_string
);
1183 err
= filter_parse(ps
);
1185 append_filter_err(ps
, call
->filter
);
1189 err
= replace_preds(NULL
, call
, ps
, filter_string
, false);
1191 append_filter_err(ps
, call
->filter
);
1194 filter_opstack_clear(ps
);
1198 mutex_unlock(&event_mutex
);
1203 int apply_subsystem_event_filter(struct event_subsystem
*system
,
1204 char *filter_string
)
1208 struct filter_parse_state
*ps
;
1210 mutex_lock(&event_mutex
);
1212 err
= init_subsystem_preds(system
);
1216 if (!strcmp(strstrip(filter_string
), "0")) {
1217 filter_free_subsystem_preds(system
, FILTER_DISABLE_ALL
);
1218 remove_filter_string(system
->filter
);
1219 mutex_unlock(&event_mutex
);
1224 ps
= kzalloc(sizeof(*ps
), GFP_KERNEL
);
1228 replace_filter_string(system
->filter
, filter_string
);
1230 parse_init(ps
, filter_ops
, filter_string
);
1231 err
= filter_parse(ps
);
1233 append_filter_err(ps
, system
->filter
);
1237 filter_free_subsystem_preds(system
, FILTER_INIT_NO_RESET
);
1239 /* try to see the filter can be applied to which events */
1240 err
= replace_preds(system
, NULL
, ps
, filter_string
, true);
1242 append_filter_err(ps
, system
->filter
);
1246 filter_free_subsystem_preds(system
, FILTER_SKIP_NO_RESET
);
1248 /* really apply the filter to the events */
1249 err
= replace_preds(system
, NULL
, ps
, filter_string
, false);
1251 append_filter_err(ps
, system
->filter
);
1252 filter_free_subsystem_preds(system
, 2);
1256 filter_opstack_clear(ps
);
1260 mutex_unlock(&event_mutex
);