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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 8D7D7C02190 for ; Thu, 30 Jan 2025 10:36:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=zVxf1UYtEnYrkLL5hJZ5QlBHDjxANnAboqvzYXh5U+g=; b=BV9cEBP4E05Rh143qIZZfDiwXS BDeIcXbZ2gRnw6o7QDNJQCTlj8F7Ziqt1ytPww3cjoIDAEMYmzrsXzUgNFjlhNBc0GZ5jiTwrnv2V xDLj7IYkDiLGK3LEbtQarMQfuvMzBeFMqYH11p0BmqaInYrfW8F8alw3uRbIVhP54w5NYbyb43DVF etYng2RwErjPaqhO2AVvSw0DipbNh+h8aMf8hvqkL1LQ128lsvZmEgLBHVeEnKaxjdrm+/s5N1DnF LKIcwdglc66BycRkeH75sKVgq4v/rkc8tEb4WqlSnebDFwM35XiELxyYKek6XX3dsO+QIBW5Fnyp6 6HQvOhZQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tdRuQ-00000008dd6-3OHl; Thu, 30 Jan 2025 10:36:30 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tdRt2-00000008dNz-30cC for linux-arm-kernel@lists.infradead.org; Thu, 30 Jan 2025 10:35:05 +0000 Received: from [10.156.205.88] (unknown [167.220.238.88]) by linux.microsoft.com (Postfix) with ESMTPSA id 08CCF2109CD7; Thu, 30 Jan 2025 02:34:59 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 08CCF2109CD7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1738233303; bh=zVxf1UYtEnYrkLL5hJZ5QlBHDjxANnAboqvzYXh5U+g=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=K1dCig9el0oa/CufgrNC59jLSZ4uDmmETUxrotOCcTRTtmSR76F0u8ePBztpNA0Dx ApYzof/Kaow0caEadeNkSHDC9/1jaqtV1XE0KzQ8OXzbNRz738nPbZZiAOBkfkKMeF ogJ+/z2GDWMeFSr/hiw+UHD5ZjxCV0VU9Gh3Lp28= Message-ID: Date: Thu, 30 Jan 2025 16:04:58 +0530 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 5/8] unwind: arm64: Add sframe unwinder on arm64 To: Weinan Liu , Josh Poimboeuf , Steven Rostedt , Indu Bhagat , Peter Zijlstra Cc: Mark Rutland , roman.gushchin@linux.dev, Will Deacon , Ian Rogers , linux-toolchains@vger.kernel.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org, joe.lawrence@redhat.com, linux-arm-kernel@lists.infradead.org References: <20250127213310.2496133-1-wnliu@google.com> <20250127213310.2496133-6-wnliu@google.com> Content-Language: en-US From: Prasanna Kumar T S M In-Reply-To: <20250127213310.2496133-6-wnliu@google.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250130_023504_797432_699449D9 X-CRM114-Status: GOOD ( 24.07 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 28-01-2025 03:03, Weinan Liu wrote: > Add unwind_next_frame_sframe() function to unwind by sframe info. > Built with GNU Binutils 2.42 to verify that this sframe unwinder can > backtrace correctly on arm64. > > Signed-off-by: Weinan Liu > --- > arch/arm64/include/asm/stacktrace/common.h | 4 ++ > arch/arm64/kernel/setup.c | 2 + > arch/arm64/kernel/stacktrace.c | 59 ++++++++++++++++++++++ > 3 files changed, 65 insertions(+) > > diff --git a/arch/arm64/include/asm/stacktrace/common.h b/arch/arm64/include/asm/stacktrace/common.h > index 821a8fdd31af..19edae8a5b1a 100644 > --- a/arch/arm64/include/asm/stacktrace/common.h > +++ b/arch/arm64/include/asm/stacktrace/common.h > @@ -25,6 +25,7 @@ struct stack_info { > * @stack: The stack currently being unwound. > * @stacks: An array of stacks which can be unwound. > * @nr_stacks: The number of stacks in @stacks. > + * @cfa: The sp value at the call site of the current function. > */ > struct unwind_state { > unsigned long fp; > @@ -33,6 +34,9 @@ struct unwind_state { > struct stack_info stack; > struct stack_info *stacks; > int nr_stacks; > +#ifdef CONFIG_SFRAME_UNWINDER > + unsigned long cfa; > +#endif > }; > > static inline struct stack_info stackinfo_get_unknown(void) > diff --git a/arch/arm64/kernel/setup.c b/arch/arm64/kernel/setup.c > index 4f613e8e0745..d3ac92b624f3 100644 > --- a/arch/arm64/kernel/setup.c > +++ b/arch/arm64/kernel/setup.c > @@ -32,6 +32,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -377,6 +378,7 @@ void __init __no_sanitize_address setup_arch(char **cmdline_p) > "This indicates a broken bootloader or old kernel\n", > boot_args[1], boot_args[2], boot_args[3]); > } > + init_sframe_table(); > } > > static inline bool cpu_can_disable(unsigned int cpu) > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > index 1d9d51d7627f..c035adb8fe8a 100644 > --- a/arch/arm64/kernel/stacktrace.c > +++ b/arch/arm64/kernel/stacktrace.c > @@ -14,6 +14,7 @@ > #include > #include > #include > +#include > > #include > #include > @@ -242,6 +243,53 @@ kunwind_next_frame_record(struct kunwind_state *state) > return 0; > } > > +#ifdef CONFIG_SFRAME_UNWINDER > +/* > + * Unwind to the next frame according to sframe. > + */ > +static __always_inline int > +unwind_next_frame_sframe(struct unwind_state *state) > +{ > + unsigned long fp = state->fp, ip = state->pc; > + unsigned long base_reg, cfa; > + unsigned long pc_addr, fp_addr; > + struct sframe_ip_entry entry; > + struct stack_info *info; > + struct frame_record *record = (struct frame_record *)fp; > + > + int err; > + > + /* frame record alignment 8 bytes */ > + if (fp & 0x7) > + return -EINVAL; > + > + info = unwind_find_stack(state, fp, sizeof(*record)); > + if (!info) > + return -EINVAL; > + > + err = sframe_find_pc(ip, &entry); > + if (err) > + return -EINVAL; > + > + unwind_consume_stack(state, info, fp, sizeof(*record)); > + > + base_reg = entry.use_fp ? fp : state->cfa; > + > + /* Set up the initial CFA using fp based info if CFA is not set */ > + if (!state->cfa) > + cfa = fp - entry.fp_offset; > + else > + cfa = base_reg + entry.cfa_offset; > + fp_addr = cfa + entry.fp_offset; > + pc_addr = cfa + entry.ra_offset; > + state->cfa = cfa; > + state->fp = READ_ONCE(*(unsigned long *)(fp_addr)); > + state->pc = READ_ONCE(*(unsigned long *)(pc_addr)); > + > + return 0; > +} > +#endif > + > /* > * Unwind from one frame record (A) to the next frame record (B). > * > @@ -261,7 +309,15 @@ kunwind_next(struct kunwind_state *state) > case KUNWIND_SOURCE_CALLER: > case KUNWIND_SOURCE_TASK: > case KUNWIND_SOURCE_REGS_PC: > +#ifdef CONFIG_SFRAME_UNWINDER > + err = unwind_next_frame_sframe(&state->common); > + > + /* Fallback to FP based unwinder */ > + if (err) > err = kunwind_next_frame_record(state); > +#else > + err = kunwind_next_frame_record(state); > +#endif > break; > default: > err = -EINVAL; > @@ -347,6 +403,9 @@ kunwind_stack_walk(kunwind_consume_fn consume_state, > .common = { > .stacks = stacks, > .nr_stacks = ARRAY_SIZE(stacks), > +#ifdef CONFIG_SFRAME_UNWINDER > + .cfa = 0, > +#endif > }, > }; > Looks good to me. Reviewed-by: Prasanna Kumar T S M .