From: Jiri Olsa <jolsa@kernel.org>
To: Ingo Molnar <mingo@kernel.org>
Cc: linux-kernel@vger.kernel.org,
Peter Zijlstra <a.p.zijlstra@chello.nl>,
Peter Zijlstra <peterz@infradead.org>,
Don Zickus <dzickus@redhat.com>, Jiri Olsa <jolsa@kernel.org>
Subject: [PATCH 08/15] perf: Pass protection and flags bits through mmap2 interface
Date: Mon, 9 Jun 2014 22:02:23 +0200 [thread overview]
Message-ID: <1402344150-14860-9-git-send-email-jolsa@kernel.org> (raw)
In-Reply-To: <1402344150-14860-1-git-send-email-jolsa@kernel.org>
From: Peter Zijlstra <a.p.zijlstra@chello.nl>
The mmap2 interface was missing the protection and flags bits needed to
accurately determine if a mmap memory area was shared or private and
if it was readable or not.
Signed-off-by: Peter Zijlstra <peterz@infradead.org>
[tweaked patch to compile and wrote changelog]
Signed-off-by: Don Zickus <dzickus@redhat.com>
Link: http://lkml.kernel.org/r/1400526833-141779-2-git-send-email-dzickus@redhat.com
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
include/uapi/linux/perf_event.h | 1 +
kernel/events/core.c | 33 +++++++++++++++++++++++++++++++++
2 files changed, 34 insertions(+)
diff --git a/include/uapi/linux/perf_event.h b/include/uapi/linux/perf_event.h
index 5312fae..9269de2 100644
--- a/include/uapi/linux/perf_event.h
+++ b/include/uapi/linux/perf_event.h
@@ -705,6 +705,7 @@ enum perf_event_type {
* u32 min;
* u64 ino;
* u64 ino_generation;
+ * u32 prot, flags;
* char filename[];
* struct sample_id sample_id;
* };
diff --git a/kernel/events/core.c b/kernel/events/core.c
index 7da5e56..eea1955 100644
--- a/kernel/events/core.c
+++ b/kernel/events/core.c
@@ -40,6 +40,7 @@
#include <linux/mm_types.h>
#include <linux/cgroup.h>
#include <linux/module.h>
+#include <linux/mman.h>
#include "internal.h"
@@ -5127,6 +5128,7 @@ struct perf_mmap_event {
int maj, min;
u64 ino;
u64 ino_generation;
+ u32 prot, flags;
struct {
struct perf_event_header header;
@@ -5168,6 +5170,8 @@ static void perf_event_mmap_output(struct perf_event *event,
mmap_event->event_id.header.size += sizeof(mmap_event->min);
mmap_event->event_id.header.size += sizeof(mmap_event->ino);
mmap_event->event_id.header.size += sizeof(mmap_event->ino_generation);
+ mmap_event->event_id.header.size += sizeof(mmap_event->prot);
+ mmap_event->event_id.header.size += sizeof(mmap_event->flags);
}
perf_event_header__init_id(&mmap_event->event_id.header, &sample, event);
@@ -5186,6 +5190,8 @@ static void perf_event_mmap_output(struct perf_event *event,
perf_output_put(&handle, mmap_event->min);
perf_output_put(&handle, mmap_event->ino);
perf_output_put(&handle, mmap_event->ino_generation);
+ perf_output_put(&handle, mmap_event->prot);
+ perf_output_put(&handle, mmap_event->flags);
}
__output_copy(&handle, mmap_event->file_name,
@@ -5204,6 +5210,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
struct file *file = vma->vm_file;
int maj = 0, min = 0;
u64 ino = 0, gen = 0;
+ u32 prot = 0, flags = 0;
unsigned int size;
char tmp[16];
char *buf = NULL;
@@ -5234,6 +5241,28 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
gen = inode->i_generation;
maj = MAJOR(dev);
min = MINOR(dev);
+
+ if (vma->vm_flags & VM_READ)
+ prot |= PROT_READ;
+ if (vma->vm_flags & VM_WRITE)
+ prot |= PROT_WRITE;
+ if (vma->vm_flags & VM_EXEC)
+ prot |= PROT_EXEC;
+
+ if (vma->vm_flags & VM_MAYSHARE)
+ flags = MAP_SHARED;
+ else
+ flags = MAP_PRIVATE;
+
+ if (vma->vm_flags & VM_DENYWRITE)
+ flags |= MAP_DENYWRITE;
+ if (vma->vm_flags & VM_MAYEXEC)
+ flags |= MAP_EXECUTABLE;
+ if (vma->vm_flags & VM_LOCKED)
+ flags |= MAP_LOCKED;
+ if (vma->vm_flags & VM_HUGETLB)
+ flags |= MAP_HUGETLB;
+
goto got_name;
} else {
name = (char *)arch_vma_name(vma);
@@ -5274,6 +5303,8 @@ got_name:
mmap_event->min = min;
mmap_event->ino = ino;
mmap_event->ino_generation = gen;
+ mmap_event->prot = prot;
+ mmap_event->flags = flags;
if (!(vma->vm_flags & VM_EXEC))
mmap_event->event_id.header.misc |= PERF_RECORD_MISC_MMAP_DATA;
@@ -5314,6 +5345,8 @@ void perf_event_mmap(struct vm_area_struct *vma)
/* .min (attr_mmap2 only) */
/* .ino (attr_mmap2 only) */
/* .ino_generation (attr_mmap2 only) */
+ /* .prot (attr_mmap2 only) */
+ /* .flags (attr_mmap2 only) */
};
perf_event_mmap_event(&mmap_event);
--
1.8.3.1
next prev parent reply other threads:[~2014-06-09 20:03 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-06-09 20:02 [GIT PULL 00/15] perf/core improvements and fixes Jiri Olsa
2014-06-09 20:02 ` [PATCH 01/15] tools lib traceevent: Add flag to not load event plugins Jiri Olsa
2014-06-09 20:02 ` [PATCH 02/15] tools lib traceevent: Add options to plugins Jiri Olsa
2014-06-09 20:02 ` [PATCH 03/15] tools lib traceevent: Add options to function plugin Jiri Olsa
2014-06-09 20:02 ` [PATCH 04/15] tools lib traceevent: Added support for __get_bitmask() macro Jiri Olsa
2014-06-09 20:02 ` [PATCH 05/15] perf tools: Fix pipe check regression in attr event callback Jiri Olsa
2014-06-09 20:02 ` [PATCH 06/15] perf tools: Prettify the tags/TAGS/cscope targets output Jiri Olsa
2014-06-09 20:02 ` [PATCH 07/15] perf script/python: Print array argument as string Jiri Olsa
2014-06-09 20:02 ` Jiri Olsa [this message]
2014-06-09 20:02 ` [PATCH 09/15] perf tools: Update mmap2 interface with protection and flag bits Jiri Olsa
2014-06-09 20:02 ` [PATCH 10/15] Revert "perf: Disable PERF_RECORD_MMAP2 support" Jiri Olsa
2014-06-09 20:02 ` [PATCH 11/15] perf report: Add mem-mode documentation to report command Jiri Olsa
2014-06-09 20:02 ` [PATCH 12/15] perf tools: Add cpumode to struct hist_entry Jiri Olsa
2014-06-09 20:02 ` [PATCH 13/15] perf tools: Add support to dynamically get cacheline size Jiri Olsa
2014-06-09 20:02 ` [PATCH 14/15] perf tools: Add dcacheline sort Jiri Olsa
2014-06-09 20:02 ` [PATCH 15/15] perf tools: Support spark lines in perf stat Jiri Olsa
2014-06-10 5:04 ` Ingo Molnar
2014-06-10 7:37 ` Peter Zijlstra
2014-06-12 11:54 ` [GIT PULL 00/15] perf/core improvements and fixes Ingo Molnar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1402344150-14860-9-git-send-email-jolsa@kernel.org \
--to=jolsa@kernel.org \
--cc=a.p.zijlstra@chello.nl \
--cc=dzickus@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.