From patchwork Tue Sep 22 15:22:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaldo Carvalho de Melo X-Patchwork-Id: 53998 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by patches.linaro.org (Postfix) with ESMTPS id 9C65422B1E for ; Tue, 22 Sep 2015 15:22:26 +0000 (UTC) Received: by wisv5 with SMTP id v5sf9967714wis.0 for ; Tue, 22 Sep 2015 08:22:25 -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:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=18/XZC7/PxQRAZId6zRjue0nzx4EPuVaeSxmRjxNWpw=; b=l1D8O82j/TZyq+8T1IVFrfUs2eKUPvaJhaOub5NEBlDTZLr58ZK4+kswqzxMkj9wik xwyfmvlqNNaaHizUDjagZLEfE7/vOAS5W5nJvsAaJSrYJHB1elZYwrz/D5Cnv92EY5hp G7qefBOmn1E26wQp8VDOQpo+nGu7q9qWYJ28KKVIrb3XpfFrKS4NbmiiN+RjyVVW/BoZ L/lLgBdB1h8o7TnQPlgDYwpJQzcgCwzfPwLPdu7x1PtJ3w5BMN9WkPGF1mRU79PuWq3Q j2QFtQPd+BU/gHWipMOKwDZSNUWxJe/618kJgex9HMQ5tiDa5aynkV8+GCr7huluVb7h 06zg== X-Gm-Message-State: ALoCoQlTBs5WgjskqlEKynMGDd4n4GI8/x/n8a1DaoHmwpDSgZ/Tx2czi4CRX9p0uZJAy9mvqoeM X-Received: by 10.112.140.195 with SMTP id ri3mr4489849lbb.22.1442935345942; Tue, 22 Sep 2015 08:22:25 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.25.21.229 with SMTP id 98ls53791lfv.97.gmail; Tue, 22 Sep 2015 08:22:25 -0700 (PDT) X-Received: by 10.152.10.4 with SMTP id e4mr10071394lab.79.1442935345766; Tue, 22 Sep 2015 08:22:25 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com. [209.85.215.47]) by mx.google.com with ESMTPS id o64si725334lfe.117.2015.09.22.08.22.25 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Sep 2015 08:22:25 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by lagj9 with SMTP id j9so17045432lag.2 for ; Tue, 22 Sep 2015 08:22:25 -0700 (PDT) X-Received: by 10.152.5.133 with SMTP id s5mr9936358las.19.1442935345622; Tue, 22 Sep 2015 08:22:25 -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 w3csp552872lbq; Tue, 22 Sep 2015 08:22:24 -0700 (PDT) X-Received: by 10.66.102.7 with SMTP id fk7mr25531875pab.119.1442935344385; Tue, 22 Sep 2015 08:22:24 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pz3si3371081pbb.48.2015.09.22.08.22.23; Tue, 22 Sep 2015 08:22:24 -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 S1758356AbbIVPWW (ORCPT + 30 others); Tue, 22 Sep 2015 11:22:22 -0400 Received: from bombadil.infradead.org ([198.137.202.9]:58092 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757856AbbIVPWU (ORCPT ); Tue, 22 Sep 2015 11:22:20 -0400 Received: from [179.235.152.40] (helo=zoo.infradead.org) by bombadil.infradead.org with esmtpsa (Exim 4.80.1 #2 (Red Hat Linux)) id 1ZePOb-0001Ti-2k; Tue, 22 Sep 2015 15:22:17 +0000 Received: by zoo.infradead.org (Postfix, from userid 1000) id A6E7B22014F; Tue, 22 Sep 2015 12:22:13 -0300 (BRT) From: Arnaldo Carvalho de Melo To: Ingo Molnar Cc: linux-kernel@vger.kernel.org, Mark Rutland , Jiri Olsa , Peter Zijlstra , Arnaldo Carvalho de Melo Subject: [PATCH 1/2] perf record: Avoid infinite loop at buildid processing with no samples Date: Tue, 22 Sep 2015 12:22:11 -0300 Message-Id: <1442935332-20791-2-git-send-email-acme@kernel.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1442935332-20791-1-git-send-email-acme@kernel.org> References: <1442935332-20791-1-git-send-email-acme@kernel.org> X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org See http://www.infradead.org/rpr.html 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: acme@kernel.org 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.47 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: , From: Mark Rutland 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 8a4537ee9bc3..fc3f7c922f99 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...");