Skip to content

Commit f972eb6

Browse files
Peter Zijlstraolsajiri
authored andcommitted
perf: Pass protection and flags bits through mmap2 interface
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 <[email protected]> [tweaked patch to compile and wrote changelog] Signed-off-by: Don Zickus <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Jiri Olsa <[email protected]>
1 parent e646fe7 commit f972eb6

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

include/uapi/linux/perf_event.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,7 @@ enum perf_event_type {
705705
* u32 min;
706706
* u64 ino;
707707
* u64 ino_generation;
708+
* u32 prot, flags;
708709
* char filename[];
709710
* struct sample_id sample_id;
710711
* };

kernel/events/core.c

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <linux/mm_types.h>
4141
#include <linux/cgroup.h>
4242
#include <linux/module.h>
43+
#include <linux/mman.h>
4344

4445
#include "internal.h"
4546

@@ -5127,6 +5128,7 @@ struct perf_mmap_event {
51275128
int maj, min;
51285129
u64 ino;
51295130
u64 ino_generation;
5131+
u32 prot, flags;
51305132

51315133
struct {
51325134
struct perf_event_header header;
@@ -5168,6 +5170,8 @@ static void perf_event_mmap_output(struct perf_event *event,
51685170
mmap_event->event_id.header.size += sizeof(mmap_event->min);
51695171
mmap_event->event_id.header.size += sizeof(mmap_event->ino);
51705172
mmap_event->event_id.header.size += sizeof(mmap_event->ino_generation);
5173+
mmap_event->event_id.header.size += sizeof(mmap_event->prot);
5174+
mmap_event->event_id.header.size += sizeof(mmap_event->flags);
51715175
}
51725176

51735177
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,
51865190
perf_output_put(&handle, mmap_event->min);
51875191
perf_output_put(&handle, mmap_event->ino);
51885192
perf_output_put(&handle, mmap_event->ino_generation);
5193+
perf_output_put(&handle, mmap_event->prot);
5194+
perf_output_put(&handle, mmap_event->flags);
51895195
}
51905196

51915197
__output_copy(&handle, mmap_event->file_name,
@@ -5204,6 +5210,7 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
52045210
struct file *file = vma->vm_file;
52055211
int maj = 0, min = 0;
52065212
u64 ino = 0, gen = 0;
5213+
u32 prot = 0, flags = 0;
52075214
unsigned int size;
52085215
char tmp[16];
52095216
char *buf = NULL;
@@ -5234,6 +5241,28 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
52345241
gen = inode->i_generation;
52355242
maj = MAJOR(dev);
52365243
min = MINOR(dev);
5244+
5245+
if (vma->vm_flags & VM_READ)
5246+
prot |= PROT_READ;
5247+
if (vma->vm_flags & VM_WRITE)
5248+
prot |= PROT_WRITE;
5249+
if (vma->vm_flags & VM_EXEC)
5250+
prot |= PROT_EXEC;
5251+
5252+
if (vma->vm_flags & VM_MAYSHARE)
5253+
flags = MAP_SHARED;
5254+
else
5255+
flags = MAP_PRIVATE;
5256+
5257+
if (vma->vm_flags & VM_DENYWRITE)
5258+
flags |= MAP_DENYWRITE;
5259+
if (vma->vm_flags & VM_MAYEXEC)
5260+
flags |= MAP_EXECUTABLE;
5261+
if (vma->vm_flags & VM_LOCKED)
5262+
flags |= MAP_LOCKED;
5263+
if (vma->vm_flags & VM_HUGETLB)
5264+
flags |= MAP_HUGETLB;
5265+
52375266
goto got_name;
52385267
} else {
52395268
name = (char *)arch_vma_name(vma);
@@ -5274,6 +5303,8 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
52745303
mmap_event->min = min;
52755304
mmap_event->ino = ino;
52765305
mmap_event->ino_generation = gen;
5306+
mmap_event->prot = prot;
5307+
mmap_event->flags = flags;
52775308

52785309
if (!(vma->vm_flags & VM_EXEC))
52795310
mmap_event->event_id.header.misc |= PERF_RECORD_MISC_MMAP_DATA;
@@ -5314,6 +5345,8 @@ void perf_event_mmap(struct vm_area_struct *vma)
53145345
/* .min (attr_mmap2 only) */
53155346
/* .ino (attr_mmap2 only) */
53165347
/* .ino_generation (attr_mmap2 only) */
5348+
/* .prot (attr_mmap2 only) */
5349+
/* .flags (attr_mmap2 only) */
53175350
};
53185351

53195352
perf_event_mmap_event(&mmap_event);

0 commit comments

Comments
 (0)