Skip to content

Commit b0c79f4

Browse files
committed
Merge branch 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull x86 asm updates from Ingo Molnar: - Introduce the ORC unwinder, which can be enabled via CONFIG_ORC_UNWINDER=y. The ORC unwinder is a lightweight, Linux kernel specific debuginfo implementation, which aims to be DWARF done right for unwinding. Objtool is used to generate the ORC unwinder tables during build, so the data format is flexible and kernel internal: there's no dependency on debuginfo created by an external toolchain. The ORC unwinder is almost two orders of magnitude faster than the (out of tree) DWARF unwinder - which is important for perf call graph profiling. It is also significantly simpler and is coded defensively: there has not been a single ORC related kernel crash so far, even with early versions. (knock on wood!) But the main advantage is that enabling the ORC unwinder allows CONFIG_FRAME_POINTERS to be turned off - which speeds up the kernel measurably: With frame pointers disabled, GCC does not have to add frame pointer instrumentation code to every function in the kernel. The kernel's .text size decreases by about 3.2%, resulting in better cache utilization and fewer instructions executed, resulting in a broad kernel-wide speedup. Average speedup of system calls should be roughly in the 1-3% range - measurements by Mel Gorman [1] have shown a speedup of 5-10% for some function execution intense workloads. The main cost of the unwinder is that the unwinder data has to be stored in RAM: the memory cost is 2-4MB of RAM, depending on kernel config - which is a modest cost on modern x86 systems. Given how young the ORC unwinder code is it's not enabled by default - but given the performance advantages the plan is to eventually make it the default unwinder on x86. See Documentation/x86/orc-unwinder.txt for more details. - Remove lguest support: its intended role was that of a temporary proof of concept for virtualization, plus its removal will enable the reduction (removal) of the paravirt API as well, so Rusty agreed to its removal. (Juergen Gross) - Clean up and fix FSGS related functionality (Andy Lutomirski) - Clean up IO access APIs (Andy Shevchenko) - Enhance the symbol namespace (Jiri Slaby) * 'x86-asm-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (47 commits) objtool: Handle GCC stack pointer adjustment bug x86/entry/64: Use ENTRY() instead of ALIGN+GLOBAL for stub32_clone() x86/fpu/math-emu: Add ENDPROC to functions x86/boot/64: Extract efi_pe_entry() from startup_64() x86/boot/32: Extract efi_pe_entry() from startup_32() x86/lguest: Remove lguest support x86/paravirt/xen: Remove xen_patch() objtool: Fix objtool fallthrough detection with function padding x86/xen/64: Fix the reported SS and CS in SYSCALL objtool: Track DRAP separately from callee-saved registers objtool: Fix validate_branch() return codes x86: Clarify/fix no-op barriers for text_poke_bp() x86/switch_to/64: Rewrite FS/GS switching yet again to fix AMD CPUs selftests/x86/fsgsbase: Test selectors 1, 2, and 3 x86/fsgsbase/64: Report FSBASE and GSBASE correctly in core dumps x86/fsgsbase/64: Fully initialize FS and GS state in start_thread_common x86/asm: Fix UNWIND_HINT_REGS macro for older binutils x86/asm/32: Fix regs_get_register() on segment registers x86/xen/64: Rearrange the SYSCALL entries x86/asm/32: Remove a bunch of '& 0xffff' from pt_regs segment reads ...
2 parents f213a6c + dd88a0a commit b0c79f4

125 files changed

