From patchwork Wed Sep 16 17:18:49 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mark Rutland X-Patchwork-Id: 53755 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by patches.linaro.org (Postfix) with ESMTPS id 7032322A0D for ; Wed, 16 Sep 2015 17:19:21 +0000 (UTC) Received: by lbbti1 with SMTP id ti1sf71691992lbb.3 for ; Wed, 16 Sep 2015 10:19:20 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=LZA0UZAuh0PzEO9BEuLG5U0uPmxyMrvCm9l4aNCL9s4=; b=Iy1NZycBhb7XaeQPTpNlqOiFnAbcU2vsIqqARHSJRM63CowcfdxywJ4414AD9158ky G26nayEABDvwFsc3uexgq1LYqsJJgbyLJIHLxrSsijp0kU+EDJnl1+UUkTNX7VG47CCm p7844XQPTNA0EF5Fcid4jNAwBeg2F/kMwbLcfE+u3TT96Jd6yI1N+Bu/Z1DGGqZq4Z4+ pFqdtt3+YmFWHyMU+kZLucAp9hoh8sAhIgqwY0oPVqWAWndgcNUerJIKIb+ueHLLei4h CadpyG94FErGwvJhXrOWpYa54QmEkjC4fbkCFZ9+IuJsY6w/SqVwjXJsVuAt0y7bPios hN9A== X-Gm-Message-State: ALoCoQnHL4kZRIfs1vOSC8YciQLNHtHD2rXOj3LGCBO8VNiZU3Mt2JKDB1IsmvgCqG135Cu28jha X-Received: by 10.152.120.233 with SMTP id lf9mr1394577lab.2.1442423960417; Wed, 16 Sep 2015 10:19:20 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.1.232 with SMTP id 8ls913753lap.103.gmail; Wed, 16 Sep 2015 10:19:20 -0700 (PDT) X-Received: by 10.152.10.34 with SMTP id f2mr30378076lab.37.1442423960220; Wed, 16 Sep 2015 10:19:20 -0700 (PDT) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id p10si11761283laf.142.2015.09.16.10.19.20 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 16 Sep 2015 10:19:20 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by lamp12 with SMTP id p12so132424685lam.0 for ; Wed, 16 Sep 2015 10:19:20 -0700 (PDT) X-Received: by 10.112.180.230 with SMTP id dr6mr20051798lbc.72.1442423960023; Wed, 16 Sep 2015 10:19:20 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.59.35 with SMTP id w3csp2583324lbq; Wed, 16 Sep 2015 10:19:19 -0700 (PDT) X-Received: by 10.107.137.162 with SMTP id t34mr50760316ioi.103.1442423959006; Wed, 16 Sep 2015 10:19:19 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k191si18202638iok.29.2015.09.16.10.19.18; Wed, 16 Sep 2015 10:19:18 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754033AbbIPRTP (ORCPT + 29 others); Wed, 16 Sep 2015 13:19:15 -0400 Received: from foss.arm.com ([217.140.101.70]:37773 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752683AbbIPRTM (ORCPT ); Wed, 16 Sep 2015 13:19:12 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 776655F9; Wed, 16 Sep 2015 10:19:12 -0700 (PDT) Received: from leverpostej.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.72.51.249]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 20FE13F51B; Wed, 16 Sep 2015 10:19:10 -0700 (PDT) From: Mark Rutland To: linux-kernel@vger.kernel.org Cc: Mark Rutland , Adrian Hunter , Arnaldo Carvalho de Melo , Ingo Molnar , Jiri Olsa , Peter Zijlstra Subject: [PATCH] perf tools: session: avoid infinite loop Date: Wed, 16 Sep 2015 18:18:49 +0100 Message-Id: <1442423929-12253-1-git-send-email-mark.rutland@arm.com> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: mark.rutland@arm.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) smtp.mailfrom=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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). Signed-off-by: Mark Rutland Cc: Adrian Hunter Cc: Arnaldo Carvalho de Melo Cc: Ingo Molnar Cc: Jiri Olsa Cc: Peter Zijlstra --- 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...");