mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] tracing: FTRACE_ITER_CONT handling fix
@ 2009-08-11 15:29 Jiri Olsa
  2009-08-19  1:01 ` Steven Rostedt
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jiri Olsa @ 2009-08-11 15:29 UTC (permalink / raw)
  To: Ingo Molnar, Steven Rostedt; +Cc: lkml

Hi,

if one filter item (for set_ftrace_filter and set_ftrace_notrace) is being 
setup by more than 1 consecutive writes (FTRACE_ITER_CONT flag), it won't
be handled corretly.

I used following program to test/verify:

[snip]
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

int main(int argc, char **argv)
{
        int fd, i;
        char *file = argv[1];

        if (-1 == (fd = open(file, O_WRONLY))) {
                perror("open failed");
                return -1;
        }

        for(i = 0; i < (argc - 2); i++) {
                int len = strlen(argv[2+i]);
                int cnt, off = 0;

                while(len) {
                        cnt = write(fd, argv[2+i] + off, len);
                        len -= cnt;
                        off += cnt;
                }
        }

        close(fd);
        return 0;
}
[snip]

before change:
sh-4.0# echo > ./set_ftrace_filter 
sh-4.0# /test ./set_ftrace_filter "sys" "_open "
sh-4.0# cat ./set_ftrace_filter 
#### all functions enabled ####
sh-4.0# 

after change:
sh-4.0# echo > ./set_ftrace_notrace   
sh-4.0# test ./set_ftrace_notrace "sys" "_open "
sh-4.0# cat ./set_ftrace_notrace 
sys_open
sh-4.0# 

wbr,
jirka


Signed-off-by: Jiri Olsa <jolsa@redhat.com>

---
diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 0948634..da0757a 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2233,7 +2233,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 	read++;
 	cnt--;
 
-	if (!(iter->flags & ~FTRACE_ITER_CONT)) {
+	/*
+	 * If the parser haven't finished with the last write,
+	 * continue reading the user input without skipping spaces.
+	 */
+	if (!(iter->flags & FTRACE_ITER_CONT)) {
 		/* skip white space */
 		while (cnt && isspace(ch)) {
 			ret = get_user(ch, ubuf++);
@@ -2243,8 +2247,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 			cnt--;
 		}
 
+		/* only spaces were written */
 		if (isspace(ch)) {
-			file->f_pos += read;
+			*ppos += read;
 			ret = read;
 			goto out;
 		}
@@ -2273,12 +2278,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 		if (ret)
 			goto out;
 		iter->buffer_idx = 0;
-	} else
+	} else {
 		iter->flags |= FTRACE_ITER_CONT;
+		iter->buffer[iter->buffer_idx++] = ch;
+	}
 
-
-	file->f_pos += read;
-
+	*ppos += read;
 	ret = read;
  out:
 	mutex_unlock(&ftrace_regex_lock);

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tracing: FTRACE_ITER_CONT handling fix
  2009-08-11 15:29 [PATCH] tracing: FTRACE_ITER_CONT handling fix Jiri Olsa
@ 2009-08-19  1:01 ` Steven Rostedt
  2009-08-19  7:18   ` Jiri Olsa
  2009-08-19  1:22 ` [GIT PULL][2.6.31] tracing: handle broken names in ftrace filter Steven Rostedt
  2009-08-19 12:36 ` [tip:tracing/urgent] " tip-bot for Jiri Olsa
  2 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2009-08-19  1:01 UTC (permalink / raw)
  To: Jiri Olsa; +Cc: Ingo Molnar, lkml


On Tue, 11 Aug 2009, Jiri Olsa wrote:

> Hi,
> 
> if one filter item (for set_ftrace_filter and set_ftrace_notrace) is being 
> setup by more than 1 consecutive writes (FTRACE_ITER_CONT flag), it won't
> be handled corretly.
> 
> I used following program to test/verify:
> 
> [snip]
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> #include <string.h>
> 
> int main(int argc, char **argv)
> {
>         int fd, i;
>         char *file = argv[1];
> 
>         if (-1 == (fd = open(file, O_WRONLY))) {
>                 perror("open failed");
>                 return -1;
>         }
> 
>         for(i = 0; i < (argc - 2); i++) {
>                 int len = strlen(argv[2+i]);
>                 int cnt, off = 0;
> 
>                 while(len) {
>                         cnt = write(fd, argv[2+i] + off, len);
>                         len -= cnt;
>                         off += cnt;
>                 }
>         }
> 
>         close(fd);
>         return 0;
> }
> [snip]

BTW, you did not need to make such a test, just doing:

 # echo sys_open | dd of=set_ftrace_filter bs=2

works as well.


> 
> before change:
> sh-4.0# echo > ./set_ftrace_filter 
> sh-4.0# /test ./set_ftrace_filter "sys" "_open "
> sh-4.0# cat ./set_ftrace_filter 
> #### all functions enabled ####
> sh-4.0# 
> 
> after change:
> sh-4.0# echo > ./set_ftrace_notrace   
> sh-4.0# test ./set_ftrace_notrace "sys" "_open "
> sh-4.0# cat ./set_ftrace_notrace 
> sys_open
> sh-4.0# 
> 
> wbr,
> jirka
> 
> 
> Signed-off-by: Jiri Olsa <jolsa@redhat.com>

Thanks, applied!

-- Steve

> 
> ---
> diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> index 0948634..da0757a 100644
> --- a/kernel/trace/ftrace.c
> +++ b/kernel/trace/ftrace.c
> @@ -2233,7 +2233,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
>  	read++;
>  	cnt--;
>  
> -	if (!(iter->flags & ~FTRACE_ITER_CONT)) {
> +	/*
> +	 * If the parser haven't finished with the last write,
> +	 * continue reading the user input without skipping spaces.
> +	 */
> +	if (!(iter->flags & FTRACE_ITER_CONT)) {
>  		/* skip white space */
>  		while (cnt && isspace(ch)) {
>  			ret = get_user(ch, ubuf++);
> @@ -2243,8 +2247,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
>  			cnt--;
>  		}
>  
> +		/* only spaces were written */
>  		if (isspace(ch)) {
> -			file->f_pos += read;
> +			*ppos += read;
>  			ret = read;
>  			goto out;
>  		}
> @@ -2273,12 +2278,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
>  		if (ret)
>  			goto out;
>  		iter->buffer_idx = 0;
> -	} else
> +	} else {
>  		iter->flags |= FTRACE_ITER_CONT;
> +		iter->buffer[iter->buffer_idx++] = ch;
> +	}
>  
> -
> -	file->f_pos += read;
> -
> +	*ppos += read;
>  	ret = read;
>   out:
>  	mutex_unlock(&ftrace_regex_lock);
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [GIT PULL][2.6.31] tracing: handle broken names in ftrace filter
  2009-08-11 15:29 [PATCH] tracing: FTRACE_ITER_CONT handling fix Jiri Olsa
  2009-08-19  1:01 ` Steven Rostedt
