[PATCH 1/2] perf/core: Allow global address filtering for kernel code
From: Andi Kleen
Date: Fri Feb 03 2017 - 17:18:59 EST
From: Andi Kleen <ak@xxxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxxx>
---
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