Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp893396pxp; Wed, 16 Mar 2022 20:25:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNKia5/cj5ZUTmnRS5H2G1W3ck7g0E9v3qIXpdWkuIAyuLjjXMCCT/9hElST333pM85hV/ X-Received: by 2002:a63:ec16:0:b0:381:6a51:6231 with SMTP id j22-20020a63ec16000000b003816a516231mr2059592pgh.189.1647487558063; Wed, 16 Mar 2022 20:25:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647487558; cv=none; d=google.com; s=arc-20160816; b=AeIVqUcgBNyZYdAwcsHVz3YBefvRTdz0s3HiXp7d5H3o0rQKcQC89aA4bOs2LBtf13 CqYUlB+f1V628XC4Nh9H7cXO6bNUNVbBOOoFCunjZqnR02MkZWqzWrRrpLTttGTa4nq3 A5gXCN616/QZ/8Hx2XG6fow8TPpOGteN5MZQm58r2L4PeOw2wSlRxsAV8k4Lxk2Uw/aV Ny5Lxe/OgiR78fdnIdqzIx3RkRlLDjIm/R+N9QDHRmu5eamGFOBajMYL4gBbxfzeI9RL L0y1xyKRIcvWye75i8LdaFBZgWRWmpm7/Gz2QmGBp/MGJyUYy8Ctx9ArdLObN4JoKY8x Ix2Q== 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=x9gQzM4WgodiwgsEK8zJj7FBjgYRuL2M0zsnUh0K7/M=; b=VlsMFJ5uIovNaYIx9SZXD87DvpLW7VYGNaTdIcjELNhLuYdEVIAiz7jT67YHSdz6f6 hDQPsJpBPzJRPXJYYYZDEaq/37K3k9IpIRmacX7B3I+l4YLZCjs0b81gD9dhVezeuiPO AlINe6YqVtxQ3NQIbmuOlTcDoPmLnwS8qOe3xQtbko20E6SCDO4PbjDL2iEh6NBomTAx //+MN87xCBb+aeBpPHpquXZ3SHk3nHVWo4pk4mp+nF/Aa5JVS6OCpkVQDbLZuZhr7Eo7 s2sGMUbhb91zcMcwmVEJ3vmsOd8vqhUwa73/ffyn2dpYUk0H5RfdE9yFM2V0ohY3eZYj ukTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=MXpBgzEx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id n3-20020a17090a5a8300b001bf35af02a6si1173773pji.0.2022.03.16.20.25.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 20:25:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=MXpBgzEx; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1: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: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 37B9031DE2; Wed, 16 Mar 2022 20:25:17 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345321AbiCOHON (ORCPT + 99 others); Tue, 15 Mar 2022 03:14:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33598 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245268AbiCOHOL (ORCPT ); Tue, 15 Mar 2022 03:14:11 -0400 Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3882755BA for ; Tue, 15 Mar 2022 00:12:59 -0700 (PDT) Received: by mail-vs1-xe36.google.com with SMTP id u124so19712395vsb.10 for ; Tue, 15 Mar 2022 00:12:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=x9gQzM4WgodiwgsEK8zJj7FBjgYRuL2M0zsnUh0K7/M=; b=MXpBgzExUEKpXk5PjEC0s1oaNP4PzMCLVbFg4yQZaP1E/P0ou5ZGPs0r9wEft4DUXR JNJegl/FezY6/tMWB3RDmkOH/9SBCYvgg93HsWT1jLSU6cMyb/FbHD0g0E/vbEJB8WFE 2FvRIDjD9nBCu4TZJUJoamB2woIqc050xFpdX80m2YhJAcn+o8yARjZTh8LSlOxdI90/ 5truD2oRixa+dcdpDrYH91SP2LvfeV1lhFr1hx5fHNyGxKHDIiPVdNec2Li1zHY+5rU7 +0ScSQqnV0QgSL4VbItOGqNwo16r+EWMEpZplbusWCNWTso6ZbGrYK2nE56Tlr9o6q0W GqBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=x9gQzM4WgodiwgsEK8zJj7FBjgYRuL2M0zsnUh0K7/M=; b=r8uRZ0y80osTOavYrCLcuYp9Tzehjsn1zLW/xMiARbHaXEbs11qbQCeDKjfMD9I+mK 8CQ9qTzKVBP9Fo/X8Ovj7HzYL6NEHwHXMO4N8P/HmRFOXsnezGrbbjdMWCOUooiTaXg4 KtmfTLRvASK1uwOuNwXjPd3nhj6loXbTjnFuwtrKHa/ZpquDwL2COyzQhzqL4zTOwvz9 rtOLcDX+5NzcZ77rkqV+S35+9KpnRnTcX3eH/xZaCMb1L79JLBre4WevzTuXwOMIdwkU oT5SGyoPRPFT57aIL2I1R26gbLzD3IgAkeNsD2TqqpIfkb7JfgxnN/rR8LPrekj5FMqc 1dAA== X-Gm-Message-State: AOAM5338N4cGRuFJkbbq5BaGyJMvCzh3Fj49lm7RUKagqN2gNGrxKAju cAzbcR/HBPvJauxk4ui9xqP38J/SmNl3CeIjq0dRVg== X-Received: by 2002:a05:6102:3748:b0:323:1115:f961 with SMTP id u8-20020a056102374800b003231115f961mr301799vst.67.1647328378092; Tue, 15 Mar 2022 00:12:58 -0700 (PDT) MIME-Version: 1.0 References: <20220208211637.2221872-1-eranian@google.com> <20220208211637.2221872-11-eranian@google.com> <5609a43a-afbe-7629-b84d-75ace62da4fe@amd.com> In-Reply-To: <5609a43a-afbe-7629-b84d-75ace62da4fe@amd.com> From: Stephane Eranian Date: Tue, 15 Mar 2022 00:12:46 -0700 Message-ID: Subject: Re: [PATCH v6 10/12] perf tools: Improve IBS error handling To: Ravi Bangoria Cc: peterz@infradead.org, kim.phillips@amd.com, acme@redhat.com, jolsa@redhat.com, songliubraving@fb.com, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 14, 2022 at 11:23 PM Ravi Bangoria wrote: > > >> +static bool is_amd(const char *arch, const char *cpuid) > >> +{ > >> + return arch && !strcmp("x86", arch) && cpuid && strstarts(cpuid, "AuthenticAMD"); > >> +} > >> + > >> +static bool is_amd_ibs(struct evsel *evsel) > >> +{ > >> + return evsel->core.attr.precise_ip || !strncmp(evsel->pmu_name, "ibs", 3); > >> +} > >> + > >> int evsel__open_strerror(struct evsel *evsel, struct target *target, > >> int err, char *msg, size_t size) > >> { > >> + struct perf_env *env = evsel__env(evsel); > >> + const char *arch = perf_env__arch(env); > >> + const char *cpuid = perf_env__cpuid(env); > > > > > > This code dies for me on the latest tip.git because env = NULL and > > perf_env_cpuid() is broken for NULL argument. > > I don't quite know where this env global variable is set but I hope > > there is a better way of doing this, maybe using > > the evsel__env() function in the same util/evsel.c file. > > > > Similarly, the is_amd_ibs() suffers from a NULL pointer dereference > > because evsel->pmu_name maybe NULL: > > > > $ perf record -e rc2 ..... > > > > causes a NULL pmu_name. > > This should fix the issue: > > @@ -2965,7 +2989,7 @@ int evsel__open_strerror(struct evsel *evsel, struct target *target, > > struct perf_env *evsel__env(struct evsel *evsel) > { > - if (evsel && evsel->evlist) > + if (evsel && evsel->evlist && evsel->evlist->env) > return evsel->evlist->env; > return &perf_env; > } > I will check with that change. Similarly, the IBS helper needs to have the following change: --- a/tools/perf/util/evsel.c +++ b/tools/perf/util/evsel.c @@ -2854,13 +2854,18 @@ static bool is_amd(const char *arch, const char *cpuid) static bool is_amd_ibs(struct evsel *evsel) { - return evsel->core.attr.precise_ip || !strncmp(evsel->pmu_name, "ibs", 3); + return evsel->core.attr.precise_ip + || (evsel->pmu_name && !strncmp(evsel->pmu_name, "ibs", 3)); }