Skip to content

Commit 95f1fa9

Browse files
committed
Merge tag 'trace-v5.5' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull tracing updates from Steven Rostedt: "New tracing features: - New PERMANENT flag to ftrace_ops when attaching a callback to a function. As /proc/sys/kernel/ftrace_enabled when set to zero will disable all attached callbacks in ftrace, this has a detrimental impact on live kernel tracing, as it disables all that it patched. If a ftrace_ops is registered to ftrace with the PERMANENT flag set, it will prevent ftrace_enabled from being disabled, and if ftrace_enabled is already disabled, it will prevent a ftrace_ops with PREMANENT flag set from being registered. - New register_ftrace_direct(). As eBPF would like to register its own trampolines to be called by the ftrace nop locations directly, without going through the ftrace trampoline, this function has been added. This allows for eBPF trampolines to live along side of ftrace, perf, kprobe and live patching. It also utilizes the ftrace enabled_functions file that keeps track of functions that have been modified in the kernel, to allow for security auditing. - Allow for kernel internal use of ftrace instances. Subsystems in the kernel can now create and destroy their own tracing instances which allows them to have their own tracing buffer, and be able to record events without worrying about other users from writing over their data. - New seq_buf_hex_dump() that lets users use the hex_dump() in their seq_buf usage. - Notifications now added to tracing_max_latency to allow user space to know when a new max latency is hit by one of the latency tracers. - Wider spread use of generic compare operations for use of bsearch and friends. - More synthetic event fields may be defined (32 up from 16) - Use of xarray for architectures with sparse system calls, for the system call trace events. This along with small clean ups and fixes" * tag 'trace-v5.5' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: (51 commits) tracing: Enable syscall optimization for MIPS tracing: Use xarray for syscall trace events tracing: Sample module to demonstrate kernel access to Ftrace instances. tracing: Adding new functions for kernel access to Ftrace instances tracing: Fix Kconfig indentation ring-buffer: Fix typos in function ring_buffer_producer ftrace: Use BIT() macro ftrace: Return ENOTSUPP when DYNAMIC_FTRACE_WITH_DIRECT_CALLS is not configured ftrace: Rename ftrace_graph_stub to ftrace_stub_graph ftrace: Add a helper function to modify_ftrace_direct() to allow arch optimization ftrace: Add helper find_direct_entry() to consolidate code ftrace: Add another check for match in register_ftrace_direct() ftrace: Fix accounting bug with direct->count in register_ftrace_direct() ftrace/selftests: Fix spelling mistake "wakeing" -> "waking" tracing: Increase SYNTH_FIELDS_MAX for synthetic_events ftrace/samples: Add a sample module that implements modify_ftrace_direct() ftrace: Add modify_ftrace_direct() tracing: Add missing "inline" in stub function of latency_fsnotify() tracing: Remove stray tab in TRACE_EVAL_MAP_FILE's help text tracing: Use seq_buf_hex_dump() to dump buffers ...
2 parents 477093b + 16c0f03 commit 95f1fa9

Some content is hidden

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

60 files changed

+2051
-205
lines changed

Documentation/trace/ftrace-uses.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ FTRACE_OPS_FL_RECURSION_SAFE
146146
itself or any nested functions that those functions call.
147147

148148
If this flag is set, it is possible that the callback will also
149-
be called with preemption enabled (when CONFIG_PREEMPT is set),
149+
be called with preemption enabled (when CONFIG_PREEMPTION is set),
150150
but this is not guaranteed.
151151

152152
FTRACE_OPS_FL_IPMODIFY
@@ -170,6 +170,14 @@ FTRACE_OPS_FL_RCU
170170
a callback may be executed and RCU synchronization will not protect
171171
it.
172172

173+
FTRACE_OPS_FL_PERMANENT
174+
If this is set on any ftrace ops, then the tracing cannot disabled by
175+
writing 0 to the proc sysctl ftrace_enabled. Equally, a callback with
176+
the flag set cannot be registered if ftrace_enabled is 0.
177+
178+
Livepatch uses it not to lose the function redirection, so the system
179+
stays protected.
180+
173181

