Skip to content

Commit 3148637

Browse files
committed
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull perf updates from Ingo Molnar: "The main changes in this cycle were: Kernel: - kprobes updates: use better W^X patterns for code modifications, improve optprobes, remove jprobes. (Masami Hiramatsu, Kees Cook) - core fixes: event timekeeping (enabled/running times statistics) fixes, perf_event_read() locking fixes and cleanups, etc. (Peter Zijlstra) - Extend x86 Intel free-running PEBS support and support x86 user-register sampling in perf record and perf script. (Andi Kleen) Tooling: - Completely rework the way inline frames are handled. Instead of querying for the inline nodes on-demand in the individual tools, we now create proper callchain nodes for inlined frames. (Milian Wolff) - 'perf trace' updates (Arnaldo Carvalho de Melo) - Implement a way to print formatted output to per-event files in 'perf script' to facilitate generate flamegraphs, elliminating the need to write scripts to do that separation (yuzhoujian, Arnaldo Carvalho de Melo) - Update vendor events JSON metrics for Intel's Broadwell, Broadwell Server, Haswell, Haswell Server, IvyBridge, IvyTown, JakeTown, Sandy Bridge, Skylake, SkyLake Server - and Goldmont Plus V1 (Andi Kleen, Kan Liang) - Multithread the synthesizing of PERF_RECORD_ events for pre-existing threads in 'perf top', speeding up that phase, greatly improving the user experience in systems such as Intel's Knights Mill (Kan Liang) - Introduce the concept of weak groups in 'perf stat': try to set up a group, but if it's not schedulable fallback to not using a group. That gives us the best of both worlds: groups if they work, but still a usable fallback if they don't. E.g: (Andi Kleen) - perf sched timehist enhancements (David Ahern) - ... various other enhancements, updates, cleanups and fixes" * 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (139 commits) kprobes: Don't spam the build log with deprecation warnings arm/kprobes: Remove jprobe test case arm/kprobes: Fix kretprobe test to check correct counter perf srcline: Show correct function name for srcline of callchains perf srcline: Fix memory leak in addr2inlines() perf trace beauty kcmp: Beautify arguments perf trace beauty: Implement pid_fd beautifier tools include uapi: Grab a copy of linux/kcmp.h perf callchain: Fix double mapping al->addr for children without self period perf stat: Make --per-thread update shadow stats to show metrics perf stat: Move the shadow stats scale computation in perf_stat__update_shadow_stats perf tools: Add perf_data_file__write function perf tools: Add struct perf_data_file perf tools: Rename struct perf_data_file to perf_data perf script: Print information about per-event-dump files perf trace beauty prctl: Generate 'option' string table from kernel headers tools include uapi: Grab a copy of linux/prctl.h perf script: Allow creating per-event dump files perf evsel: Restore evsel->priv as a tool private area perf script: Use event_format__fprintf() ...
2 parents 8e9a2db + fcdfafc commit 3148637

File tree

182 files changed

+8370
-2521
lines changed

Some content is hidden

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

182 files changed

+8370
-2521
lines changed

Documentation/kprobes.txt

+57-102
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ Kernel Probes (Kprobes)
88

99
.. CONTENTS
1010

11-
1. Concepts: Kprobes, Jprobes, Return Probes
11+
1. Concepts: Kprobes, and Return Probes
1212
2. Architectures Supported
1313
3. Configuring Kprobes
1414
4. API Reference
1515
5. Kprobes Features and Limitations
1616
6. Probe Overhead
1717
7. TODO
1818
8. Kprobes Example
19-
9. Jprobes Example
20-
10. Kretprobes Example
19+
9. Kretprobes Example
20+
10. Deprecated Features
2121
Appendix A: The kprobes debugfs interface
2222
Appendix B: The kprobes sysctl interface
2323

24-
Concepts: Kprobes, Jprobes, Return Probes
24+
Concepts: Kprobes and Return Probes
2525
=========================================
2626

2727
Kprobes enables you to dynamically break into any kernel routine and
@@ -32,12 +32,10 @@ routine to be invoked when the breakpoint is hit.
3232
.. [1] some parts of the kernel code can not be trapped, see
3333
:ref:`kprobes_blacklist`)
3434

