Commit 998bedc8c56c6869de457c845cbd328592e5e82e

Authored by Frederic Weisbecker
Committed by Ingo Molnar
1 parent 4eec42f392

perf tools: Fix ommitted mmap data update on remap

Commit eac9eacee16 "perf tools: Check we are able to read the event
size on mmap" brought a check to ensure we can read the size of the
event before dereferencing it, and do a remap otherwise to move the
buffer forward.

However that remap was ommitting all the necessary work to
update the new page offset, head, and to unmap previous pages,
etc...

To fix this, gather all the code that fetches the event in a
seperate helper which does all the necessary checks about the
header/event size and tells us anytime a remap is needed.

Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Arnaldo Carvalho de Melo <acme@redhat.com>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/r/1306148788-6179-3-git-send-email-fweisbec@gmail.com
Signed-off-by: Ingo Molnar <mingo@elte.hu>

Showing 1 changed file with 26 additions and 13 deletions Side-by-side Diff

tools/perf/util/session.c
... ... @@ -960,6 +960,30 @@
960 960 return err;
961 961 }
962 962  
  963 +static union perf_event *
  964 +fetch_mmaped_event(struct perf_session *session,
  965 + u64 head, size_t mmap_size, char *buf)
  966 +{
  967 + union perf_event *event;
  968 +
  969 + /*
  970 + * Ensure we have enough space remaining to read
  971 + * the size of the event in the headers.
  972 + */
  973 + if (head + sizeof(event->header) > mmap_size)
  974 + return NULL;
  975 +
  976 + event = (union perf_event *)(buf + head);
  977 +
  978 + if (session->header.needs_swap)
  979 + perf_event_header__bswap(&event->header);
  980 +
  981 + if (head + event->header.size > mmap_size)
  982 + return NULL;
  983 +
  984 + return event;
  985 +}
  986 +
963 987 int __perf_session__process_events(struct perf_session *session,
964 988 u64 data_offset, u64 data_size,
965 989 u64 file_size, struct perf_event_ops *ops)
... ... @@ -1014,19 +1038,8 @@
1014 1038 file_pos = file_offset + head;
1015 1039  
1016 1040 more:
1017   - /*
1018   - * Ensure we have enough space remaining to read
1019   - * the size of the event in the headers.
1020   - */
1021   - if (head + sizeof(event->header) > mmap_size)
1022   - goto remap;
1023   -
1024   - event = (union perf_event *)(buf + head);
1025   -
1026   - if (session->header.needs_swap)
1027   - perf_event_header__bswap(&event->header);
1028   -
1029   - if (head + event->header.size > mmap_size) {
  1041 + event = fetch_mmaped_event(session, head, mmap_size, buf);
  1042 + if (!event) {
1030 1043 if (mmaps[map_idx]) {
1031 1044 munmap(mmaps[map_idx], mmap_size);
1032 1045 mmaps[map_idx] = NULL;