Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1722388pxb; Mon, 8 Mar 2021 04:59:35 -0800 (PST) X-Google-Smtp-Source: ABdhPJyCVwVlw3a25Xi3kt6ZL94quKTMLUb7t8pHEfXxO+FdyojRu7uwAxeZvgJJkSqoYFYN1K2m X-Received: by 2002:aa7:cf90:: with SMTP id z16mr22019417edx.273.1615208375423; Mon, 08 Mar 2021 04:59:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615208375; cv=none; d=google.com; s=arc-20160816; b=l/uBpQMXWp2M8exWQcDsN3kjccWp0Gx7VocrZHuahZxFKpzyRnsZ1cjEnhuzPOoLiR ufD4dxjqTxvftIFIzjpg/BEPpzPf1+Hlq62JjGC1raggsBnHd0wd8BJUWVGXV2v70fwR fQ3iKsNgS2ad3xU9EiEToSjtctnrdJVAzqyn1r/ZF8XoUsGJk8BoYOnE9F0WaZ7PxvJt teHT7of7hmBysmCkPwFIlI5ZbJE5QpHegWvm5Z4z6+ABM8De0EUxJO/vxKcpVL8ZKRQ1 1OLxYT6oZSoLyGtYeULYbQ0mPnk/N7uZ8xAs84RhBtG1/eQtn9xp6qrRhfULVT+Sl21D xJEw== 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=Nxz/NKeABK8Gs1f155TltOFWcZqST4g6js3wK7blp4w=; b=yat+Whc9f7A2mFJ0/R1+cm1orCrHgwWeob7K23BHjMYULO6E0TOnbG0LvNAAtCBJCV LlZafFrX6QFjGlAsnYz2qRKyFDZuLCxTKbafIKzL0hLFfgmypFmHQZEPuwEapeiwrHZ0 DXJaStjraZ74o8NfppKBxqhmHgBTPvcVNeljDScl7czhpPBC3MzE6GfCrjmqdfk3VbYP aWN9Hr0ve8ndCDuQPNAoNNIBcWQzcETpgIV4iszkCAF8NdEnyyDEiXwUoDFj+CuRNG2p H5wpkykQ+eQQy7vN8cPkob3Cozo6LLNRW/SVEiSQ8Ws5jkOokZrH3IGNhdFg/K++Nc0m WfhQ== 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 e7si6755093ejz.428.2021.03.08.04.59.12; Mon, 08 Mar 2021 04:59:35 -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 S229573AbhCHM6C (ORCPT + 99 others); Mon, 8 Mar 2021 07:58:02 -0500 Received: from mga01.intel.com ([192.55.52.88]:14592 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229459AbhCHM54 (ORCPT ); Mon, 8 Mar 2021 07:57:56 -0500 IronPort-SDR: qB7c5mIyGQRxaXJHNw7QOAvu1n4fRS3a/kdturSHHnDnS7n+VSReOjgGaLKcq0zfu9hxUUbyMU D3ALZIMkEl2w== X-IronPort-AV: E=McAfee;i="6000,8403,9916"; a="207786806" X-IronPort-AV: E=Sophos;i="5.81,232,1610438400"; d="scan'208";a="207786806" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2021 04:57:56 -0800 IronPort-SDR: KLfwtnP4cQslc8+bjJygTR3OoeonRsGy+kYS6FRmKvSBDKNIjH69/5/I6rHSoWmB46Amay2mLn //8H7F5uuEhQ== X-IronPort-AV: E=Sophos;i="5.81,232,1610438400"; d="scan'208";a="409289301" Received: from yjin15-mobl1.ccr.corp.intel.com (HELO [10.249.172.44]) ([10.249.172.44]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Mar 2021 04:57:51 -0800 Subject: Re: [PATCH v3] perf pmu: Validate raw event with sysfs exported format bits To: Jiri Olsa Cc: acme@kernel.org, jolsa@kernel.org, peterz@infradead.org, mingo@redhat.com, alexander.shishkin@linux.intel.com, Linux-kernel@vger.kernel.org, ak@linux.intel.com, kan.liang@intel.com, yao.jin@intel.com References: <20210308031506.23019-1-yao.jin@linux.intel.com> From: "Jin, Yao" Message-ID: Date: Mon, 8 Mar 2021 20:57:49 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.8.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 Jiri, On 3/8/2021 6:35 PM, Jiri Olsa wrote: > On Mon, Mar 08, 2021 at 11:15:06AM +0800, Jin Yao wrote: > > SNIP > >> diff --git a/tools/perf/util/pmu.c b/tools/perf/util/pmu.c >> index 44ef28302fc7..03ab1e6d0418 100644 >> --- a/tools/perf/util/pmu.c >> +++ b/tools/perf/util/pmu.c >> @@ -1812,3 +1812,39 @@ int perf_pmu__caps_parse(struct perf_pmu *pmu) >> >> return nr_caps; >> } >> + >> +void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, >> + char *name) >> +{ >> + struct perf_pmu_format *format; >> + __u64 masks = 0, bits; >> + char buf[100]; >> + unsigned int i; >> + >> + list_for_each_entry(format, &pmu->format, list) { >> + /* >> + * Skip extra configs such as config1/config2. >> + */ >> + if (format->value > 0) >> + continue; > > sorry I did not notice before, but could you please use more direct > approach like: > > if (format->value == PERF_PMU_FORMAT_VALUE_CONFIG) { > break; > } > > this will be more obvious, also no need for the comment.. I spent some > time looking what's the value for ;-) > > thanks, > jirka > Oh, yes, using PERF_PMU_FORMAT_VALUE_CONFIG is much more obvious. Sorry about that! While it can't break the loop, because we need to iterate over the whole list to get the total valid bits. So like: if (format->value != PERF_PMU_FORMAT_VALUE_CONFIG) continue; Is it right? I will post v4 tomorrow. Thanks Jin Yao >> + >> + for_each_set_bit(i, format->bits, PERF_PMU_FORMAT_BITS) >> + masks |= 1ULL << i; >> + } >> + >> + /* >> + * Kernel doesn't export any valid format bits. >> + */ >> + if (masks == 0) >> + return; >> + >> + bits = config & ~masks; >> + if (bits == 0) >> + return; >> + >> + bitmap_scnprintf((unsigned long *)&bits, sizeof(bits) * 8, buf, sizeof(buf)); >> + >> + pr_warning("WARNING: event '%s' not valid (bits %s of config " >> + "'%llx' not supported by kernel)!\n", >> + name ?: "N/A", buf, config); >> +} >> diff --git a/tools/perf/util/pmu.h b/tools/perf/util/pmu.h >> index 8164388478c6..160b0f561771 100644 >> --- a/tools/perf/util/pmu.h >> +++ b/tools/perf/util/pmu.h >> @@ -123,4 +123,7 @@ int perf_pmu__convert_scale(const char *scale, char **end, double *sval); >> >> int perf_pmu__caps_parse(struct perf_pmu *pmu); >> >> +void perf_pmu__warn_invalid_config(struct perf_pmu *pmu, __u64 config, >> + char *name); >> + >> #endif /* __PMU_H */ >> -- >> 2.17.1 >> >