174182
Filtering which functions to trace
175183
==================================

Documentation/trace/ftrace.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2976,7 +2976,9 @@ Note, the proc sysctl ftrace_enable is a big on/off switch for the
29762976
function tracer. By default it is enabled (when function tracing is
29772977
enabled in the kernel). If it is disabled, all function tracing is
29782978
disabled. This includes not only the function tracers for ftrace, but
2979-
also for any other uses (perf, kprobes, stack tracing, profiling, etc).
2979+
also for any other uses (perf, kprobes, stack tracing, profiling, etc). It
2980+
cannot be disabled if there is a callback with FTRACE_OPS_FL_PERMANENT set
2981+
registered.
29802982

29812983
Please disable this with care.
29822984

arch/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,14 @@ config RELR
939939
config ARCH_HAS_MEM_ENCRYPT
940940
bool
941941

942+
config HAVE_SPARSE_SYSCALL_NR
943+
bool
944+
help
945+
An architecture should select this if its syscall numbering is sparse
946+
to save space. For example, MIPS architecture has a syscall array with
947+
entries at 4000, 5000 and 6000 locations. This option turns on syscall
948+
related optimizations for a given architecture.
949+
942950
source "kernel/gcov/Kconfig"
943951

944952
source "scripts/gcc-plugins/Kconfig"

arch/mips/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ config MIPS
7474
select HAVE_PERF_EVENTS
7575
select HAVE_REGS_AND_STACK_ACCESS_API
7676
select HAVE_RSEQ
77+
select HAVE_SPARSE_SYSCALL_NR
7778
select HAVE_STACKPROTECTOR
7879
select HAVE_SYSCALL_TRACEPOINTS
7980
select HAVE_VIRT_CPU_ACCOUNTING_GEN if 64BIT || !SMP

arch/sh/boot/compressed/misc.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,11 @@ void __stack_chk_fail(void)
111111
error("stack-protector: Kernel stack is corrupted\n");
112112
}
113113

114+
/* Needed because vmlinux.lds.h references this */
115+
void ftrace_stub(void)
116+
{
117+
}
118+
114119
#ifdef CONFIG_SUPERH64
115120
#define stackalign 8
116121
#else

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ config X86
157157
select HAVE_DMA_CONTIGUOUS
158158
select HAVE_DYNAMIC_FTRACE
159159
select HAVE_DYNAMIC_FTRACE_WITH_REGS
160+
select HAVE_DYNAMIC_FTRACE_WITH_DIRECT_CALLS
160161
select HAVE_EBPF_JIT
161162
select HAVE_EFFICIENT_UNALIGNED_ACCESS
162163
select HAVE_EISA

arch/x86/include/asm/ftrace.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ static inline unsigned long ftrace_call_adjust(unsigned long addr)
2828
return addr;
2929
}
3030

31+
/*
32+
* When a ftrace registered caller is tracing a function that is
33+
* also set by a register_ftrace_direct() call, it needs to be
34+
* differentiated in the ftrace_caller trampoline. To do this, we
35+
* place the direct caller in the ORIG_AX part of pt_regs. This
36+
* tells the ftrace_caller that there's a direct caller.
37+
*/
38+
static inline void arch_ftrace_set_direct_caller(struct pt_regs *regs, unsigned long addr)
39+
{
40+
/* Emulate a call */
41+
regs->orig_ax = addr;
42+
}
43+
3144
#ifdef CONFIG_DYNAMIC_FTRACE
3245

