Skip to contentSkip to conversation

bkl ftrace events + filter regex support

GIT PULL Superseded Frederic Weisbecker 4 participants 20 messages Aug 1, 2009 – Aug 7, 2009

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

Hi everyone,

This patchset provides the support for bkl tracing, with the support of regex in ftrace filters, so that one can easily filter the bkl event traces per subsystem/directory/file.

Thanks,
Frederic.

The following changes since commit d34a4debef933061924ee17c2ede33f5c44925fb:
[email protected] (1):
tracing: Remove .globl in the scripts/recordmcount.pl doc

are available in the git repository at:

git://git.kernel.org/pub/scm/linux/kernel/git/frederic/random-tracing.git tracing/bkl

Frederic Weisbecker (5):
tracing/bkl: Add bkl ftrace events tracing/event: Cleanup the useless dentry variable tracing/filters: Cleanup useless headers tracing/filters: Provide basic regex support tracing/filters: Provide support for char * pointers

 include/linux/smp_lock.h           |   19 +++-
 include/trace/events/bkl.h         |   61 +++++++++++
 kernel/trace/trace.h               |   33 ++++--
 kernel/trace/trace_events.c        |  106 +++++++++++++++-----
 kernel/trace/trace_events_filter.c |  192 +++++++++++++++++++++++++++++-------
 lib/kernel_lock.c                  |   11 +-
 6 files changed, 340 insertions(+), 82 deletions(-)
 create mode 100644 include/trace/events/bkl.h
#1 lore raw

RFC PATCH 1/5 tracing/bkl: Add bkl ftrace events

Add two events lock_kernel and unlock_kernel() to trace the bkl uses. This opens the door for userspace tools to perform statistics about the callsites that use it, dependencies with other locks (by pairing the trace with lock events), use with recursivity and so on...

The {__reacquire,release}_kernel_lock() events are not traced because these are called from schedule, thus the sched events are sufficient to trace them.

Example of a trace:

hald-addon-stor-4152  [000]   165.875501: unlock_kernel: depth: 0, fs/block_dev.c:1358 __blkdev_put()
hald-addon-stor-4152  [000]   167.832974: lock_kernel: depth: 0, fs/block_dev.c:1167 __blkdev_get()

How to get the callsites that acquire it recursively:

cd /debug/tracing/events/bkl
echo "lock_depth > 0" > filter

firefox-4951 [001] 206.276967: unlock_kernel: depth: 1, fs/reiserfs/super.c:575 reiserfs_dirty_inode()

You can also filter by file and/or line.

---
 include/linux/smp_lock.h   |   19 +++++++++++---
 include/trace/events/bkl.h |   61 ++++++++++++++++++++++++++++++++++++++++++++
 lib/kernel_lock.c          |   11 ++++---
 3 files changed, 82 insertions(+), 9 deletions(-)
 create mode 100644 include/trace/events/bkl.h
include/linux/smp_lock.h +15 -4
index 813be59..d48cc77 100644
@@ -3,6 +3,7 @@
 
 #ifdef CONFIG_LOCK_KERNEL
 #include <linux/sched.h>
+#include <trace/events/bkl.h>
 
 #define kernel_locked()		(current->lock_depth >= 0)
 
@@ -24,8 +25,18 @@ static inline int reacquire_kernel_lock(struct task_struct *task)
 	return 0;
 }
 
-extern void __lockfunc lock_kernel(void)	__acquires(kernel_lock);
-extern void __lockfunc unlock_kernel(void)	__releases(kernel_lock);
+extern void __lockfunc _lock_kernel(void)	__acquires(kernel_lock);
+extern void __lockfunc _unlock_kernel(void)	__releases(kernel_lock);
+
+#define lock_kernel()	{					\
+	trace_lock_kernel(__func__, __FILE__, __LINE__);	\
+	_lock_kernel();						\
+}
+
+#define unlock_kernel()	{					\
+	trace_unlock_kernel(__func__, __FILE__, __LINE__);	\
+	_unlock_kernel();					\
+}
 
 /*
  * Various legacy drivers don't really need the BKL in a specific
@@ -41,8 +52,8 @@ static inline void cycle_kernel_lock(void)
 
 #else
 
-#define lock_kernel()				do { } while(0)
-#define unlock_kernel()				do { } while(0)
+#define lock_kernel()	   trace_lock_kernel(__func__, __FILE__, __LINE__);
+#define unlock_kernel()    trace_unlock_kernel(__func__, __FILE__, __LINE__);
 #define release_kernel_lock(task)		do { } while(0)
 #define cycle_kernel_lock()			do { } while(0)
 #define reacquire_kernel_lock(task)		0
include/trace/events/bkl.h new file +61 -0

61 lines not on this page · raw message

lib/kernel_lock.c +6 -5
index 39f1029..5c10b2e 100644
@@ -5,10 +5,11 @@
  * relegated to obsolescence, but used by various less
  * important (or lazy) subsystems.
  */
