Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp148812pxa; Tue, 4 Aug 2020 19:33:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt9dTt7o/qRSJOCQXMAVTwew/qFHqJu7zudfkXVciaAcvUa5ZPWNRH7N8k1xgdGPXl1W+C X-Received: by 2002:aa7:d809:: with SMTP id v9mr801452edq.94.1596594812896; Tue, 04 Aug 2020 19:33:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1596594812; cv=none; d=google.com; s=arc-20160816; b=Qf+K9RKcX3ThLr4pZwqJlBY7dxLk3nZvHdgLX0t15LZW9f31MU7cetwOKDUree4GCr wqlrT1m+SuI8NVj3lzar4jVJ6zBb+KZj659/TPbcUvBf/2cMC48tsaYW0dau85KIKci/ NVBIY+ATCxwLUUMZU1HJO3nvKoZk/qB6okwjdsilcdw3/kduTYnoa1TV2ZWKXEsxjFlP DfzB5M7X751zQopU9X3E2QIzfRLMQrNquePuWsHrIrI2MnTP/904a+WCZbInnBRFV3m2 /ASnJV3fu/XtJBWQ8GQC6YnE/sYnP/IBnKrzhbbAPDAM8AaiiE84Qr0VBe/rgLXBLrbE V7sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :ironport-sdr:ironport-sdr; bh=BHoeGLKwvUoVYJEy6ZXL7Td5o5FFyni+B3inq3JKn0M=; b=RUNYv8bnicAaG8h22/fBhbBBgzBoSDKiTkEJhn7knJ6Y+b4FVxUE4j/bvh9qpwWjDc OynB3PmRJ1BBKhgxe/elGs7bpinsJR3r2rw546QyG1pQ8jgqmPIYfVRMw27Zt08obcTj Jq2xVu1xCZgiNJ2IP5X5CcNMyvKXUpdg1xshBhcpLr0IcBDYhUMXZYY/Gz9PA9l1Cubo s+DuQkB+mN4kJboja3KnyCRzWpF/BCU7pTX7yLmNlf2qJMlFlblEoSjot4Oxun9xgwjj TTn9QuBuKcsgYQlQVvsFo176MjpeaUfsv8O6MFQ7PljXa9xvHKFxLqUYYM23H/lkx4yD 9WYg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z61si385577ede.593.2020.08.04.19.33.10; Tue, 04 Aug 2020 19:33:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726788AbgHECaq (ORCPT + 99 others); Tue, 4 Aug 2020 22:30:46 -0400 Received: from mga02.intel.com ([134.134.136.20]:34424 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725904AbgHECap (ORCPT ); Tue, 4 Aug 2020 22:30:45 -0400 IronPort-SDR: w0R6HdRuta3wQnwHE3jloiA8hez15e7QvCTXwT1iYV7Iono22BJwauzNuQt7scD6ZhPCcYeH/v +fmzJhqYyU4g== X-IronPort-AV: E=McAfee;i="6000,8403,9703"; a="140353813" X-IronPort-AV: E=Sophos;i="5.75,436,1589266800"; d="scan'208";a="140353813" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Aug 2020 19:30:44 -0700 IronPort-SDR: KiVfCb/EB4siU5NMnIraOgBsPLwm126019NYOkFJzcGATO/rcDIF03kIgqsbp3kaHHKEFAb8i7 zRtwFDVWMIAQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,436,1589266800"; d="scan'208";a="330794387" Received: from kbl-ppc.sh.intel.com ([10.239.159.118]) by FMSMGA003.fm.intel.com with ESMTP; 04 Aug 2020 19:30:42 -0700 From: Jin Yao To: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com Cc: Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com, Jin Yao Subject: [PATCH] perf record: Skip side-band event setup if HAVE_LIBBPF_SUPPORT is not set Date: Wed, 5 Aug 2020 10:29:37 +0800 Message-Id: <20200805022937.29184-1-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We received an error report that perf-record caused 'Segmentation fault' on a newly system (e.g. on the new installed ubuntu). (gdb) backtrace #0 __read_once_size (size=4, res=, p=0x14) at /root/0-jinyao/acme/tools/include/linux/compiler.h:139 #1 atomic_read (v=0x14) at /root/0-jinyao/acme/tools/include/asm/../../arch/x86/include/asm/atomic.h:28 #2 refcount_read (r=0x14) at /root/0-jinyao/acme/tools/include/linux/refcount.h:65 #3 perf_mmap__read_init (map=map@entry=0x0) at mmap.c:177 #4 0x0000561ce5c0de39 in perf_evlist__poll_thread (arg=0x561ce68584d0) at util/sideband_evlist.c:62 #5 0x00007fad78491609 in start_thread (arg=) at pthread_create.c:477 #6 0x00007fad7823c103 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95 The root cause is, evlist__add_bpf_sb_event() just returns 0 if HAVE_LIBBPF_SUPPORT is not defined (inline function path). So it will not create a valid evsel for side-band event. But perf-record still creates BPF side band thread to process the side-band event, then the error happpens. We can reproduce this issue by removing the libelf-dev. e.g. 1. apt-get remove libelf-dev 2. perf record -a -- sleep 1 root@test:~# ./perf record -a -- sleep 1 perf: Segmentation fault Obtained 6 stack frames. ./perf(+0x28eee8) [0x5562d6ef6ee8] /lib/x86_64-linux-gnu/libc.so.6(+0x46210) [0x7fbfdc65f210] ./perf(+0x342e74) [0x5562d6faae74] ./perf(+0x257e39) [0x5562d6ebfe39] /lib/x86_64-linux-gnu/libpthread.so.0(+0x9609) [0x7fbfdc990609] /lib/x86_64-linux-gnu/libc.so.6(clone+0x43) [0x7fbfdc73b103] Segmentation fault (core dumped) To fix this issue, 1. We either install the missing libraries to let HAVE_LIBBPF_SUPPORT be defined. e.g. apt-get install libelf-dev and install other related libraries. 2. Use this patch to skip the side-band event setup if HAVE_LIBBPF_SUPPORT is not set. Signed-off-by: Jin Yao --- tools/perf/builtin-record.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index b6bdccd875bc..ae97f98e2753 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1506,6 +1506,7 @@ static int record__synthesize(struct record *rec, bool tail) return err; } +#ifdef HAVE_LIBBPF_SUPPORT static int record__process_signal_event(union perf_event *event __maybe_unused, void *data) { struct record *rec = data; @@ -1550,6 +1551,12 @@ static int record__setup_sb_evlist(struct record *rec) return 0; } +#else +static int record__setup_sb_evlist(struct record *rec __maybe_unused) +{ + return 0; +} +#endif static int __cmd_record(struct record *rec, int argc, const char **argv) { -- 2.17.1