From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: Thomas Gleixner <tglx@linutronix.de>,
Ingo Molnar <mingo@kernel.org>, "H . Peter Anvin" <hpa@zytor.com>,
x86@kernel.org, linux-kernel@vger.kernel.org,
Andy Lutomirski <luto@amacapital.net>,
Linus Torvalds <torvalds@linux-foundation.org>,
Brian Gerst <brgerst@gmail.com>,
Kees Cook <keescook@chromium.org>,
Peter Zijlstra <peterz@infradead.org>,
Frederic Weisbecker <fweisbec@gmail.com>,
Byungchul Park <byungchul.park@lge.com>
Subject: Re: [PATCH 05/19] x86/dumpstack: fix function graph tracing stack dump reliability issues
Date: Tue, 2 Aug 2016 16:00:11 -0500 [thread overview]
Message-ID: <20160802210011.k6li4mnyvky5jtev@treble> (raw)
In-Reply-To: <20160801153633.c7sa2rclkqwbdagd@treble>
On Mon, Aug 01, 2016 at 10:36:33AM -0500, Josh Poimboeuf wrote:
> On Mon, Aug 01, 2016 at 10:28:21AM -0400, Steven Rostedt wrote:
> > On Sat, 30 Jul 2016 08:51:25 -0500
> > Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> >
> > > On Fri, Jul 29, 2016 at 10:20:36PM -0400, Steven Rostedt wrote:
> > > > On Fri, 29 Jul 2016 19:50:59 -0500
> > > > Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > > >
> > > > > BTW, it would be really nice if ftrace_graph_ret_addr() were idempotent
> > > > > so we could get the "real" return address without having to pass in a
> > > > > state variable.
> > > > >
> > > > > For example we could add an "unsigned long *retp" pointer to
> > > > > ftrace_ret_stack, which points to the return address on the stack. Then
> > > > > we could get rid of the index state variable in ftrace_graph_ret_addr,
> > > > > and also then there would never be a chance of the stack dump getting
> > > > > out of sync with the ret_stack.
> > > > >
> > > > > What do you think?
> > > > >
> > > >
> > > > I don't want to extend ret_stack as that is allocated 50 of these
> > > > structures for every task. That said, we have the "fp" field that's
> > > > used to check for frame pointer corruption when mcount is used. With
> > > > CC_USING_FENTRY, that field is ignored. Perhaps we could overload that
> > > > field for this.
> > >
> > > In that case, I guess we would need two versions of
> > > ftrace_graph_ret_addr(), with the current implementation still needed
> > > for mcount+HAVE_FUNCTION_GRAPH_FP_TEST.
> >
> > How hard would it be in that case?
>
> Well, it would be easy enough, but then the caller would still need to
> pass in the state variable. So maybe it's not worth the trouble.
I did some stack trace testing on mainline with function graph tracing.
As it turns out, print_ftrace_graph_addr() is already buggy today if the
caller of dump_trace() specifies a stack pointer or a pt_regs (which is
usually done in order to skip some irrelevant stack frames in the
trace).
For example, here's a stack trace based on NMI regs:
$ echo 1 > /proc/sys/kernel/sysrq
$ echo l > /proc/sysrq-trigger
...
Call Trace:
[<ffffffff81066141>] ? __x2apic_send_IPI_dest.constprop.4+0x31/0x40
[<ffffffff810661e5>] __x2apic_send_IPI_mask+0x95/0xe0
[<ffffffff81061d70>] ? irq_force_complete_move+0xf0/0xf0
[<ffffffff810662a3>] x2apic_send_IPI_mask+0x13/0x20
[<ffffffff81061d8b>] nmi_raise_cpu_backtrace+0x1b/0x20
[<ffffffff8144ff76>] nmi_trigger_all_cpu_backtrace+0xc6/0xf0
[<ffffffff81061de9>] arch_trigger_all_cpu_backtrace+0x19/0x20
[<ffffffff8155c463>] sysrq_handle_showallcpus+0x13/0x20
[<ffffffff8155cc18>] __handle_sysrq+0x138/0x220
[<ffffffff8155cae5>] ? __handle_sysrq+0x5/0x220
[<ffffffff8155d111>] write_sysrq_trigger+0x51/0x60
[<ffffffff813104e2>] proc_reg_write+0x42/0x70
[<ffffffff81291877>] __vfs_write+0x37/0x140
[<ffffffff8110d161>] ? update_fast_ctr+0x51/0x80
[<ffffffff8110d217>] ? percpu_down_read+0x57/0xa0
[<ffffffff81296074>] ? __sb_start_write+0xb4/0xf0
[<ffffffff81296074>] ? __sb_start_write+0xb4/0xf0
[<ffffffff81292b38>] vfs_write+0xb8/0x1a0
[<ffffffff81293fe8>] SyS_write+0x58/0xc0
[<ffffffff818af97c>] entry_SYSCALL_64_fastpath+0x1f/0xbd
And here's the same trace with function graph tracing:
$ echo function_graph > /sys/kernel/debug/tracing/current_tracer
$ echo l > /proc/sysrq-trigger
...
Call Trace:
[<ffffffff81066141>] ? __x2apic_send_IPI_dest.constprop.4+0x31/0x40
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff810394cc>] print_context_stack+0xfc/0x100
[<ffffffff81061d70>] ? irq_force_complete_move+0xf0/0xf0
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff8103891b>] dump_trace+0x12b/0x350
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff810396eb>] show_trace_log_lvl+0x4b/0x60
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff81038c76>] show_stack_log_lvl+0x136/0x1d0
[<ffffffff81061de9>] arch_trigger_all_cpu_backtrace+0x19/0x20
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff81038db8>] show_regs+0xa8/0x1b0
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff8144fe96>] nmi_cpu_backtrace+0x46/0x60
[<ffffffff8155cae5>] ? __handle_sysrq+0x5/0x220
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff81039b5f>] nmi_handle+0xbf/0x2f0
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff8103a2b3>] default_do_nmi+0x73/0x180
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff8103a4d9>] do_nmi+0x119/0x170
[<ffffffff811bb3cd>] ? ftrace_return_to_handler+0x9d/0x110
[<ffffffff81291845>] ? __vfs_write+0x5/0x140
[<ffffffff81291845>] ? __vfs_write+0x5/0x140
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff810661e5>] __x2apic_send_IPI_mask+0x95/0xe0
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff810662a3>] x2apic_send_IPI_mask+0x13/0x20
[<ffffffff818b2428>] ftrace_graph_caller+0xa8/0xa8
[<ffffffff81061d8b>] nmi_raise_cpu_backtrace+0x1b/0x20
The ret_stack is out of sync with the stack dump because the stack dump
was started with the regs from the NMI, instead of being started from
the current frame.
So I guess there are a couple of ways to fix it:
a) keep track of the return address pointer like we discussed above;
or
b) have the unwinder count the # of skipped frames which refer to
'return_to_handler', and pass that as the initial index value to
ftrace_graph_ret_addr().
Option a) would be much cleaner. But to fix it for both mcount and
fentry, we couldn't override 'fp' so I guess we'd need to add a new
field to ftrace_ret_stack.
Option b) is uglier, but I could probably make it work with the new
unwinder.
--
Josh
next prev parent reply other threads:[~2016-08-02 21:00 UTC|newest]
Thread overview: 91+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-07-21 21:21 [PATCH 00/19] x86/dumpstack: rewrite x86 stack dump code Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 01/19] x86/dumpstack: remove show_trace() Josh Poimboeuf
2016-07-21 21:49 ` Andy Lutomirski
2016-07-21 21:21 ` [PATCH 02/19] x86/dumpstack: add get_stack_pointer() and get_frame_pointer() Josh Poimboeuf
2016-07-21 21:53 ` Andy Lutomirski
2016-07-21 21:21 ` [PATCH 03/19] x86/dumpstack: remove unnecessary stack pointer arguments Josh Poimboeuf
2016-07-21 21:56 ` Andy Lutomirski
2016-07-22 1:41 ` Josh Poimboeuf
2016-07-22 2:29 ` Andy Lutomirski
2016-07-22 3:08 ` Brian Gerst
2016-07-21 21:21 ` [PATCH 04/19] x86/dumpstack: make printk_stack_address() more generally useful Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 05/19] x86/dumpstack: fix function graph tracing stack dump reliability issues Josh Poimboeuf
2016-07-29 22:55 ` Steven Rostedt
2016-07-30 0:50 ` Josh Poimboeuf
2016-07-30 2:20 ` Steven Rostedt
2016-07-30 13:51 ` Josh Poimboeuf
2016-08-01 14:28 ` Steven Rostedt
2016-08-01 15:36 ` Josh Poimboeuf
2016-08-02 21:00 ` Josh Poimboeuf [this message]
2016-08-02 21:16 ` Steven Rostedt
2016-08-02 22:13 ` Josh Poimboeuf
2016-08-02 23:16 ` Steven Rostedt
2016-08-03 1:56 ` Josh Poimboeuf
2016-08-03 2:30 ` Steven Rostedt
2016-08-03 2:50 ` Josh Poimboeuf
2016-08-03 2:59 ` Steven Rostedt
2016-08-03 3:12 ` Josh Poimboeuf
2016-08-03 3:18 ` Steven Rostedt
2016-08-03 3:21 ` Steven Rostedt
2016-08-03 3:31 ` Josh Poimboeuf
2016-08-03 3:45 ` Steven Rostedt
2016-08-03 14:13 ` Josh Poimboeuf
2016-08-03 3:30 ` Josh Poimboeuf
2016-08-01 15:59 ` Josh Poimboeuf
2016-08-01 16:05 ` Steven Rostedt
2016-08-01 16:19 ` Josh Poimboeuf
2016-08-01 16:24 ` Josh Poimboeuf
2016-08-01 16:56 ` Steven Rostedt
2016-07-21 21:21 ` [PATCH 06/19] x86/dumpstack: remove extra brackets around "EOE" Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 07/19] x86/dumpstack: add IRQ_USABLE_STACK_SIZE define Josh Poimboeuf
2016-07-21 22:01 ` Andy Lutomirski
2016-07-22 1:48 ` Josh Poimboeuf
2016-07-22 8:24 ` Ingo Molnar
2016-07-21 21:21 ` [PATCH 08/19] x86/dumpstack: don't disable preemption in show_stack_log_lvl() and dump_trace() Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 09/19] x86/dumpstack: simplify in_exception_stack() Josh Poimboeuf
2016-07-21 22:05 ` Andy Lutomirski
2016-07-21 21:21 ` [PATCH 10/19] x86/dumpstack: add get_stack_info() interface Josh Poimboeuf
2016-07-22 23:26 ` Andy Lutomirski
2016-07-22 23:52 ` Andy Lutomirski
2016-07-23 13:09 ` Josh Poimboeuf
2016-07-22 23:54 ` Josh Poimboeuf
2016-07-23 0:15 ` Andy Lutomirski
2016-07-23 14:04 ` Josh Poimboeuf
2016-07-26 0:09 ` Andy Lutomirski
2016-07-26 16:26 ` Josh Poimboeuf
2016-07-26 17:51 ` Steven Rostedt
2016-07-26 18:56 ` Josh Poimboeuf
2016-07-26 20:59 ` Andy Lutomirski
2016-07-26 22:24 ` Josh Poimboeuf
2016-07-26 22:31 ` Steven Rostedt
2016-07-26 22:37 ` Andy Lutomirski
2016-07-26 16:47 ` Josh Poimboeuf
2016-07-26 17:49 ` Brian Gerst
2016-07-26 18:59 ` Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 11/19] x86/dumptrace: add new unwind interface and implementations Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 12/19] perf/x86: convert perf_callchain_kernel() to the new unwinder Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 13/19] x86/stacktrace: convert save_stack_trace_*() " Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 14/19] oprofile/x86: convert x86_backtrace() " Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 15/19] x86/dumpstack: convert show_trace_log_lvl() " Josh Poimboeuf
2016-07-21 21:49 ` Byungchul Park
2016-07-22 1:38 ` Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 16/19] x86/dumpstack: remove dump_trace() Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 17/19] x86/entry/dumpstack: encode pt_regs pointer in frame pointer Josh Poimboeuf
2016-07-21 22:27 ` Andy Lutomirski
2016-07-21 21:21 ` [PATCH 18/19] x86/dumpstack: print stack identifier on its own line Josh Poimboeuf
2016-07-21 21:21 ` [PATCH 19/19] x86/dumpstack: print any pt_regs found on the stack Josh Poimboeuf
2016-07-21 22:32 ` Andy Lutomirski
2016-07-22 3:30 ` Josh Poimboeuf
2016-07-22 5:13 ` Andy Lutomirski
2016-07-22 15:57 ` Josh Poimboeuf
2016-07-22 21:46 ` Andy Lutomirski
2016-07-22 22:20 ` Josh Poimboeuf
2016-07-22 23:18 ` Andy Lutomirski
2016-07-22 23:30 ` Josh Poimboeuf
2016-07-22 23:39 ` Andy Lutomirski
2016-07-23 0:00 ` Josh Poimboeuf
2016-07-23 0:22 ` [PATCH 00/19] x86/dumpstack: rewrite x86 stack dump code Linus Torvalds
2016-07-23 0:31 ` Andy Lutomirski
2016-07-23 5:35 ` Josh Poimboeuf
2016-07-23 5:39 ` Linus Torvalds
2016-07-23 12:53 ` Josh Poimboeuf
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=20160802210011.k6li4mnyvky5jtev@treble \
--to=jpoimboe@redhat.com \
--cc=brgerst@gmail.com \
--cc=byungchul.park@lge.com \
--cc=fweisbec@gmail.com \
--cc=hpa@zytor.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=mingo@kernel.org \
--cc=peterz@infradead.org \
--cc=rostedt@goodmis.org \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=x86@kernel.org \
/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
all inboxes | Powered by JetHome®