All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 00/44] x86/dumpstack: rewrite x86 stack dump code
@ 2016-08-04 22:21 Josh Poimboeuf
  2016-08-04 22:21 ` [PATCH v2 01/44] x86/dumpstack: remove show_trace() Josh Poimboeuf
                   ` (43 more replies)
  0 siblings, 44 replies; 66+ messages in thread
From: Josh Poimboeuf @ 2016-08-04 22:21 UTC (permalink / raw)
  To: Thomas Gleixner, Ingo Molnar, H . Peter Anvin
  Cc: x86, linux-kernel, Andy Lutomirski, Linus Torvalds,
	Steven Rostedt, Brian Gerst, Kees Cook, Peter Zijlstra,
	Frederic Weisbecker, Byungchul Park

There are a lot of changes since last time.  See the v2 changelog for
more details.

A git branch is available at:
  
  https://github.com/jpoimboe/linux unwind-v2

Based on tip/master.

v2 changelog:
- split up several of the patches and reorder them with lower-risk
  patches first
- add a lot more comments
- remove the 64-byte gap at the end of the irq stack
- fix some existing ftrace function graph unwinding issues
- fix an existing bug in kernel_stack_pointer()
- clarify the origins of the stack_info "next stack" pointers
- do visit_mask checking in get_stack_info() instead of in_*_stack()
- add some new unwinder warnings
- remove uses of test_and_set_bit()
- dont print regs->ip twice
- remove unwind_state.sp
- have unwind_get_return_address() validate the return address
- change /proc/pid/stack to use %pB
- several minor cleanups and fixes

----

The x86 stack dump code is a bit of a mess.  dump_trace() uses
callbacks, and each user of it seems to have slightly different
requirements, so there are several slightly different callbacks floating
around.

Also there are some upcoming features which will require more changes to
the stack dump code: reliable stack detection for live patching,
hardened user copy, and the DWARF unwinder.  Each of those features
would at least need more callbacks and/or callback interfaces, resulting
in a much bigger mess than what we have today.

Before doing all that, we should try to clean things up and replace
dump_trace() with something cleaner and more flexible.

The new unwinder is a simple state machine which was heavily inspired by
a suggestion from Andy Lutomirski:

  https://lkml.kernel.org/r/CALCETrUbNTqaM2LRyXGRx=kVLRPeY5A3Pc6k4TtQxF320rUT=w@mail.gmail.com

It's also similar to the libunwind API:

  http://www.nongnu.org/libunwind/man/libunwind(3).html

Some if its advantages:

- simplicity: no more callback sprawl and less code duplication.

- flexibility: allows the caller to stop and inspect the stack state at
  each step in the unwinding process.

- modularity: the unwinder code, console stack dump code, and stack
  metadata analysis code are all better separated so that changing one
  of them shouldn't have much of an impact on any of the others.


