Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp428075pxu; Thu, 26 Nov 2020 02:14:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJwVAoSuZGhmaoWZS9Skh23385Ag2HC9/vctODw12HBVqOuNNKnqYMYzHXiKW25ILefiATy8 X-Received: by 2002:a50:f98b:: with SMTP id q11mr1792630edn.345.1606385684474; Thu, 26 Nov 2020 02:14:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606385684; cv=none; d=google.com; s=arc-20160816; b=C1QEncxANmrcLiy858dQHG9/aw8oLyi0IvBu4dLugpbV4oUcEad6ae5NFHo2v8Bcrk 41FNHid400AsHsySxVzmvIhemnCq6JOCfn593sQ0jvePd+VHaoPEbfHSRzWyYw05egT7 rV1I1daTGIi9LydlXosswqcltNrQcs1Cb/i67mJDEq0f3zpkETK27rbbT+vbcN9r/d6J BhEnhwcqDaOwPGArENMvdLKScIPB7N4RSCcC8OYA/Hw+s4UTc26g569poplYOwhz7RqA Swx1qGl4uQV+p3IWAzFZ9WWMMzng3yxO4dhwqkYfL/OXswg7U4yXUa6RYODV96mEepOr pPNQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=/lLIVNWU60teNO32UCLRWiBgeP/zrEkdsNrEvcyO+J8=; b=Oskv+IF2mmIzxhQF7XKYHbZ1pTYXd/mIvdkVj++SyLY2je4tcOO+9sl1fCTMwggaUz JP4l+CCTKEP8BeihRCBXf2ign0DuQ/1nyLbEZjzoJJKkO1bulBYnkUfw/BQpec2WuMkp gDK65qSI+IH1LFuochTQEaI2Ues0usjFxRVec4NRXQX9nqpAkFlmJ/p7b7I3mg8qNWkj 6RmNT31/JGnfMzsww1tU3x6Xnn6Cltk34B8MOlk2JdhrOkw0NfWJbszi6b+J1aIA7/rU Kndbk55XKTeFthIfqzOaHJqAzmDU8X/ZfL62DHXZzyH7Gf+pA8ryXBmWXSVvMFoeNcjH 5pyg== 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 i12si2898828edr.244.2020.11.26.02.14.21; Thu, 26 Nov 2020 02:14:44 -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 S2388288AbgKZHHB (ORCPT + 99 others); Thu, 26 Nov 2020 02:07:01 -0500 Received: from mga11.intel.com ([192.55.52.93]:43220 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388248AbgKZHHA (ORCPT ); Thu, 26 Nov 2020 02:07:00 -0500 IronPort-SDR: g5ncQLcTw5tnJjMeXcL/w7VIrtUqVekWPXr/3grE17VHKu+fEzJ7PAXoTYHINJIJn28AbSrnnX i4uPQ7Yr9E7Q== X-IronPort-AV: E=McAfee;i="6000,8403,9816"; a="168738293" X-IronPort-AV: E=Sophos;i="5.78,371,1599548400"; d="scan'208";a="168738293" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2020 23:06:59 -0800 IronPort-SDR: Q4k3HavhM5h6Zfp3d3mU1ySpbyz5o6zPpzZAh9h1Kf3r7xFREvu27e1o1wFzuWDrSwrRSJ9Ro7 RxFCHSFXuO8w== X-IronPort-AV: E=Sophos;i="5.78,371,1599548400"; d="scan'208";a="479243562" Received: from yjin15-mobl1.ccr.corp.intel.com (HELO [10.238.4.27]) ([10.238.4.27]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 25 Nov 2020 23:06:55 -0800 Subject: Re: [PATCH] perf script: Fix overrun issue for dynamically-allocated pmu type number To: Adrian Hunter , 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 References: <20201126032425.19226-1-yao.jin@linux.intel.com> From: "Jin, Yao" Message-ID: <8509ed3b-378f-5ee0-5a3e-bbd8cb9d86c4@linux.intel.com> Date: Thu, 26 Nov 2020 15:06:53 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Adrian, On 11/26/2020 2:51 PM, Adrian Hunter wrote: > On 26/11/20 5:24 am, Jin Yao wrote: >> When unpacking the event which is from dynamic pmu, the array >> output[OUTPUT_TYPE_MAX] may be overrun. For example, type number of >> SKL uncore_imc is 10, but OUTPUT_TYPE_MAX is 7 now (OUTPUT_TYPE_MAX = >> PERF_TYPE_MAX + 1). >> >> /* In builtin-script.c */ >> process_event() >> { >> unsigned int type = output_type(attr->type); >> >> if (output[type].fields == 0) >> return; >> } >> >> output[10] is overrun. >> >> Create a type OUTPUT_TYPE_OTHER for dynamic pmu events, then >> output_type(attr->type) will return OUTPUT_TYPE_OTHER here. >> >> Note that if PERF_TYPE_MAX ever changed, then there would be a conflict >> between old perf.data files that had a dynamicaliy allocated PMU number >> that would then be the same as a fixed PERF_TYPE. >> >> Example: >> >> perf record --switch-events -C 0 -e "{cpu-clock,uncore_imc/data_reads/,uncore_imc/data_writes/}:SD" -a -- sleep 1 >> perf script >> >> Before: >> swapper 0 [000] 1479253.987551: 277766 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> swapper 0 [000] 1479253.987797: 246709 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> swapper 0 [000] 1479253.988127: 329883 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> swapper 0 [000] 1479253.988273: 146393 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> swapper 0 [000] 1479253.988523: 249977 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> swapper 0 [000] 1479253.988877: 354090 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> swapper 0 [000] 1479253.989023: 145940 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> swapper 0 [000] 1479253.989383: 359856 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> swapper 0 [000] 1479253.989523: 140082 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> >> After: >> swapper 0 [000] 1397040.402011: 272384 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> swapper 0 [000] 1397040.402011: 5396 uncore_imc/data_reads/: >> swapper 0 [000] 1397040.402011: 967 uncore_imc/data_writes/: >> swapper 0 [000] 1397040.402259: 249153 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> swapper 0 [000] 1397040.402259: 7231 uncore_imc/data_reads/: >> swapper 0 [000] 1397040.402259: 1297 uncore_imc/data_writes/: >> swapper 0 [000] 1397040.402508: 249108 cpu-clock: ffffffff9d4ddb6f cpuidle_enter_state+0xdf ([kernel.kallsyms]) >> swapper 0 [000] 1397040.402508: 5333 uncore_imc/data_reads/: >> swapper 0 [000] 1397040.402508: 1008 uncore_imc/data_writes/: >> >> Fixes: 1405720d4f26 ("perf script: Add 'synth' event type for synthesized events") > > It does not look to me like the problem was introduced by that commit. Are > you sure this Fixes tag is correct? > Commit 1405720d4f26 added the change: @@ -1215,8 +1253,9 @@ static void process_event(struct perf_script *script, { struct thread *thread = al->thread; struct perf_event_attr *attr = &evsel->attr; + unsigned int type = output_type(attr->type); - if (output[attr->type].fields == 0) + if (output[type].fields == 0) return; But of course, we can also say the original "output[attr->type].fields" introduced the issue, I'm not sure. Maybe Arnaldo can help to make the decision. :) Thanks Jin Yao