All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] perf parse-events: Reduce casts around bp_addr
@ 2020-09-25  0:39 Ian Rogers
  2020-09-25 13:01 ` Jiri Olsa
  0 siblings, 1 reply; 3+ messages in thread
From: Ian Rogers @ 2020-09-25  0:39 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Jin Yao, Adrian Hunter, Leo Yan, linux-kernel, Stephane Eranian
  Cc: Ian Rogers

perf_event_attr bp_addr is a u64. parse-events.y parses it as a u64, but
casts it to a void* and then parse-events.c casts it back to a u64.
Rather than all the casts, change the type of the address to be a u64.
This removes an issue noted in:
https://lore.kernel.org/lkml/20200903184359.GC3495158@kernel.org/

Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/parse-events.c | 4 ++--
 tools/perf/util/parse-events.h | 2 +-
 tools/perf/util/parse-events.y | 8 ++++----
 3 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 667cbca1547a..f82ef1e840b2 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -940,12 +940,12 @@ do {					\
 }
 
 int parse_events_add_breakpoint(struct list_head *list, int *idx,
-				void *ptr, char *type, u64 len)
+				u64 addr, char *type, u64 len)
 {
 	struct perf_event_attr attr;
 
 	memset(&attr, 0, sizeof(attr));
-	attr.bp_addr = (unsigned long) ptr;
+	attr.bp_addr = addr;
 
 	if (parse_breakpoint_type(type, &attr))
 		return -EINVAL;
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 00cde7d2e30c..e80c9b74f2f2 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -190,7 +190,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
 			   struct parse_events_error *error,
 			   struct list_head *head_config);
 int parse_events_add_breakpoint(struct list_head *list, int *idx,
-				void *ptr, char *type, u64 len);
+				u64 addr, char *type, u64 len);
 int parse_events_add_pmu(struct parse_events_state *parse_state,
 			 struct list_head *list, char *name,
 			 struct list_head *head_config,
diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
index 645bf4f1859f..d5b6aff82f21 100644
--- a/tools/perf/util/parse-events.y
+++ b/tools/perf/util/parse-events.y
@@ -511,7 +511,7 @@ PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
 	list = alloc_list();
 	ABORT_ON(!list);
 	err = parse_events_add_breakpoint(list, &parse_state->idx,
-					(void *)(uintptr_t) $2, $6, $4);
+					  $2, $6, $4);
 	free($6);
 	if (err) {
 		free(list);
@@ -528,7 +528,7 @@ PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
 	list = alloc_list();
 	ABORT_ON(!list);
 	if (parse_events_add_breakpoint(list, &parse_state->idx,
-						(void *)(uintptr_t) $2, NULL, $4)) {
+					$2, NULL, $4)) {
 		free(list);
 		YYABORT;
 	}
@@ -544,7 +544,7 @@ PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
 	list = alloc_list();
 	ABORT_ON(!list);
 	err = parse_events_add_breakpoint(list, &parse_state->idx,
-					(void *)(uintptr_t) $2, $4, 0);
+					  $2, $4, 0);
 	free($4);
 	if (err) {
 		free(list);
@@ -561,7 +561,7 @@ PE_PREFIX_MEM PE_VALUE sep_dc
 	list = alloc_list();
 	ABORT_ON(!list);
 	if (parse_events_add_breakpoint(list, &parse_state->idx,
-						(void *)(uintptr_t) $2, NULL, 0)) {
+					$2, NULL, 0)) {
 		free(list);
 		YYABORT;
 	}
-- 
2.28.0.681.g6f77f65b4e-goog


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

* Re: [PATCH] perf parse-events: Reduce casts around bp_addr
  2020-09-25  0:39 [PATCH] perf parse-events: Reduce casts around bp_addr Ian Rogers
@ 2020-09-25 13:01 ` Jiri Olsa
  2020-09-28 12:22   ` Arnaldo Carvalho de Melo
  0 siblings, 1 reply; 3+ messages in thread
From: Jiri Olsa @ 2020-09-25 13:01 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Namhyung Kim, Jin Yao,
	Adrian Hunter, Leo Yan, linux-kernel, Stephane Eranian

On Thu, Sep 24, 2020 at 05:39:03PM -0700, Ian Rogers wrote:
> perf_event_attr bp_addr is a u64. parse-events.y parses it as a u64, but
> casts it to a void* and then parse-events.c casts it back to a u64.
> Rather than all the casts, change the type of the address to be a u64.
> This removes an issue noted in:
> https://lore.kernel.org/lkml/20200903184359.GC3495158@kernel.org/
> 
> Signed-off-by: Ian Rogers <irogers@google.com>

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

thanks,
jirka

> ---
>  tools/perf/util/parse-events.c | 4 ++--
>  tools/perf/util/parse-events.h | 2 +-
>  tools/perf/util/parse-events.y | 8 ++++----
>  3 files changed, 7 insertions(+), 7 deletions(-)
> 
> diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> index 667cbca1547a..f82ef1e840b2 100644
> --- a/tools/perf/util/parse-events.c
> +++ b/tools/perf/util/parse-events.c
> @@ -940,12 +940,12 @@ do {					\
>  }
>  
>  int parse_events_add_breakpoint(struct list_head *list, int *idx,
> -				void *ptr, char *type, u64 len)
> +				u64 addr, char *type, u64 len)
>  {
>  	struct perf_event_attr attr;
>  
>  	memset(&attr, 0, sizeof(attr));
> -	attr.bp_addr = (unsigned long) ptr;
> +	attr.bp_addr = addr;
>  
>  	if (parse_breakpoint_type(type, &attr))
>  		return -EINVAL;
> diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
> index 00cde7d2e30c..e80c9b74f2f2 100644
> --- a/tools/perf/util/parse-events.h
> +++ b/tools/perf/util/parse-events.h
> @@ -190,7 +190,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
>  			   struct parse_events_error *error,
>  			   struct list_head *head_config);
>  int parse_events_add_breakpoint(struct list_head *list, int *idx,
> -				void *ptr, char *type, u64 len);
> +				u64 addr, char *type, u64 len);
>  int parse_events_add_pmu(struct parse_events_state *parse_state,
>  			 struct list_head *list, char *name,
>  			 struct list_head *head_config,
> diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
> index 645bf4f1859f..d5b6aff82f21 100644
> --- a/tools/perf/util/parse-events.y
> +++ b/tools/perf/util/parse-events.y
> @@ -511,7 +511,7 @@ PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
>  	list = alloc_list();
>  	ABORT_ON(!list);
>  	err = parse_events_add_breakpoint(list, &parse_state->idx,
> -					(void *)(uintptr_t) $2, $6, $4);
> +					  $2, $6, $4);
>  	free($6);
>  	if (err) {
>  		free(list);
> @@ -528,7 +528,7 @@ PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
>  	list = alloc_list();
>  	ABORT_ON(!list);
>  	if (parse_events_add_breakpoint(list, &parse_state->idx,
> -						(void *)(uintptr_t) $2, NULL, $4)) {
> +					$2, NULL, $4)) {
>  		free(list);
>  		YYABORT;
>  	}
> @@ -544,7 +544,7 @@ PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
>  	list = alloc_list();
>  	ABORT_ON(!list);
>  	err = parse_events_add_breakpoint(list, &parse_state->idx,
> -					(void *)(uintptr_t) $2, $4, 0);
> +					  $2, $4, 0);
>  	free($4);
>  	if (err) {
>  		free(list);
> @@ -561,7 +561,7 @@ PE_PREFIX_MEM PE_VALUE sep_dc
>  	list = alloc_list();
>  	ABORT_ON(!list);
>  	if (parse_events_add_breakpoint(list, &parse_state->idx,
> -						(void *)(uintptr_t) $2, NULL, 0)) {
> +					$2, NULL, 0)) {
>  		free(list);
>  		YYABORT;
>  	}
> -- 
> 2.28.0.681.g6f77f65b4e-goog
> 


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

* Re: [PATCH] perf parse-events: Reduce casts around bp_addr
  2020-09-25 13:01 ` Jiri Olsa
