[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220817222836.72aa77bd@gandalf.local.home>
Date: Wed, 17 Aug 2022 22:28:36 -0400
From: Steven Rostedt <rostedt@...dmis.org>
To: Chen Zhongjin <chenzhongjin@...wei.com>
Cc: <linux-kernel@...r.kernel.org>, <jpoimboe@...nel.org>,
<peterz@...radead.org>, <tglx@...utronix.de>, <mingo@...hat.com>,
<bp@...en8.de>, <dave.hansen@...ux.intel.com>, <x86@...nel.org>,
<hpa@...or.com>
Subject: Re: [PATCH] x86/unwind/orc: unwind ftrace trampolines with correct
orc
On Thu, 18 Aug 2022 09:55:25 +0800
Chen Zhongjin <chenzhongjin@...wei.com> wrote:
> arch/x86/kernel/unwind_orc.c | 13 ++++++++-----
> 1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
> index 38185aedf7d1..a938c5d0ed6f 100644
> --- a/arch/x86/kernel/unwind_orc.c
> +++ b/arch/x86/kernel/unwind_orc.c
> @@ -93,22 +93,25 @@ static struct orc_entry *orc_find(unsigned long ip);
> static struct orc_entry *orc_ftrace_find(unsigned long ip)
> {
> struct ftrace_ops *ops;
> - unsigned long caller;
> + unsigned long tramp_addr, offset;
>
> ops = ftrace_ops_trampoline(ip);
> if (!ops)
> return NULL;
>
Now if this is that unlikely recursion mentioned below then ops->trampoline
will be NULL, and if we do that offset addition, it will be incorrect.
Perhaps we should add here:
if (!ops->trampoline)
return NULL;
Let's add some comments.
/* Set tramp_addr to the start of the code copied by the trampoline */
> if (ops->flags & FTRACE_OPS_FL_SAVE_REGS)
> - caller = (unsigned long)ftrace_regs_call;
> + tramp_addr = (unsigned long)ftrace_regs_caller;
> else
> - caller = (unsigned long)ftrace_call;
> + tramp_addr = (unsigned long)ftrace_caller;
> +
/* Now place tramp_addr to the location within the trampoline ip is at */
> + offset = ip - ops->trampoline;
> + tramp_addr += offset;
>
> /* Prevent unlikely recursion */
> - if (ip == caller)
> + if (ip == tramp_addr)
> return NULL;
>
> - return orc_find(caller);
> + return orc_find(tramp_addr);
> }
> #else
> static struct orc_entry *orc_ftrace_find(unsigned long ip)
Powered by blists - more mailing lists