linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kefeng Wang <wangkefeng.wang@huawei.com>
To: Chen Huang <chenhuang5@huawei.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Albert Ou <aou@eecs.berkeley.edu>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	<linux-riscv@lists.infradead.org>, <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] riscv/stacktrace: fix stackframe without ra on the top
Date: Fri, 27 Nov 2020 19:43:19 +0800	[thread overview]
Message-ID: <22dbe32a-0757-97ad-8885-0f2ba55bb743@huawei.com> (raw)
In-Reply-To: <20201127084502.2133722-1-chenhuang5@huawei.com>


On 2020/11/27 16:45, Chen Huang wrote:
> When a function doesn't have a callee, then it will not push ra
> into the stack, such as lkdtm_BUG() function:
>
> addi	sp,sp,-16
> sd	s0,8(sp)
> addi	s0,sp,16
> ebreak
>
> Then we use pt_regs as a parameter to walk_stackframe(), for the
> struct stackframe use {fp,ra} to get information from stack, it
> will get the wrong value. And the call trace will be:
>
> [<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8
> ---[ end trace 18da3fbdf08e25d5 ]---
>
> It should be that:
> [<ffffffe00066c56c>] lkdtm_BUG+0x6/0x8
> [<ffffffe0008b24a4>] lkdtm_do_action+0x14/0x1c
> [<ffffffe00066c372>] direct_entry+0xc0/0x10a
> [<ffffffe000439f86>] full_proxy_write+0x42/0x6a
> [<ffffffe000309626>] vfs_write+0x7e/0x214
> [<ffffffe00030992a>] ksys_write+0x98/0xc0
> [<ffffffe000309960>] sys_write+0xe/0x16
> [<ffffffe0002014bc>] ret_from_syscall+0x0/0x2
> ---[ end trace 61917f3d9a9fadcd ]---
>
> Signed-off-by: Chen Huang <chenhuang5@huawei.com>
> ---
>   arch/riscv/kernel/stacktrace.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c
> index 595342910c3f..d1d4c18335c4 100644
> --- a/arch/riscv/kernel/stacktrace.c
> +++ b/arch/riscv/kernel/stacktrace.c
> @@ -57,7 +57,14 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs,
>   		/* Unwind stack frame */
>   		frame = (struct stackframe *)fp - 1;
>   		sp = fp;
> -		fp = frame->fp;
> +		if (regs && (frame->fp & 0x7) && (pc == regs->epc)) {
> +			fp = frame->ra;
> +			pc = regs->ra;
> +			continue;
> +		} else {
> +			fp = frame->fp;
> +		}
> +
>   		pc = ftrace_graph_ret_addr(current, NULL, frame->ra,
>   					   (unsigned long *)(fp - 8));

Better to move above code into else branch

>   	}

  reply	other threads:[~2020-11-27 11:43 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27  8:45 [PATCH] riscv/stacktrace: fix stackframe without ra on the top Chen Huang
2020-11-27 11:43 ` Kefeng Wang [this message]
2020-11-28  6:22   ` [PATCH v2] riscv: stacktrace: " Chen Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=22dbe32a-0757-97ad-8885-0f2ba55bb743@huawei.com \
    --to=wangkefeng.wang@huawei.com \
    --cc=akpm@linux-foundation.org \
    --cc=aou@eecs.berkeley.edu \
    --cc=chenhuang5@huawei.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).