35-
There are currently three types of probes: kprobes, jprobes, and
36-
kretprobes (also called return probes). A kprobe can be inserted
37-
on virtually any instruction in the kernel. A jprobe is inserted at
38-
the entry to a kernel function, and provides convenient access to the
39-
function's arguments. A return probe fires when a specified function
40-
returns.
35+
There are currently two types of probes: kprobes, and kretprobes
36+
(also called return probes). A kprobe can be inserted on virtually
37+
any instruction in the kernel. A return probe fires when a specified
38+
function returns.
4139

4240
In the typical case, Kprobes-based instrumentation is packaged as
4341
a kernel module. The module's init function installs ("registers")
@@ -82,45 +80,6 @@ After the instruction is single-stepped, Kprobes executes the
8280
"post_handler," if any, that is associated with the kprobe.
8381
Execution then continues with the instruction following the probepoint.
8482

85-
How Does a Jprobe Work?
86-
-----------------------
87-
88-
A jprobe is implemented using a kprobe that is placed on a function's
89-
entry point. It employs a simple mirroring principle to allow
90-
seamless access to the probed function's arguments. The jprobe
91-
handler routine should have the same signature (arg list and return
92-
type) as the function being probed, and must always end by calling
93-
the Kprobes function jprobe_return().
94-
95-
Here's how it works. When the probe is hit, Kprobes makes a copy of
96-
the saved registers and a generous portion of the stack (see below).
97-
Kprobes then points the saved instruction pointer at the jprobe's
98-
handler routine, and returns from the trap. As a result, control
99-
passes to the handler, which is presented with the same register and
100-
stack contents as the probed function. When it is done, the handler
101-
calls jprobe_return(), which traps again to restore the original stack
102-
contents and processor state and switch to the probed function.
103-
104-
By convention, the callee owns its arguments, so gcc may produce code
105-
that unexpectedly modifies that portion of the stack. This is why
106-
Kprobes saves a copy of the stack and restores it after the jprobe
107-
handler has run. Up to MAX_STACK_SIZE bytes are copied -- e.g.,
108-
64 bytes on i386.
109-
110-
Note that the probed function's args may be passed on the stack
111-
or in registers. The jprobe will work in either case, so long as the
112-
handler's prototype matches that of the probed function.
113-
114-
Note that in some architectures (e.g.: arm64 and sparc64) the stack
115-
copy is not done, as the actual location of stacked parameters may be
116-
outside of a reasonable MAX_STACK_SIZE value and because that location
117-
cannot be determined by the jprobes code. In this case the jprobes
118-
user must be careful to make certain the calling signature of the
119-
function does not cause parameters to be passed on the stack (e.g.:
120-
more than eight function arguments, an argument of more than sixteen
121-
bytes, or more than 64 bytes of argument data, depending on
122-
architecture).
123-
12483
Return Probes
12584
-------------
12685

@@ -245,8 +204,7 @@ Pre-optimization
245204
After preparing the detour buffer, Kprobes verifies that none of the
246205
following situations exist:
247206

