linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] perf/core: Allow global address filtering for kernel code
@ 2017-02-03 22:18 Andi Kleen
  2017-02-03 22:18 ` [PATCH 2/2] perf tools: Support end symbols with no size for filters Andi Kleen
  0 siblings, 1 reply; 4+ messages in thread
From: Andi Kleen @ 2017-02-03 22:18 UTC (permalink / raw)
  To: peterz; +Cc: alexander.shishkin, linux-kernel, Andi Kleen

From: Andi Kleen <ak@linux.intel.com>

The address filter code disallows filtering for per-cpu events,
because it would require dynamically changing user address filters
in context switches.

For the special case of filtering on kernel code only,
we can allow it, as the kernel code always stays at the same
addresses.

So move the check for the global filter in the parser code
and only check after we know there are user space filters.

In addition also handle this case when applying the filter.

Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 kernel/events/core.c | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 110b38a58493..15fd58177e73 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -8016,6 +8016,9 @@ static void perf_event_addr_filters_apply(struct perf_event *event)
 	if (task == TASK_TOMBSTONE)
 		return;
 
+	if (!event->ctx->task)
+		goto restart;
+
 	mm = get_task_mm(event->ctx->task);
 	if (!mm)
 		goto restart;
@@ -8190,6 +8193,20 @@ perf_event_parse_addr_filter(struct perf_event *event, char *fstr,
 				goto fail;
 
 			if (!kernel) {
+				/*
+				 * For now, we only support user
+				 * filtering in per-task events; doing
+				 * so for CPU-wide events requires
+				 * additional context switching
+				 * trickery, since same object code
+				 * will be mapped at different virtual
+				 * addresses in different processes.
+				 */
+				ret = -EOPNOTSUPP;
+				if (!event->ctx->task)
+					goto fail;
+
+				ret = -EINVAL;
 				if (!filename)
 					goto fail;
 
@@ -8247,15 +8264,6 @@ perf_event_set_addr_filter(struct perf_event *event, char *filter_str)
 	if (WARN_ON_ONCE(event->parent))
 		return -EINVAL;
 
-	/*
-	 * For now, we only support filtering in per-task events; doing so
-	 * for CPU-wide events requires additional context switching trickery,
-	 * since same object code will be mapped at different virtual
-	 * addresses in different processes.
-	 */
-	if (!event->ctx->task)
-		return -EOPNOTSUPP;
-
 	ret = perf_event_parse_addr_filter(event, filter_str, &filters);
 	if (ret)
 		return ret;
-- 
2.9.3

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

* [PATCH 2/2] perf tools: Support end symbols with no size for filters
  2017-02-03 22:18 [PATCH 1/2] perf/core: Allow global address filtering for kernel code Andi Kleen
@ 2017-02-03 22:18 ` Andi Kleen
  2017-02-06 13:15   ` Adrian Hunter
  0 siblings, 1 reply; 4+ messages in thread
From: Andi Kleen @ 2017-02-03 22:18 UTC (permalink / raw)
  To: peterz; +Cc: alexander.shishkin, linux-kernel, Andi Kleen, adrian.hunter

From: Andi Kleen <ak@linux.intel.com>

Currently a filter like
--filter "filter _text / _end"
doesn't work because _end doesn't have a size. The
filter resolution always wants to use the end of the function
as end.

Allow this case by assuming the filter just spawns to the
start of the end symbol when there is no size. This makes
the above useful filter work.

Cc: adrian.hunter@intel.com
Signed-off-by: Andi Kleen <ak@linux.intel.com>
---
 tools/perf/util/auxtrace.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index c5a6e0b12452..4c5ccb2b1298 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -1840,7 +1840,12 @@ static int addr_filter__resolve_kernel_syms(struct addr_filter *filt)
 		if (err)
 			return err;
 		filt->size = start + size - filt->addr;
-		no_size = !!size;
+		/*
+		 * When to has no size assume it's a end symbol.
+		 * This allows filters like _text / _end
+		 */
+		if (size == 0)
+			filt->size = start - filt->addr;
 	}
 
 	/* The very last symbol in kallsyms does not imply a particular size */
-- 
2.9.3

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

* Re: [PATCH 2/2] perf tools: Support end symbols with no size for filters
  2017-02-03 22:18 ` [PATCH 2/2] perf tools: Support end symbols with no size for filters Andi Kleen
