Documentation: livepatch: Document reliable stacktrace and minor cleanup
Subsystems (2)
v5 cover Documentation: livepatch: Document reliable stacktrace and minor cleanup
This series adds a document, mainly written by Mark Rutland, which makes explicit the requirements for implementing reliable stacktrace in order to aid architectures adding this feature. It also updates the other livepatching documents to use automatically generated tables of contents following review comments on Mark's document.
v5:
- Tweaks to the commit message for the new document.
- Convert new and existing documents to autogenerated tables of contents.
v4:
- Renumber table of contents
v3:
- Incorporated objtool section from Mark.
- Deleted confusing notes about using annotations.
Mark Brown (1):
Documentation: livepatch: Convert to automatically generated contents
Mark Rutland (1):
Documentation: livepatch: document reliable stacktrace
Documentation/livepatch/index.rst | 1 + Documentation/livepatch/livepatch.rst | 15 +- Documentation/livepatch/module-elf-format.rst | 10 +- .../livepatch/reliable-stacktrace.rst | 309 ++++++++++++++++++ 4 files changed, 313 insertions(+), 22 deletions(-) create mode 100644 Documentation/livepatch/reliable-stacktrace.rst
base-commit: 7c53f6b671f4aba70ff15e1b05148b10d58c2837
Signature · 1 line
2.20.1
PATCH v5 1/2 Documentation: livepatch: Convert to automatically generated contents
Automatically generate the tables of contents for livepatch documentation files that have tables of contents rather than open coding them so things are a little easier to maintain.
--- Documentation/livepatch/livepatch.rst | 15 +-------------- Documentation/livepatch/module-elf-format.rst | 10 ++-------- 2 files changed, 3 insertions(+), 22 deletions(-)
Documentation/livepatch/livepatch.rst +1 -14
@@ -6,20 +6,7 @@ This document outlines basic information about kernel livepatching. .. Table of Contents: - 1. Motivation - 2. Kprobes, Ftrace, Livepatching - 3. Consistency model - 4. Livepatch module - 4.1. New functions - 4.2. Metadata - 5. Livepatch life-cycle - 5.1. Loading - 5.2. Enabling - 5.3. Replacing - 5.4. Disabling - 5.5. Removing - 6. Sysfs - 7. Limitations +.. contents:: :local: 1. Motivation
Documentation/livepatch/module-elf-format.rst +2 -8
@@ -7,14 +7,8 @@ This document outlines the Elf format requirements that livepatch modules must f .. Table of Contents - 1. Background and motivation - 2. Livepatch modinfo field - 3. Livepatch relocation sections - 3.1 Livepatch relocation section format - 4. Livepatch symbols - 4.1 A livepatch module's symbol table - 4.2 Livepatch symbol format - 5. Symbol table and Elf section access +.. contents:: :local: + 1. Background and motivation ============================
Signature · 1 line
2.20.1
PATCH v5 2/2 Documentation: livepatch: document reliable stacktrace
In reply to Mark BrownFrom: Mark Rutland <[email protected]>
Add documentation for reliable stacktrace. This is intended to describe the semantics and to be an aid for implementing architecture support for HAVE_RELIABLE_STACKTRACE.
Unwinding is a subtle area, and architectures vary greatly in both implementation and the set of concerns that affect them, so I've tried to avoid making this too specific to any given architecture. I've used examples from both x86_64 and arm64 to explain corner cases in more detail, but I've tried to keep the descriptions sufficient for those who are unfamiliar with the particular architecture.
This document aims to give rationale for all the recommendations and requirements, since that makes it easier to spot nearby issues, or when a check happens to catch a few things at once.
--- Documentation/livepatch/index.rst | 1 + .../livepatch/reliable-stacktrace.rst | 309 ++++++++++++++++++ 2 files changed, 310 insertions(+) create mode 100644 Documentation/livepatch/reliable-stacktrace.rst
Documentation/livepatch/index.rst +1 -0
@@ -13,6 +13,7 @@ Kernel Livepatching module-elf-format shadow-vars system-state + reliable-stacktrace .. only:: subproject and html
Documentation/livepatch/reliable-stacktrace.rst new file +309 -0
309 lines not on this page · raw message
Signature · 1 line
2.20.1
Re: [PATCH v5 2/2] Documentation: livepatch: document reliable stacktrace
Hi,
Quoted 69 lines · Mark Brown
From: Mark Rutland <[email protected]>
Add documentation for reliable stacktrace. This is intended to describe the semantics and to be an aid for implementing architecture support for
HAVE_RELIABLE_STACKTRACE.Unwinding is a subtle area, and architectures vary greatly in both implementation and the set of concerns that affect them, so I've tried to avoid making this too specific to any given architecture. I've used examples from both
x86_64and arm64 to explain corner cases in more detail, but I've tried to keep the descriptions sufficient for those who are unfamiliar with the particular architecture.This document aims to give rationale for all the recommendations and requirements, since that makes it easier to spot nearby issues, or when a check happens to catch a few things at once.
Signed-off-by Mark Rutland <[email protected]>[Updates following review -- broonie]Acked-by Josh Poimboeuf <[email protected]>Signed-off-by Mark Brown <[email protected]>--- Documentation/livepatch/index.rst | 1 + .../livepatch/reliable-stacktrace.rst | 309 ++++++++++++++++++ 2 files changed, 310 insertions(+) create mode 100644 Documentation/livepatch/reliable-stacktrace.rstDocumentation/livepatch/reliable-stacktrace.rst new file +35
-0@@ -0,0 +1,309 @@ +4.4 Rewriting of return addresses +--------------------------------- + +Some trampolines temporarily modify the return address of a function in order +to intercept when that function returns with a return trampoline, e.g. + +* An ftrace trampoline may modify the return address so that function graph + tracing can intercept returns. + +* A kprobes (or optprobes) trampoline may modify the return address so that + kretprobes can intercept returns. + +When this happens, the original return address will not be in its usual +location. For trampolines which are not subject to live patching, where an +unwinder can reliably determine the original return address and no unwind state +is altered by the trampoline, the unwinder may report the original return +address in place of the trampoline and report this as reliable. Otherwise, an +unwinder must report these cases as unreliable. + +Special care is required when identifying the original return address, as this +information is not in a consistent location for the duration of the entry +trampoline or return trampoline. For example, considering the x86_64 +'return_to_handler' return trampoline: + +.. code-block:: none + + SYM_CODE_START(return_to_handler) + UNWIND_HINT_EMPTY + subq $24, %rsp + + /* Save the return values */ + movq %rax, (%rsp) + movq %rdx, 8(%rsp) + movq %rbp, %rdi +
Documentation/livepatch/reliable-stacktrace.rst line 203
Quoted 10 lines
Documentation/livepatch/reliable-stacktrace.rst new file +10
-0+ call ftrace_return_to_handler + + movq %rax, %rdi + movq 8(%rsp), %rdx + movq (%rsp), %rax + addq $24, %rsp + JMP_NOSPEC rdi + SYM_CODE_END(return_to_handler) + +While the traced function runs its return address points on the stack points to
too many "points" above.
Otherwise:
Thanks.
Quoted 20 lines
Documentation/livepatch/reliable-stacktrace.rst new file +20
-0+the start of return_to_handler, and the original return address is stored in +the task's cur_ret_stack. During this time the unwinder can find the return +address using ftrace_graph_ret_addr(). + +When the traced function returns to return_to_handler, there is no longer a +return address on the stack, though the original return address is still stored +in the task's cur_ret_stack. Within ftrace_return_to_handler(), the original +return address is removed from cur_ret_stack and is transiently moved +arbitrarily by the compiler before being returned in rax. The return_to_handler +trampoline moves this into rdi before jumping to it. + +Architectures might not always be able to unwind such sequences, such as when +ftrace_return_to_handler() has removed the address from cur_ret_stack, and the +location of the return address cannot be reliably determined. + +It is recommended that architectures unwind cases where return_to_handler has +not yet been returned to, but architectures are not required to unwind from the +middle of return_to_handler and can report this as unreliable. Architectures +are not required to unwind from other trampolines which modify the return +address.
Signature · 3 lines
~Randy You can't do anything without having to do something else first. -- Belefant's Law
Quoted 16 lines · Mark Brown
This series adds a document, mainly written by Mark Rutland, which makes explicit the requirements for implementing reliable stacktrace in order to aid architectures adding this feature. It also updates the other livepatching documents to use automatically generated tables of contents following review comments on Mark's document.
v5:
- Tweaks to the commit message for the new document.
- Convert new and existing documents to autogenerated tables of contents.
v4:
- Renumber table of contents
v3:
- Incorporated objtool section from Mark.
- Deleted confusing notes about using annotations.
Quoted 5 lines
Mark Brown (1):
Documentation: livepatch: Convert to automatically generated contentsMark Rutland (1):
Documentation: livepatch: document reliable stacktrace
Signature · 1 line
Josh