From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Andy Lutomirski <luto@amacapital.net>
Cc: Frederic Weisbecker <fweisbec@gmail.com>,
Thomas Gleixner <tglx@linutronix.de>,
Kees Cook <keescook@chromium.org>, x86 <x86@kernel.org>,
"H . Peter Anvin" <hpa@zytor.com>,
Nilay Vaish <nilayvaish@gmail.com>,
Steven Rostedt <rostedt@goodmis.org>,
Ingo Molnar <mingo@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
Brian Gerst <brgerst@gmail.com>,
Byungchul Park <byungchul.park@lge.com>,
Peter Zijlstra <peterz@infradead.org>,
Linus Torvalds <torvalds@linux-foundation.org>
Subject: Re: [PATCH v2 30/44] x86/unwind: add new unwind interface and implementations
Date: Thu, 11 Aug 2016 14:15:19 -0500 [thread overview]
Message-ID: <20160811191519.vw23au4bblcwps3a@treble> (raw)
In-Reply-To: <CALCETrWT7j4_ScPSN-fZi6D0+TS7mE+LzKM=NkJxwOH5UsQ2ew@mail.gmail.com>
On Thu, Aug 11, 2016 at 11:58:13AM -0700, Andy Lutomirski wrote:
> On Aug 11, 2016 7:09 PM, "Josh Poimboeuf" <jpoimboe@redhat.com> wrote:
> >
> > On Thu, Aug 11, 2016 at 07:58:34AM -0700, Andy Lutomirski wrote:
> > > On Thu, Aug 11, 2016 at 7:28 AM, Josh Poimboeuf <jpoimboe@redhat.com> wrote:
> > > > On Thu, Aug 11, 2016 at 12:18:54AM -0700, Andy Lutomirski wrote:
> > > >> > > I admit I don't fully understand the use case. If someone wants to
> > > >> > > start a trace in the middle, shouldn't they just pass regs in?
> > > >> >
> > > >> > The regs aren't always available. Some callers just want to skip the
> > > >> > first few frames so the stack dump code itself isn't traced.
> > > >>
> > > >> I suspect that all users are okay with your algorithm simply because
> > > >> they don't switch stacks. Maybe the thing to do is to stop advancing
> > > >> when sp is passed or if the stack switches at all.
> > > >
> > > > There are actually some cases which could be broken by the sloppy "while
> > > > state->bp < sp" check. When starting with sp from 'regs->sp', sp often
> > > > points to a different stack than the current one. It seemed to work in
> > > > my testing, but I guess I got lucky, with irq percpu stack addresses
> > > > being smaller than the thread stack addresses.
> > > >
> > > >> Could you point me at a user that passes anything other than regs->sp
> > > >> here? On brief inspection, I haven't found any at all.
> > > >
> > > > For example, see show_stack().
> > >
> > > Is that a non-trivial case? show_stack() is generating sp *and* bp.
> > > Why not just pass both of them all the way in to show_trace_log_lvl
> > > (which the existing code already does) and then pass it into
> > > unwind_start?
> > >
> > > Alternatively, since that risks causing a bit of loss if you implement
> > > DWARF, you could add an unwind_start_here() function that captures the
> > > state in the calling function and pass the result all the way through.
> > > Or you could write a silly asm helper that literally fills in a struct
> > > pt_regs for the current context (although that could get a bit awkward
> > > for 32-bit, since pt_regs doesn't really contain sp there).
> > >
> > > If there are genuinely zero non-trivial cases, then this should fully
> > > solve the problem, no?
> >
> > Hm, what do you mean by non-trivial cases?
> >
> > As far as I can tell, they're all trivial, and we don't need the caller
> > to provide bp. Just start with the current frame's bp and unwind until
> > bp and sp are on the same stack and bp > sp.
>
> Given that your unwind-till-we-get-there algorithm isn't quite
> correct
But it *will* be correct in v3, with a minor change. Sneak preview:
/*
* The caller can optionally provide a stack pointer directly
* (first_sp) or indirectly (regs->sp), which indicates which stack
* frame to start unwinding at. Skip ahead until we reach that frame.
*/
while (!unwind_done(state) &&
(!on_stack(&state->stack_info, first_sp, sizeof(*first_sp) ||
state->bp < first_sp)))
unwind_next_frame(state);
> wouldn't it be easier to just pass all the needed information
> through? Especially since that information is there (in at least one
> case) on current kernels, so the diff would be smaller.
Why focus on diff size? Isn't it the resulting code that's most
important? It's not like removing the bp argument causes a big diff
anyway.
> It seems overcomplicated to me to regenerate the state that was
> already in the registers by unwinding to it rather than just passing
> it in to the unwinder directly.
Passing in the frame pointer when it isn't needed makes the interface
more complex. It creates more opportunity for the caller to mess things
up and more edge cases to consider in the unwinder.
And as you mentioned, it's not compatible with DWARF. Adding
unwind_start_here() would add even more interface complexity.
--
Josh
next prev parent reply other threads:[~2016-08-11 19:15 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-04 22:21 [PATCH v2 00/44] x86/dumpstack: rewrite x86 stack dump code Josh Poimboeuf
2016-08-04 22:21 ` [PATCH v2 01/44] x86/dumpstack: remove show_trace() Josh Poimboeuf
2016-08-04 22:21 ` [PATCH v2 02/44] x86/asm/head: remove unused init_rsp variable Josh Poimboeuf
2016-08-04 22:21 ` [PATCH v2 03/44] x86/asm/head: rename 'stack_start' -> 'initial_stack' Josh Poimboeuf
2016-08-05 15:28 ` Nilay Vaish
2016-08-05 16:01 ` Josh Poimboeuf
2016-08-06 5:25 ` Borislav Petkov
2016-08-06 13:13 ` Josh Poimboeuf
2016-08-06 13:15 ` Brian Gerst
2016-08-06 13:38 ` Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 04/44] x86/asm/head: use a common function for starting CPUs Josh Poimboeuf
2016-08-05 15:41 ` Nilay Vaish
2016-08-05 16:17 ` Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 05/44] x86/dumpstack: make printk_stack_address() more generally useful Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 06/44] x86/dumpstack: add IRQ_USABLE_STACK_SIZE define Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 07/44] x86/dumpstack: remove extra brackets around "<EOE>" Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 08/44] x86/dumpstack: fix irq stack bounds calculation in show_stack_log_lvl() Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 09/44] x86/dumpstack: fix x86_32 kernel_stack_pointer() previous stack access Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 10/44] x86/dumpstack: add get_stack_pointer() and get_frame_pointer() Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 11/44] x86/dumpstack: remove unnecessary stack pointer arguments Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 12/44] x86: move _stext marker to before head code Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 13/44] x86/asm/head: remove useless zeroed word Josh Poimboeuf
2016-08-05 16:13 ` Brian Gerst
2016-08-05 16:23 ` Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 14/44] x86/asm/head: put real return address on idle task stack Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 15/44] perf/x86: check perf_callchain_store() error Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 16/44] oprofile/x86: add regs->ip to oprofile trace Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 17/44] proc: fix return address printk conversion specifer in /proc/<pid>/stack Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 18/44] ftrace: remove CONFIG_HAVE_FUNCTION_GRAPH_FP_TEST from config Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 19/44] ftrace: only allocate the ret_stack 'fp' field when needed Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 20/44] ftrace: add return address pointer to ftrace_ret_stack Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 21/44] ftrace: add ftrace_graph_ret_addr() stack unwinding helpers Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 22/44] x86/dumpstack/ftrace: convert dump_trace() callbacks to use ftrace_graph_ret_addr() Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 23/44] ftrace/x86: implement HAVE_FUNCTION_GRAPH_RET_ADDR_PTR Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 24/44] x86/dumpstack/ftrace: mark function graph handler function as unreliable Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 25/44] x86/dumpstack/ftrace: don't print unreliable addresses in print_context_stack_bp() Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 26/44] x86/dumpstack: allow preemption in show_stack_log_lvl() and dump_trace() Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 27/44] x86/dumpstack: simplify in_exception_stack() Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 28/44] x86/dumpstack: add get_stack_info() interface Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 29/44] x86/dumpstack: add recursion checking for all stacks Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 30/44] x86/unwind: add new unwind interface and implementations Josh Poimboeuf
2016-08-09 23:17 ` Nilay Vaish
2016-08-09 23:27 ` Josh Poimboeuf
2016-08-10 7:25 ` Andy Lutomirski
2016-08-10 14:16 ` Josh Poimboeuf
2016-08-11 7:18 ` Andy Lutomirski
2016-08-11 14:28 ` Josh Poimboeuf
2016-08-11 14:58 ` Andy Lutomirski
2016-08-11 16:09 ` Josh Poimboeuf
2016-08-11 18:58 ` Andy Lutomirski
2016-08-11 19:15 ` Josh Poimboeuf [this message]
2016-08-04 22:22 ` [PATCH v2 31/44] perf/x86: convert perf_callchain_kernel() to use the new unwinder Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 32/44] x86/stacktrace: convert save_stack_trace_*() " Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 33/44] oprofile/x86: convert x86_backtrace() " Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 34/44] x86/dumpstack: convert show_trace_log_lvl() " Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 35/44] x86/dumpstack: remove dump_trace() and related callbacks Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 36/44] x86/entry/unwind: encode pt_regs pointer in frame pointer Josh Poimboeuf
2016-08-08 23:06 ` Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 37/44] x86/unwind: detect syscall entry regs Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 38/44] x86/dumpstack: print stack identifier on its own line Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 39/44] x86/dumpstack: print any pt_regs found on the stack Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 40/44] x86: remove 64-byte gap at end of irq stack Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 41/44] x86/asm/head: standardize the end of the stack for idle tasks Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 42/44] x86/unwind: warn on kernel stack corruption Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 43/44] x86/unwind: warn on bad stack return address Josh Poimboeuf
2016-08-04 22:22 ` [PATCH v2 44/44] x86/unwind: warn if stack grows up 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=20160811191519.vw23au4bblcwps3a@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=nilayvaish@gmail.com \
--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®