From patchwork Mon Sep 7 12:51:55 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wang Nan X-Patchwork-Id: 53234 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by patches.linaro.org (Postfix) with ESMTPS id 6634722B06 for ; Mon, 7 Sep 2015 12:56:11 +0000 (UTC) Received: by wicgb1 with SMTP id gb1sf25115919wic.3 for ; Mon, 07 Sep 2015 05:56:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:cc:subject:date:message-id :mime-version:content-type:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=qKuZatIAFhQKjxe/msD9NO/dVXL4qicxv1VU3uMSCGY=; b=ddGrSGRLw3S02jM2ZwbRiSsIoQgO4a80aMvsHpK9fxixeXAjG1ysxrhCNy2LoSrkZ1 DyGgiIaDSFREDB8pdKT3R7VmZaSW9X/J3Q5WQGBaQ43ynyX3WirVgRYmnvXRM95jWmno MmLZHzCsEu//aw0UhqDDS75vjn763HN3WW+4cD3JQPNAI6h9TYUM8eNeZmyd4sEMyFnb S4PXyN1fi+xpcI6Mo3VHOtXAa3WzVJgVG8J8sZCarZrjDd6FKGeDxMT+5iBfXPUq3ER4 6Q5un4q6oNRGcuyCKR6TByUqM9woYf1VU0btzR+09nhSCm0jrFe4FavzfsH5pAjvmSKa aa8A== X-Gm-Message-State: ALoCoQlZOEexlHWYqVold3IFGYWVHCPYWyqZgZywmvT52PjPf/n+z1jp23A8TDrXRT05SDjQmO9M X-Received: by 10.180.89.104 with SMTP id bn8mr5062597wib.4.1441630570719; Mon, 07 Sep 2015 05:56:10 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.180.75 with SMTP id dm11ls118795lac.102.gmail; Mon, 07 Sep 2015 05:56:10 -0700 (PDT) X-Received: by 10.152.8.233 with SMTP id u9mr17084181laa.8.1441630570520; Mon, 07 Sep 2015 05:56:10 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com. [209.85.217.181]) by mx.google.com with ESMTPS id r3si5936894lar.2.2015.09.07.05.56.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 07 Sep 2015 05:56:10 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by lbcao8 with SMTP id ao8so38753379lbc.3 for ; Mon, 07 Sep 2015 05:56:10 -0700 (PDT) X-Received: by 10.112.166.106 with SMTP id zf10mr16858058lbb.36.1441630570323; Mon, 07 Sep 2015 05:56:10 -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 w3csp361793lbq; Mon, 7 Sep 2015 05:56:09 -0700 (PDT) X-Received: by 10.68.135.161 with SMTP id pt1mr45459911pbb.47.1441630569327; Mon, 07 Sep 2015 05:56:09 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e5si19971756pas.193.2015.09.07.05.56.08; Mon, 07 Sep 2015 05:56:09 -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 S1752135AbbIGM4H (ORCPT + 28 others); Mon, 7 Sep 2015 08:56:07 -0400 Received: from szxga01-in.huawei.com ([58.251.152.64]:60705 "EHLO szxga01-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751450AbbIGM4C (ORCPT ); Mon, 7 Sep 2015 08:56:02 -0400 Received: from 172.24.1.48 (EHLO szxeml431-hub.china.huawei.com) ([172.24.1.48]) by szxrg01-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id CUM90630; Mon, 07 Sep 2015 20:52:12 +0800 (CST) Received: from linux-4hy3.site (10.107.193.248) by szxeml431-hub.china.huawei.com (10.82.67.208) with Microsoft SMTP Server id 14.3.235.1; Mon, 7 Sep 2015 20:52:01 +0800 From: Wang Nan To: , CC: , , , Wang Nan , Adrian Hunter , Andi Kleen , Jiri Olsa , Namhyung Kim , Stephane Eranian , "Arnaldo Carvalho de Melo" Subject: [PATCH] perf report: Fix invalid memory accessing Date: Mon, 7 Sep 2015 12:51:55 +0000 Message-ID: <1441630315-189525-1-git-send-email-wangnan0@huawei.com> X-Mailer: git-send-email 1.8.3.4 MIME-Version: 1.0 X-Originating-IP: [10.107.193.248] X-CFilter-Loop: Reflected 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: wangnan0@huawei.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.217.181 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: , Commit e1e499aba570a2ea84d29822b7ea637ac41d9a51 (perf tools: Add processor socket info to hist_entry and addr_location) reads env->cpu array for each sample using index al.cpu. However, al.cpu can be -1 if sample doesn't select PERF_SAMPLE_CPU. Also, env->cpu can be invalid if feature CPU_TOPOLOGY not selected. We should validate env->cpu and al.cpu before setting al.socket. Signed-off-by: Wang Nan Cc: Kan Liang Cc: Adrian Hunter Cc: Andi Kleen Cc: Jiri Olsa Cc: Namhyung Kim Cc: Stephane Eranian Cc: Arnaldo Carvalho de Melo --- Although theoretically CPU_TOPOLOGY feature should always be selected by 'perf record', I did generate a perf.data without that feature. It has header like this: # perf report -i ./bad.perf.data --header-only # ======== # captured on: Thu Jan 8 09:30:15 2009 # hostname : localhost # os release : 3.10.49-gd672fc4 # perf version : 4.2.gc9df # arch : aarch64 # nrcpus online : 8 # nrcpus avail : 8 # total memory : 1850768 kB # cmdline : /system/bin/perf record -e sync:sync_timeline -e kgsl:kgsl_register_event -g -a sleep 5 # event : name = sync:sync_timeline, , id = { 1107, 1108, 1109, 1110, 1111, 1112 }, type = 2, size = 112, config = 0x3e7, { sample_period, sample_freq } = 1, sample_type = IP|TID|TIME|CALLCHAIN|ID|CPU|PERIOD|RAW, read_format = ID, disabled = 1, inherit = 1, mmap = 1, comm = 1, task = 1, sample_id_all = 1, exclude_guest = 1, mmap2 = 1, comm_exec = 1 # event : name = kgsl:kgsl_register_event, , id = { 1113, 1114, 1115, 1116, 1117, 1118 }, type = 2, size = 112, config = 0x350, { sample_period, sample_freq } = 1, sample_type = IP|TID|TIME|CALLCHAIN|ID|CPU|PERIOD|RAW, read_format = ID, disabled = 1, inherit = 1, sample_id_all = 1, exclude_guest = 1 # pmu mappings: cpu = 4, software = 1, tracepoint = 2 # ======== # It should be: # ======== # captured on: Thu Jan 8 11:26:41 2009 ... # HEADER_CPU_TOPOLOGY info available, use -I to display # pmu mappings: cpu = 4, software = 1, tracepoint = 2 # ======== However, bad perf.data appears randomly. I can't stably reproduce it, so I guess there might have another invalid memory accessing. --- tools/perf/builtin-report.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tools/perf/builtin-report.c b/tools/perf/builtin-report.c index 4b43245..16d097d 100644 --- a/tools/perf/builtin-report.c +++ b/tools/perf/builtin-report.c @@ -158,8 +158,16 @@ static int process_sample_event(struct perf_tool *tool, return -1; } - /* read socket id from perf.data for perf report */ - al.socket = env->cpu[al.cpu].socket_id; + /* + * read socket id from perf.data for perf report + * al.cpu is invalid if PERF_SAMPLE_CPU is not selected by this + * sample. + * env->cpu is invalid if CPU_TOPOLOGY feature is not set in + * header. + */ + al.socket = -1; + if (env->cpu && al.cpu >= 0) + al.socket = env->cpu[al.cpu].socket_id; if (rep->hide_unresolved && al.sym == NULL) goto out_put;