Lines changed: 3325 additions & 11368 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/x86/orc-unwinder.txt‎

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
ORC unwinder
2+
============
3+
4+
Overview
5+
--------
6+
7+
The kernel CONFIG_ORC_UNWINDER option enables the ORC unwinder, which is
8+
similar in concept to a DWARF unwinder. The difference is that the
9+
format of the ORC data is much simpler than DWARF, which in turn allows
10+
the ORC unwinder to be much simpler and faster.
11+
12+
The ORC data consists of unwind tables which are generated by objtool.
13+
They contain out-of-band data which is used by the in-kernel ORC
14+
unwinder. Objtool generates the ORC data by first doing compile-time
15+
stack metadata validation (CONFIG_STACK_VALIDATION). After analyzing
16+
all the code paths of a .o file, it determines information about the
17+
stack state at each instruction address in the file and outputs that
18+
information to the .orc_unwind and .orc_unwind_ip sections.
19+
20+
The per-object ORC sections are combined at link time and are sorted and
21+
post-processed at boot time. The unwinder uses the resulting data to
22+
correlate instruction addresses with their stack states at run time.
23+
24+
25+
ORC vs frame pointers
26+
---------------------
27+
28+
With frame pointers enabled, GCC adds instrumentation code to every
29+
function in the kernel. The kernel's .text size increases by about
30+
3.2%, resulting in a broad kernel-wide slowdown. Measurements by Mel
31+
Gorman [1] have shown a slowdown of 5-10% for some workloads.
32+
33+
In contrast, the ORC unwinder has no effect on text size or runtime
34+
performance, because the debuginfo is out of band. So if you disable
35+
frame pointers and enable the ORC unwinder, you get a nice performance
36+
improvement across the board, and still have reliable stack traces.
37+
38+
Ingo Molnar says:
39+
40+
"Note that it's not just a performance improvement, but also an
41+
instruction cache locality improvement: 3.2% .text savings almost
42+
directly transform into a similarly sized reduction in cache
43+
footprint. That can transform to even higher speedups for workloads
44+
whose cache locality is borderline."
45+
46+
Another benefit of ORC compared to frame pointers is that it can
47+
reliably unwind across interrupts and exceptions. Frame pointer based
48+
unwinds can sometimes skip the caller of the interrupted function, if it
49+
was a leaf function or if the interrupt hit before the frame pointer was
50+
saved.
51+
52+
The main disadvantage of the ORC unwinder compared to frame pointers is
53+
that it needs more memory to store the ORC unwind tables: roughly 2-4MB
54+
depending on the kernel config.
55+
56+
57+
ORC vs DWARF
58+
------------
59+
60+
ORC debuginfo's advantage over DWARF itself is that it's much simpler.
61+
It gets rid of the complex DWARF CFI state machine and also gets rid of
62+
the tracking of unnecessary registers. This allows the unwinder to be
63+
much simpler, meaning fewer bugs, which is especially important for
64+
mission critical oops code.
65+
66+
The simpler debuginfo format also enables the unwinder to be much faster
67+
than DWARF, which is important for perf and lockdep. In a basic
68+
performance test by Jiri Slaby [2], the ORC unwinder was about 20x
69+
faster than an out-of-tree DWARF unwinder. (Note: That measurement was
70+
taken before some performance tweaks were added, which doubled
71+
performance, so the speedup over DWARF may be closer to 40x.)
72+
73+
The ORC data format does have a few downsides compared to DWARF. ORC
74+
unwind tables take up ~50% more RAM (+1.3MB on an x86 defconfig kernel)
75+
than DWARF-based eh_frame tables.
76+
77+
Another potential downside is that, as GCC evolves, it's conceivable
78+
that the ORC data may end up being *too* simple to describe the state of
79+
the stack for certain optimizations. But IMO this is unlikely because
80+
GCC saves the frame pointer for any unusual stack adjustments it does,
81+
so I suspect we'll really only ever need to keep track of the stack
82+
pointer and the frame pointer between call frames. But even if we do
83+
end up having to track all the registers DWARF tracks, at least we will
84+
still be able to control the format, e.g. no complex state machines.
85+
86+
87+
ORC unwind table generation
88+
---------------------------
89+
90+
The ORC data is generated by objtool. With the existing compile-time
91+
stack metadata validation feature, objtool already follows all code
92+
paths, and so it already has all the information it needs to be able to
93+
generate ORC data from scratch. So it's an easy step to go from stack
94+
validation to ORC data generation.
95+
96+
It should be possible to instead generate the ORC data with a simple
97+
tool which converts DWARF to ORC data. However, such a solution would
98+
be incomplete due to the kernel's extensive use of asm, inline asm, and
99+
special sections like exception tables.
100+
101+
That could be rectified by manually annotating those special code paths
102+
using GNU assembler .cfi annotations in .S files, and homegrown
103+
annotations for inline asm in .c files. But asm annotations were tried
104+
in the past and were found to be unmaintainable. They were often
105+
incorrect/incomplete and made the code harder to read and keep updated.
106+
And based on looking at glibc code, annotating inline asm in .c files
107+
might be even worse.
108+
109+
Objtool still needs a few annotations, but only in code which does
110+
unusual things to the stack like entry code. And even then, far fewer
111+
annotations are needed than what DWARF would need, so they're much more
112+
maintainable than DWARF CFI annotations.
113+
114+
So the advantages of using objtool to generate ORC data are that it
115+
gives more accurate debuginfo, with very few annotations. It also
116+
insulates the kernel from toolchain bugs which can be very painful to
117+
deal with in the kernel since we often have to workaround issues in
118+
older versions of the toolchain for years.
119+
120+
The downside is that the unwinder now becomes dependent on objtool's
121+
ability to reverse engineer GCC code flow. If GCC optimizations become
122+
too complicated for objtool to follow, the ORC data generation might
123+
stop working or become incomplete. (It's worth noting that livepatch
124+
already has such a dependency on objtool's ability to follow GCC code
125+
flow.)
126+
127+
If newer versions of GCC come up with some optimizations which break
128+
objtool, we may need to revisit the current implementation. Some
129+
possible solutions would be asking GCC to make the optimizations more
130+
palatable, or having objtool use DWARF as an additional input, or
131+
creating a GCC plugin to assist objtool with its analysis. But for now,
132+
objtool follows GCC code quite well.
133+
134+
135+
Unwinder implementation details
136+
-------------------------------
137+
138+
Objtool generates the ORC data by integrating with the compile-time
139+
stack metadata validation feature, which is described in detail in
140+
tools/objtool/Documentation/stack-validation.txt. After analyzing all
141+
the code paths of a .o file, it creates an array of orc_entry structs,
142+
and a parallel array of instruction addresses associated with those
143+
structs, and writes them to the .orc_unwind and .orc_unwind_ip sections
144+
respectively.
145+
146+
The ORC data is split into the two arrays for performance reasons, to
147+
make the searchable part of the data (.orc_unwind_ip) more compact. The
148+
arrays are sorted in parallel at boot time.
149+
150+
Performance is further improved by the use of a fast lookup table which
151+
is created at runtime. The fast lookup table associates a given address
152+
with a range of indices for the .orc_unwind table, so that only a small
153+
subset of the table needs to be searched.
154+
155+
156+
Etymology
157+
---------
158+
159+
Orcs, fearsome creatures of medieval folklore, are the Dwarves' natural
160+
enemies. Similarly, the ORC unwinder was created in opposition to the
161+
complexity and slowness of DWARF.
162+
163+
"Although Orcs rarely consider multiple solutions to a problem, they do
164+
excel at getting things done because they are creatures of action, not
165+
thought." [3] Similarly, unlike the esoteric DWARF unwinder, the
166+
veracious ORC unwinder wastes no time or siloconic effort decoding
167+
variable-length zero-extended unsigned-integer byte-coded
168+
state-machine-based debug information entries.
169+
170+
Similar to how Orcs frequently unravel the well-intentioned plans of
171+
their adversaries, the ORC unwinder frequently unravels stacks with
172+
brutal, unyielding efficiency.
173+
174+
ORC stands for Oops Rewind Capability.
175+
176+
177+
[1] https://lkml.kernel.org/r/20170602104048.jkkzssljsompjdwy@suse.de
178+
[2] https://lkml.kernel.org/r/d2ca5435-6386-29b8-db87-7f227c2b713a@suse.cz
179+
[3] http://dustin.wikidot.com/half-orcs-and-orcs

