All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH V3 0/3] perf/core: Miscellaneous fix for address filtering
@ 2016-08-11 19:47 Mathieu Poirier
  2016-08-11 19:47 ` [PATCH V3 1/3] perf/core: Fixing filename for start/stop filters Mathieu Poirier
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mathieu Poirier @ 2016-08-11 19:47 UTC (permalink / raw)
  To: peterz; +Cc: mingo, alexander.shishkin, linux-kernel

This patchset has been sent out late in the 4.7 cycle, probably too late
for the merge window.  Resending here after making sure it applies to
v4.8-rc1 - please consider for merging.

Thanks,
Mathieu 

Mathieu Poirier (3):
  perf/core: Fixing filename for start/stop filters
  perf/core: Update filter only on executable mmap
  perf/core: Enabling mapping of the stop filters

 kernel/events/core.c | 28 ++++++++++++++++------------
 1 file changed, 16 insertions(+), 12 deletions(-)

-- 
2.7.4

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

* [PATCH V3 1/3] perf/core: Fixing filename for start/stop filters
  2016-08-11 19:47 [PATCH V3 0/3] perf/core: Miscellaneous fix for address filtering Mathieu Poirier
@ 2016-08-11 19:47 ` Mathieu Poirier
  2016-08-11 19:47 ` [PATCH V3 2/3] perf/core: Update filter only on executable mmap Mathieu Poirier
  2016-08-11 19:47 ` [PATCH V3 3/3] perf/core: Enabling mapping of the stop filters Mathieu Poirier
  2 siblings, 0 replies; 4+ messages in thread
From: Mathieu Poirier @ 2016-08-11 19:47 UTC (permalink / raw)
  To: peterz; +Cc: mingo, alexander.shishkin, linux-kernel

Binary file names have to be supplied for both range and start/stop
filters but the current code only process the filename if an
address range filter is specified.  This code adds processing of
the filename for start/stop filters.

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 kernel/events/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index a19550d80ab1..0662279c5729 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -7905,8 +7905,10 @@ perf_event_parse_addr_filter(struct perf_event *event, char *fstr,
 					goto fail;
 			}
 
