From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95125C47080 for ; Tue, 1 Jun 2021 12:44:23 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C75E60234 for ; Tue, 1 Jun 2021 12:44:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C75E60234 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FBJAjjgpfNBAZpMRQdhhFymj2958z8maiL3lTlDPrbY=; b=XBRIjTv3l2cyeX 6pjitEJjLGeGXuyPwHXTlnk0bf6QtIu8PV5+9/WOdGYuv4tvdzt3O64RpZFs4a0a1wbfRbEvWJIf2 TTXTgr8jF3Iq3AApA5OK0gdAoDelEbgvBoN5ZN2dUgpv4ESNPTa7DrzQJFaBt8FnJpn3pWapYuO2C GCnpwqVEQmuIJuwHrNeXiN5umJNSpv5K/uz7pXIhm0P7cxiPmeEfjK5ovxtBuPxM+iO7AF0JpE/JS ntXIOX3czG66Bka/RLv6MaOHryxTHNP8VB6OhPf9NlKeEKCOIfRZwuG1td43kvnBzdMQUEKiqokbG Y9pExQBUV19WA+Jkk9ag==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lo3jc-00GZLt-1G; Tue, 01 Jun 2021 12:43:04 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lo3jY-00GZLC-NX for linux-arm-kernel@lists.infradead.org; Tue, 01 Jun 2021 12:43:02 +0000 Received: by mail.kernel.org (Postfix) with ESMTPSA id C83876135D; Tue, 1 Jun 2021 12:42:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1622551380; bh=iTiBcVaNoYtwDKTpYwYm/tYAiBu0G6h7tUR39Sv4k/0=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Gg5O8CFYz89fsVPqdqDCEXWxFkiXjPbFgw/hSEGQFRE4myqGwo2eJkuxqSLpXOG6X +XyIXUc2KVDEpL/T2h1Rj9m2DI3uzBTT4MwtT2tuxtneQDrVf8BE9H3+pubOio9uJ7 LpOsWdFsA7NtuDVjv0eIsi9jCGxigtRnGAzQszQH6YcsVls/Gz3u+RmeGrAVDJZ2go q/1Uw9MtMkt30v8VWPKAaELgw+rgFvmD8eBKRyGNferWCWaT6GcXiCuZqhSigpFjLj OdGJIUX6TRNHBXj6UjoM6mGexQPqiWSr/5RBGYnbAMSI4SfkkKNN2UVaN6SC8AWw6y nGf7y+vt6nHbQ== Date: Tue, 1 Jun 2021 13:42:54 +0100 From: Will Deacon To: Lexi Shao Cc: linux-arm-kernel@lists.infradead.org, mark.rutland@arm.com, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, qiuxi1@huawei.com, nixiaoming@huawei.com, zengweilin@huawei.com Subject: Re: [PATCH] arm: perf: fix sw event kernel backtrace with unwind Message-ID: <20210601124254.GA28025@willie-the-truck> References: <20210511130912.118504-1-shaolexi@huawei.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210511130912.118504-1-shaolexi@huawei.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210601_054300_828431_1E063A1C X-CRM114-Status: GOOD ( 23.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Tue, May 11, 2021 at 09:09:12PM +0800, Lexi Shao wrote: > For perf sample not generated with interrupt/exception, there is no > pt_regs information, so perf_fetch_caller_regs() is used to fill > necessary information for sampling and backtracing. > perf_fetch_caller_regs() puts LR as PC to skip unwanted frame. > > For ARM images with CONFIG_ARM_UNWIND=y, this does not work because > backtracing with unwind requires PC to match FP and SP, but we have the > previous PC with current FP and SP here. Therefore backtrace fails and > stack in kernel only has one entry. > > Before this patch: > perf record -e sched:sched_switch -ag sleep 2 > perf script > perf 1512 [000] 51.976113: sched:sched_switch: perf:1512 [120] S > ==> swapper/0:0 [120] > c048d9e8 __schedule ([kernel.kallsyms]) > d0618 __poll (/lib/libc-2.31.so) > 6b678 [unknown] (/usr/bin/perf) > b0b0 [unknown] (/usr/bin/perf) > 17700 __libc_start_main (/lib/libc-2.31.so) > > Notice there is only one frame in kernel text. > > After this patch, the kernel callchain is fully displayed: > perf 1545 [000] 10403.005915: sched:sched_switch: perf:1545 [120] S > ==> swapper/0:0 [120] > c014bff0 perf_trace_sched_switch ([kernel.kallsyms]) > c048d9d8 __schedule ([kernel.kallsyms]) > c048df4c schedule ([kernel.kallsyms]) > c0491940 schedule_hrtimeout_range_clock ([kernel.kallsyms]) > c0255164 poll_schedule_timeout ([kernel.kallsyms]) > c02567dc do_sys_poll ([kernel.kallsyms]) > c02568f8 sys_poll ([kernel.kallsyms]) > c01084b0 __sys_trace_return ([kernel.kallsyms]) > d0618 __poll (/lib/libc-2.31.so) > 6b678 [unknown] (/usr/bin/perf) > b0b0 [unknown] (/usr/bin/perf) > 17700 __libc_start_main (/lib/libc-2.31.so) > > Fixes: b3eac0265bf62 ("arm: perf: Fix callchain parse error with kernel > tracepoint events") #v4.2+ > > Signed-off-by: Lexi Shao > --- > arch/arm/include/asm/perf_event.h | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/arch/arm/include/asm/perf_event.h b/arch/arm/include/asm/perf_event.h > index fe87397c3d8c..e326520f9386 100644 > --- a/arch/arm/include/asm/perf_event.h > +++ b/arch/arm/include/asm/perf_event.h > @@ -15,8 +15,20 @@ extern unsigned long perf_misc_flags(struct pt_regs *regs); > #define perf_misc_flags(regs) perf_misc_flags(regs) > #endif > > +#ifdef CONFIG_ARM_UNWIND > +/* > + * With ARM unwind, the pc must match with fp and sp, otherwise > + * backtrace method unwind_frame() does not work properly. > + * Get pc with assembly instead of using __ip. > + */ > +#define perf_get_arm_pc(regs, __ip) \ > + __asm__ __volatile__ ("mov %0, pc" : "=r"((regs)->ARM_pc)::) > +#else > +#define perf_get_arm_pc(regs, __ip) ((regs)->ARM_pc = (__ip)) > +#endif > + > #define perf_arch_fetch_caller_regs(regs, __ip) { \ > - (regs)->ARM_pc = (__ip); \ > + perf_get_arm_pc(regs, __ip); \ > (regs)->ARM_fp = (unsigned long) __builtin_frame_address(0); \ > (regs)->ARM_sp = current_stack_pointer; \ > (regs)->ARM_cpsr = SVC_MODE; \ This doesn't feel like the right solution to me: the caller is passing us '__ip' with the expectation that it corresponds to the PC, so that is what we should be using, not recreating our own value like this. In other words, if unwinding doesn't work using CALLER_ADDR0, then this seems like an issue that would affect more than just perf. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel