Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4288376pxb; Mon, 1 Feb 2021 18:29:49 -0800 (PST) X-Google-Smtp-Source: ABdhPJzky/ohlgr0tfM/JN2bSje8Y96QfnJzWOEJfCEm243VQ4pHOqbWIBpEi/LV8+gXs3BT/3l5 X-Received: by 2002:a17:906:6bca:: with SMTP id t10mr20247478ejs.35.1612232989058; Mon, 01 Feb 2021 18:29:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1612232989; cv=none; d=google.com; s=arc-20160816; b=mGSUlI90dKvcBWTyuGUlMt6P1MMi1R4Mz5yb2Wt3K06Myg3Xt63Abn5vSHutGbUSbZ beetvdv+/d0UQ55s57LzNpYCPzjelAGYZMyN1auRf01OgvMPBHpOlKxDWjmYJuYp0PF3 DpCvkEO1Ra40gIQmDbXyScyfhC6cR8VtCHl6NQF2KVk76X2jzEwrPEmMOSMcZG2zzzJ7 zM830ZVsKfml1HbUd2BGllkY3U698RqKBfNUt/s7S+l7ZBnWnt/Psr8YRhbFFnrwWoR3 /mCoy3Iu21RIv8MUmkvCBi6fa9AozVhJqdK6dPu+cPlH0WFp6sEujA4OXfe4G5n1YdFC PbFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from:ironport-sdr :ironport-sdr; bh=Y/wwpo0Y3MfBbehye0ZSjoWMqr+72ATzbhsrcN0wcQM=; b=NkvhlnKu+3PNBI972/oTNOj++hd9JGJZguNYqk0IclC8ypIkizxy9cZZENX5Ppb7rN fdktFdhdsMG7rj2VmykluGLY3/RKjhi6O3XrKkF1P7/6LstcCcSWPHjqvWFgucPFx9A9 qR8lxUu3oIcxPnPbCkQ3tefqWxVufmNLcbTG3+zCAul5y1uRN8vQMaqCcHDQ9L55xWpV v6OCqmgEVLPQs8F9Re6z//4MA5pHtfmBkp8EbJF2VXo1bNC2XSsrXPyaS4vm/Qb+Jerh s6j5LMoqyZmZ3Ak5a3qZkFkR3ibNFm9rztSbWPkJhmIhNxlkB7WtVwYqtOGqP+BJibaS 99jQ== 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 c15si11606634ejr.124.2021.02.01.18.29.25; Mon, 01 Feb 2021 18:29:49 -0800 (PST) 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 S231160AbhBBC1F (ORCPT + 99 others); Mon, 1 Feb 2021 21:27:05 -0500 Received: from mga14.intel.com ([192.55.52.115]:40273 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229612AbhBBC1B (ORCPT ); Mon, 1 Feb 2021 21:27:01 -0500 IronPort-SDR: P9iaLMxu/mifkhPVLXnkeEFS1kgPQX5L9X3H5TAJu0Ra4uDa1vq5SUK3yydG8+M/90G7cD3+zd DBScRaGXC5hQ== X-IronPort-AV: E=McAfee;i="6000,8403,9882"; a="180009046" X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="180009046" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 01 Feb 2021 18:25:16 -0800 IronPort-SDR: BwjMNl1gpT2wbFsYBKn4zpeRWFwksJQFNqnWVgFz7ohL2fSBapHZw4AXT4Bb8IxR848GM2K2ZR Mvo8wk8iQj5A== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.79,393,1602572400"; d="scan'208";a="479385046" Received: from kbl-ppc.sh.intel.com ([10.239.159.163]) by fmsmga001.fm.intel.com with ESMTP; 01 Feb 2021 18:25:13 -0800 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, john.garry@huawei.com, Jin Yao Subject: [PATCH] perf metricgroup: Fix segmentation fault for metrics with no pmu event Date: Tue, 2 Feb 2021 10:24:24 +0800 Message-Id: <20210202022424.10787-1-yao.jin@linux.intel.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hit a segmentation fault for DRAM_BW_Use on SKL/KBL. # perf stat -M DRAM_BW_Use -a -- sleep 1 Segmentation fault (core dumped) (gdb) backtrace #0 __strcmp_sse2_unaligned () at ../sysdeps/x86_64/multiarch/strcmp-sse2-unaligned.S:31 #1 0x0000555c9facd9ce in find_evsel_group (evlist_used=0x555ca16d09c0, metric_events=0x555ca16e9160, has_constraint=false, metric_no_merge=false, pctx=0x555ca16c8ff0, perf_evlist=0x555ca16c5340) at util/metricgroup.c:281 #2 metricgroup__setup_events (metric_events_list=0x555ca0044378 , perf_evlist=0x555ca16c5340, metric_no_merge=, groups=0x7ffc599193f0) at util/metricgroup.c:323 #3 parse_groups (perf_evlist=perf_evlist@entry=0x555ca16c5340, str=str@entry=0x7ffc599205f8 "DRAM_BW_Use", metric_no_group=metric_no_group@entry=false, metric_no_merge=metric_no_merge@entry=false, fake_pmu=fake_pmu@entry=0x0, metric_events=metric_events@entry=0x555ca0044378 , map=0x555ca004e780 ) at util/metricgroup.c:1235 #4 0x0000555c9face096 in metricgroup__parse_groups (opt=, str=0x7ffc599205f8 "DRAM_BW_Use", metric_no_group=, metric_no_merge=, metric_events=0x555ca0044378 ) at util/metricgroup.c:1253 #5 0x0000555c9fbd084e in get_value (p=p@entry=0x7ffc599196b0, opt=0x555ca0043f60 , flags=flags@entry=1) at parse-options.c:251 #6 0x0000555c9fbd1aa2 in parse_short_opt (options=, p=) at parse-options.c:351 #7 parse_options_step (usagestr=0x7ffc59919830, options=0x555ca0042fa0 , ctx=0x7ffc599196b0) at parse-options.c:539 #8 parse_options_subcommand (argc=argc@entry=7, argv=argv@entry=0x7ffc5991e6c0, options=options@entry=0x555ca0042fa0 , subcommands=subcommands@entry=0x7ffc59919840, usagestr=usagestr@entry=0x7ffc59919830, flags=flags@entry=2) at parse-options.c:654 #9 0x0000555c9fa15154 in cmd_stat (argc=7, argv=0x7ffc5991e6c0) at builtin-stat.c:2136 #10 0x0000555c9fa8bafd in run_builtin (p=0x555ca004df20 , argc=7, argv=0x7ffc5991e6c0) at perf.c:312 #11 0x0000555c9f9f413a in handle_internal_command (argv=0x7ffc5991e6c0, argc=7) at perf.c:364 #12 run_argv (argcp=, argv=) at perf.c:408 #13 main (argc=7, argv=0x7ffc5991e6c0) at perf.c:538 DRAM_BW_Use uses an event 'duration_time' but it doesn't have pmu, so ev->leader->pmu_name is NULL for this case. See following code piece: !strcmp(ev->leader->pmu_name, metric_events[i]->leader->pmu_name) It causes the segmentation fault. Now check the pmu_name before strcmp. Fixes: c2337d67199a("perf metricgroup: Fix metrics using aliases covering multiple PMUs") Signed-off-by: Jin Yao --- tools/perf/util/metricgroup.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index ee94d3e8dd65..a36a1305c506 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -280,6 +280,7 @@ static struct evsel *find_evsel_group(struct evlist *perf_evlist, */ if (!has_constraint && ev->leader != metric_events[i]->leader && + ev->leader->pmu_name && !strcmp(ev->leader->pmu_name, metric_events[i]->leader->pmu_name)) break; -- 2.17.1