Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp3894029pxj; Tue, 15 Jun 2021 10:52:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySWXGyd6HJIaD1kLVR0jqNl3/f5+/qbSrhSMY3/NtW2ZRwAy9Es97QKuO/tTrOe9+XlXmM X-Received: by 2002:a05:6402:254d:: with SMTP id l13mr896422edb.286.1623779572653; Tue, 15 Jun 2021 10:52:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1623779572; cv=none; d=google.com; s=arc-20160816; b=QUB5SYJIWQ/V2edjbYMwqRVZbJq82rHndFQaRdHVocgRAJ3w9O5iJ7aStJQX+X3Rqc 8IhMHKxR1V1O/FxeDI9qcLzeo5wU+s1i3Cb3rizTvzLUL8+Xaxz0NDZuhBTVbQ894k6x F8XDjdLrhegOGbMi7OQxqZzzSZdzLEyufrTG8QnzTLqa4AN+S0sKOHVnwIB9GE2BQrgn AB/ZnK/74DFdJ2j2orY5yPO+mF0OoYC+YMWTp4XLfNrOOXvipDovDazoDp1AGqHUAo5m mDn8e66vMX9OYuAAtbsOILwADXHnORdMfK2q/nOerOz/aVWU8ZSMaJEeVnuYQn5pQeEe ErZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=c5k8c03lkLJ0kEuGDXFoZR8zuq5YE2cs2QXAAUVdxSs=; b=F8lKe97BVE1s4cRbo3+5JGwxOzk+klJ7AT1MBpN8bL6xDam2RhREEsgBEH9IMR0GXL UrD+h74tPPYJyTyohoIBlTaLR8eNXHXYCVAllU+RpgZYSktypoYDWJxKejVrb0Bm/GkK 6JDGTkOuJn0Tra84aMAAq/Qr1NYZThPkr47+4Poi/CwCAbmRb6M5Jix+6mz54JNFHoHt yM4HUQ/mwpJNQ/Pkjm4gX/tHKqusej3/MYJnaEDy2NuMPXhpLdHsg8u0t5XMjqJihqQQ AZPD+8Tts6lC5PbN8XNcYwfgT4ctVoji3QSED6XfDvgqAKRvh8YfsbqDlTBuZakvA3fr i8ZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=eeDbpFBW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bh4si17663476ejb.358.2021.06.15.10.52.29; Tue, 15 Jun 2021 10:52:52 -0700 (PDT) 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=@google.com header.s=20161025 header.b=eeDbpFBW; 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=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231410AbhFORxZ (ORCPT + 99 others); Tue, 15 Jun 2021 13:53:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229976AbhFORxY (ORCPT ); Tue, 15 Jun 2021 13:53:24 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A23E9C06175F for ; Tue, 15 Jun 2021 10:51:18 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id h11-20020a05600c350bb02901b59c28e8b4so2354201wmq.1 for ; Tue, 15 Jun 2021 10:51:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=c5k8c03lkLJ0kEuGDXFoZR8zuq5YE2cs2QXAAUVdxSs=; b=eeDbpFBW6hZkvOkv0vqEMQ4rHjp/8/P3u86ix65h8unQyzzjZ48xAnYzu0XzxIRL2x IFAEn1IGnXV57IcRuVoUEtfAnKlZzIJr8XuX+GwXZEbj27U0MZE5UcRUO9XKfqPCuqvc +OdFitdRSlcCJoaqFyX9WgreqA8HM6S8iqMPgvPluqq0iB9SPmP9Jp4z4uLpVRct7koX O+cLf4lk5PGSDQ8Hx+zbn2zpGei3ejlvjbkKBk5emlLXATKpak8QA6sEnk7RQDN4NpO6 Ys6zRsL7RniAX0SE8bBKhKT8cmIOuq8G6NWk3PAy/Etf+FczjA231bV6+ogt89ETWMI0 N/1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=c5k8c03lkLJ0kEuGDXFoZR8zuq5YE2cs2QXAAUVdxSs=; b=Ny0ouJysiqmCiHzy6Y8YDtLEmqPzU4dmY+/InRIP+bQ5P5mv6SRBU0BcZaMT2bTt+0 lnc4Qn29iiXyb5KbwmVN1wovkw0b1ICCxveWF4z949QNgDk8mOS4RQ896Gu3IkBNVD3V CD6ygrTwi+AgiAft2xx8wxnMlg7G48Q6iu1JtMtdNcZP/eK3BvDB0BGLs2BLqiQYX1HK GrmQe67WUMMs09DfkthHcVtcoYMiLW9peddV1ErG92vM5+cCL8O0OqTIYQIGPzx9ZdIJ vpSRkSIZ8P43ocJM2ceb8M6u7e/5jk4N3o75VZJvLtWzJ9IItsiJ9An/mkwPCP8c/cKu lLBw== X-Gm-Message-State: AOAM532bC2UKMpt7LXvsEtDLZtrKHBf94l8Fkj2+IjHpL+qrLWWDWKEx UD0zEzdnSk0/9tPGX/6YL3+2c//c0uOyvEF2930n4Q== X-Received: by 2002:a05:600c:a01:: with SMTP id z1mr6625877wmp.77.1623779477124; Tue, 15 Jun 2021 10:51:17 -0700 (PDT) MIME-Version: 1.0 References: <1623335580-187317-1-git-send-email-john.garry@huawei.com> <1623335580-187317-3-git-send-email-john.garry@huawei.com> In-Reply-To: From: Ian Rogers Date: Tue, 15 Jun 2021 10:51:04 -0700 Message-ID: Subject: Re: [PATCH 2/2] perf metricgroup: Return error code from metricgroup__add_metric_sys_event_iter() To: Arnaldo Carvalho de Melo Cc: John Garry , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Jiri Olsa , Namhyung Kim , kajoljain , linux-perf-users , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 14, 2021 at 7:56 AM Arnaldo Carvalho de Melo wrote: > > Em Thu, Jun 10, 2021 at 11:45:17AM -0700, Ian Rogers escreveu: > > On Thu, Jun 10, 2021 at 7:37 AM John Garry wrote: > > > > > > The error code is not set at all in the sys event iter function. > > > > > > This may lead to an uninitialized value of "ret" in > > > metricgroup__add_metric() when no CPU metric is added. > > > > > > Fix by properly setting the error code. > > > > > > It is not necessary to init "ret" to 0 in metricgroup__add_metric(), as > > > if we have no CPU or sys event metric matching, then "has_match" should > > > be 0 and "ret" is set to -EINVAL. > > > > > > However gcc cannot detect that it may not have been set after the > > > map_for_each_metric() loop for CPU metrics, which is strange. > > > > > > Fixes: be335ec28efa8 ("perf metricgroup: Support adding metrics for system PMUs") > > > Signed-off-by: John Garry > > > > Acked-by: Ian Rogers > > Do your Acked-by applies to both patches? Or just 2/2? I reproduced the > problem fixed by 1/2 on a Thinkpad T450S (broadwell) and after applying > the patch it doesn't segfaults. IIRC I need to look at what is going on with the names in patch 1/2 and didn't have a repro. I don't mind to ack it given that you've repro-ed the problem and confirmed the fix. In general this logic isn't working well (especially for --metric-no-group) so I plan to take a stab at reorganizing it. Thanks, Ian > Please clarify, > > - Arnaldo > > > > Thanks, > > Ian > > > > > --- > > > tools/perf/util/metricgroup.c | 8 +++++--- > > > 1 file changed, 5 insertions(+), 3 deletions(-) > > > > > > diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c > > > index c456fdeae06a..d3cf2dee36c8 100644 > > > --- a/tools/perf/util/metricgroup.c > > > +++ b/tools/perf/util/metricgroup.c > > > @@ -1073,16 +1073,18 @@ static int metricgroup__add_metric_sys_event_iter(struct pmu_event *pe, > > > > > > ret = add_metric(d->metric_list, pe, d->metric_no_group, &m, NULL, d->ids); > > > if (ret) > > > - return ret; > > > + goto out; > > > > > > ret = resolve_metric(d->metric_no_group, > > > d->metric_list, NULL, d->ids); > > > if (ret) > > > - return ret; > > > + goto out; > > > > > > *(d->has_match) = true; > > > > > > - return *d->ret; > > > +out: > > > + *(d->ret) = ret; > > > + return ret; > > > } > > > > > > static int metricgroup__add_metric(const char *metric, bool metric_no_group, > > > -- > > > 2.26.2 > > > > > -- > > - Arnaldo