@ 2017-02-06 13:15   ` Adrian Hunter
  2017-02-09 22:59     ` Andi Kleen
  0 siblings, 1 reply; 4+ messages in thread
From: Adrian Hunter @ 2017-02-06 13:15 UTC (permalink / raw)
  To: Andi Kleen, peterz; +Cc: alexander.shishkin, linux-kernel, Andi Kleen

On 04/02/17 00:18, Andi Kleen wrote:
> From: Andi Kleen <ak@linux.intel.com>
> 
> Currently a filter like
> --filter "filter _text / _end"
> doesn't work because _end doesn't have a size. The
> filter resolution always wants to use the end of the function
> as end.
> 
> Allow this case by assuming the filter just spawns to the
> start of the end symbol when there is no size. This makes
> the above useful filter work.
> 
> Cc: adrian.hunter@intel.com
> Signed-off-by: Andi Kleen <ak@linux.intel.com>
> ---
>  tools/perf/util/auxtrace.c | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index c5a6e0b12452..4c5ccb2b1298 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
> @@ -1840,7 +1840,12 @@ static int addr_filter__resolve_kernel_syms(struct addr_filter *filt)
>  		if (err)
>  			return err;
>  		filt->size = start + size - filt->addr;
> -		no_size = !!size;

Erk!  Isn't the logic is the wrong way around here.  Sorry!
i.e. should be:

diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
index c5a6e0b12452..78bd632f144d 100644
--- a/tools/perf/util/auxtrace.c
+++ b/tools/perf/util/auxtrace.c
@@ -1826,7 +1826,7 @@ static int addr_filter__resolve_kernel_syms(struct addr_filter *filt)
 		filt->addr = start;
 		if (filt->range && !filt->size && !filt->sym_to) {
 			filt->size = size;
-			no_size = !!size;
+			no_size = !size;
 		}
 	}
 
@@ -1840,7 +1840,7 @@ static int addr_filter__resolve_kernel_syms(struct addr_filter *filt)
 		if (err)
 			return err;
 		filt->size = start + size - filt->addr;
-		no_size = !!size;
+		no_size = !size;
 	}
 
 	/* The very last symbol in kallsyms does not imply a particular size */

> +		/*
> +		 * When to has no size assume it's a end symbol.
> +		 * This allows filters like _text / _end
> +		 */
> +		if (size == 0)
> +			filt->size = start - filt->addr;
>  	}
>  
>  	/* The very last symbol in kallsyms does not imply a particular size */
> 

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

* Re: [PATCH 2/2] perf tools: Support end symbols with no size for filters
  2017-02-06 13:15   ` Adrian Hunter
@ 2017-02-09 22:59     ` Andi Kleen
  0 siblings, 0 replies; 4+ messages in thread
From: Andi Kleen @ 2017-02-09 22:59 UTC (permalink / raw)
  To: Adrian Hunter; +Cc: Andi Kleen, peterz, alexander.shishkin, linux-kernel

> > -		no_size = !!size;
> 
> Erk!  Isn't the logic is the wrong way around here.  Sorry!
> i.e. should be:

Yes it works with that change too.

> 
> diff --git a/tools/perf/util/auxtrace.c b/tools/perf/util/auxtrace.c
> index c5a6e0b12452..78bd632f144d 100644
> --- a/tools/perf/util/auxtrace.c
> +++ b/tools/perf/util/auxtrace.c
> @@ -1826,7 +1826,7 @@ static int addr_filter__resolve_kernel_syms(struct addr_filter *filt)
>  		filt->addr = start;
>  		if (filt->range && !filt->size && !filt->sym_to) {
>  			filt->size = size;
> -			no_size = !!size;
> +			no_size = !size;
>  		}
>  	}
>  
> @@ -1840,7 +1840,7 @@ static int addr_filter__resolve_kernel_syms(struct addr_filter *filt)
>  		if (err)
>  			return err;
>  		filt->size = start + size - filt->addr;
> -		no_size = !!size;
> +		no_size = !size;
>  	}
>  

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

end of thread, other threads:[~2017-02-09 23:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-03 22:18 [PATCH 1/2] perf/core: Allow global address filtering for kernel code Andi Kleen
2017-02-03 22:18 ` [PATCH 2/2] perf tools: Support end symbols with no size for filters Andi Kleen
2017-02-06 13:15   ` Adrian Hunter
2017-02-09 22:59     ` Andi Kleen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).