-#include <linux/smp_lock.h>
 #include <linux/module.h>
 #include <linux/kallsyms.h>
 #include <linux/semaphore.h>
+#define CREATE_TRACE_POINTS
+#include <linux/smp_lock.h>
 
 /*
  * The 'big kernel lock'
@@ -113,7 +114,7 @@ static inline void __unlock_kernel(void)
  * This cannot happen asynchronously, so we only need to
  * worry about other CPU's.
  */
-void __lockfunc lock_kernel(void)
+void __lockfunc _lock_kernel(void)
 {
 	int depth = current->lock_depth+1;
 	if (likely(!depth))
@@ -121,13 +122,13 @@ void __lockfunc lock_kernel(void)
 	current->lock_depth = depth;
 }
 
-void __lockfunc unlock_kernel(void)
+void __lockfunc _unlock_kernel(void)
 {
 	BUG_ON(current->lock_depth < 0);
 	if (likely(--current->lock_depth < 0))
 		__unlock_kernel();
 }
 
-EXPORT_SYMBOL(lock_kernel);
-EXPORT_SYMBOL(unlock_kernel);
+EXPORT_SYMBOL(_lock_kernel);
+EXPORT_SYMBOL(_unlock_kernel);
 
Signature · 1 line
1.6.2.3
#2 lore raw

RFC PATCH 2/5 tracing/event: Cleanup the useless dentry variable

In reply to Frederic Weisbecker

Cleanup the useless dentry variable while creating a kernel event set of files. trace_create_file() warns if it fails to create the file anyway, and we don't store the dentry anywhere.

---
 kernel/trace/trace_events.c |   23 +++++++++++------------
 1 files changed, 11 insertions(+), 12 deletions(-)
kernel/trace/trace_events.c +11 -12
index 90cf936..d8d8434 100644
@@ -901,9 +901,9 @@ event_subsystem_dir(const char *name, struct dentry *d_events)
 			   "'%s/filter' entry\n", name);
 	}
 
-	entry = trace_create_file("enable", 0644, system->entry,
-				  (void *)system->name,
-				  &ftrace_system_enable_fops);
+	trace_create_file("enable", 0644, system->entry,
+			  (void *)system->name,
+			  &ftrace_system_enable_fops);
 
 	return system->entry;
 }
@@ -941,7 +941,6 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
 		 const struct file_operations *filter,
 		 const struct file_operations *format)
 {
-	struct dentry *entry;
 	int ret;
 
 	/*
@@ -968,12 +967,12 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
 	}
 
 	if (call->regfunc)
-		entry = trace_create_file("enable", 0644, call->dir, call,
-					  enable);
+		trace_create_file("enable", 0644, call->dir, call,
+				  enable);
 
 	if (call->id)
-		entry = trace_create_file("id", 0444, call->dir, call,
-					  id);
+		trace_create_file("id", 0444, call->dir, call,
+		 		  id);
 
 	if (call->define_fields) {
 		ret = call->define_fields();
@@ -982,16 +981,16 @@ event_create_dir(struct ftrace_event_call *call, struct dentry *d_events,
 				   " events/%s\n", call->name);
 			return ret;
 		}
-		entry = trace_create_file("filter", 0644, call->dir, call,
-					  filter);
+		trace_create_file("filter", 0644, call->dir, call,
+				  filter);
 	}
 
 	/* A trace may not want to export its format */
 	if (!call->show_format)
 		return 0;
 
-	entry = trace_create_file("format", 0444, call->dir, call,
-				  format);
+	trace_create_file("format", 0444, call->dir, call,
+			  format);
 
 	return 0;
 }
Signature · 1 line
1.6.2.3
#3 lore raw

RFC PATCH 3/5 tracing/filters: Cleanup useless headers

In reply to Frederic Weisbecker

Cleanup remaining headers inclusion that were only useful when the filter framework and its tracing related filesystem user interface weren't yet separated.

Cc Tom Zanussi <[email protected]>
Cc Steven Rostedt <[email protected]>
---
 kernel/trace/trace_events_filter.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
kernel/trace/trace_events_filter.c +0 -3
index b9aae72..a2f8bef 100644
@@ -18,9 +18,6 @@
  * Copyright (C) 2009 Tom Zanussi <[email protected]>
  */
 
-#include <linux/debugfs.h>
-#include <linux/uaccess.h>
-#include <linux/module.h>
 #include <linux/ctype.h>
 #include <linux/mutex.h>
 
Signature · 1 line
1.6.2.3
#4 lore raw

Re: [RFC][PATCH 3/5] tracing/filters: Cleanup useless headers