@ 2009-08-19  1:22 ` Steven Rostedt
  2009-08-19 12:20   ` Ingo Molnar
  2009-08-19 12:36 ` [tip:tracing/urgent] " tip-bot for Jiri Olsa
  2 siblings, 1 reply; 6+ messages in thread
From: Steven Rostedt @ 2009-08-19  1:22 UTC (permalink / raw)
  To: lkml; +Cc: Jiri Olsa, Ingo Molnar, Andrew Morton


Ingo,

Please pull the latest tip/tracing/urgent tree, which can be found at:

  git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
tip/tracing/urgent


Jiri Olsa (1):
      tracing: handle broken names in ftrace filter

----
 kernel/trace/ftrace.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)
---------------------------
commit eda1e328556565e211b7450250e40d6de751563a
Author: Jiri Olsa <jolsa@redhat.com>
Date:   Tue Aug 11 17:29:04 2009 +0200

    tracing: handle broken names in ftrace filter
    
    If one filter item (for set_ftrace_filter and set_ftrace_notrace) is being
    setup by more than 1 consecutive writes (FTRACE_ITER_CONT flag), it won't
    be handled corretly.
    
    I used following program to test/verify:
    
    [snip]
    #include <stdio.h>
    #include <sys/types.h>
    #include <sys/stat.h>
    #include <fcntl.h>
    #include <string.h>
    
    int main(int argc, char **argv)
    {
            int fd, i;
            char *file = argv[1];
    
            if (-1 == (fd = open(file, O_WRONLY))) {
                    perror("open failed");
                    return -1;
            }
    
            for(i = 0; i < (argc - 2); i++) {
                    int len = strlen(argv[2+i]);
                    int cnt, off = 0;
    
                    while(len) {
                            cnt = write(fd, argv[2+i] + off, len);
                            len -= cnt;
                            off += cnt;
                    }
            }
    
            close(fd);
            return 0;
    }
    [snip]
    
    before change:
    sh-4.0# echo > ./set_ftrace_filter
    sh-4.0# /test ./set_ftrace_filter "sys" "_open "
    sh-4.0# cat ./set_ftrace_filter
    #### all functions enabled ####
    sh-4.0#
    
    after change:
    sh-4.0# echo > ./set_ftrace_notrace
    sh-4.0# test ./set_ftrace_notrace "sys" "_open "
    sh-4.0# cat ./set_ftrace_notrace
    sys_open
    sh-4.0#
    
    Signed-off-by: Jiri Olsa <jolsa@redhat.com>
    LKML-Reference: <20090811152904.GA26065@jolsa.lab.eng.brq.redhat.com>
    Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 1e1d23c..25edd5c 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2278,7 +2278,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 	read++;
 	cnt--;
 
-	if (!(iter->flags & ~FTRACE_ITER_CONT)) {
+	/*
+	 * If the parser haven't finished with the last write,
+	 * continue reading the user input without skipping spaces.
+	 */
+	if (!(iter->flags & FTRACE_ITER_CONT)) {
 		/* skip white space */
 		while (cnt && isspace(ch)) {
 			ret = get_user(ch, ubuf++);
@@ -2288,8 +2292,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 			cnt--;
 		}
 
+		/* only spaces were written */
 		if (isspace(ch)) {
-			file->f_pos += read;
+			*ppos += read;
 			ret = read;
 			goto out;
 		}
@@ -2319,12 +2324,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 		if (ret)
 			goto out;
 		iter->buffer_idx = 0;
-	} else
+	} else {
 		iter->flags |= FTRACE_ITER_CONT;
+		iter->buffer[iter->buffer_idx++] = ch;
+	}
 
-
-	file->f_pos += read;
-
+	*ppos += read;
 	ret = read;
  out:
 	mutex_unlock(&ftrace_regex_lock);



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] tracing: FTRACE_ITER_CONT handling fix
  2009-08-19  1:01 ` Steven Rostedt