@ 2020-09-28 12:22   ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2020-09-28 12:22 UTC (permalink / raw)
  To: Jiri Olsa
  Cc: Ian Rogers, Peter Zijlstra, Ingo Molnar, Mark Rutland,
	Alexander Shishkin, Namhyung Kim, Jin Yao, Adrian Hunter, Leo Yan,
	linux-kernel, Stephane Eranian

Em Fri, Sep 25, 2020 at 03:01:03PM +0200, Jiri Olsa escreveu:
> On Thu, Sep 24, 2020 at 05:39:03PM -0700, Ian Rogers wrote:
> > perf_event_attr bp_addr is a u64. parse-events.y parses it as a u64, but
> > casts it to a void* and then parse-events.c casts it back to a u64.
> > Rather than all the casts, change the type of the address to be a u64.
> > This removes an issue noted in:
> > https://lore.kernel.org/lkml/20200903184359.GC3495158@kernel.org/
> > 
> > Signed-off-by: Ian Rogers <irogers@google.com>
> 
> Acked-by: Jiri Olsa <jolsa@redhat.com>


Thanks, applied.

- Arnaldo

 
> thanks,
> jirka
> 
> > ---
> >  tools/perf/util/parse-events.c | 4 ++--
> >  tools/perf/util/parse-events.h | 2 +-
> >  tools/perf/util/parse-events.y | 8 ++++----
> >  3 files changed, 7 insertions(+), 7 deletions(-)
> > 
> > diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
> > index 667cbca1547a..f82ef1e840b2 100644
> > --- a/tools/perf/util/parse-events.c
> > +++ b/tools/perf/util/parse-events.c
> > @@ -940,12 +940,12 @@ do {					\
> >  }
> >  
> >  int parse_events_add_breakpoint(struct list_head *list, int *idx,
> > -				void *ptr, char *type, u64 len)
> > +				u64 addr, char *type, u64 len)
> >  {
> >  	struct perf_event_attr attr;
> >  
> >  	memset(&attr, 0, sizeof(attr));
> > -	attr.bp_addr = (unsigned long) ptr;
> > +	attr.bp_addr = addr;
> >  
> >  	if (parse_breakpoint_type(type, &attr))
> >  		return -EINVAL;
> > diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
> > index 00cde7d2e30c..e80c9b74f2f2 100644
> > --- a/tools/perf/util/parse-events.h
> > +++ b/tools/perf/util/parse-events.h
> > @@ -190,7 +190,7 @@ int parse_events_add_cache(struct list_head *list, int *idx,
> >  			   struct parse_events_error *error,
> >  			   struct list_head *head_config);
> >  int parse_events_add_breakpoint(struct list_head *list, int *idx,
> > -				void *ptr, char *type, u64 len);
> > +				u64 addr, char *type, u64 len);
> >  int parse_events_add_pmu(struct parse_events_state *parse_state,
> >  			 struct list_head *list, char *name,
> >  			 struct list_head *head_config,
> > diff --git a/tools/perf/util/parse-events.y b/tools/perf/util/parse-events.y
> > index 645bf4f1859f..d5b6aff82f21 100644
> > --- a/tools/perf/util/parse-events.y
> > +++ b/tools/perf/util/parse-events.y
> > @@ -511,7 +511,7 @@ PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
> >  	list = alloc_list();
> >  	ABORT_ON(!list);
> >  	err = parse_events_add_breakpoint(list, &parse_state->idx,
> > -					(void *)(uintptr_t) $2, $6, $4);
> > +					  $2, $6, $4);
> >  	free($6);
> >  	if (err) {
> >  		free(list);
> > @@ -528,7 +528,7 @@ PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
> >  	list = alloc_list();
> >  	ABORT_ON(!list);
> >  	if (parse_events_add_breakpoint(list, &parse_state->idx,
> > -						(void *)(uintptr_t) $2, NULL, $4)) {
> > +					$2, NULL, $4)) {
> >  		free(list);
> >  		YYABORT;
> >  	}
> > @@ -544,7 +544,7 @@ PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
> >  	list = alloc_list();
> >  	ABORT_ON(!list);
> >  	err = parse_events_add_breakpoint(list, &parse_state->idx,
> > -					(void *)(uintptr_t) $2, $4, 0);
> > +					  $2, $4, 0);
> >  	free($4);
> >  	if (err) {
> >  		free(list);
> > @@ -561,7 +561,7 @@ PE_PREFIX_MEM PE_VALUE sep_dc
> >  	list = alloc_list();
> >  	ABORT_ON(!list);
> >  	if (parse_events_add_breakpoint(list, &parse_state->idx,
> > -						(void *)(uintptr_t) $2, NULL, 0)) {
> > +					$2, NULL, 0)) {
> >  		free(list);
> >  		YYABORT;
> >  	}
> > -- 
> > 2.28.0.681.g6f77f65b4e-goog
> > 
> 

-- 

- Arnaldo

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

end of thread, other threads:[~2020-09-28 12:22 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-09-25  0:39 [PATCH] perf parse-events: Reduce casts around bp_addr Ian Rogers
2020-09-25 13:01 ` Jiri Olsa
2020-09-28 12:22   ` Arnaldo Carvalho de Melo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.