All of lore.kernel.org
 help / color / mirror / Atom feed
From: Josh Poimboeuf <jpoimboe@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@kernel.org>, "H . Peter Anvin" <hpa@zytor.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org,
	Andy Lutomirski <luto@amacapital.net>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	Steven Rostedt <rostedt@goodmis.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>,
	Nilay Vaish <nilayvaish@gmail.com>
Subject: [PATCH v4 00/57] x86/dumpstack: rewrite x86 stack dump code
Date: Thu, 18 Aug 2016 08:05:40 -0500	[thread overview]
Message-ID: <cover.1471525031.git.jpoimboe@redhat.com> (raw)

Mostly minor changes this time.  See below for the full list of changes.

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

Based on tip/master.

v4: 
- complete rewrite of arch_within_stack_frames() for hardened usercopy
- handle empty stacks better:
  - change in_*_stack() functions to consider the end to be part of the
    stack
  - add loop in update_stack_state() to handle empty stacks more
    gracefully
- prevent false positive warnings when unwinding interrupts in entry code
- fix misplaced parentheses bug in __unwind_start()
- move 32-bit ret_from_fork change to a separate commit: "fix the end of
  the stack for newly forked tasks"
- add infinite loop after call to initial_code
- print orig_ax in __show_regs()
- fix duplicate RIP address display in __show_regs()
- rename "next_sp" to "next_frame" in unwind_next_frame() and "first_sp" to 
  "first_frame" in unwind_start() to improve readability
- improve a few patch header descriptions

v3:
- partial unwinder rewrite: each pt_regs gets its own frame
- add frame pointer encoding support for 32-bit
- several 32-bit fixes and cleanups for issues found by the new warnings
- convert CONFIG_HARDENED_USERCOPY arch_within_stack_frames()
- fix bug in unwinder when skipping stack frames (and add a comment)
- warn on stack recursion
- put start_cpu() in its own function
- export symbols in unwind_guess.c

v2:
- 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 (57):
  x86/dumpstack: remove show_trace()
  x86/asm/head: remove unused init_rsp variable extern
  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/head: remove useless zeroed word
  x86/head: put real return address on idle task stack
  x86/head: fix the end of the stack for idle tasks
  x86/entry/32: fix the end of the stack for newly forked tasks
  x86/head/32: fix the end of the stack for idle tasks
  x86/smp: fix initial idle stack location on 32-bit
  x86/entry/head/32: use local labels
  x86/entry/32: rename 'error_code' to 'common_exception'
  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: create stack frames for saved interrupt registers
  x86/unwind: create stack frames for saved syscall registers
  x86/dumpstack: print stack identifier on its own line
  x86/dumpstack: print any pt_regs found on the stack
  x86/dumpstack: fix duplicate RIP address display in __show_regs()
  x86/dumpstack: print orig_ax in __show_regs()
  x86: remove 64-byte gap at end of irq stack
  x86/unwind: warn on kernel stack corruption
  x86/unwind: warn on bad stack return address
  x86/unwind: warn if stack grows up
  x86/dumpstack: warn on stack recursion
  x86/mm: move arch_within_stack_frames() to usercopy.c
  x86/mm: convert arch_within_stack_frames() to use the new unwinder
  x86/mm: simplify starting frame logic for hardened usercopy
  x86/mm: removed unused arch_within_stack_frames() arguments
  mm: re-enable gcc frame address warning

 Documentation/trace/ftrace-design.txt |  11 ++
 arch/Kconfig                          |   4 +-
 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_32.S             | 158 +++++++++++------
 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     | 116 ++++++------
 arch/x86/include/asm/thread_info.h    |  48 +----
 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        | 141 ++++++++-------
 arch/x86/kernel/dumpstack_64.c        | 320 +++++++++++-----------------------
 arch/x86/kernel/ftrace.c              |   2 +-
 arch/x86/kernel/head_32.S             |  57 +++---
 arch/x86/kernel/head_64.S             |  50 +++---
 arch/x86/kernel/process_64.c          |  11 +-
 arch/x86/kernel/ptrace.c              |   4 +-
 arch/x86/kernel/setup_percpu.c        |   2 +-
 arch/x86/kernel/smpboot.c             |   6 +-
 arch/x86/kernel/stacktrace.c          |  74 +++-----
 arch/x86/kernel/unwind_frame.c        | 245 ++++++++++++++++++++++++++
 arch/x86/kernel/unwind_guess.c        |  43 +++++
 arch/x86/kernel/vmlinux.lds.S         |   2 +-
 arch/x86/lib/usercopy.c               |  49 ++++++
 arch/x86/oprofile/backtrace.c         |  49 +++---
 fs/proc/base.c                        |   2 +-
 include/linux/ftrace.h                |  17 +-
 include/linux/thread_info.h           |   3 +-
 kernel/trace/Kconfig                  |   5 -
 kernel/trace/trace_functions_graph.c  |  67 ++++++-
 mm/Makefile                           |   3 -
 mm/usercopy.c                         |  14 +-
 56 files changed, 1225 insertions(+), 795 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

             reply	other threads:[~2016-08-18 13:14 UTC|newest]