‎MAINTAINERS‎

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7660,17 +7660,6 @@ T: git git://linuxtv.org/mkrufky/tuners.git
76607660
S: Maintained
76617661
F: drivers/media/dvb-frontends/lgdt3305.*
76627662

7663-
LGUEST
7664-
M: Rusty Russell <rusty@rustcorp.com.au>
7665-
L: lguest@lists.ozlabs.org
7666-
W: http://lguest.ozlabs.org/
7667-
S: Odd Fixes
7668-
F: arch/x86/include/asm/lguest*.h
7669-
F: arch/x86/lguest/
7670-
F: drivers/lguest/
7671-
F: include/linux/lguest*.h
7672-
F: tools/lguest/
7673-
76747663
LIBATA PATA ARASAN COMPACT FLASH CONTROLLER
76757664
M: Viresh Kumar <vireshk@kernel.org>
76767665
L: linux-ide@vger.kernel.org

‎arch/um/include/asm/unwind.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef _ASM_UML_UNWIND_H
2+
#define _ASM_UML_UNWIND_H
3+
4+
static inline void
5+
unwind_module_init(struct module *mod, void *orc_ip, size_t orc_ip_size,
6+
void *orc, size_t orc_size) {}
7+
8+
#endif /* _ASM_UML_UNWIND_H */

‎arch/x86/Kbuild‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ obj-$(CONFIG_XEN) += xen/
1010
# Hyper-V paravirtualization support
1111
obj-$(CONFIG_HYPERVISOR_GUEST) += hyperv/
1212

13-
# lguest paravirtualization support
14-
obj-$(CONFIG_LGUEST_GUEST) += lguest/
15-
1613
obj-y += realmode/
1714
obj-y += kernel/
1815
obj-y += mm/