Quoted 16 lines · Frederic Weisbecker

Cleanup remaining headers inclusion that were only useful when the filter framework and its tracing related filesystem user interface weren't yet separated.

Cc Tom Zanussi <[email protected]>
Cc Steven Rostedt <[email protected]>
---
 kernel/trace/trace_events_filter.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
kernel/trace/trace_events_filter.c +0 -0
index b9aae72..a2f8bef 100644

kernel/trace/trace_events_filter.c line 23

Quoted 6 lines
kernel/trace/trace_events_filter.c +0 -3
@@ -18,9 +18,6 @@
  * Copyright (C) 2009 Tom Zanussi <[email protected]>
  */
 
-#include <linux/debugfs.h>
-#include <linux/uaccess.h>
-#include <linux/module.h>

But module.h is needed for the use of EXPORT_SYMBOL_GPL().

Quoted 3 lines
kernel/trace/trace_events_filter.c +0 -0
 #include <linux/ctype.h>
 #include <linux/mutex.h>
 
#5 lore raw

Re: [RFC][PATCH 3/5] tracing/filters: Cleanup useless headers

Quoted 20 lines · Li Zefan
Quoted 19 lines · Frederic Weisbecker

Cleanup remaining headers inclusion that were only useful when the filter framework and its tracing related filesystem user interface weren't yet separated.

Cc Tom Zanussi <[email protected]>
Cc Steven Rostedt <[email protected]>
---
 kernel/trace/trace_events_filter.c |    3 ---
 1 files changed, 0 insertions(+), 3 deletions(-)
kernel/trace/trace_events_filter.c +0 -0
index b9aae72..a2f8bef 100644
@@ -18,9 +18,6 @@
  * Copyright (C) 2009 Tom Zanussi <[email protected]>
  */
 
Quoted 5 lines

kernel/trace/trace_events_filter.c line 23

Quoted 3 lines
kernel/trace/trace_events_filter.c +0 -3
-#include <linux/debugfs.h>
-#include <linux/uaccess.h>
-#include <linux/module.h>

But module.h is needed for the use of EXPORT_SYMBOL_GPL().

Oh, indeed, I'll fix that in the v2.

Thanks.

Quoted 4 lines
Quoted 4 lines
kernel/trace/trace_events_filter.c +0 -0
 #include <linux/ctype.h>
 #include <linux/mutex.h>
 
#6 lore raw

RFC PATCH 4/5 tracing/filters: Provide basic regex support

In reply to Frederic Weisbecker

This patch provides basic support for regular expressions in filters. The common filter file doesn't support any regex but a new filter_regex file is created for each subsystem/event.

It supports the following types of regexp:

- *match_beginning
- *match_middle*
- match_end*
- !don't match

Every string is now handled as a regexp in the filter framework, which helps to factorize the code for handling both simple strings and regexp comparisons.

(The regexp code has been savagely cherry picked from ftrace.c writtent by Steve. If this patch makes its way, I'll be happy to change ftrace to use the new filter helpers)

Cc Steven Rostedt <[email protected]>
Cc Tom Zanussi <[email protected]>
---
 kernel/trace/trace.h               |   33 +++++---
 kernel/trace/trace_events.c        |   83 ++++++++++++++++---
 kernel/trace/trace_events_filter.c |  163 ++++++++++++++++++++++++++++--------
 3 files changed, 222 insertions(+), 57 deletions(-)
kernel/trace/trace.h +22 -11
index 94305c7..d96a54c 100644
@@ -761,28 +761,37 @@ struct event_subsystem {
 };
 
 struct filter_pred;
+struct regex;
 
 typedef int (*filter_pred_fn_t) (struct filter_pred *pred, void *event,
 				 int val1, int val2);
+typedef int (*regex_match_func)(char *str, struct regex *r);
+
+struct regex {
+	char			pattern[MAX_FILTER_STR_VAL];
+	int			len;
+	char			*search;
+	int			search_len;
+	regex_match_func	match;
+};
 
 struct filter_pred {
-	filter_pred_fn_t fn;
-	u64 val;
-	char str_val[MAX_FILTER_STR_VAL];
-	int str_len;
-	char *field_name;
-	int offset;
-	int not;
-	int op;
-	int pop_n;
+	filter_pred_fn_t 	fn;
+	u64 			val;
+	struct regex		regex;
+	char 			*field_name;
+	int 			offset;
+	int 			not;
+	int 			op;
+	int 			pop_n;
 };
 
 extern void print_event_filter(struct ftrace_event_call *call,
 			       struct trace_seq *s);
 extern int apply_event_filter(struct ftrace_event_call *call,
-			      char *filter_string);
+			      char *filter_string, bool regex);
 extern int apply_subsystem_event_filter(struct event_subsystem *system,
-					char *filter_string);
+					char *filter_string, bool regex);
 extern void print_subsystem_event_filter(struct event_subsystem *system,
 					 struct trace_seq *s);
 