Josh Poimboeuf (44):
  x86/dumpstack: remove show_trace()
  x86/asm/head: remove unused init_rsp variable
  x86/asm/head: rename 'stack_start' -> 'initial_stack'
  x86/asm/head: use a common function for starting CPUs
  x86/dumpstack: make printk_stack_address() more generally useful
  x86/dumpstack: add IRQ_USABLE_STACK_SIZE define
  x86/dumpstack: remove extra brackets around "<EOE>"
  x86/dumpstack: fix irq stack bounds calculation in
    show_stack_log_lvl()
  x86/dumpstack: fix x86_32 kernel_stack_pointer() previous stack access
  x86/dumpstack: add get_stack_pointer() and get_frame_pointer()
  x86/dumpstack: remove unnecessary stack pointer arguments
  x86: move _stext marker to before head code
  x86/asm/head: remove useless zeroed word
  x86/asm/head:  put real return address on idle task stack
  perf/x86: check perf_callchain_store() error
  oprofile/x86: add regs->ip to oprofile trace
  proc: fix return address printk conversion specifer in
    /proc/<pid>/stack
  ftrace: remove CONFIG_HAVE_FUNCTION_GRAPH_FP_TEST from config
  ftrace: only allocate the ret_stack 'fp' field when needed
  ftrace: add return address pointer to ftrace_ret_stack
  ftrace: add ftrace_graph_ret_addr() stack unwinding helpers
  x86/dumpstack/ftrace: convert dump_trace() callbacks to use
    ftrace_graph_ret_addr()
  ftrace/x86: implement HAVE_FUNCTION_GRAPH_RET_ADDR_PTR
  x86/dumpstack/ftrace: mark function graph handler function as
    unreliable
  x86/dumpstack/ftrace: don't print unreliable addresses in
    print_context_stack_bp()
  x86/dumpstack: allow preemption in show_stack_log_lvl() and
    dump_trace()
  x86/dumpstack: simplify in_exception_stack()
  x86/dumpstack: add get_stack_info() interface
  x86/dumpstack: add recursion checking for all stacks
  x86/unwind: add new unwind interface and implementations
  perf/x86: convert perf_callchain_kernel() to use the new unwinder
  x86/stacktrace: convert save_stack_trace_*() to use the new unwinder
  oprofile/x86: convert x86_backtrace() to use the new unwinder
  x86/dumpstack: convert show_trace_log_lvl() to use the new unwinder
  x86/dumpstack: remove dump_trace() and related callbacks
  x86/entry/unwind: encode pt_regs pointer in frame pointer
  x86/unwind: detect syscall entry regs
  x86/dumpstack: print stack identifier on its own line
  x86/dumpstack: print any pt_regs found on the stack
  x86: remove 64-byte gap at end of irq stack
  x86/asm/head: standardize the end of the stack for idle tasks
  x86/unwind: warn on kernel stack corruption
  x86/unwind: warn on bad stack return address
  x86/unwind: warn if stack grows up

 Documentation/trace/ftrace-design.txt |  11 ++
 arch/arm/kernel/ftrace.c              |   2 +-
 arch/arm64/kernel/entry-ftrace.S      |   2 +-
 arch/arm64/kernel/ftrace.c            |   2 +-
 arch/blackfin/kernel/ftrace-entry.S   |   4 +-
 arch/blackfin/kernel/ftrace.c         |   2 +-
 arch/microblaze/kernel/ftrace.c       |   2 +-
 arch/mips/kernel/ftrace.c             |   4 +-
 arch/parisc/kernel/ftrace.c           |   2 +-
 arch/powerpc/kernel/ftrace.c          |   3 +-
 arch/s390/kernel/ftrace.c             |   3 +-
 arch/sh/kernel/ftrace.c               |   2 +-
 arch/sparc/Kconfig                    |   1 -
 arch/sparc/include/asm/ftrace.h       |   4 +
 arch/sparc/kernel/ftrace.c            |   2 +-
 arch/tile/kernel/ftrace.c             |   2 +-
 arch/x86/Kconfig                      |   1 -
 arch/x86/entry/calling.h              |  21 +++
 arch/x86/entry/entry_64.S             |  10 +-
 arch/x86/events/core.c                |  36 ++--
 arch/x86/include/asm/ftrace.h         |   3 +
 arch/x86/include/asm/kdebug.h         |   2 -
 arch/x86/include/asm/page_64_types.h  |  16 +-
 arch/x86/include/asm/realmode.h       |   2 +-
 arch/x86/include/asm/smp.h            |   3 -
 arch/x86/include/asm/stacktrace.h     | 114 ++++++------
 arch/x86/include/asm/unwind.h         | 104 +++++++++++
 arch/x86/kernel/Makefile              |   6 +
 arch/x86/kernel/acpi/sleep.c          |   2 +-
 arch/x86/kernel/cpu/common.c          |   2 +-
 arch/x86/kernel/dumpstack.c           | 272 ++++++++++++++---------------
 arch/x86/kernel/dumpstack_32.c        | 138 ++++++++-------
 arch/x86/kernel/dumpstack_64.c        | 319 ++++++++++------------------------
 arch/x86/kernel/ftrace.c              |   2 +-
 arch/x86/kernel/head_32.S             |   8 +-
 arch/x86/kernel/head_64.S             |  33 ++--
 arch/x86/kernel/ptrace.c              |   4 +-
 arch/x86/kernel/setup_percpu.c        |   2 +-
 arch/x86/kernel/smpboot.c             |   2 +-
 arch/x86/kernel/stacktrace.c          |  74 ++++----
 arch/x86/kernel/unwind_frame.c        | 222 +++++++++++++++++++++++
 arch/x86/kernel/unwind_guess.c        |  40 +++++
 arch/x86/kernel/vmlinux.lds.S         |   2 +-
 arch/x86/oprofile/backtrace.c         |  49 +++---
 fs/proc/base.c                        |   2 +-
 include/linux/ftrace.h                |  17 +-
 kernel/trace/Kconfig                  |   5 -
 kernel/trace/trace_functions_graph.c  |  67 ++++++-
 48 files changed, 977 insertions(+), 651 deletions(-)
 create mode 100644 arch/x86/include/asm/unwind.h
 create mode 100644 arch/x86/kernel/unwind_frame.c
 create mode 100644 arch/x86/kernel/unwind_guess.c

-- 
2.7.4

^ permalink raw reply	[flat|nested] 66+ messages in thread

end of thread, other threads:[~2016-08-11 19:15 UTC | newest]

Thread overview: 66+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.