@ 2009-08-19  7:18   ` Jiri Olsa
  0 siblings, 0 replies; 6+ messages in thread
From: Jiri Olsa @ 2009-08-19  7:18 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: Ingo Molnar, lkml

On Tue, Aug 18, 2009 at 09:01:08PM -0400, Steven Rostedt wrote:
> 
> On Tue, 11 Aug 2009, Jiri Olsa wrote:
> 
> > Hi,
> > 
> > if one filter item (for set_ftrace_filter and set_ftrace_notrace) is being 
> > setup by more than 1 consecutive writes (FTRACE_ITER_CONT flag), it won't
> > be handled corretly.
> > 
> > I used following program to test/verify:
> > 
> > [snip]
> > #include <stdio.h>
> > #include <sys/types.h>
> > #include <sys/stat.h>
> > #include <fcntl.h>
> > #include <string.h>
> > 
> > int main(int argc, char **argv)
> > {
> >         int fd, i;
> >         char *file = argv[1];
> > 
> >         if (-1 == (fd = open(file, O_WRONLY))) {
> >                 perror("open failed");
> >                 return -1;
> >         }
> > 
> >         for(i = 0; i < (argc - 2); i++) {
> >                 int len = strlen(argv[2+i]);
> >                 int cnt, off = 0;
> > 
> >                 while(len) {
> >                         cnt = write(fd, argv[2+i] + off, len);
> >                         len -= cnt;
> >                         off += cnt;
> >                 }
> >         }
> > 
> >         close(fd);
> >         return 0;
> > }
> > [snip]
> 
> BTW, you did not need to make such a test, just doing:
> 
>  # echo sys_open | dd of=set_ftrace_filter bs=2
> 
> works as well.
> 

cool :) thanks

jirka

> 
> > 
> > before change:
> > sh-4.0# echo > ./set_ftrace_filter 
> > sh-4.0# /test ./set_ftrace_filter "sys" "_open "
> > sh-4.0# cat ./set_ftrace_filter 
> > #### all functions enabled ####
> > sh-4.0# 
> > 
> > after change:
> > sh-4.0# echo > ./set_ftrace_notrace   
> > sh-4.0# test ./set_ftrace_notrace "sys" "_open "
> > sh-4.0# cat ./set_ftrace_notrace 
> > sys_open
> > sh-4.0# 
> > 
> > wbr,
> > jirka
> > 
> > 
> > Signed-off-by: Jiri Olsa <jolsa@redhat.com>
> 
> Thanks, applied!
> 
> -- Steve
> 
> > 
> > ---
> > diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
> > index 0948634..da0757a 100644
> > --- a/kernel/trace/ftrace.c
> > +++ b/kernel/trace/ftrace.c
> > @@ -2233,7 +2233,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
> >  	read++;
> >  	cnt--;
> >  
> > -	if (!(iter->flags & ~FTRACE_ITER_CONT)) {
> > +	/*
> > +	 * If the parser haven't finished with the last write,
> > +	 * continue reading the user input without skipping spaces.
> > +	 */
> > +	if (!(iter->flags & FTRACE_ITER_CONT)) {
> >  		/* skip white space */
> >  		while (cnt && isspace(ch)) {
> >  			ret = get_user(ch, ubuf++);
> > @@ -2243,8 +2247,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
> >  			cnt--;
> >  		}
> >  
> > +		/* only spaces were written */
> >  		if (isspace(ch)) {
> > -			file->f_pos += read;
> > +			*ppos += read;
> >  			ret = read;
> >  			goto out;
> >  		}
> > @@ -2273,12 +2278,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
> >  		if (ret)
> >  			goto out;
> >  		iter->buffer_idx = 0;
> > -	} else
> > +	} else {
> >  		iter->flags |= FTRACE_ITER_CONT;
> > +		iter->buffer[iter->buffer_idx++] = ch;
> > +	}
> >  
> > -
> > -	file->f_pos += read;
> > -
> > +	*ppos += read;
> >  	ret = read;
> >   out:
> >  	mutex_unlock(&ftrace_regex_lock);
> > 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [GIT PULL][2.6.31] tracing: handle broken names in ftrace filter
  2009-08-19  1:22 ` [GIT PULL][2.6.31] tracing: handle broken names in ftrace filter Steven Rostedt