Thread overview: 107+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-18 13:05 Josh Poimboeuf [this message]
2016-08-18 13:05 ` [PATCH v4 01/57] x86/dumpstack: remove show_trace() Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 02/57] x86/asm/head: remove unused init_rsp variable extern Josh Poimboeuf
2016-08-18 16:22   ` Sebastian Andrzej Siewior
2016-08-18 13:05 ` [PATCH v4 03/57] x86/asm/head: rename 'stack_start' -> 'initial_stack' Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 04/57] x86/asm/head: use a common function for starting CPUs Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 05/57] x86/dumpstack: make printk_stack_address() more generally useful Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 06/57] x86/dumpstack: add IRQ_USABLE_STACK_SIZE define Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 07/57] x86/dumpstack: remove extra brackets around "<EOE>" Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 08/57] x86/dumpstack: fix irq stack bounds calculation in show_stack_log_lvl() Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 09/57] x86/dumpstack: fix x86_32 kernel_stack_pointer() previous stack access Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 10/57] x86/dumpstack: add get_stack_pointer() and get_frame_pointer() Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 11/57] x86/dumpstack: remove unnecessary stack pointer arguments Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 12/57] x86: move _stext marker to before head code Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 13/57] x86/head: remove useless zeroed word Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 14/57] x86/head: put real return address on idle task stack Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 15/57] x86/head: fix the end of the stack for idle tasks Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 16/57] x86/entry/32: fix the end of the stack for newly forked tasks Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 17/57] x86/head/32: fix the end of the stack for idle tasks Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 18/57] x86/smp: fix initial idle stack location on 32-bit Josh Poimboeuf
2016-08-18 13:05 ` [PATCH v4 19/57] x86/entry/head/32: use local labels Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 20/57] x86/entry/32: rename 'error_code' to 'common_exception' Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 21/57] perf/x86: check perf_callchain_store() error Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 22/57] oprofile/x86: add regs->ip to oprofile trace Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 23/57] proc: fix return address printk conversion specifer in /proc/<pid>/stack Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 24/57] ftrace: remove CONFIG_HAVE_FUNCTION_GRAPH_FP_TEST from config Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 25/57] ftrace: only allocate the ret_stack 'fp' field when needed Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 26/57] ftrace: add return address pointer to ftrace_ret_stack Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 27/57] ftrace: add ftrace_graph_ret_addr() stack unwinding helpers Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 28/57] x86/dumpstack/ftrace: convert dump_trace() callbacks to use ftrace_graph_ret_addr() Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 29/57] ftrace/x86: implement HAVE_FUNCTION_GRAPH_RET_ADDR_PTR Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 30/57] x86/dumpstack/ftrace: mark function graph handler function as unreliable Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 31/57] x86/dumpstack/ftrace: don't print unreliable addresses in print_context_stack_bp() Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 32/57] x86/dumpstack: allow preemption in show_stack_log_lvl() and dump_trace() Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 33/57] x86/dumpstack: simplify in_exception_stack() Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 34/57] x86/dumpstack: add get_stack_info() interface Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 35/57] x86/dumpstack: add recursion checking for all stacks Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 36/57] x86/unwind: add new unwind interface and implementations Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 37/57] perf/x86: convert perf_callchain_kernel() to use the new unwinder Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 38/57] x86/stacktrace: convert save_stack_trace_*() " Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 39/57] oprofile/x86: convert x86_backtrace() " Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 40/57] x86/dumpstack: convert show_trace_log_lvl() " Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 41/57] x86/dumpstack: remove dump_trace() and related callbacks Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 42/57] x86/entry/unwind: create stack frames for saved interrupt registers Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 43/57] x86/unwind: create stack frames for saved syscall registers Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 44/57] x86/dumpstack: print stack identifier on its own line Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 45/57] x86/dumpstack: print any pt_regs found on the stack Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 46/57] x86/dumpstack: fix duplicate RIP address display in __show_regs() Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 47/57] x86/dumpstack: print orig_ax " Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 48/57] x86: remove 64-byte gap at end of irq stack Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 49/57] x86/unwind: warn on kernel stack corruption Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 50/57] x86/unwind: warn on bad stack return address Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 51/57] x86/unwind: warn if stack grows up Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 52/57] x86/dumpstack: warn on stack recursion Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 53/57] x86/mm: move arch_within_stack_frames() to usercopy.c Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 54/57] x86/mm: convert arch_within_stack_frames() to use the new unwinder Josh Poimboeuf
2016-08-19 18:27   ` Kees Cook
2016-08-19 21:55     ` Josh Poimboeuf
2016-08-22 20:27       ` Josh Poimboeuf
2016-08-22 23:33         ` Josh Poimboeuf
2016-08-23  0:59           ` Kees Cook
2016-08-23  4:21             ` Josh Poimboeuf
2016-08-22 22:11   ` Linus Torvalds
2016-08-23  1:27     ` Kees Cook
2016-08-23 16:21       ` Josh Poimboeuf
2016-08-23 18:47       ` Linus Torvalds
2016-08-23 16:06     ` Josh Poimboeuf
2016-08-23 19:28       ` [PATCH 1/2] mm/usercopy: get rid of "provably correct" warnings Josh Poimboeuf
2016-08-24  2:36         ` Kees Cook
2016-08-23 19:28       ` [PATCH 2/2] mm/usercopy: enable usercopy size checking for modern versions of gcc Josh Poimboeuf
2016-08-24  2:37         ` Kees Cook
2016-08-25 20:47           ` Josh Poimboeuf
2016-08-26  2:14             ` Kees Cook
2016-08-26  3:27               ` Josh Poimboeuf
2016-08-26 13:42                 ` Kees Cook
2016-08-26 13:55                   ` Josh Poimboeuf
2016-08-26 20:56                     ` Josh Poimboeuf
2016-08-26 21:00                       ` Josh Poimboeuf
2016-08-27  0:37                       ` Linus Torvalds
2016-08-29 14:48                         ` Josh Poimboeuf
2016-08-29 15:36                           ` Linus Torvalds
2016-08-29 17:08                             ` [PATCH v2] mm/usercopy: get rid of CONFIG_DEBUG_STRICT_USER_COPY_CHECKS Josh Poimboeuf
2016-08-29 17:59                               ` Josh Poimboeuf
2016-08-30 13:04                               ` [PATCH v3] " Josh Poimboeuf
2016-08-30 17:02                                 ` Linus Torvalds
2016-08-30 18:12                                   ` Al Viro
2016-08-30 18:13                                     ` Linus Torvalds
2016-08-30 18:15                                   ` Kees Cook
2016-08-30 19:09                                     ` Josh Poimboeuf
2016-08-30 19:20                                       ` Kees Cook
2016-08-30 20:13                                     ` Al Viro
2016-08-30 22:20                                       ` Kees Cook
2016-08-31  9:43                                       ` Mark Rutland
2016-08-30 18:33                           ` [PATCH 2/2] mm/usercopy: enable usercopy size checking for modern versions of gcc Kees Cook
2016-08-23 20:31     ` [PATCH v4 54/57] x86/mm: convert arch_within_stack_frames() to use the new unwinder Andy Lutomirski
2016-08-23 21:06       ` Linus Torvalds
2016-08-23 21:08       ` Josh Poimboeuf
2016-08-24  1:37         ` Kees Cook
2016-08-18 13:06 ` [PATCH v4 55/57] x86/mm: simplify starting frame logic for hardened usercopy Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 56/57] x86/mm: removed unused arch_within_stack_frames() arguments Josh Poimboeuf
2016-08-18 13:06 ` [PATCH v4 57/57] mm: re-enable gcc frame address warning Josh Poimboeuf
2016-08-18 13:25 ` [PATCH v4 00/57] x86/dumpstack: rewrite x86 stack dump code Frederic Weisbecker
2016-08-18 13:39   ` Ingo Molnar
2016-08-18 14:31     ` Josh Poimboeuf
2016-08-18 14:41       ` Steven Rostedt
2016-08-18 16:36       ` Ingo Molnar
2016-08-18 14:34     ` Steven Rostedt

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=cover.1471525031.git.jpoimboe@redhat.com \
    --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 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.