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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F1D8C4332F for ; Tue, 19 Apr 2022 13:09:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351930AbiDSNMH (ORCPT ); Tue, 19 Apr 2022 09:12:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39746 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239259AbiDSNMF (ORCPT ); Tue, 19 Apr 2022 09:12:05 -0400 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EB58335DC3; Tue, 19 Apr 2022 06:09:22 -0700 (PDT) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 92A48106F; Tue, 19 Apr 2022 06:09:22 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.75.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4A73B3F766; Tue, 19 Apr 2022 06:09:19 -0700 (PDT) Date: Tue, 19 Apr 2022 14:09:14 +0100 From: Mark Rutland To: He Zhe Cc: catalin.marinas@arm.com, will@kernel.org, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, keescook@chromium.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, benh@kernel.crashing.org, paulus@samba.org, borntraeger@linux.ibm.com, svens@linux.ibm.com, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC 1/8] stacktrace: Change callback prototype to pass more information Message-ID: References: <20220418132217.1573072-1-zhe.he@windriver.com> <20220418132217.1573072-2-zhe.he@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220418132217.1573072-2-zhe.he@windriver.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Apr 18, 2022 at 09:22:10PM +0800, He Zhe wrote: > Currently stack_trace_consume_fn can only have pc of each frame of the > stack. Copying-beyond-the-frame-detection also needs fp of current and > previous frame. Other detection algorithm in the future may need more > information of the frame. > > We define a frame_info to include them all. > > > Signed-off-by: He Zhe > --- > include/linux/stacktrace.h | 9 ++++++++- > kernel/stacktrace.c | 10 +++++----- > 2 files changed, 13 insertions(+), 6 deletions(-) > > diff --git a/include/linux/stacktrace.h b/include/linux/stacktrace.h > index 97455880ac41..5a61bfafe6f0 100644 > --- a/include/linux/stacktrace.h > +++ b/include/linux/stacktrace.h > @@ -10,15 +10,22 @@ struct pt_regs; > > #ifdef CONFIG_ARCH_STACKWALK > > +struct frame_info { > + unsigned long pc; > + unsigned long fp; > + unsigned long prev_fp; > +}; I don't think this should be exposed through a generic interface; the `fp` and `prev_fp` values are only meaningful with arch-specific knowledge, and they're *very* easy to misuse (e.g. when transitioning from one stack to another). There's also a bunch of other information one may or may not want, depending on what you're trying to achieve. I am happy to have an arch-specific internal unwinder where we can access this information, and *maybe* it makes sense to have a generic API that passes some opaque token, but I don't think we should make the structure generic. Thanks, Mark. > + > /** > * stack_trace_consume_fn - Callback for arch_stack_walk() > * @cookie: Caller supplied pointer handed back by arch_stack_walk() > * @addr: The stack entry address to consume > + * @fi: The frame information to consume > * > * Return: True, if the entry was consumed or skipped > * False, if there is no space left to store > */ > -typedef bool (*stack_trace_consume_fn)(void *cookie, unsigned long addr); > +typedef bool (*stack_trace_consume_fn)(void *cookie, struct frame_info *fi); > /** > * arch_stack_walk - Architecture specific function to walk the stack > * @consume_entry: Callback which is invoked by the architecture code for > diff --git a/kernel/stacktrace.c b/kernel/stacktrace.c > index 9ed5ce989415..2d0a2812e92b 100644 > --- a/kernel/stacktrace.c > +++ b/kernel/stacktrace.c > @@ -79,7 +79,7 @@ struct stacktrace_cookie { > unsigned int len; > }; > > -static bool stack_trace_consume_entry(void *cookie, unsigned long addr) > +static bool stack_trace_consume_entry(void *cookie, struct frame_info *fi) > { > struct stacktrace_cookie *c = cookie; > > @@ -90,15 +90,15 @@ static bool stack_trace_consume_entry(void *cookie, unsigned long addr) > c->skip--; > return true; > } > - c->store[c->len++] = addr; > + c->store[c->len++] = fi->pc; > return c->len < c->size; > } > > -static bool stack_trace_consume_entry_nosched(void *cookie, unsigned long addr) > +static bool stack_trace_consume_entry_nosched(void *cookie, struct frame_info *fi) > { > - if (in_sched_functions(addr)) > + if (in_sched_functions(fi->pc)) > return true; > - return stack_trace_consume_entry(cookie, addr); > + return stack_trace_consume_entry(cookie, fi); > } > > /** > -- > 2.25.1 > 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 lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (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 86EA8C433F5 for ; Tue, 19 Apr 2022 13:10:24 +0000 (UTC) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjPL64qSbz3bbN for ; Tue, 19 Apr 2022 23:10:22 +1000 (AEST) Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=arm.com (client-ip=217.140.110.172; helo=foss.arm.com; envelope-from=mark.rutland@arm.com; receiver=) Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lists.ozlabs.org (Postfix) with ESMTP id 4KjPKd6BgFz2xBv for ; Tue, 19 Apr 2022 23:09:55 +1000 (AEST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 92A48106F; Tue, 19 Apr 2022 06:09:22 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.75.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4A73B3F766; Tue, 19 Apr 2022 06:09:19 -0700 (PDT) Date: Tue, 19 Apr 2022 14:09:14 +0100 From: Mark Rutland To: He Zhe Subject: Re: [PATCH RFC 1/8] stacktrace: Change callback prototype to pass more information Message-ID: References: <20220418132217.1573072-1-zhe.he@windriver.com> <20220418132217.1573072-2-zhe.he@windriver.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220418132217.1573072-2-zhe.he@windriver.com> X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, linux-s390@vger.kernel.org, x86@kernel.org, hpa@zytor.com, keescook@chromium.org, alexander.shishkin@linux.intel.com, catalin.marinas@arm.com, dave.hansen@linux.intel.com, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, bp@alien8.de, svens@linux.ibm.com, jolsa@kernel.org, namhyung@kernel.org, tglx@linutronix.de, borntraeger@linux.ibm.com, will@kernel.org, linux-riscv@lists.infradead.org, paulus@samba.org Errors-To: linuxppc-dev-bounces+linuxppc-dev=archiver.kernel.org@lists.ozlabs.org Sender: "Linuxppc-dev" On Mon, Apr 18, 2022 at 09:22:10PM +0800, He Zhe wrote: > Currently stack_trace_consume_fn can only have pc of each frame of the > stack. Copying-beyond-the-frame-detection also needs fp of current and > previous frame. Other detection algorithm in the future may need more > information of the frame. > > We define a frame_info to include them all. > > > Signed-off-by: He Zhe > --- > include/linux/stacktrace.h | 9 ++++++++- > kernel/stacktrace.c | 10 +++++----- > 2 files changed, 13 insertions(+), 6 deletions(-) > > diff --git a/include/linux/stacktrace.h b/include/linux/stacktrace.h > index 97455880ac41..5a61bfafe6f0 100644 > --- a/include/linux/stacktrace.h > +++ b/include/linux/stacktrace.h > @@ -10,15 +10,22 @@ struct pt_regs; > > #ifdef CONFIG_ARCH_STACKWALK > > +struct frame_info { > + unsigned long pc; > + unsigned long fp; > + unsigned long prev_fp; > +}; I don't think this should be exposed through a generic interface; the `fp` and `prev_fp` values are only meaningful with arch-specific knowledge, and they're *very* easy to misuse (e.g. when transitioning from one stack to another). There's also a bunch of other information one may or may not want, depending on what you're trying to achieve. I am happy to have an arch-specific internal unwinder where we can access this information, and *maybe* it makes sense to have a generic API that passes some opaque token, but I don't think we should make the structure generic. Thanks, Mark. > + > /** > * stack_trace_consume_fn - Callback for arch_stack_walk() > * @cookie: Caller supplied pointer handed back by arch_stack_walk() > * @addr: The stack entry address to consume > + * @fi: The frame information to consume > * > * Return: True, if the entry was consumed or skipped > * False, if there is no space left to store > */ > -typedef bool (*stack_trace_consume_fn)(void *cookie, unsigned long addr); > +typedef bool (*stack_trace_consume_fn)(void *cookie, struct frame_info *fi); > /** > * arch_stack_walk - Architecture specific function to walk the stack > * @consume_entry: Callback which is invoked by the architecture code for > diff --git a/kernel/stacktrace.c b/kernel/stacktrace.c > index 9ed5ce989415..2d0a2812e92b 100644 > --- a/kernel/stacktrace.c > +++ b/kernel/stacktrace.c > @@ -79,7 +79,7 @@ struct stacktrace_cookie { > unsigned int len; > }; > > -static bool stack_trace_consume_entry(void *cookie, unsigned long addr) > +static bool stack_trace_consume_entry(void *cookie, struct frame_info *fi) > { > struct stacktrace_cookie *c = cookie; > > @@ -90,15 +90,15 @@ static bool stack_trace_consume_entry(void *cookie, unsigned long addr) > c->skip--; > return true; > } > - c->store[c->len++] = addr; > + c->store[c->len++] = fi->pc; > return c->len < c->size; > } > > -static bool stack_trace_consume_entry_nosched(void *cookie, unsigned long addr) > +static bool stack_trace_consume_entry_nosched(void *cookie, struct frame_info *fi) > { > - if (in_sched_functions(addr)) > + if (in_sched_functions(fi->pc)) > return true; > - return stack_trace_consume_entry(cookie, addr); > + return stack_trace_consume_entry(cookie, fi); > } > > /** > -- > 2.25.1 > 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 18402C43217 for ; Tue, 19 Apr 2022 13:56:43 +0000 (UTC) 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=yPCyd7JwHAFFM5jYg0C9PwjwgEMDCNH4NG2A5JrHXEc=; b=ITtH0ZagBALcaS cZN8RFNzNMoTjWAKxhmkr264bm40obbX18n7DkfQ72+BzmfiRUhxE3ZZtJUjpq7IstPH93V8/6OMj KPkrkd20MvZ/smuH96l7cMMKotYWI35JpogvY2okx8jKhZfBwL8Ko1L6OkDYY564keS9myBFP8h7f oKXN/CQ9vOaXhEOy9hAMP3UTdecthsb0z04EtYe8l+c6Exr0Ur6sLDsrplWjv5yzqHt3JFPoYblQ/ WD1gDpLUb1bvHC8iQj0b4Rn7Pl6Xu9miVACT62BVGb0Jdkbn2V5f8ioYbu5GhXDG9BfoGx4Hx3L3f FTynQxXL9Mszeim1lWyg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngoLI-0043NA-OH; Tue, 19 Apr 2022 13:56:32 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngnbi-003j0q-CR; Tue, 19 Apr 2022 13:09:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 92A48106F; Tue, 19 Apr 2022 06:09:22 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.75.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4A73B3F766; Tue, 19 Apr 2022 06:09:19 -0700 (PDT) Date: Tue, 19 Apr 2022 14:09:14 +0100 From: Mark Rutland To: He Zhe Cc: catalin.marinas@arm.com, will@kernel.org, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, keescook@chromium.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, benh@kernel.crashing.org, paulus@samba.org, borntraeger@linux.ibm.com, svens@linux.ibm.com, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC 1/8] stacktrace: Change callback prototype to pass more information Message-ID: References: <20220418132217.1573072-1-zhe.he@windriver.com> <20220418132217.1573072-2-zhe.he@windriver.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220418132217.1573072-2-zhe.he@windriver.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220419_060926_561694_A08C85F6 X-CRM114-Status: GOOD ( 23.59 ) X-BeenThere: linux-riscv@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-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org On Mon, Apr 18, 2022 at 09:22:10PM +0800, He Zhe wrote: > Currently stack_trace_consume_fn can only have pc of each frame of the > stack. Copying-beyond-the-frame-detection also needs fp of current and > previous frame. Other detection algorithm in the future may need more > information of the frame. > > We define a frame_info to include them all. > > > Signed-off-by: He Zhe > --- > include/linux/stacktrace.h | 9 ++++++++- > kernel/stacktrace.c | 10 +++++----- > 2 files changed, 13 insertions(+), 6 deletions(-) > > diff --git a/include/linux/stacktrace.h b/include/linux/stacktrace.h > index 97455880ac41..5a61bfafe6f0 100644 > --- a/include/linux/stacktrace.h > +++ b/include/linux/stacktrace.h > @@ -10,15 +10,22 @@ struct pt_regs; > > #ifdef CONFIG_ARCH_STACKWALK > > +struct frame_info { > + unsigned long pc; > + unsigned long fp; > + unsigned long prev_fp; > +}; I don't think this should be exposed through a generic interface; the `fp` and `prev_fp` values are only meaningful with arch-specific knowledge, and they're *very* easy to misuse (e.g. when transitioning from one stack to another). There's also a bunch of other information one may or may not want, depending on what you're trying to achieve. I am happy to have an arch-specific internal unwinder where we can access this information, and *maybe* it makes sense to have a generic API that passes some opaque token, but I don't think we should make the structure generic. Thanks, Mark. > + > /** > * stack_trace_consume_fn - Callback for arch_stack_walk() > * @cookie: Caller supplied pointer handed back by arch_stack_walk() > * @addr: The stack entry address to consume > + * @fi: The frame information to consume > * > * Return: True, if the entry was consumed or skipped > * False, if there is no space left to store > */ > -typedef bool (*stack_trace_consume_fn)(void *cookie, unsigned long addr); > +typedef bool (*stack_trace_consume_fn)(void *cookie, struct frame_info *fi); > /** > * arch_stack_walk - Architecture specific function to walk the stack > * @consume_entry: Callback which is invoked by the architecture code for > diff --git a/kernel/stacktrace.c b/kernel/stacktrace.c > index 9ed5ce989415..2d0a2812e92b 100644 > --- a/kernel/stacktrace.c > +++ b/kernel/stacktrace.c > @@ -79,7 +79,7 @@ struct stacktrace_cookie { > unsigned int len; > }; > > -static bool stack_trace_consume_entry(void *cookie, unsigned long addr) > +static bool stack_trace_consume_entry(void *cookie, struct frame_info *fi) > { > struct stacktrace_cookie *c = cookie; > > @@ -90,15 +90,15 @@ static bool stack_trace_consume_entry(void *cookie, unsigned long addr) > c->skip--; > return true; > } > - c->store[c->len++] = addr; > + c->store[c->len++] = fi->pc; > return c->len < c->size; > } > > -static bool stack_trace_consume_entry_nosched(void *cookie, unsigned long addr) > +static bool stack_trace_consume_entry_nosched(void *cookie, struct frame_info *fi) > { > - if (in_sched_functions(addr)) > + if (in_sched_functions(fi->pc)) > return true; > - return stack_trace_consume_entry(cookie, addr); > + return stack_trace_consume_entry(cookie, fi); > } > > /** > -- > 2.25.1 > _______________________________________________ linux-riscv mailing list linux-riscv@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-riscv 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 05D96C433FE for ; Tue, 19 Apr 2022 13:57:57 +0000 (UTC) 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=gXs8AGAQV1VW8enGMMZmV7kr8FB3STQoTpQ/zTtd3LI=; b=i6I+zyAKXr/Jii TWqYo2MJdJTKw1VOXzFYNom4NMUAJftFvpkGZSJcOBczgJdXpGTkhibRRhfVJ5XCjaTvf3JuRzsQh weh42E4Jv7kZ35SKAGPBFnwU+bPe1ez4LU+eaYnS4zEWTZHwfUlR0SFUrVQDg+O5FNJp3Xlhm1Sn9 SFXj6pjxNvVfuQ1y498Xmvhj3mMHqwXgGB7MeEA0Z3dlFgG4oGvNBpbMItTkMnZV0q+6YY0EZnW2T cMYV/S0Ux15R/kEN4USDlxWkYXqtp2zX+FM5HGUMHLzRkWaF4HyMgZvu7RHGyilS6YFoXPwOlrbua T2Qmp34FkiCnlPIyrBfg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngoKP-00430A-E0; Tue, 19 Apr 2022 13:55:38 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1ngnbi-003j0q-CR; Tue, 19 Apr 2022 13:09:28 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 92A48106F; Tue, 19 Apr 2022 06:09:22 -0700 (PDT) Received: from FVFF77S0Q05N (unknown [10.57.75.72]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 4A73B3F766; Tue, 19 Apr 2022 06:09:19 -0700 (PDT) Date: Tue, 19 Apr 2022 14:09:14 +0100 From: Mark Rutland To: He Zhe Cc: catalin.marinas@arm.com, will@kernel.org, tglx@linutronix.de, bp@alien8.de, dave.hansen@linux.intel.com, keescook@chromium.org, alexander.shishkin@linux.intel.com, jolsa@kernel.org, namhyung@kernel.org, benh@kernel.crashing.org, paulus@samba.org, borntraeger@linux.ibm.com, svens@linux.ibm.com, hpa@zytor.com, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-perf-users@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH RFC 1/8] stacktrace: Change callback prototype to pass more information Message-ID: References: <20220418132217.1573072-1-zhe.he@windriver.com> <20220418132217.1573072-2-zhe.he@windriver.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220418132217.1573072-2-zhe.he@windriver.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220419_060926_561694_A08C85F6 X-CRM114-Status: GOOD ( 23.59 ) 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 Mon, Apr 18, 2022 at 09:22:10PM +0800, He Zhe wrote: > Currently stack_trace_consume_fn can only have pc of each frame of the > stack. Copying-beyond-the-frame-detection also needs fp of current and > previous frame. Other detection algorithm in the future may need more > information of the frame. > > We define a frame_info to include them all. > > > Signed-off-by: He Zhe > --- > include/linux/stacktrace.h | 9 ++++++++- > kernel/stacktrace.c | 10 +++++----- > 2 files changed, 13 insertions(+), 6 deletions(-) > > diff --git a/include/linux/stacktrace.h b/include/linux/stacktrace.h > index 97455880ac41..5a61bfafe6f0 100644 > --- a/include/linux/stacktrace.h > +++ b/include/linux/stacktrace.h > @@ -10,15 +10,22 @@ struct pt_regs; > > #ifdef CONFIG_ARCH_STACKWALK > > +struct frame_info { > + unsigned long pc; > + unsigned long fp; > + unsigned long prev_fp; > +}; I don't think this should be exposed through a generic interface; the `fp` and `prev_fp` values are only meaningful with arch-specific knowledge, and they're *very* easy to misuse (e.g. when transitioning from one stack to another). There's also a bunch of other information one may or may not want, depending on what you're trying to achieve. I am happy to have an arch-specific internal unwinder where we can access this information, and *maybe* it makes sense to have a generic API that passes some opaque token, but I don't think we should make the structure generic. Thanks, Mark. > + > /** > * stack_trace_consume_fn - Callback for arch_stack_walk() > * @cookie: Caller supplied pointer handed back by arch_stack_walk() > * @addr: The stack entry address to consume > + * @fi: The frame information to consume > * > * Return: True, if the entry was consumed or skipped > * False, if there is no space left to store > */ > -typedef bool (*stack_trace_consume_fn)(void *cookie, unsigned long addr); > +typedef bool (*stack_trace_consume_fn)(void *cookie, struct frame_info *fi); > /** > * arch_stack_walk - Architecture specific function to walk the stack > * @consume_entry: Callback which is invoked by the architecture code for > diff --git a/kernel/stacktrace.c b/kernel/stacktrace.c > index 9ed5ce989415..2d0a2812e92b 100644 > --- a/kernel/stacktrace.c > +++ b/kernel/stacktrace.c > @@ -79,7 +79,7 @@ struct stacktrace_cookie { > unsigned int len; > }; > > -static bool stack_trace_consume_entry(void *cookie, unsigned long addr) > +static bool stack_trace_consume_entry(void *cookie, struct frame_info *fi) > { > struct stacktrace_cookie *c = cookie; > > @@ -90,15 +90,15 @@ static bool stack_trace_consume_entry(void *cookie, unsigned long addr) > c->skip--; > return true; > } > - c->store[c->len++] = addr; > + c->store[c->len++] = fi->pc; > return c->len < c->size; > } > > -static bool stack_trace_consume_entry_nosched(void *cookie, unsigned long addr) > +static bool stack_trace_consume_entry_nosched(void *cookie, struct frame_info *fi) > { > - if (in_sched_functions(addr)) > + if (in_sched_functions(fi->pc)) > return true; > - return stack_trace_consume_entry(cookie, addr); > + return stack_trace_consume_entry(cookie, fi); > } > > /** > -- > 2.25.1 > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel