Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b314e5cf authored by Namhyung Kim's avatar Namhyung Kim Committed by Arnaldo Carvalho de Melo
Browse files

perf session: Fix infinite loop on invalid perf.data file



perf-record updates the header in the perf.data file at termination.
Without this update perf-report (and other processing built-ins) it
caused an infinite loop when perf report (or something like) called.

This is because the algorithm in __perf_session__process_events()
depends on the data_size which is read from file header.  Use file size
directly instead in this case to do the best-effort processing.

Signed-off-by: default avatarNamhyung Kim <namhyung@kernel.org>
Tested-by: default avatarDavid Ahern <dsahern@gmail.com>
Tested-by: default avatarSonny Rao <sonnyrao@chromium.org>
Acked-by: default avatarIngo Molnar <mingo@kernel.org>
Cc: David Ahern <dsahern@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Cc: Sonny Rao <sonnyrao@chromium.org>
Link: http://lkml.kernel.org/r/1380529188-27193-1-git-send-email-namhyung@kernel.org


Signed-off-by: default avatarDavid Ahern <dsahern@gmail.com>
[ Reworded warning as per Ingo Molnar suggestion, replaces 'perf.data'
  with session->filename, to precisely identify the data file involved ]
Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 027a7e86
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -2768,6 +2768,18 @@ int perf_session__read_header(struct perf_session *session)
	if (perf_file_header__read(&f_header, header, fd) < 0)
		return -EINVAL;

	/*
	 * Sanity check that perf.data was written cleanly; data size is
	 * initialized to 0 and updated only if the on_exit function is run.
	 * If data size is still 0 then the file contains only partial
	 * information.  Just warn user and process it as much as it can.
	 */
	if (f_header.data.size == 0) {
		pr_warning("WARNING: The %s file's data size field is 0 which is unexpected.\n"
			   "Was the 'perf record' command properly terminated?\n",
			   session->filename);
	}

	nr_attrs = f_header.attrs.size / f_header.attr_size;
	lseek(fd, f_header.attrs.offset, SEEK_SET);

+1 −1
Original line number Diff line number Diff line
@@ -1312,7 +1312,7 @@ int __perf_session__process_events(struct perf_session *session,
	file_offset = page_offset;
	head = data_offset - page_offset;

	if (data_offset + data_size < file_size)
	if (data_size && (data_offset + data_size < file_size))
		file_size = data_offset + data_size;

	progress_next = file_size / 16;