Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp3813009iob; Mon, 2 May 2022 06:22:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJypnhEkPLzR8MiiyWgIKnTvbtwOPPTKJtqIaQ3rVJx5jsBxdOrxl+xwlpiRBZz9DKWoMiT1 X-Received: by 2002:a05:6512:1109:b0:472:25d9:d262 with SMTP id l9-20020a056512110900b0047225d9d262mr9091563lfg.128.1651497773227; Mon, 02 May 2022 06:22:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651497773; cv=none; d=google.com; s=arc-20160816; b=UPWcuFJMEomrdzzZTN4Dr8zamt8hlU9TeO4x6dOTpupQt2jJeq/vUQ3OB//zmGKztN m9bkLGKUH4R2RTFhuHW5eJTZCF0fltD4rJXRVJjBzrQ8ZJ6V2WunVz1Vj0VO0IF8ApyV ck+fXG6Cm8AwBmUxCxTruMMATLup1xWwwuuE6JtkOcq4u25GXRNJdo1nr1axWPJqZ20y seQz3lSXcIPdIUiZw18zTB1PdwJ+2AUs2Fxn7DuLMqulSnZ6NYpGc2jJm3rt+155Fyrg hkfaKzmYnXlaQ+30sBoLbp9CWDl1QgK236A4eYoGI8Z08AjwdVgoNvWTsgfF45BL61+q TyGQ== 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; bh=k/APYmYxk61kZdXntHMEICTz/dMuoCskS3mvYdYDNX0=; b=WEqCE9m19gJhUVQk+q+PXUMyZqlKIoK67SCJUmYFWnDiQqGoBTQ91gLs+M/iwmkBsx TiLypMXz+7l7Z697xdrm29UEO/BgUgoYH6LxdYF52uM2rBkRdpgxqq2E5QggEUB5w+mv pipA+UspauGdPahrJqC56cV8xCVIlOkS3OR21FX+fULzSVaw1UrIDQ3fE6K1n+ZywtLn QdXVNrAk9Q6tMtPdQnljOj0F7pXOooAN1k/dYbfllbptVwXEoIa8chGi6/KCM8ACRDBa xtp/O4Tv8IBk1HEXdNZyZSMP2P6omHGOgFAWD7w4UPCZwQZ3qPQ9YjbEarHZJraUeIO6 ByYA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u7-20020a2e9b07000000b0024dc0918fd6si14641038lji.348.2022.05.02.06.22.26; Mon, 02 May 2022 06:22:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383593AbiEBGLm (ORCPT + 99 others); Mon, 2 May 2022 02:11:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53958 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383562AbiEBGLX (ORCPT ); Mon, 2 May 2022 02:11:23 -0400 Received: from mail-lf1-f47.google.com (mail-lf1-f47.google.com [209.85.167.47]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D5A4E57B02; Sun, 1 May 2022 23:07:26 -0700 (PDT) Received: by mail-lf1-f47.google.com with SMTP id j4so23598740lfh.8; Sun, 01 May 2022 23:07:26 -0700 (PDT) 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=k/APYmYxk61kZdXntHMEICTz/dMuoCskS3mvYdYDNX0=; b=CneDfyv0OGkr3LedF4KXXtzgyL0BksvUhZZ1ZDEG0SVxDhUjUcVsIaxRVzOOFWR3lq yLKvvj6EpG5yiQQ0yrHzp6pXHVmjo/1rDLxQP9I9cZxsk6rIe3IwK75F0hbM1qHQSSJ6 KsY/CWok/qvyDhAbmOhhyg/cfSuSdCA5dkR+j/vuX/J8r8Hax6YNVtYQZDFM79Wx1W0Q BC52gtWMLxkhv8Q0wMZKuqCV5elAZyRYp7zi+Bt2Od/dmEOMQaKR1UmLC/sDegEtMDFi zHm1n5CukttsX60HmvO2caO2MswG4SMbkzFkkwGuvt0YLkGK1N9HSYoRlSD7RB3L/jLo 1CFg== X-Gm-Message-State: AOAM532XXU5ang2TitASfSoX096SgjfL5pYJP3MtDGe4g7PKY/Kox+JM mihzw53vZzTpUn1vIV7qJmTT1gchdiZsv5od6HojBY3W X-Received: by 2002:a05:6512:39d3:b0:472:4920:96d7 with SMTP id k19-20020a05651239d300b00472492096d7mr8236899lfu.47.1651471645095; Sun, 01 May 2022 23:07:25 -0700 (PDT) MIME-Version: 1.0 References: <20220429051441.14251-1-ravi.bangoria@amd.com> In-Reply-To: <20220429051441.14251-1-ravi.bangoria@amd.com> From: Namhyung Kim Date: Sun, 1 May 2022 23:07:14 -0700 Message-ID: Subject: Re: [PATCH] perf/amd/ibs: Use interrupt regs ip for stack unwinding To: Ravi Bangoria Cc: Peter Zijlstra , Dmitry Monakhov , Josh Poimboeuf , Arnaldo Carvalho de Melo , Ingo Molnar , Mark Rutland , Jiri Olsa , Alexander Shishkin , Thomas Gleixner , Borislav Petkov , dave.hansen@linux.intel.com, "H. Peter Anvin" , x86@kernel.org, linux-perf-users , linux-kernel , sandipan.das@amd.com, ananth.narayan@amd.com, Kim Phillips , santosh.shukla@amd.com, Stephane Eranian Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.4 required=5.0 tests=BAYES_00, FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM,HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE 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 Hello, On Thu, Apr 28, 2022 at 10:15 PM Ravi Bangoria wrote: > > IbsOpRip is recorded when IBS interrupt is triggered. But there is > a skid from the time IBS interrupt gets triggered to the time the > interrupt is presented to the core. Meanwhile processor would have > moved ahead and thus IbsOpRip will be inconsistent with rsp and rbp > recorded as part of the interrupt regs. This causes issues while > unwinding stack using the ORC unwinder as it needs consistent rip, > rsp and rbp. Fix this by using rip from interrupt regs instead of > IbsOpRip for stack unwinding. > > Fixes: ee9f8fce99640 ("x86/unwind: Add the ORC unwinder") > Reported-by: Dmitry Monakhov > Suggested-by: Peter Zijlstra > Signed-off-by: Ravi Bangoria Acked-by: Namhyung Kim Thanks, Namhyung > --- > arch/x86/events/amd/ibs.c | 18 ++++++++++++++++++ > 1 file changed, 18 insertions(+) > > diff --git a/arch/x86/events/amd/ibs.c b/arch/x86/events/amd/ibs.c > index 9739019d4b67..171941043f53 100644 > --- a/arch/x86/events/amd/ibs.c > +++ b/arch/x86/events/amd/ibs.c > @@ -304,6 +304,16 @@ static int perf_ibs_init(struct perf_event *event) > hwc->config_base = perf_ibs->msr; > hwc->config = config; > > + /* > + * rip recorded by IbsOpRip will not be consistent with rsp and rbp > + * recorded as part of interrupt regs. Thus we need to use rip from > + * interrupt regs while unwinding call stack. Setting _EARLY flag > + * makes sure we unwind call-stack before perf sample rip is set to > + * IbsOpRip. > + */ > + if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) > + event->attr.sample_type |= __PERF_SAMPLE_CALLCHAIN_EARLY; > + > return 0; > } > > @@ -687,6 +697,14 @@ static int perf_ibs_handle_irq(struct perf_ibs *perf_ibs, struct pt_regs *iregs) > data.raw = &raw; > } > > + /* > + * rip recorded by IbsOpRip will not be consistent with rsp and rbp > + * recorded as part of interrupt regs. Thus we need to use rip from > + * interrupt regs while unwinding call stack. > + */ > + if (event->attr.sample_type & PERF_SAMPLE_CALLCHAIN) > + data.callchain = perf_callchain(event, iregs); > + > throttle = perf_event_overflow(event, &data, ®s); > out: > if (throttle) { > -- > 2.27.0 >