-			if (token == IF_SRC_FILE) {
-				filename = match_strdup(&args[2]);
+			if (token == IF_SRC_FILE || token == IF_SRC_FILEADDR) {
+				int fpos = filter->range ? 2 : 1;
+
+				filename = match_strdup(&args[fpos]);
 				if (!filename) {
 					ret = -ENOMEM;
 					goto fail;
-- 
2.7.4

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

* [PATCH V3 2/3] perf/core: Update filter only on executable mmap
  2016-08-11 19:47 [PATCH V3 0/3] perf/core: Miscellaneous fix for address filtering Mathieu Poirier
  2016-08-11 19:47 ` [PATCH V3 1/3] perf/core: Fixing filename for start/stop filters Mathieu Poirier
@ 2016-08-11 19:47 ` Mathieu Poirier
  2016-08-11 19:47 ` [PATCH V3 3/3] perf/core: Enabling mapping of the stop filters Mathieu Poirier
  2 siblings, 0 replies; 4+ messages in thread
From: Mathieu Poirier @ 2016-08-11 19:47 UTC (permalink / raw)
  To: peterz; +Cc: mingo, alexander.shishkin, linux-kernel

Function perf_event_mmap() is called by the MM subsystem each time
part of a binary is loaded in memory.  There can be several mapping
for a binary, many times unrelated to the code section.

Each time a section of a binary is mapped address filters are
updated, event when the map doesn't pertain to the code section.
The end result is that filters are configured based on the last map
event that was received rather than the last mapping of the code
segment.

For example if we have an executable 'main' that calls library
'libcstest.so.1.0', and that we want to collect traces on code
that is in that library.  The perf cmd line for this scenario
would be:

perf record -e cs_etm// --filter 'filter 0x72c/0x40@/opt/lib/libcstest.so.1.0' --per-thread ./main

Resulting in binaries being mapped this way:

root@linaro-nano:~# cat /proc/1950/maps
00400000-00401000 r-xp 00000000 08:02 33169     /home/linaro/main
00410000-00411000 r--p 00000000 08:02 33169     /home/linaro/main
00411000-00412000 rw-p 00001000 08:02 33169     /home/linaro/main
7fa2464000-7fa2474000 rw-p 00000000 00:00 0
7fa2474000-7fa25a4000 r-xp 00000000 08:02 543   /lib/aarch64-linux-gnu/libc-2.21.so
7fa25a4000-7fa25b3000 ---p 00130000 08:02 543   /lib/aarch64-linux-gnu/libc-2.21.so
7fa25b3000-7fa25b7000 r--p 0012f000 08:02 543   /lib/aarch64-linux-gnu/libc-2.21.so
7fa25b7000-7fa25b9000 rw-p 00133000 08:02 543   /lib/aarch64-linux-gnu/libc-2.21.so
7fa25b9000-7fa25bd000 rw-p 00000000 00:00 0
7fa25bd000-7fa25be000 r-xp 00000000 08:02 38308 /opt/lib/libcstest.so.1.0
7fa25be000-7fa25cd000 ---p 00001000 08:02 38308 /opt/lib/libcstest.so.1.0
7fa25cd000-7fa25ce000 r--p 00000000 08:02 38308 /opt/lib/libcstest.so.1.0
7fa25ce000-7fa25cf000 rw-p 00001000 08:02 38308 /opt/lib/libcstest.so.1.0
7fa25cf000-7fa25eb000 r-xp 00000000 08:02 574   /lib/aarch64-linux-gnu/ld-2.21.so
7fa25ef000-7fa25f2000 rw-p 00000000 00:00 0
7fa25f7000-7fa25f9000 rw-p 00000000 00:00 0
7fa25f9000-7fa25fa000 r--p 00000000 00:00 0     [vvar]
7fa25fa000-7fa25fb000 r-xp 00000000 00:00 0     [vdso]
7fa25fb000-7fa25fc000 r--p 0001c000 08:02 574   /lib/aarch64-linux-gnu/ld-2.21.so
7fa25fc000-7fa25fe000 rw-p 0001d000 08:02 574   /lib/aarch64-linux-gnu/ld-2.21.so
7ff2ea8000-7ff2ec9000 rw-p 00000000 00:00 0     [stack]
root@linaro-nano:~#

Before 'main' can execute 'libcstest.so.1.0' has to be loaded in
memory.  Once that has been done perf_event_mmap() has been called
4 times, with the last map starting at address 0x7fa25ce000 and
the address filter configured to start filtering when the
IP has passed over address 0x0x7fa25ce72c (0x7fa25ce000 + 0x72c).

But that is wrong since the code segment for library 'libcstest.so.1.0'
as been mapped at 0x7fa25bd000, resulting in traces not being
collected.

This patch corrects the situation by requesting that address
filters be updated only if the mapped event is for a code
segment.

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Cc: <stable@vger.kernel.org> # 4.7
Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 kernel/events/core.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 0662279c5729..463235ffc39c 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6622,6 +6622,13 @@ static void perf_addr_filters_adjust(struct vm_area_struct *vma)
 	struct perf_event_context *ctx;
 	int ctxn;
 
+	/*
+	 * Data tracing isn't supported yet and as such there is no need
+	 * to keep track of anything that isn't related to executable code.
+	 */
+	if (!(vma->vm_flags & VM_EXEC))
+		return;
+
 	rcu_read_lock();
 	for_each_task_context_nr(ctxn) {
 		ctx = rcu_dereference(current->perf_event_ctxp[ctxn]);
-- 
2.7.4

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

* [PATCH V3 3/3] perf/core: Enabling mapping of the stop filters
  2016-08-11 19:47 [PATCH V3 0/3] perf/core: Miscellaneous fix for address filtering Mathieu Poirier
  2016-08-11 19:47 ` [PATCH V3 1/3] perf/core: Fixing filename for start/stop filters Mathieu Poirier
  2016-08-11 19:47 ` [PATCH V3 2/3] perf/core: Update filter only on executable mmap Mathieu Poirier
@ 2016-08-11 19:47 ` Mathieu Poirier
  2 siblings, 0 replies; 4+ messages in thread
From: Mathieu Poirier @ 2016-08-11 19:47 UTC (permalink / raw)
  To: peterz; +Cc: mingo, alexander.shishkin, linux-kernel

At this time function perf_addr_filter_needs_mmap() will _not_
return true on a user space 'stop' filter.  But stop filters
needs exactly the same kind of mapping that range and start
filters get.

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Acked-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
---
 kernel/events/core.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/kernel/events/core.c b/kernel/events/core.c
index 463235ffc39c..b5022836649a 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -6553,15 +6553,6 @@ got_name:
 }
 
 /*
- * Whether this @filter depends on a dynamic object which is not loaded
- * yet or its load addresses are not known.
- */
-static bool perf_addr_filter_needs_mmap(struct perf_addr_filter *filter)
-{
-	return filter->filter && filter->inode;
-}
-
-/*
  * Check whether inode and address range match filter criteria.
  */
 static bool perf_addr_filter_match(struct perf_addr_filter *filter,
@@ -7781,7 +7772,11 @@ static void perf_event_addr_filters_apply(struct perf_event *event)
 	list_for_each_entry(filter, &ifh->list, entry) {
 		event->addr_filters_offs[count] = 0;
 
-		if (perf_addr_filter_needs_mmap(filter))
+		/*
+		 * Adjust base offset if the filter is associated to a binary
+		 * that needs to be mapped.
+		 */
+		if (filter->inode)
 			event->addr_filters_offs[count] =
 				perf_addr_filter_apply(filter, mm);
 
-- 
2.7.4

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

end of thread, other threads:[~2016-08-11 19:47 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-11 19:47 [PATCH V3 0/3] perf/core: Miscellaneous fix for address filtering Mathieu Poirier
2016-08-11 19:47 ` [PATCH V3 1/3] perf/core: Fixing filename for start/stop filters Mathieu Poirier
2016-08-11 19:47 ` [PATCH V3 2/3] perf/core: Update filter only on executable mmap Mathieu Poirier
2016-08-11 19:47 ` [PATCH V3 3/3] perf/core: Enabling mapping of the stop filters Mathieu Poirier

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.