Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp633941iog; Mon, 13 Jun 2022 09:33:30 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyozI1tuFIBSR57pw+36gFBE6W3z8fyUvrM7Hzfs7/hjwvedHB8S7nSdl2k80DuttTLi5x8 X-Received: by 2002:a63:81c7:0:b0:3fc:a44e:832f with SMTP id t190-20020a6381c7000000b003fca44e832fmr386850pgd.37.1655138010107; Mon, 13 Jun 2022 09:33:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655138010; cv=none; d=google.com; s=arc-20160816; b=dNNEh5okUNRzrTu/VvNMP8oZuRksAbomDHLeplxYnJUD5U58XO7KiBHZxnc/NRNfjL RxXk/WC5t4n0tP/R2ibI4RnTOsIKjL0dqMCgDM4IKF+hpnHCrCIBwzoIaiOcMzCMFn2P 6Bo8J9YOQctJBegtYL2ss1gFVEHolAEDgSNPcqT2f+P+6+yMWfnwJA/Esw2/JlbHtpm0 CDVHa/riYpbxsA//Jq9U0qPNPjEwvmaY4pBhJ4Grj5LfLAh5IvcZ+VCJu3KlJN8Kv72Q 2t37EiSIpaE1Om13Cd79p0u7mEXIG9jOrH5zp0IqH2xO2Wt4ULdUEhOPAqAoZLE5MVni D15Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mU9qQzKsLkFyaFfCdN1NalrIlRFnOiFpZ+TZ7fjiGUc=; b=ouuotd2h5pE/CZoEB7efaFw7fcxRHe4hE5XNvH4+sVc6jDDF/XvjmD2p/Gs9rqDS1Q E3llNhJ7jgCXoiugceY50thNX4zHM2Eawn8UyXWzHZ+q8e1kvdPBEKhY+7CrZulJCz+u JLoUowGwTKwwumol8Dtr6CKM5zWLuPHHoDruvZg/hMEuQWXw3kx1HIlpv4jprzO6b9vW hoi0Z+UGu5iZ5AMuIn9Kzje1acwbZFhWdWqGILaPQImDsVs06jdcmRxT1UP7xcybBcYU 8lzTWnIBkZRZX+Sp7dn04TvfeoNvuIvrAEY6PnhfFxUULkPJiJYtO3zxgw1SM62IOXVe pZLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XOOOXAFs; 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=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g13-20020a170902d1cd00b001619b733920si8976813plb.51.2022.06.13.09.33.15; Mon, 13 Jun 2022 09:33:30 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=XOOOXAFs; 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=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357186AbiFML6R (ORCPT + 99 others); Mon, 13 Jun 2022 07:58:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356621AbiFMLur (ORCPT ); Mon, 13 Jun 2022 07:50:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8AC4022B27; Mon, 13 Jun 2022 03:54:39 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 26CF160F00; Mon, 13 Jun 2022 10:54:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 38F2BC34114; Mon, 13 Jun 2022 10:54:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1655117678; bh=aumf9yAoZ5XHJ9DWTFSBRcccitJ4jRF/Eo0ETcWmvzQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=XOOOXAFs+qyCRocM6qwGi//r7Duzawsmq8SZtNiBOl/whZQcG1+9uHWWVUYD347sW 28fMfKXdsfWrFOjx6Ec1cKwELD7wDNG5UOIL8AVPEqXlAoe05v8HeHBicAAdPEtgDj T3CCSGcLwOxAaPGWhJkPZXDYp8xG/uWyXrSRj9KE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dmitry Monakhov , Peter Zijlstra , Ravi Bangoria , Sasha Levin Subject: [PATCH 4.19 092/287] perf/amd/ibs: Use interrupt regs ip for stack unwinding Date: Mon, 13 Jun 2022 12:08:36 +0200 Message-Id: <20220613094926.668894523@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220613094923.832156175@linuxfoundation.org> References: <20220613094923.832156175@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham 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 From: Ravi Bangoria [ Upstream commit 3d47083b9ff46863e8374ad3bb5edb5e464c75f8 ] 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 Signed-off-by: Peter Zijlstra (Intel) Link: https://lkml.kernel.org/r/20220429051441.14251-1-ravi.bangoria@amd.com Signed-off-by: Sasha Levin --- 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 2d9e1372b070..d157d0adef06 100644 --- a/arch/x86/events/amd/ibs.c +++ b/arch/x86/events/amd/ibs.c @@ -324,6 +324,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; } @@ -693,6 +703,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.35.1