Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1637262pxb; Mon, 8 Mar 2021 02:36:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJzxtOyl97qaomzeJ0s/rSmsZDfpE3L0erWF7DgmedZMKuMumk4OJH8/yoYM1iVH4FrpJd4p X-Received: by 2002:a05:6402:447:: with SMTP id p7mr10102468edw.89.1615199801767; Mon, 08 Mar 2021 02:36:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615199801; cv=none; d=google.com; s=arc-20160816; b=yGfI5Mnkwo1oD9tz1i1U4meAeJh/aZ1FcBZRfQIscv6a3Kby+tgY7jacnj0bCjGhjb 1F6B/xLLkYs+j41syl5doscubO8LFrJvVhDMGcVWBJHV9tC3cWy7vCiYHQqpZhnvcsnd yxu8hUNPoE/nfLih5Bgz0i0r2VGOATeuJ0+ZfUXHj6CuKGT0dSo055v/J+UKwkmi5bTC e8JVlets3UVIDaXcDsFT2/MaCAqx/LbzVDsmk7A8SNu/nQ18oxWWDvHfGFKuxPNhrwrn j8g1/qXgDur0dGPhT3U4yOpuN5PcvGl/uYiF/615zC9dkpsbS9Ya6kaN815TvWRMBqSg jcuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=nclqJ27m5QoP4UshNB90N0ys4ZVj0yjmV7Cz+sGl5Fc=; b=E9ypSgRtU+KNPnzqC+vfv+h4ON9kwc8Rp4f0Txpa5C6CdwQ9Zu62oeIUbCcoEYFukx La2CsQ6WpctQublQGLdW6OtS6v1Ha+CUB8VXNJj4tDpRbH4kH5870f6iForRm72yuz0Z mv1CgeFJ800tg24c9LRSYD//tU3pmfjwtEh6PWlTSXDUnGccaG+nybGJG9/yVICbN7T+ rgJj86YH2T1uqnL2j47yLh2vi7u9Bx+M1lyyxTIcu18Rr5l3zcIX5reJi0BeXA0Ptiew OleeYvoMYlG8id9CPp3UH0Q/Y3tzfTovuZ+1O7vqpokOnLIOAzidgS0LOc/NPDfQ3Gmq V07A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cMpprt4f; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id z18si6925458edx.124.2021.03.08.02.36.19; Mon, 08 Mar 2021 02:36:41 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=cMpprt4f; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230511AbhCHKfU (ORCPT + 99 others); Mon, 8 Mar 2021 05:35:20 -0500 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:60636 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbhCHKfJ (ORCPT ); Mon, 8 Mar 2021 05:35:09 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615199709; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=nclqJ27m5QoP4UshNB90N0ys4ZVj0yjmV7Cz+sGl5Fc=; b=cMpprt4fQgrhZr1zXW81xq+awI7vNqOuduS85K14PxDDLeYQCiB4GyOlNyTXHceQtBXinH 3qIMFpTr5ngjhLbm7QUHQ3/uILHSTLtnUWsVfz1sTY37fB0DgbKTLinFqNeZZsjfQEhqeB 8g24qJUoWgpWTwJAzTcWtaOl1CunvSU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-528-uqxMuZlWPayLI_3d_vfKxA-1; Mon, 08 Mar 2021 05:35:05 -0500 X-MC-Unique: uqxMuZlWPayLI_3d_vfKxA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 3446F57; Mon, 8 Mar 2021 10:35:03 +0000 (UTC) Received: from krava (unknown [10.40.195.248]) by smtp.corp.redhat.com (Postfix) with SMTP id 269C662460; Mon, 8 Mar 2021 10:35:00 +0000 (UTC) Date: Mon, 8 Mar 2021 11:35:00 +0100 From: Jiri Olsa To: Jin Yao 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 Subject: Re: [PATCH v3] perf pmu: Validate raw event with sysfs exported format bits Message-ID: References: <20210308031506.23019-1-yao.jin@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210308031506.23019-1-yao.jin@linux.intel.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 > + > + 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 >