3346
struct dyn_arch_ftrace {

arch/x86/include/asm/unwind_hints.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,14 @@
8686
UNWIND_HINT sp_offset=\sp_offset
8787
.endm
8888

89+
.macro UNWIND_HINT_SAVE
90+
UNWIND_HINT type=UNWIND_HINT_TYPE_SAVE
91+
.endm
92+
93+
.macro UNWIND_HINT_RESTORE
94+
UNWIND_HINT type=UNWIND_HINT_TYPE_RESTORE
95+
.endm
96+
8997
#else /* !__ASSEMBLY__ */
9098

9199
#define UNWIND_HINT(sp_reg, sp_offset, type, end) \

arch/x86/kernel/ftrace.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,6 +1042,20 @@ void prepare_ftrace_return(unsigned long self_addr, unsigned long *parent,
10421042
if (unlikely(atomic_read(&current->tracing_graph_pause)))
10431043
return;
10441044

1045+
/*
1046+
* If the return location is actually pointing directly to
1047+
* the start of a direct trampoline (if we trace the trampoline
1048+
* it will still be offset by MCOUNT_INSN_SIZE), then the
1049+
* return address is actually off by one word, and we
1050+
* need to adjust for that.
1051+
*/
1052+
if (ftrace_direct_func_count) {
1053+
if (ftrace_find_direct_func(self_addr + MCOUNT_INSN_SIZE)) {
1054+
self_addr = *parent;
1055+
parent++;
1056+
}
1057+
}
1058+
10451059
/*
10461060
* Protect against fault, even if it shouldn't
10471061
* happen. This tool is too much intrusive to

arch/x86/kernel/ftrace_64.S

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
movq %rdi, RDI(%rsp)
8686
movq %r8, R8(%rsp)
8787
movq %r9, R9(%rsp)
88+
movq $0, ORIG_RAX(%rsp)
8889
/*
8990
* Save the original RBP. Even though the mcount ABI does not
9091
* require this, it helps out callers.
@@ -111,7 +112,11 @@
111112
subq $MCOUNT_INSN_SIZE, %rdi
112113
.endm
113114

114-
.macro restore_mcount_regs
115+
.macro restore_mcount_regs save=0
116+
117+
/* ftrace_regs_caller or frame pointers require this */
118+
movq RBP(%rsp), %rbp
119+
115120
movq R9(%rsp), %r9
116121
movq R8(%rsp), %r8
117122
movq RDI(%rsp), %rdi
@@ -120,10 +125,7 @@
120125
movq RCX(%rsp), %rcx
121126
movq RAX(%rsp), %rax
122127

123-
/* ftrace_regs_caller can modify %rbp */
124-
movq RBP(%rsp), %rbp
125-
126-
addq $MCOUNT_REG_SIZE, %rsp
128+
addq $MCOUNT_REG_SIZE-\save, %rsp
127129

128130
.endm
129131

@@ -174,6 +176,8 @@ SYM_FUNC_START(ftrace_regs_caller)
174176
/* Save the current flags before any operations that can change them */
175177
pushfq
176178

179+
UNWIND_HINT_SAVE
180+
177181
/* added 8 bytes to save flags */
178182
save_mcount_regs 8
179183
/* save_mcount_regs fills in first two parameters */
@@ -226,7 +230,33 @@ SYM_INNER_LABEL(ftrace_regs_call, SYM_L_GLOBAL)
226230
movq R10(%rsp), %r10
227231
movq RBX(%rsp), %rbx
228232

229-
restore_mcount_regs
233+
movq ORIG_RAX(%rsp), %rax
234+
movq %rax, MCOUNT_REG_SIZE-8(%rsp)
235+
236+
/* If ORIG_RAX is anything but zero, make this a call to that */
237+
movq ORIG_RAX(%rsp), %rax
238+
cmpq $0, %rax
239+
je 1f
240+
241+
/* Swap the flags with orig_rax */
242+
movq MCOUNT_REG_SIZE(%rsp), %rdi
243+
movq %rdi, MCOUNT_REG_SIZE-8(%rsp)
244+
movq %rax, MCOUNT_REG_SIZE(%rsp)
245+
246+
restore_mcount_regs 8
247+
248+
jmp 2f
249+
250+
1: restore_mcount_regs
251+
252+
253+
2:
254+
/*
255+
* The stack layout is nondetermistic here, depending on which path was
256+
* taken. This confuses objtool and ORC, rightfully so. For now,
257+
* pretend the stack always looks like the non-direct case.
258+
*/
259+
UNWIND_HINT_RESTORE
230260

231261
/* Restore flags */
232262
popfq

0 commit comments

Comments
 (0)