From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753543AbbIWInh (ORCPT ); Wed, 23 Sep 2015 04:43:37 -0400 Received: from terminus.zytor.com ([198.137.202.10]:34792 "EHLO terminus.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753484AbbIWIn3 (ORCPT ); Wed, 23 Sep 2015 04:43:29 -0400 Date: Wed, 23 Sep 2015 01:42:45 -0700 From: tip-bot for Mark Rutland Message-ID: Cc: acme@redhat.com, hpa@zytor.com, linux-kernel@vger.kernel.org, acme@kernel.org, mingo@kernel.org, mark.rutland@arm.com, jolsa@redhat.com, adrian.hunter@intel.com, peterz@infradead.org, tglx@linutronix.de Reply-To: mark.rutland@arm.com, jolsa@redhat.com, tglx@linutronix.de, peterz@infradead.org, adrian.hunter@intel.com, acme@redhat.com, hpa@zytor.com, linux-kernel@vger.kernel.org, acme@kernel.org, mingo@kernel.org In-Reply-To: <1442423929-12253-1-git-send-email-mark.rutland@arm.com> References: <1442423929-12253-1-git-send-email-mark.rutland@arm.com> To: linux-tip-commits@vger.kernel.org Subject: [tip:perf/core] perf record: Avoid infinite loop at buildid processing with no samples Git-Commit-ID: 381c02f6d8ccad8ed574630f879c40fb59715124 X-Mailer: tip-git-log-daemon Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=UTF-8 Content-Disposition: inline Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit-ID: 381c02f6d8ccad8ed574630f879c40fb59715124 Gitweb: http://git.kernel.org/tip/381c02f6d8ccad8ed574630f879c40fb59715124 Author: Mark Rutland AuthorDate: Wed, 16 Sep 2015 18:18:49 +0100 Committer: Arnaldo Carvalho de Melo CommitDate: Fri, 18 Sep 2015 12:31:40 -0300 perf record: Avoid infinite loop at buildid processing with no samples If a session contains no events, we can get stuck in an infinite loop in __perf_session__process_events, with a non-zero file_size and data_offset, but a zero data_size. In this case, we can mmap the entirety of the file (consisting of the file and attribute headers), and fetch_mmaped_event will correctly refuse to read any (unmapped and non-existent) event headers. This causes __perf_session__process_events to unmap the file and retry with the exact same parameters, getting stuck in an infinite loop. This has been observed to result in an exit-time hang when counting rare/unschedulable events with perf record, and can be triggered artificially with the script below: ---- #!/bin/sh printf "REPRO: launching perf\n"; ./perf record -e software/config=9/ sleep 1 & PERF_PID=$!; sleep 0.002; kill -2 $PERF_PID; printf "REPRO: waiting for perf (%d) to exit...\n" "$PERF_PID"; wait $PERF_PID; printf "REPRO: perf exited\n"; ---- To avoid this, have __perf_session__process_events bail out early when the file has no data (i.e. it has no events). Commiter note: I only managed to reproduce this when setting /proc/sys/kernel/kptr_restrict to '1' and changing the code to purposefully not process any samples and no synthesized samples, i.e. kptr_restrict prevents 'record' from synthesizing the kernel mmaps for vmlinux + modules and since it is a workload started from perf, we don't synthesize mmap/comm records for existing threads. Adrian Hunter managed to reproduce it in his environment tho. Signed-off-by: Mark Rutland Tested-by: Arnaldo Carvalho de Melo Tested-by: Adrian Hunter Cc: Jiri Olsa Cc: Peter Zijlstra Link: http://lkml.kernel.org/r/1442423929-12253-1-git-send-email-mark.rutland@arm.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/util/session.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tools/perf/util/session.c b/tools/perf/util/session.c index 8a4537e..fc3f7c9 100644 --- a/tools/perf/util/session.c +++ b/tools/perf/util/session.c @@ -1580,7 +1580,10 @@ static int __perf_session__process_events(struct perf_session *session, file_offset = page_offset; head = data_offset - page_offset; - if (data_size && (data_offset + data_size < file_size)) + if (data_size == 0) + goto out; + + if (data_offset + data_size < file_size) file_size = data_offset + data_size; ui_progress__init(&prog, file_size, "Processing events...");