‎arch/x86/Kconfig‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ config X86
7373
select ARCH_USE_QUEUED_RWLOCKS
7474
select ARCH_USE_QUEUED_SPINLOCKS
7575
select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
76-
select ARCH_WANT_FRAME_POINTERS
7776
select ARCH_WANTS_DYNAMIC_TASK_STRUCT
7877
select ARCH_WANTS_THP_SWAP if X86_64
7978
select BUILDTIME_EXTABLE_SORT
@@ -158,6 +157,7 @@ config X86
158157
select HAVE_MEMBLOCK
159158
select HAVE_MEMBLOCK_NODE_MAP
160159
select HAVE_MIXED_BREAKPOINTS_REGS
160+
select HAVE_MOD_ARCH_SPECIFIC
161161
select HAVE_NMI
162162
select HAVE_OPROFILE
163163
select HAVE_OPTPROBES
@@ -168,7 +168,7 @@ config X86
168168
select HAVE_PERF_REGS
169169
select HAVE_PERF_USER_STACK_DUMP
170170
select HAVE_REGS_AND_STACK_ACCESS_API
171-
select HAVE_RELIABLE_STACKTRACE if X86_64 && FRAME_POINTER && STACK_VALIDATION
171+
select HAVE_RELIABLE_STACKTRACE if X86_64 && FRAME_POINTER_UNWINDER && STACK_VALIDATION
172172
select HAVE_STACK_VALIDATION if X86_64
173173
select HAVE_SYSCALL_TRACEPOINTS
174174
select HAVE_UNSTABLE_SCHED_CLOCK
@@ -778,8 +778,6 @@ config KVM_DEBUG_FS
778778
Statistics are displayed in debugfs filesystem. Enabling this option
779779
may incur significant overhead.
780780

781-
source "arch/x86/lguest/Kconfig"
782-
783781
config PARAVIRT_TIME_ACCOUNTING
784782
bool "Paravirtual steal time accounting"
785783
depends on PARAVIRT

‎arch/x86/Kconfig.debug‎

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,6 @@ config DEBUG_ENTRY
305305
Some of these sanity checks may slow down kernel entries and
306306
exits or otherwise impact performance.
307307

308-
This is currently used to help test NMI code.
309-
310308
If unsure, say N.
311309

312310
config DEBUG_NMI_SELFTEST
@@ -358,4 +356,61 @@ config PUNIT_ATOM_DEBUG
358356
The current power state can be read from
359357
/sys/kernel/debug/punit_atom/dev_power_state
360358

359+
choice
360+
prompt "Choose kernel unwinder"
361+
default FRAME_POINTER_UNWINDER
362+
---help---
363+
This determines which method will be used for unwinding kernel stack
364+
traces for panics, oopses, bugs, warnings, perf, /proc/<pid>/stack,
365+
livepatch, lockdep, and more.
366+
367+
config FRAME_POINTER_UNWINDER
368+
bool "Frame pointer unwinder"
369+
select FRAME_POINTER
370+
---help---
371+
This option enables the frame pointer unwinder for unwinding kernel
372+
stack traces.
373+
374+
The unwinder itself is fast and it uses less RAM than the ORC
375+
unwinder, but the kernel text size will grow by ~3% and the kernel's
376+
overall performance will degrade by roughly 5-10%.
377+
378+
This option is recommended if you want to use the livepatch
379+
consistency model, as this is currently the only way to get a
380+
reliable stack trace (CONFIG_HAVE_RELIABLE_STACKTRACE).
381+
382+
config ORC_UNWINDER
383+
bool "ORC unwinder"
384+
depends on X86_64
385+
select STACK_VALIDATION
386+
---help---
387+
This option enables the ORC (Oops Rewind Capability) unwinder for
388+
unwinding kernel stack traces. It uses a custom data format which is
389+
a simplified version of the DWARF Call Frame Information standard.
390+
391+
This unwinder is more accurate across interrupt entry frames than the
392+
frame pointer unwinder. It also enables a 5-10% performance
393+
improvement across the entire kernel compared to frame pointers.
394+
395+
Enabling this option will increase the kernel's runtime memory usage
396+
by roughly 2-4MB, depending on your kernel config.
397+
398+
config GUESS_UNWINDER
399+
bool "Guess unwinder"
400+
depends on EXPERT
401+
---help---
402+
This option enables the "guess" unwinder for unwinding kernel stack
403+
traces. It scans the stack and reports every kernel text address it
404+
finds. Some of the addresses it reports may be incorrect.
405+
406+
While this option often produces false positives, it can still be
407+
useful in many cases. Unlike the other unwinders, it has no runtime
408+
overhead.
409+
410+
endchoice
411+
412+
config FRAME_POINTER
413+
depends on !ORC_UNWINDER && !GUESS_UNWINDER
414+
bool
415+
361416
endmenu

0 commit comments

Comments
 (0)