@ 2009-08-19 12:20   ` Ingo Molnar
  0 siblings, 0 replies; 6+ messages in thread
From: Ingo Molnar @ 2009-08-19 12:20 UTC (permalink / raw)
  To: Steven Rostedt; +Cc: lkml, Jiri Olsa, Andrew Morton


* Steven Rostedt <rostedt@goodmis.org> wrote:

> 
> Ingo,
> 
> Please pull the latest tip/tracing/urgent tree, which can be found at:
> 
>   git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-2.6-trace.git
> tip/tracing/urgent
> 
> 
> Jiri Olsa (1):
>       tracing: handle broken names in ftrace filter
> 
> ----
>  kernel/trace/ftrace.c |   17 +++++++++++------
>  1 files changed, 11 insertions(+), 6 deletions(-)

Pulled, thanks Steve!

	Ingo

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [tip:tracing/urgent] tracing: handle broken names in ftrace filter
  2009-08-11 15:29 [PATCH] tracing: FTRACE_ITER_CONT handling fix Jiri Olsa
  2009-08-19  1:01 ` Steven Rostedt
  2009-08-19  1:22 ` [GIT PULL][2.6.31] tracing: handle broken names in ftrace filter Steven Rostedt
@ 2009-08-19 12:36 ` tip-bot for Jiri Olsa
  2 siblings, 0 replies; 6+ messages in thread
