From patchwork Tue Sep 25 15:53:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Garry X-Patchwork-Id: 147511 Delivered-To: patch@linaro.org Received: by 2002:a2e:8595:0:0:0:0:0 with SMTP id b21-v6csp893820lji; Tue, 25 Sep 2018 08:53:59 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Dr9MA6bG9EouI0EdC8og82wjcLGgaJAQbTEGMIZ6umigWmRPQcqjpJTXrv/Dd+BjP7Y6f X-Received: by 2002:a63:f616:: with SMTP id m22-v6mr1663060pgh.293.1537890838935; Tue, 25 Sep 2018 08:53:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537890838; cv=none; d=google.com; s=arc-20160816; b=hI4vSFQIwxBmMPDGhvZn8hfLPSOAmv5bYPdKMOmxcNcBgfktsxkSwPa0LJNlmQZQgX KdFTpSyqyH/+OJ3IS5Psf/RbJpPelmNzs6kljBG2Xxj1Be5tIO2RgfzY1QStMwUCo6Yo ZtzjNwme61GXW3Li7OidI6CKGK1QH7TChgQRDDcyt+hoIUq0wMr3Y9HUZJfhsdLjIKPf sp3JFZQ3/KAVPRHNaw5LhhANXF6kf3X2DBzCisB5ITmHWT7hbgpWgjNw1ljpk+HHr1gS +t1x91EWDXshEPKDvXdCeQv3lVyV5xKGH1+aWSGbuXWxzp00v4iK6UMb3AKRw9KFhXcl DtOw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:date:message-id:to:subject:from:cc; bh=8D3GQKtSfq0kjjCW6nQCQgrlI5mZpbfVYxiqiwLsLSU=; b=0bQ+fCrEXJgd5G31cMcaG41VdbMP8o9D9nwm05Tnq+prWk+/fpfDYR9NBoUWsGewex zxGVhWlcnxGHLc0SIk1SKNf1Ws42J9+hqa/BgWbqNkdsISPxv7dcCl73OcRV8AwAZwqz 12x7fCiEoPtpFybYmIaXXY3J6YF8lBI/e7gxAZOmjvnQtz3ieT3HK4gqFsMoCwkTxlAz n3zYKWO6QetNnxWCPF3WwVo+rvzV4G4zUv6akHIs9EZ/JzQCEWDRfN38GlCHrpg+YdV3 IQ6uxu20geTH0HKlNJhN+NlUKDoX5byXQCHC0g281UaIqXr7/3jl47SXi1U5bT6T47S+ Q7Tw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c17-v6si2580917pgp.299.2018.09.25.08.53.58; Tue, 25 Sep 2018 08:53:58 -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; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729603AbeIYWCE (ORCPT + 32 others); Tue, 25 Sep 2018 18:02:04 -0400 Received: from szxga06-in.huawei.com ([45.249.212.32]:60848 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728598AbeIYWCE (ORCPT ); Tue, 25 Sep 2018 18:02:04 -0400 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 78DC81109240A; Tue, 25 Sep 2018 23:53:53 +0800 (CST) Received: from [127.0.0.1] (10.202.226.41) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.399.0; Tue, 25 Sep 2018 23:53:46 +0800 CC: Linuxarm , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , Namhyung Kim From: John Garry Subject: perf segmentation fault from NULL dereference To: Andi Kleen , Jiri Olsa , Ingo Molnar , Peter Zijlstra , "Arnaldo Carvalho de Melo" , Alexander Shishkin Message-ID: <712b7c31-f681-7737-71e7-c028b8d2bba5@huawei.com> Date: Tue, 25 Sep 2018 16:53:40 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.3.0 MIME-Version: 1.0 X-Originating-IP: [10.202.226.41] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, I am seeing this perf crash on my arm64-based system: root@localhost:~# ./perf_debug_ record -e armv8_pmuv3_0/br_mis_pred/ sleep 1 perf: Segmentation fault Obtained 9 stack frames. ./perf_debug_() [0x4c5ef8] [0xffff82ba267c] ./perf_debug_() [0x4bc5a8] ./perf_debug_() [0x419550] ./perf_debug_() [0x41a928] ./perf_debug_() [0x472f58] ./perf_debug_() [0x473210] ./perf_debug_() [0x4070f4] /lib/aarch64-linux-gnu/libc.so.6(__libc_start_main+0xe0) [0xffff8294c8a0] Segmentation fault (core dumped) I find 'cycles' event is fine. I bisected the issue to here: commit bfd8f72c2778f5bd63dc9eb6d23bd7a0d99cff6d (HEAD, refs/bisect/bad) Author: Andi Kleen Date: Fri Nov 17 13:42:58 2017 -0800 perf record: Synthesize unit/scale/... in event update Move the code to synthesize event updates for scale/unit/cpus to a common utility file, and use it both from stat and record. This allows to access scale and other extra qualifiers from perf script. Signed-off-by: Andi Kleen Acked-by: Jiri Olsa Link: http://lkml.kernel.org/r/20171117214300.32746-2-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo I am suspicious that this is a real issue, as this patch has been in mainline for some time... This simple change fixes the issue me: ev = cpu_map_data__alloc(evsel->own_cpus, &size, &type, &max); It turns out that evsel->id is NULL on a call to perf_event__process_feature(), which upsets this code: ev->header.type = PERF_RECORD_EVENT_UPDATE; ev->header.size = (u16)size; ev->type = PERF_EVENT_UPDATE__CPUS; ev->id = evsel->id[0]; Please me let me know if a valid issue so we can get a fix in. Apologies for crying wolf if I'm off the mark. Cheers, John Tested-by: John Garry diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c index 91e6d9c..f4fd826 100644 --- a/tools/perf/util/header.c +++ b/tools/perf/util/header.c @@ -3576,7 +3576,7 @@ int perf_event__process_feature(struct perf_tool *tool, int max, err; u16 type; - if (!evsel->own_cpus) + if (!evsel->own_cpus || !(evsel->attr.read_format & PERF_FORMAT_ID)) // roundabout check for !evsel->id return 0;