248-
- The probe has either a break_handler (i.e., it's a jprobe) or a
249-
post_handler.
207+
- The probe has a post_handler.
250208
- Other instructions in the optimized region are probed.
251209
- The probe is disabled.
252210

@@ -331,7 +289,7 @@ rejects registering it, if the given address is in the blacklist.
331289
Architectures Supported
332290
=======================
333291

334-
Kprobes, jprobes, and return probes are implemented on the following
292+
Kprobes and return probes are implemented on the following
335293
architectures:
336294

337295
- i386 (Supports jump optimization)
@@ -446,27 +404,6 @@ architecture-specific trap number associated with the fault (e.g.,
446404
on i386, 13 for a general protection fault or 14 for a page fault).
447405
Returns 1 if it successfully handled the exception.
448406

449-
register_jprobe
450-
---------------
451-
452-
::
453-
454-
#include <linux/kprobes.h>
455-
int register_jprobe(struct jprobe *jp)
456-
457-
Sets a breakpoint at the address jp->kp.addr, which must be the address
458-
of the first instruction of a function. When the breakpoint is hit,
459-
Kprobes runs the handler whose address is jp->entry.
460-
461-
The handler should have the same arg list and return type as the probed
462-
function; and just before it returns, it must call jprobe_return().
463-
(The handler never actually returns, since jprobe_return() returns
464-
control to Kprobes.) If the probed function is declared asmlinkage
465-
or anything else that affects how args are passed, the handler's
466-
declaration must match.
467-
468-
register_jprobe() returns 0 on success, or a negative errno otherwise.
469-
470407
register_kretprobe
471408
------------------
472409

@@ -513,7 +450,6 @@ unregister_*probe
513450

514451
#include <linux/kprobes.h>
515452
void unregister_kprobe(struct kprobe *kp);
516-
void unregister_jprobe(struct jprobe *jp);
517453
void unregister_kretprobe(struct kretprobe *rp);
518454

519455
Removes the specified probe. The unregister function can be called
@@ -532,7 +468,6 @@ register_*probes
532468
#include <linux/kprobes.h>
533469
int register_kprobes(struct kprobe **kps, int num);
534470
int register_kretprobes(struct kretprobe **rps, int num);
535-
int register_jprobes(struct jprobe **jps, int num);
536471

537472
Registers each of the num probes in the specified array. If any
538473
error occurs during registration, all probes in the array, up to
@@ -555,7 +490,6 @@ unregister_*probes
555490
#include <linux/kprobes.h>
556491
void unregister_kprobes(struct kprobe **kps, int num);
557492
void unregister_kretprobes(struct kretprobe **rps, int num);
558-
void unregister_jprobes(struct jprobe **jps, int num);
559493

560494
Removes each of the num probes in the specified array at once.
561495

@@ -574,7 +508,6 @@ disable_*probe
574508
#include <linux/kprobes.h>
575509
int disable_kprobe(struct kprobe *kp);
576510
int disable_kretprobe(struct kretprobe *rp);
577-
int disable_jprobe(struct jprobe *jp);
578511

579512
Temporarily disables the specified ``*probe``. You can enable it again by using
580513
enable_*probe(). You must specify the probe which has been registered.
@@ -587,20 +520,17 @@ enable_*probe
587520
#include <linux/kprobes.h>
588521
int enable_kprobe(struct kprobe *kp);
589522
int enable_kretprobe(struct kretprobe *rp);
590-
int enable_jprobe(struct jprobe *jp);
591523

592524
Enables ``*probe`` which has been disabled by disable_*probe(). You must specify
593525
the probe which has been registered.
594526

595527
Kprobes Features and Limitations
596528
================================
597529

598-
Kprobes allows multiple probes at the same address. Currently,
599-
however, there cannot be multiple jprobes on the same function at
600-
the same time. Also, a probepoint for which there is a jprobe or
601-
a post_handler cannot be optimized. So if you install a jprobe,
602-
or a kprobe with a post_handler, at an optimized probepoint, the
603-
probepoint will be unoptimized automatically.
530+
Kprobes allows multiple probes at the same address. Also,
531+
a probepoint for which there is a post_handler cannot be optimized.
532+
So if you install a kprobe with a post_handler, at an optimized
533+
probepoint, the probepoint will be unoptimized automatically.
604534

605535
In general, you can install a probe anywhere in the kernel.
606536
In particular, you can probe interrupt handlers. Known exceptions
@@ -662,7 +592,7 @@ We're unaware of other specific cases where this could be a problem.
662592
If, upon entry to or exit from a function, the CPU is running on
663593
a stack other than that of the current task, registering a return
664594
probe on that function may produce undesirable results. For this
665-
reason, Kprobes doesn't support return probes (or kprobes or jprobes)
595+
reason, Kprobes doesn't support return probes (or kprobes)
666596
on the x86_64 version of __switch_to(); the registration functions
667597
return -EINVAL.
668598

@@ -706,24 +636,24 @@ Probe Overhead
706636
On a typical CPU in use in 2005, a kprobe hit takes 0.5 to 1.0
707637
microseconds to process. Specifically, a benchmark that hits the same
708638
probepoint repeatedly, firing a simple handler each time, reports 1-2
709-
million hits per second, depending on the architecture. A jprobe or
710-
return-probe hit typically takes 50-75% longer than a kprobe hit.
639+
million hits per second, depending on the architecture. A return-probe
640+
hit typically takes 50-75% longer than a kprobe hit.
711641
When you have a return probe set on a function, adding a kprobe at
712642
the entry to that function adds essentially no overhead.
713643

714644
Here are sample overhead figures (in usec) for different architectures::
715645

716-
k = kprobe; j = jprobe; r = return probe; kr = kprobe + return probe
717-
on same function; jr = jprobe + return probe on same function::
646+
k = kprobe; r = return probe; kr = kprobe + return probe
647+
on same function
718648

719649
i386: Intel Pentium M, 1495 MHz, 2957.31 bogomips
720-
k = 0.57 usec; j = 1.00; r = 0.92; kr = 0.99; jr = 1.40
650+
k = 0.57 usec; r = 0.92; kr = 0.99
721651

722652
x86_64: AMD Opteron 246, 1994 MHz, 3971.48 bogomips
723-
k = 0.49 usec; j = 0.76; r = 0.80; kr = 0.82; jr = 1.07
653+
k = 0.49 usec; r = 0.80; kr = 0.82
724654

725655
ppc64: POWER5 (gr), 1656 MHz (SMT disabled, 1 virtual CPU per physical CPU)
726-
k = 0.77 usec; j = 1.31; r = 1.26; kr = 1.45; jr = 1.99
656+
k = 0.77 usec; r = 1.26; kr = 1.45
727657

728658
Optimized Probe Overhead
729659
------------------------
@@ -755,11 +685,6 @@ Kprobes Example
755685

756686
See samples/kprobes/kprobe_example.c
757687

758-
Jprobes Example
759-
===============
760-
761-
See samples/kprobes/jprobe_example.c
762-
763688
Kretprobes Example
764689
==================
765690

@@ -772,6 +697,37 @@ For additional information on Kprobes, refer to the following URLs:
772697
- http://www-users.cs.umn.edu/~boutcher/kprobes/
773698
- http://www.linuxsymposium.org/2006/linuxsymposium_procv2.pdf (pages 101-115)
774699

700+
Deprecated Features
701+
===================
702+
703+
Jprobes is now a deprecated feature. People who are depending on it should
704+
migrate to other tracing features or use older kernels. Please consider to
705+
migrate your tool to one of the following options:
706+
707+
- Use trace-event to trace target function with arguments.
708+
709+
trace-event is a low-overhead (and almost no visible overhead if it
710+
is off) statically defined event interface. You can define new events
711+
and trace it via ftrace or any other tracing tools.
712+
713+
See the following urls:
714+
715+
- https://lwn.net/Articles/379903/
716+
- https://lwn.net/Articles/381064/
717+
- https://lwn.net/Articles/383362/
718+
719+
- Use ftrace dynamic events (kprobe event) with perf-probe.
720+
721+
If you build your kernel with debug info (CONFIG_DEBUG_INFO=y), you can
722+
find which register/stack is assigned to which local variable or arguments
723+
by using perf-probe and set up new event to trace it.
724+
725+
See following documents:
726+
727+
- Documentation/trace/kprobetrace.txt
728+
- Documentation/trace/events.txt
729+
- tools/perf/Documentation/perf-probe.txt
730+
775731

776732
The kprobes debugfs interface
777733
=============================
@@ -783,14 +739,13 @@ under the /sys/kernel/debug/kprobes/ directory (assuming debugfs is mounted at /
783739
/sys/kernel/debug/kprobes/list: Lists all registered probes on the system::
784740

785741
c015d71a k vfs_read+0x0
786-
c011a316 j do_fork+0x0
787742
c03dedc5 r tcp_v4_rcv+0x0
788743

789744
The first column provides the kernel address where the probe is inserted.
790-
The second column identifies the type of probe (k - kprobe, r - kretprobe
791-
and j - jprobe), while the third column specifies the symbol+offset of
792-
the probe. If the probed function belongs to a module, the module name
793-
is also specified. Following columns show probe status. If the probe is on
745+
The second column identifies the type of probe (k - kprobe and r - kretprobe)
746+
while the third column specifies the symbol+offset of the probe.
747+
If the probed function belongs to a module, the module name is also
748+
specified. Following columns show probe status. If the probe is on
794749
a virtual address that is no longer valid (module init sections, module
795750
virtual addresses that correspond to modules that've been unloaded),
796751
such probes are marked with [GONE]. If the probe is temporarily disabled,

arch/Kconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ config STATIC_KEYS_SELFTEST
9191
config OPTPROBES
9292
def_bool y
9393
depends on KPROBES && HAVE_OPTPROBES
94-
depends on !PREEMPT
94+
select TASKS_RCU if PREEMPT
9595

9696
config KPROBES_ON_FTRACE
9797
def_bool y

arch/arm/probes/kprobes/test-core.c

+1-58
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ static bool test_regs_ok;
227227
static int test_func_instance;
228228
static int pre_handler_called;
229229
static int post_handler_called;
230-
static int jprobe_func_called;
231230
static int kretprobe_handler_called;
232231
static int tests_failed;
233232

@@ -370,50 +369,6 @@ static int test_kprobe(long (*func)(long, long))
370369
return 0;
371370
}
372371

373-
static void __kprobes jprobe_func(long r0, long r1)
374-
{
375-
jprobe_func_called = test_func_instance;
376-
if (r0 == FUNC_ARG1 && r1 == FUNC_ARG2)
377-
test_regs_ok = true;
378-
jprobe_return();
379-
}
380-
381-
static struct jprobe the_jprobe = {
382-
.entry = jprobe_func,
383-
};
384-
385-
static int test_jprobe(long (*func)(long, long))
386-
{
387-
int ret;
388-
389-
the_jprobe.kp.addr = (kprobe_opcode_t *)func;
390-
ret = register_jprobe(&the_jprobe);
391-
if (ret < 0) {
392-
pr_err("FAIL: register_jprobe failed with %d\n", ret);
393-
return ret;
394-
}
395-
396-
ret = call_test_func(func, true);
397-
398-
unregister_jprobe(&the_jprobe);
399-
the_jprobe.kp.flags = 0; /* Clear disable flag to allow reuse */
400-
401-
if (!ret)
402-
return -EINVAL;
403-
if (jprobe_func_called != test_func_instance) {
404-
pr_err("FAIL: jprobe handler function not called\n");
405-
return -EINVAL;
406-
}
407-
if (!call_test_func(func, false))
408-
return -EINVAL;
409-
if (jprobe_func_called == test_func_instance) {
410-
pr_err("FAIL: probe called after unregistering\n");
411-
return -EINVAL;
412-
}
413-
414-
return 0;
415-
}
416-
417372
static int __kprobes
418373
kretprobe_handler(struct kretprobe_instance *ri, struct pt_regs *regs)
419374
{
@@ -451,7 +406,7 @@ static int test_kretprobe(long (*func)(long, long))
451406
}
452407
if (!call_test_func(func, false))
453408
return -EINVAL;
454-
if (jprobe_func_called == test_func_instance) {
409+
if (kretprobe_handler_called == test_func_instance) {
455410
pr_err("FAIL: kretprobe called after unregistering\n");
456411
return -EINVAL;
457412
}
@@ -468,18 +423,6 @@ static int run_api_tests(long (*func)(long, long))
468423
if (ret < 0)
469424
return ret;
470425

471-
pr_info(" jprobe\n");
472-
ret = test_jprobe(func);
473-
#if defined(CONFIG_THUMB2_KERNEL) && !defined(MODULE)
474-
if (ret == -EINVAL) {
475-
pr_err("FAIL: Known longtime bug with jprobe on Thumb kernels\n");
476-
tests_failed = ret;
477-
ret = 0;
478-
}
479-
#endif
480-
if (ret < 0)
481-
return ret;
482-
483426
pr_info(" kretprobe\n");
484427
ret = test_kretprobe(func);
485428
if (ret < 0)

0 commit comments

Comments
 (0)