@@ -840,6 +849,8 @@ static int filter_pred_##size(struct filter_pred *pred, void *event,	\
 	return match;							\
 }
 
+void filter_parse_regex(char *buff, int len, struct regex *r, int *not);
+
 extern struct mutex event_mutex;
 extern struct list_head ftrace_events;
 
kernel/trace/trace_events.c +71 -12

181 lines not on this page · raw message

kernel/trace/trace_events_filter.c +129 -34

277 lines not on this page · raw message

Signature · 1 line
1.6.2.3
#7 lore raw

Re: [RFC][PATCH 4/5] tracing/filters: Provide basic regex support

Quoted 11 lines · Frederic Weisbecker

This patch provides basic support for regular expressions in filters. The common filter file doesn't support any regex but a new filter_regex file is created for each subsystem/event.

It supports the following types of regexp:

- *match_beginning
- *match_middle*
- match_end*
- !don't match

I don't see why adding "filter_regex" is necessary, why not just make "filter" support regex?

Quoted 7 lines

Every string is now handled as a regexp in the filter framework, which helps to factorize the code for handling both simple strings and regexp comparisons.

(The regexp code has been savagely cherry picked from ftrace.c writtent by Steve. If this patch makes its way, I'll be happy to change ftrace to use the new filter helpers)

#8 lore raw

Re: [RFC][PATCH 4/5] tracing/filters: Provide basic regex support

Quoted 7 lines · Li Zefan
Quoted 6 lines · Frederic Weisbecker

This patch provides basic support for regular expressions in filters. The common filter file doesn't support any regex but a new filter_regex file is created for each subsystem/event.

It supports the following types of regexp:

Quoted 8 lines
Quoted 5 lines

- *match_beginning
- *match_middle*
- match_end*
- !don't match

I don't see why adding "filter_regex" is necessary, why not just make "filter" support regex?

I did that because I feared about people beeing unable to filter using
* as a real character inside a filter string.
If we are using only one file, we are forced to get the '*' interpreted. That would also break the ABI.

Quoted 7 lines
Quoted 7 lines

Every string is now handled as a regexp in the filter framework, which helps to factorize the code for handling both simple strings and regexp comparisons.

(The regexp code has been savagely cherry picked from ftrace.c writtent by Steve. If this patch makes its way, I'll be happy to change ftrace to use the new filter helpers)

#9 lore raw

Re: [RFC][PATCH 4/5] tracing/filters: Provide basic regex support

Quoted 13 lines · Frederic Weisbecker
Quoted 12 lines · Li Zefan
Quoted 11 lines · Frederic Weisbecker

This patch provides basic support for regular expressions in filters. The common filter file doesn't support any regex but a new filter_regex file is created for each subsystem/event.

It supports the following types of regexp:

- *match_beginning
- *match_middle*
- match_end*
- !don't match

Quoted 8 lines
Quoted 2 lines

I don't see why adding "filter_regex" is necessary, why not just make "filter" support regex?

I did that because I feared about people beeing unable to filter using
* as a real character inside a filter string.
If we are using only one file, we are forced to get the '*' interpreted. That would also break the ABI.

I think we don't maintain stable ABI for debugfs and we've been changing the "ABI" in debugfs/tracing/, but of course we shouldn't change it without good reasons.

One alternative is to use '"' to prevent '*' to be translated, but seems using "filter_regex" is more convenient, so I agree with this patch.

#10 lore raw

Re: [RFC][PATCH 4/5] tracing/filters: Provide basic regex support

Quoted 23 lines · Li Zefan
Quoted 13 lines · Frederic Weisbecker
Quoted 12 lines · Li Zefan
Quoted 11 lines · Frederic Weisbecker

This patch provides basic support for regular expressions in filters. The common filter file doesn't support any regex but a new filter_regex file is created for each subsystem/event.

It supports the following types of regexp:

- *match_beginning
- *match_middle*
- match_end*
- !don't match

Quoted 8 lines
Quoted 2 lines

I don't see why adding "filter_regex" is necessary, why not just make "filter" support regex?

I did that because I feared about people beeing unable to filter using
* as a real character inside a filter string.
If we are using only one file, we are forced to get the '*' interpreted. That would also break the ABI.

Quoted 3 lines

I think we don't maintain stable ABI for debugfs and we've been changing the "ABI" in debugfs/tracing/, but of course we shouldn't change it without good reasons.

Yeah. May be I'm too much careful there but i prefer not to take the risk.

Quoted 2 lines

One alternative is to use '"' to prevent '*' to be translated, but seems using "filter_regex" is more convenient, so I agree with this patch.

The problem is that most of the time, the '"' is about mandatory to delimit a string.
Say you want to filter the lock name &REISERFS_SB(sb)->lock, you can't do that by just typing:

echo name == &REISERFS_SB(sb)->lock > events/lockdep/filter

because the '&' character is considered as an operator and that will trigger an error.
Instead you must type:

echo 'name == "&REISERFS_SB(sb)->lock"' > events/lockdep/filter

The '' are there to delimit the string for echo, and the "" are interpreted by the filter api which take it as a whole string and not strings interleaved with operators. I even fear - and > may be considered as operators if we omit the "".

I also thought about using an antislash for those who don't want the * to be interpreted. But although it seems intuitive, it's not as much as two distinct and visible files.

Also, we can think about the fact the regexp support could be extended one day if someone needs to. And we could then encounter even more ambiguous characters such as $, ^, [, {, etc...

#11 lore raw

Re: [RFC][PATCH 4/5] tracing/filters: Provide basic regex support

Hi Frederic,

Quoted 54 lines · Frederic Weisbecker
Quoted 23 lines · Li Zefan
Quoted 13 lines · Frederic Weisbecker
Quoted 12 lines · Li Zefan
Quoted 11 lines · Frederic Weisbecker

This patch provides basic support for regular expressions in filters. The common filter file doesn't support any regex but a new filter_regex file is created for each subsystem/event.

It supports the following types of regexp:

- *match_beginning
- *match_middle*
- match_end*
- !don't match

Quoted 8 lines
Quoted 2 lines

I don't see why adding "filter_regex" is necessary, why not just make "filter" support regex?

I did that because I feared about people beeing unable to filter using
* as a real character inside a filter string.
If we are using only one file, we are forced to get the '*' interpreted. That would also break the ABI.

Quoted 3 lines

I think we don't maintain stable ABI for debugfs and we've been changing the "ABI" in debugfs/tracing/, but of course we shouldn't change it without good reasons.

Yeah. May be I'm too much careful there but i prefer not to take the risk.

Quoted 2 lines

One alternative is to use '"' to prevent '*' to be translated, but seems using "filter_regex" is more convenient, so I agree with this patch.

The problem is that most of the time, the '"' is about mandatory to delimit a string.
Say you want to filter the lock name &REISERFS_SB(sb)->lock, you can't do that by just typing:

echo name == &REISERFS_SB(sb)->lock > events/lockdep/filter

because the '&' character is considered as an operator and that will trigger an error.
Instead you must type:

echo 'name == "&REISERFS_SB(sb)->lock"' > events/lockdep/filter

The '' are there to delimit the string for echo, and the "" are interpreted by the filter api which take it as a whole string and not strings interleaved with operators. I even fear - and > may be considered as operators if we omit the "".

Quoted 8 lines

I also thought about using an antislash for those who don't want the * to be interpreted. But although it seems intuitive, it's not as much as two distinct and visible files.

Also, we can think about the fact the regexp support could be extended one day if someone needs to. And we could then encounter even more ambiguous characters such as $, ^, [, {, etc...

This a nice new feature - I considered doing it (not complete regexp support, just * in strings) for the original patch, but ran out of time
- glad you added it.

I still think it makes sense to have some basic support for * in the regular filter file, so I'd vote for getting rid of the filter_regex file for now and just adding * support with the antislash escape to the regular filter file. If you later wanted to add more full-fledged regexp support and it didn't make sense to do it in the regular filter file, then you could go crazy and add the filter_regex later...

Thanks,

Tom

#12 lore raw

Re: [RFC][PATCH 4/5] tracing/filters: Provide basic regex support

Quoted 70 lines · Tom Zanussi

Hi Frederic,

Quoted 54 lines · Frederic Weisbecker
Quoted 23 lines · Li Zefan
Quoted 13 lines · Frederic Weisbecker
Quoted 12 lines · Li Zefan
Quoted 11 lines · Frederic Weisbecker

This patch provides basic support for regular expressions in filters. The common filter file doesn't support any regex but a new filter_regex file is created for each subsystem/event.

It supports the following types of regexp:

- *match_beginning
- *match_middle*
- match_end*
- !don't match

Quoted 8 lines
Quoted 2 lines

I don't see why adding "filter_regex" is necessary, why not just make "filter" support regex?

I did that because I feared about people beeing unable to filter using
* as a real character inside a filter string.
If we are using only one file, we are forced to get the '*' interpreted. That would also break the ABI.

Quoted 3 lines

I think we don't maintain stable ABI for debugfs and we've been changing the "ABI" in debugfs/tracing/, but of course we shouldn't change it without good reasons.

Yeah. May be I'm too much careful there but i prefer not to take the risk.

Quoted 2 lines

One alternative is to use '"' to prevent '*' to be translated, but seems using "filter_regex" is more convenient, so I agree with this patch.

The problem is that most of the time, the '"' is about mandatory to delimit a string.
Say you want to filter the lock name &REISERFS_SB(sb)->lock, you can't do that by just typing:

echo name == &REISERFS_SB(sb)->lock > events/lockdep/filter

because the '&' character is considered as an operator and that will trigger an error.
Instead you must type:

echo 'name == "&REISERFS_SB(sb)->lock"' > events/lockdep/filter

The '' are there to delimit the string for echo, and the "" are interpreted by the filter api which take it as a whole string and not strings interleaved with operators. I even fear - and > may be considered as operators if we omit the "".

Quoted 8 lines

I also thought about using an antislash for those who don't want the * to be interpreted. But although it seems intuitive, it's not as much as two distinct and visible files.

Also, we can think about the fact the regexp support could be extended one day if someone needs to. And we could then encounter even more ambiguous characters such as $, ^, [, {, etc...

This a nice new feature - I considered doing it (not complete regexp support, just * in strings) for the original patch, but ran out of time
- glad you added it.

Quoted 6 lines

I still think it makes sense to have some basic support for * in the regular filter file, so I'd vote for getting rid of the filter_regex file for now and just adding * support with the antislash escape to the regular filter file. If you later wanted to add more full-fledged regexp support and it didn't make sense to do it in the regular filter file, then you could go crazy and add the filter_regex later...

Ok, if you and Li both prefer the single file, I'm fine with that. It shouldn't really harm.
I'll change that in the next version.

Thanks.

#13 lore raw

Re: [RFC][PATCH 4/5] tracing/filters: Provide basic regex support

In reply to Tom Zanussi
Quoted 10 lines · Tom Zanussi

This a nice new feature - I considered doing it (not complete regexp support, just * in strings) for the original patch, but ran out of time
- glad you added it.

I still think it makes sense to have some basic support for * in the regular filter file, so I'd vote for getting rid of the filter_regex file for now and just adding * support with the antislash escape to the regular filter file. If you later wanted to add more full-fledged regexp support and it didn't make sense to do it in the regular filter file, then you could go crazy and add the filter_regex later...

I'll have to second this, /debug doesn't provide an ABI and having multiple ways of expressing filters is just a pain.

I'm thinking of adding this filter capability to the perf tracepoints by passing along a filter expression, having multiple ways of writing this expression is just going to cause confusion.

#14 lore raw

RFC PATCH 5/5 tracing/filters: Provide support for char * pointers

In reply to Frederic Weisbecker

Provide support for char * pointers in the filtering framework. Usually, char * entries are dangerous in traces because the string can be released whereas a pointer to it can still wait to be read from the ring buffer. But sometimes we can assume it's safe, like in case of RO data (eg: __file__ or __line__, used in bkl trace event). If these RO data are in a module and so is the call to the trace event, then it's safe, because the ring buffer will be flushed once this module get unloaded.

Now the bkl events becomes more useful. Say that you want to trace only the bkl use in reiserfs:

cd /debug/tracing/events/bkl/lock_kernel
echo "file == fs/reiserfs*" > filter_regex
cat /debug/tracing/trace

syslogd-3658  [001]  1874.661878: lock_kernel: depth: 1, fs/reiserfs/super.c:563 reiserfs_dirty_inode()
syslogd-3658  [001]  1874.662266: lock_kernel: depth: 0, fs/reiserfs/inode.c:2695 reiserfs_write_end()
syslogd-3658  [001]  1874.662268: lock_kernel: depth: 1, fs/reiserfs/super.c:563 reiserfs_dirty_inode()
syslogd-3658  [001]  1874.662291: lock_kernel: depth: 0, fs/reiserfs/inode.c:2695 reiserfs_write_end()
Cc Tom Zanussi <[email protected]>
Cc Steven Rostedt <[email protected]>
---
 kernel/trace/trace_events_filter.c |   34 +++++++++++++++++++++++++++++-----
 1 files changed, 29 insertions(+), 5 deletions(-)
kernel/trace/trace_events_filter.c +29 -5
index 51b4e24..071c93e 100644
@@ -160,6 +160,20 @@ static int filter_pred_string(struct filter_pred *pred, void *event,
 	return match;
 }
 
+/* Filter predicate for char * pointers */
+static int filter_pred_pchar(struct filter_pred *pred, void *event,
+			      int val1, int val2)
+{
+	char **addr = (char **)(event + pred->offset);
+	int cmp, match;
+
+	cmp = pred->regex.match(*addr, &pred->regex);
+
+	match = (!!cmp) ^ pred->not;
+
+	return match;
+}
+
 /*
  * Filter predicate for dynamic sized arrays of characters.
  * These are implemented through a list of strings at the end
@@ -547,6 +561,7 @@ static int filter_add_pred_fn(struct filter_parse_state *ps,
 enum {
 	FILTER_STATIC_STRING = 1,
 	FILTER_DYN_STRING,
+	FILTER_PTR_STRING
 };
 
 static int is_string_field(const char *type)
@@ -557,6 +572,9 @@ static int is_string_field(const char *type)
 	if (strchr(type, '[') && strstr(type, "char"))
 		return FILTER_STATIC_STRING;
 
+	if (strstr(type, "char *"))
+		return FILTER_PTR_STRING;
+
 	return 0;
 }
 
@@ -646,12 +664,18 @@ static int filter_add_pred(struct filter_parse_state *ps,
 
 	string_type = is_string_field(field->type);
 	if (string_type) {
-		if (string_type == FILTER_DYN_STRING)
-			fn = filter_pred_strloc;
-		else
-			fn = filter_pred_string;
+		if (string_type == FILTER_PTR_STRING) {
+			fn = filter_pred_pchar;
+			pred->regex.len = strlen(pred->regex.pattern);
+		} else {
+			pred->regex.len = field->size;
+
+			if (string_type == FILTER_DYN_STRING)
+				fn = filter_pred_strloc;
+			else
+				fn = filter_pred_string;
+		}
 
-		pred->regex.len = field->size;
 		if (pred->op == OP_NE)
 			pred->not = 1;
 
Signature · 1 line
1.6.2.3
#15 lore raw

Re: [RFC][PATCH 5/5] tracing/filters: Provide support for char * pointers

Quoted 9 lines · Frederic Weisbecker

Provide support for char * pointers in the filtering framework. Usually, char * entries are dangerous in traces because the string can be released whereas a pointer to it can still wait to be read from the ring buffer. But sometimes we can assume it's safe, like in case of RO data (eg: __file__ or __line__, used in bkl trace event). If these RO data are in a module and so is the call to the trace event, then it's safe, because the ring buffer will be flushed once this module get unloaded.

The problem is we don't distinguish dangerous char * from safe char *... They are both defined as:

	__field(char *, str)

So for those dangerous ones, a string filter still can be applied, which will dereference those pointers.

Quoted 11 lines

Now the bkl events becomes more useful. Say that you want to trace only the bkl use in reiserfs:

cd /debug/tracing/events/bkl/lock_kernel
echo "file == fs/reiserfs*" > filter_regex
cat /debug/tracing/trace

syslogd-3658  [001]  1874.661878: lock_kernel: depth: 1, fs/reiserfs/super.c:563 reiserfs_dirty_inode()
syslogd-3658  [001]  1874.662266: lock_kernel: depth: 0, fs/reiserfs/inode.c:2695 reiserfs_write_end()
syslogd-3658  [001]  1874.662268: lock_kernel: depth: 1, fs/reiserfs/super.c:563 reiserfs_dirty_inode()
syslogd-3658  [001]  1874.662291: lock_kernel: depth: 0, fs/reiserfs/inode.c:2695 reiserfs_write_end()
#16 lore raw

Re: [RFC][PATCH 5/5] tracing/filters: Provide support for char * pointers

Quoted 11 lines · Li Zefan
Quoted 9 lines · Frederic Weisbecker

Provide support for char * pointers in the filtering framework. Usually, char * entries are dangerous in traces because the string can be released whereas a pointer to it can still wait to be read from the ring buffer. But sometimes we can assume it's safe, like in case of RO data (eg: __file__ or __line__, used in bkl trace event). If these RO data are in a module and so is the call to the trace event, then it's safe, because the ring buffer will be flushed once this module get unloaded.

Quoted 6 lines

The problem is we don't distinguish dangerous char * from safe char *... They are both defined as:

	__field(char *, str)

So for those dangerous ones, a string filter still can be applied, which will dereference those pointers.

Yeah, but only reviewing can distinguish them. It depends on the context.
IMO, a __builtin_constant check would be wrong. I don't remember who posted recently tracepoints with char * types that were safe although he didn't use string constants.

Quoted 11 lines
Quoted 11 lines

Now the bkl events becomes more useful. Say that you want to trace only the bkl use in reiserfs:

cd /debug/tracing/events/bkl/lock_kernel
echo "file == fs/reiserfs*" > filter_regex
cat /debug/tracing/trace

syslogd-3658  [001]  1874.661878: lock_kernel: depth: 1, fs/reiserfs/super.c:563 reiserfs_dirty_inode()
syslogd-3658  [001]  1874.662266: lock_kernel: depth: 0, fs/reiserfs/inode.c:2695 reiserfs_write_end()
syslogd-3658  [001]  1874.662268: lock_kernel: depth: 1, fs/reiserfs/super.c:563 reiserfs_dirty_inode()
syslogd-3658  [001]  1874.662291: lock_kernel: depth: 0, fs/reiserfs/inode.c:2695 reiserfs_write_end()
#17 lore raw

Re: [RFC][PATCH 5/5] tracing/filters: Provide support for char * pointers

Quoted 15 lines · Frederic Weisbecker
Quoted 14 lines · Li Zefan
Quoted 9 lines · Frederic Weisbecker

Provide support for char * pointers in the filtering framework. Usually, char * entries are dangerous in traces because the string can be released whereas a pointer to it can still wait to be read from the ring buffer. But sometimes we can assume it's safe, like in case of RO data (eg: __file__ or __line__, used in bkl trace event). If these RO data are in a module and so is the call to the trace event, then it's safe, because the ring buffer will be flushed once this module get unloaded.

The problem is we don't distinguish dangerous char * from safe char *... They are both defined as:

	__field(char *, str)
Quoted 9 lines
Quoted 2 lines

So for those dangerous ones, a string filter still can be applied, which will dereference those pointers.

Yeah, but only reviewing can distinguish them. It depends on the context.
IMO, a __builtin_constant check would be wrong. I don't remember who posted recently tracepoints with char * types that were safe although he didn't use string constants.

IMO it's really bad to rely on review to prevent wrong use of an API..

Other developers won't know this restriction, and not all tracepoint patches go through -tip tree, and not all trace_event source files are in include/trace/events/.

How about add __field_type()? So we can define:

__field_type(char *, str, FILTER_PTR_STR)

the advantage is he who wrote the code really knows this field is safe to be used in filtering as a string.

I had some patches that does similar job. I can rewrite and post them.

#18 lore raw

Re: [RFC][PATCH 5/5] tracing/filters: Provide support for char * pointers

Quoted 33 lines · Li Zefan
Quoted 15 lines · Frederic Weisbecker
Quoted 14 lines · Li Zefan
Quoted 9 lines · Frederic Weisbecker

Provide support for char * pointers in the filtering framework. Usually, char * entries are dangerous in traces because the string can be released whereas a pointer to it can still wait to be read from the ring buffer. But sometimes we can assume it's safe, like in case of RO data (eg: __file__ or __line__, used in bkl trace event). If these RO data are in a module and so is the call to the trace event, then it's safe, because the ring buffer will be flushed once this module get unloaded.

The problem is we don't distinguish dangerous char * from safe char *... They are both defined as:

	__field(char *, str)
Quoted 9 lines
Quoted 2 lines

So for those dangerous ones, a string filter still can be applied, which will dereference those pointers.

Yeah, but only reviewing can distinguish them. It depends on the context.
IMO, a __builtin_constant check would be wrong. I don't remember who posted recently tracepoints with char * types that were safe although he didn't use string constants.

IMO it's really bad to rely on review to prevent wrong use of an API..

Other developers won't know this restriction, and not all tracepoint patches go through -tip tree, and not all trace_event source files are in include/trace/events/.

Quoted 8 lines

How about add __field_type()? So we can define:

__field_type(char *, str, FILTER_PTR_STR)

the advantage is he who wrote the code really knows this field is safe to be used in filtering as a string.

I had some patches that does similar job. I can rewrite and post them.

Ah good idea. That may even be useful for further typedef'ed types which filter process match existing supported types.

Just one neat however: __field_type looks too much ambiguous. __field() is already here to define a typed field. This seems confusing.

Why not __field_ext() for "extended"? We may probably add more flags than FILTER_PTR_STR in the future to define options for filtering or even for larger scope.

I then wait for your patches to be posted and I'll integrate them in the current queue.

Thanks a lot!

#19 lore raw

Re: [RFC][PATCH 5/5] tracing/filters: Provide support for char * pointers

Quoted 4 lines
Quoted 4 lines

How about add __field_type()? So we can define:

__field_type(char *, str, FILTER_PTR_STR)

Quoted 8 lines
Quoted 4 lines

the advantage is he who wrote the code really knows this field is safe to be used in filtering as a string.

I had some patches that does similar job. I can rewrite and post them.

Ah good idea. That may even be useful for further typedef'ed types which filter process match existing supported types.

That's why I wrote those patches, to allow:

	# dev is type dev_t
	echo "dev == 8:0" > filter
	# callsite is void *
	echo "callsite == kfree_skb" > filter
Quoted 7 lines

Just one neat however: __field_type looks too much ambiguous. __field() is already here to define a typed field. This seems confusing.

Why not __field_ext() for "extended"? We may probably add more flags than FILTER_PTR_STR in the future to define options for filtering or even for larger scope.

Sure. You know I'm not good at naming. ;)

Quoted 3 lines

I then wait for your patches to be posted and I'll integrate them in the current queue.

Will soon be ready.