* [PATCH v2] x86/unwind/orc: unwind ftrace trampolines with correct orc
@ 2022-08-19 8:43 Chen Zhongjin
2022-08-19 17:28 ` Steven Rostedt
2022-08-21 10:33 ` [tip: x86/urgent] x86/unwind/orc: Unwind ftrace trampolines with correct ORC entry tip-bot2 for Chen Zhongjin
0 siblings, 2 replies; 5+ messages in thread
From: Chen Zhongjin @ 2022-08-19 8:43 UTC (permalink / raw)
To: linux-kernel
Cc: jpoimboe, peterz, tglx, mingo, bp, dave.hansen, x86, hpa, rostedt,
chenzhongjin
When meeting ftrace trampolines in orc unwinding, unwinder uses address
of ftrace_{regs_}call address to find the orc, which gets next frame at
sp+176.
If there is an irq hitting at sub $0xa8,%rsp, the next frame should be
sp+8 instead of 176. It makes unwinder skip correct frame and throw
warnings such as "wrong direction" or "can't access registers", etc,
depending on the content of the wrong frame address.
By adding the base address ftrace_{regs_}caller with the offset
*ip - ops->trampoline*,
we can get the correct address to find orc.
Also change "caller" to "tramp_addr" to make variable name conform to
its content.
Fixes: 6be7fa3c74d1 ("ftrace, orc, x86: Handle ftrace dynamically allocated trampolines")
Cc: <stable@vger.kernel.org>
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
---
v1 -> v2:
Add some comments.
---
arch/x86/kernel/unwind_orc.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
index 38185aedf7d1..0ea57da92940 100644
--- a/arch/x86/kernel/unwind_orc.c
+++ b/arch/x86/kernel/unwind_orc.c
@@ -93,22 +93,27 @@ 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;
+ /* 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)
--
2.17.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] x86/unwind/orc: unwind ftrace trampolines with correct orc
2022-08-19 8:43 [PATCH v2] x86/unwind/orc: unwind ftrace trampolines with correct orc Chen Zhongjin
@ 2022-08-19 17:28 ` Steven Rostedt
2022-08-21 10:20 ` Ingo Molnar
2022-08-21 10:33 ` [tip: x86/urgent] x86/unwind/orc: Unwind ftrace trampolines with correct ORC entry tip-bot2 for Chen Zhongjin
1 sibling, 1 reply; 5+ messages in thread
From: Steven Rostedt @ 2022-08-19 17:28 UTC (permalink / raw)
To: Chen Zhongjin
Cc: linux-kernel, jpoimboe, peterz, tglx, mingo, bp, dave.hansen, x86,
hpa
On Fri, 19 Aug 2022 16:43:34 +0800
Chen Zhongjin <chenzhongjin@huawei.com> wrote:
> When meeting ftrace trampolines in orc unwinding, unwinder uses address
> of ftrace_{regs_}call address to find the orc, which gets next frame at
> sp+176.
>
> If there is an irq hitting at sub $0xa8,%rsp, the next frame should be
> sp+8 instead of 176. It makes unwinder skip correct frame and throw
> warnings such as "wrong direction" or "can't access registers", etc,
> depending on the content of the wrong frame address.
>
> By adding the base address ftrace_{regs_}caller with the offset
> *ip - ops->trampoline*,
> we can get the correct address to find orc.
>
> Also change "caller" to "tramp_addr" to make variable name conform to
> its content.
>
> Fixes: 6be7fa3c74d1 ("ftrace, orc, x86: Handle ftrace dynamically allocated trampolines")
> Cc: <stable@vger.kernel.org>
> Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Would someone from the tip tree care to pull this in?
-- Steve
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v2] x86/unwind/orc: unwind ftrace trampolines with correct orc
2022-08-19 17:28 ` Steven Rostedt
@ 2022-08-21 10:20 ` Ingo Molnar
2022-08-22 15:00 ` Steven Rostedt
0 siblings, 1 reply; 5+ messages in thread
From: Ingo Molnar @ 2022-08-21 10:20 UTC (permalink / raw)
To: Steven Rostedt
Cc: Chen Zhongjin, linux-kernel, jpoimboe, peterz, tglx, mingo, bp,
dave.hansen, x86, hpa
* Steven Rostedt <rostedt@goodmis.org> wrote:
> On Fri, 19 Aug 2022 16:43:34 +0800
> Chen Zhongjin <chenzhongjin@huawei.com> wrote:
>
> > When meeting ftrace trampolines in orc unwinding, unwinder uses address
> > of ftrace_{regs_}call address to find the orc, which gets next frame at
> > sp+176.
> >
> > If there is an irq hitting at sub $0xa8,%rsp, the next frame should be
> > sp+8 instead of 176. It makes unwinder skip correct frame and throw
> > warnings such as "wrong direction" or "can't access registers", etc,
> > depending on the content of the wrong frame address.
> >
> > By adding the base address ftrace_{regs_}caller with the offset
> > *ip - ops->trampoline*,
> > we can get the correct address to find orc.
> >
> > Also change "caller" to "tramp_addr" to make variable name conform to
> > its content.
> >
> > Fixes: 6be7fa3c74d1 ("ftrace, orc, x86: Handle ftrace dynamically allocated trampolines")
> > Cc: <stable@vger.kernel.org>
> > Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
>
> Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
>
> Would someone from the tip tree care to pull this in?
Picked it up into tip:x86/urgent with minor edits to the changelog - will
push it out after some testing.
Thanks,
Ingo
^ permalink raw reply [flat|nested] 5+ messages in thread
* [tip: x86/urgent] x86/unwind/orc: Unwind ftrace trampolines with correct ORC entry
2022-08-19 8:43 [PATCH v2] x86/unwind/orc: unwind ftrace trampolines with correct orc Chen Zhongjin
2022-08-19 17:28 ` Steven Rostedt
@ 2022-08-21 10:33 ` tip-bot2 for Chen Zhongjin
1 sibling, 0 replies; 5+ messages in thread
From: tip-bot2 for Chen Zhongjin @ 2022-08-21 10:33 UTC (permalink / raw)
To: linux-tip-commits
Cc: Chen Zhongjin, Ingo Molnar, Steven Rostedt (Google), stable, x86,
linux-kernel
The following commit has been merged into the x86/urgent branch of tip:
Commit-ID: fc2e426b1161761561624ebd43ce8c8d2fa058da
Gitweb: https://git.kernel.org/tip/fc2e426b1161761561624ebd43ce8c8d2fa058da
Author: Chen Zhongjin <chenzhongjin@huawei.com>
AuthorDate: Fri, 19 Aug 2022 16:43:34 +08:00
Committer: Ingo Molnar <mingo@kernel.org>
CommitterDate: Sun, 21 Aug 2022 12:19:32 +02:00
x86/unwind/orc: Unwind ftrace trampolines with correct ORC entry
When meeting ftrace trampolines in ORC unwinding, unwinder uses address
of ftrace_{regs_}call address to find the ORC entry, which gets next frame at
sp+176.
If there is an IRQ hitting at sub $0xa8,%rsp, the next frame should be
sp+8 instead of 176. It makes unwinder skip correct frame and throw
warnings such as "wrong direction" or "can't access registers", etc,
depending on the content of the incorrect frame address.
By adding the base address ftrace_{regs_}caller with the offset
*ip - ops->trampoline*, we can get the correct address to find the ORC entry.
Also change "caller" to "tramp_addr" to make variable name conform to
its content.
[ mingo: Clarified the changelog a bit. ]
Fixes: 6be7fa3c74d1 ("ftrace, orc, x86: Handle ftrace dynamically allocated trampolines")
Signed-off-by: Chen Zhongjin <chenzhongjin@huawei.com>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
Cc: <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20220819084334.244016-1-chenzhongjin@huawei.com
---
arch/x86/kernel/unwind_orc.c | 15 ++++++++++-----
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c
index 38185ae..0ea57da 100644
--- a/arch/x86/kernel/unwind_orc.c
+++ b/arch/x86/kernel/unwind_orc.c
@@ -93,22 +93,27 @@ 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;
+ /* 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)
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v2] x86/unwind/orc: unwind ftrace trampolines with correct orc
2022-08-21 10:20 ` Ingo Molnar
@ 2022-08-22 15:00 ` Steven Rostedt
0 siblings, 0 replies; 5+ messages in thread
From: Steven Rostedt @ 2022-08-22 15:00 UTC (permalink / raw)
To: Ingo Molnar
Cc: Chen Zhongjin, linux-kernel, jpoimboe, peterz, tglx, mingo, bp,
dave.hansen, x86, hpa
On Sun, 21 Aug 2022 12:20:50 +0200
Ingo Molnar <mingo@kernel.org> wrote:
> > Reviewed-by: Steven Rostedt (Google) <rostedt@goodmis.org>
> >
> > Would someone from the tip tree care to pull this in?
>
> Picked it up into tip:x86/urgent with minor edits to the changelog - will
> push it out after some testing.
Thanks Ingo!
-- Steve
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2022-08-22 14:59 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-08-19 8:43 [PATCH v2] x86/unwind/orc: unwind ftrace trampolines with correct orc Chen Zhongjin
2022-08-19 17:28 ` Steven Rostedt
2022-08-21 10:20 ` Ingo Molnar
2022-08-22 15:00 ` Steven Rostedt
2022-08-21 10:33 ` [tip: x86/urgent] x86/unwind/orc: Unwind ftrace trampolines with correct ORC entry tip-bot2 for Chen Zhongjin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox