Skip to content

Commit 7fb0a5e

Browse files
nikunjadacmel
authored andcommitted
perf kvm: Finding struct machine fails for PERF_RECORD_MMAP
Running 'perf kvm --host --guest --guestmount /tmp/guestmount record -a -g -- sleep 2' Was resulting in a segfault. For event type PERF_RECORD_MMAP, event->ip.pid is being used in perf_session__find_machine_for_cpumode, which is not correct. The event->ip.pid field happens to be 0 in this case and results in returning a NULL machine object. Finally, access to self->pid in machine__mmap_name, results in a segfault later. For PERF_RECORD_MMAP type, pass event->mmap.pid. Signed-off-by: Nikunj A. Dadhania <[email protected]> Reviewed-by: David Ahern <[email protected]> Tested-by: David Ahern <[email protected]> Cc: David Ahern <[email protected]> Cc: Frederic Weisbecker <[email protected]> Cc: Ingo Molnar <[email protected]> Cc: Paul Mackerras <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Nikunj A. Dadhania <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 31d68e7 commit 7fb0a5e

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

tools/perf/util/session.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -826,8 +826,16 @@ static struct machine *
826826
{
827827
const u8 cpumode = event->header.misc & PERF_RECORD_MISC_CPUMODE_MASK;
828828

829-
if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest)
830-
return perf_session__find_machine(session, event->ip.pid);
829+
if (cpumode == PERF_RECORD_MISC_GUEST_KERNEL && perf_guest) {
830+
u32 pid;
831+
832+
if (event->header.type == PERF_RECORD_MMAP)
833+
pid = event->mmap.pid;
834+
else
835+
pid = event->ip.pid;
836+
837+
return perf_session__find_machine(session, pid);
838+
}
831839

832840
return perf_session__find_host_machine(session);
833841
}

0 commit comments

Comments
 (0)