From: tip-bot for Jiri Olsa @ 2009-08-19 12:36 UTC (permalink / raw)
  To: linux-tip-commits; +Cc: linux-kernel, hpa, mingo, rostedt, tglx, jolsa

Commit-ID:  eda1e328556565e211b7450250e40d6de751563a
Gitweb:     http://git.kernel.org/tip/eda1e328556565e211b7450250e40d6de751563a
Author:     Jiri Olsa <jolsa@redhat.com>
AuthorDate: Tue, 11 Aug 2009 17:29:04 +0200
Committer:  Steven Rostedt <rostedt@goodmis.org>
CommitDate: Tue, 18 Aug 2009 20:39:48 -0400

tracing: handle broken names in ftrace filter

If one filter item (for set_ftrace_filter and set_ftrace_notrace) is being
setup by more than 1 consecutive writes (FTRACE_ITER_CONT flag), it won't
be handled corretly.

I used following program to test/verify:

[snip]
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>

int main(int argc, char **argv)
{
        int fd, i;
        char *file = argv[1];

        if (-1 == (fd = open(file, O_WRONLY))) {
                perror("open failed");
                return -1;
        }

        for(i = 0; i < (argc - 2); i++) {
                int len = strlen(argv[2+i]);
                int cnt, off = 0;

                while(len) {
                        cnt = write(fd, argv[2+i] + off, len);
                        len -= cnt;
                        off += cnt;
                }
        }

        close(fd);
        return 0;
}
[snip]

before change:
sh-4.0# echo > ./set_ftrace_filter
sh-4.0# /test ./set_ftrace_filter "sys" "_open "
sh-4.0# cat ./set_ftrace_filter
#### all functions enabled ####
sh-4.0#

after change:
sh-4.0# echo > ./set_ftrace_notrace
sh-4.0# test ./set_ftrace_notrace "sys" "_open "
sh-4.0# cat ./set_ftrace_notrace
sys_open
sh-4.0#

Signed-off-by: Jiri Olsa <jolsa@redhat.com>
LKML-Reference: <20090811152904.GA26065@jolsa.lab.eng.brq.redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>


---
 kernel/trace/ftrace.c |   17 +++++++++++------
 1 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
index 1e1d23c..25edd5c 100644
--- a/kernel/trace/ftrace.c
+++ b/kernel/trace/ftrace.c
@@ -2278,7 +2278,11 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 	read++;
 	cnt--;
 
-	if (!(iter->flags & ~FTRACE_ITER_CONT)) {
+	/*
+	 * If the parser haven't finished with the last write,
+	 * continue reading the user input without skipping spaces.
+	 */
+	if (!(iter->flags & FTRACE_ITER_CONT)) {
 		/* skip white space */
 		while (cnt && isspace(ch)) {
 			ret = get_user(ch, ubuf++);
@@ -2288,8 +2292,9 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 			cnt--;
 		}
 
+		/* only spaces were written */
 		if (isspace(ch)) {
-			file->f_pos += read;
+			*ppos += read;
 			ret = read;
 			goto out;
 		}
@@ -2319,12 +2324,12 @@ ftrace_regex_write(struct file *file, const char __user *ubuf,
 		if (ret)
 			goto out;
 		iter->buffer_idx = 0;
-	} else
+	} else {
 		iter->flags |= FTRACE_ITER_CONT;
+		iter->buffer[iter->buffer_idx++] = ch;
+	}
 
-
-	file->f_pos += read;
-
+	*ppos += read;
 	ret = read;
  out:
 	mutex_unlock(&ftrace_regex_lock);

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-08-19 12:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-11 15:29 [PATCH] tracing: FTRACE_ITER_CONT handling fix Jiri Olsa
2009-08-19  1:01 ` Steven Rostedt
2009-08-19  7:18   ` Jiri Olsa
2009-08-19  1:22 ` [GIT PULL][2.6.31] tracing: handle broken names in ftrace filter Steven Rostedt
2009-08-19 12:20   ` Ingo Molnar
2009-08-19 12:36 ` [tip:tracing/urgent] " tip-bot for Jiri Olsa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

Powered by JetHome