Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1736830pxb; Mon, 8 Mar 2021 05:17:27 -0800 (PST) X-Google-Smtp-Source: ABdhPJywSKzfAhH585hMI+CgCNyoeUnuJtabtfHYVYD5UajVwq7KJSGfJxLG+B7H6gwN1nfpPCKc X-Received: by 2002:a17:906:3850:: with SMTP id w16mr15432363ejc.286.1615209447492; Mon, 08 Mar 2021 05:17:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1615209447; cv=none; d=google.com; s=arc-20160816; b=NHI/eEiFsDTZQtoZ3Y3qEBpfbfC4AB35MTwjl3VsNhHzJMiVLBLG14kZr82yNcShd6 lbVeuxgIIIuoCMWY5YESPmST85Rj6jMEvidAIDwqQmFxhTXdnXfAqxYQhdsN+PhywCjf /X2bAM5zhyuyrMqa1b8wHMay7FljEDB8bTxI+r0VjIkGOrKDvlg9Q2Bia/mB2wpOPpQ0 9PbSFCV715oG9vZqBWWfq2IqQ2ESLIyv61hEhVfZMondhro76l4wJY4jtMugQfHmzOte jKPJA0aKVRwWnFuncnz7DZRBiS1JOl464tLjLKqmftza0Bb6k2dK0fdIfpLWjInF6XNm F+oQ== 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=elYv3u6ByCeI5rhesd+IetH8Zfo/QbBmOMDByurjQ5k=; b=cK3yV0cOAwnG62ffwNtQundybZsf0uoIeCs6LO7hLTZfBUBOPWePNXGdBd8ERlwaWy NXG5fotGrqJ4wtEx1THvvMQaBC0h0ddlgBG9bFX5n5zV1f2xo4Dkz2OYIyGhWvnvIzza 81TIHUkYBFIENGyR9p/LkEEjbEIJonx64sS7kwtQcg/spyDO1f5kx0PKD7Rjqw/OVzRD KOgVI/Cv3hgb8c7dxGi/aJs1BKW56ZHf1+bLCNpZOnjZ+I++t2gJ9qyqBAtVuMoIPv3G laRLYOYxcbOCLdbjaN8QlHt4frukVtQCDYnvQxLxjByDydXJEd2ExvT13pPGU/BAzeD5 JImQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=e2CDhJgJ; 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 jx25si851447ejc.382.2021.03.08.05.16.51; Mon, 08 Mar 2021 05:17:27 -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=e2CDhJgJ; 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 S229922AbhCHNPW (ORCPT + 99 others); Mon, 8 Mar 2021 08:15:22 -0500 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:21181 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230047AbhCHNOt (ORCPT ); Mon, 8 Mar 2021 08:14:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1615209289; 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=elYv3u6ByCeI5rhesd+IetH8Zfo/QbBmOMDByurjQ5k=; b=e2CDhJgJlkKls08IJeGlK0PP8L0GCQ7VzqxyO8JtuokBqLsnEfh/C4OXc1WVfztBZVHCz+ yZIZGO031OhyoaOn20Vr0Os/y6wvxMr0QCm+swu4OtVJfozmHeiyUeDGiN0SEFr4WxK2Ih 1jC0vLHYGr6w0kJXkOc/lUJ2SukWe3Y= 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-415-TKbhoZiqO7aEXCm2Xhta3g-1; Mon, 08 Mar 2021 08:14:45 -0500 X-MC-Unique: TKbhoZiqO7aEXCm2Xhta3g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9F5C68018A1; Mon, 8 Mar 2021 13:14:43 +0000 (UTC) Received: from krava (unknown [10.40.195.248]) by smtp.corp.redhat.com (Postfix) with SMTP id 8517410023AC; Mon, 8 Mar 2021 13:14:41 +0000 (UTC) Date: Mon, 8 Mar 2021 14:14:40 +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: X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 08, 2021 at 08:57:49PM +0800, Jin, Yao wrote: > 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? sure, what I meant was to process only PERF_PMU_FORMAT_VALUE_CONFIG and then call break, because there's no need to iterate further jirka