Skip to content

Commit 3737a12

Browse files
committed
Merge branch 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip
Pull more perf updates from Ingo Molnar: "A second round of perf updates: - wide reaching kprobes sanitization and robustization, with the hope of fixing all 'probe this function crashes the kernel' bugs, by Masami Hiramatsu. - uprobes updates from Oleg Nesterov: tmpfs support, corner case fixes and robustization work. - perf tooling updates and fixes from Jiri Olsa, Namhyung Ki, Arnaldo et al: * Add support to accumulate hist periods (Namhyung Kim) * various fixes, refactorings and enhancements" * 'perf-core-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip/tip: (101 commits) perf: Differentiate exec() and non-exec() comm events perf: Fix perf_event_comm() vs. exec() assumption uprobes/x86: Rename arch_uprobe->def to ->defparam, minor comment updates perf/documentation: Add description for conditional branch filter perf/x86: Add conditional branch filtering support perf/tool: Add conditional branch filter 'cond' to perf record perf: Add new conditional branch filter 'PERF_SAMPLE_BRANCH_COND' uprobes: Teach copy_insn() to support tmpfs uprobes: Shift ->readpage check from __copy_insn() to uprobe_register() perf/x86: Use common PMU interrupt disabled code perf/ARM: Use common PMU interrupt disabled code perf: Disable sampled events if no PMU interrupt perf: Fix use after free in perf_remove_from_context() perf tools: Fix 'make help' message error perf record: Fix poll return value propagation perf tools: Move elide bool into perf_hpp_fmt struct perf tools: Remove elide setup for SORT_MODE__MEMORY mode perf tools: Fix "==" into "=" in ui_browser__warning assignment perf tools: Allow overriding sysfs and proc finding with env var perf tools: Consider header files outside perf directory in tags target ...
2 parents c29deef + 82b8977 commit 3737a12

81 files changed

Lines changed: 2979 additions & 1182 deletions

Some content is hidden

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

‎Documentation/kprobes.txt‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ Appendix B: The kprobes sysctl interface
2222

2323
Kprobes enables you to dynamically break into any kernel routine and
2424
collect debugging and performance information non-disruptively. You
25-
can trap at almost any kernel code address, specifying a handler
25+
can trap at almost any kernel code address(*), specifying a handler
2626
routine to be invoked when the breakpoint is hit.
27+
(*: some parts of the kernel code can not be trapped, see 1.5 Blacklist)
2728

2829
There are currently three types of probes: kprobes, jprobes, and
2930
kretprobes (also called return probes). A kprobe can be inserted
@@ -273,6 +274,19 @@ using one of the following techniques:
273274
or
274275
- Execute 'sysctl -w debug.kprobes_optimization=n'
275276

277+
1.5 Blacklist
278+
279+
Kprobes can probe most of the kernel except itself. This means
280+
that there are some functions where kprobes cannot probe. Probing
281+
(trapping) such functions can cause a recursive trap (e.g. double
282+
fault) or the nested probe handler may never be called.
283+
Kprobes manages such functions as a blacklist.
284+
If you want to add a function into the blacklist, you just need
285+
to (1) include linux/kprobes.h and (2) use NOKPROBE_SYMBOL() macro
286+
to specify a blacklisted function.
287+
Kprobes checks the given probe address against the blacklist and
288+
rejects registering it, if the given address is in the blacklist.
289+
276290
2. Architectures Supported
277291

278292
Kprobes, jprobes, and return probes are implemented on the following

‎arch/arm/kernel/perf_event.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ __hw_perf_event_init(struct perf_event *event)
410410
*/
411411
hwc->config_base |= (unsigned long)mapping;
412412

413-
if (!hwc->sample_period) {
413+
if (!is_sampling_event(event)) {
414414
/*
415415
* For non-sampling runs, limit the sample_period to half
416416
* of the counter width. That way, the new counter value

‎arch/arm/kernel/perf_event_cpu.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ static int cpu_pmu_request_irq(struct arm_pmu *cpu_pmu, irq_handler_t handler)
126126

127127
irqs = min(pmu_device->num_resources, num_possible_cpus());
128128
if (irqs < 1) {
129-
pr_err("no irqs for PMUs defined\n");
130-
return -ENODEV;
129+
printk_once("perf/ARM: No irqs for PMU defined, sampling events not supported\n");
130+
return 0;
131131
}
132132

133133
irq = platform_get_irq(pmu_device, 0);
@@ -191,6 +191,10 @@ static void cpu_pmu_init(struct arm_pmu *cpu_pmu)
191191
/* Ensure the PMU has sane values out of reset. */
192192
if (cpu_pmu->reset)
193193
on_each_cpu(cpu_pmu->reset, cpu_pmu, 1);
194+
195+
/* If no interrupts available, set the corresponding capability flag */
196+
if (!platform_get_irq(cpu_pmu->plat_device, 0))
197+
cpu_pmu->pmu.capabilities |= PERF_PMU_CAP_NO_INTERRUPT;
194198
}
195199

196200
/*

‎arch/x86/include/asm/asm.h‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@
5757
.long (from) - . ; \
5858
.long (to) - . + 0x7ffffff0 ; \
5959
.popsection
60+
61+
# define _ASM_NOKPROBE(entry) \
62+
.pushsection "_kprobe_blacklist","aw" ; \
63+
_ASM_ALIGN ; \
64+
_ASM_PTR (entry); \
65+
.popsection
6066
#else
6167
# define _ASM_EXTABLE(from,to) \
6268
" .pushsection \"__ex_table\",\"a\"\n" \
@@ -71,6 +77,7 @@
7177
" .long (" #from ") - .\n" \
7278
" .long (" #to ") - . + 0x7ffffff0\n" \
7379
" .popsection\n"
80+
/* For C file, we already have NOKPROBE_SYMBOL macro */
7481
#endif
7582

7683
#endif /* _ASM_X86_ASM_H */

‎arch/x86/include/asm/kprobes.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,6 @@ struct kprobe_ctlblk {
116116
extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
117117
extern int kprobe_exceptions_notify(struct notifier_block *self,
118118
unsigned long val, void *data);
119+
extern int kprobe_int3_handler(struct pt_regs *regs);
120+
extern int kprobe_debug_handler(struct pt_regs *regs);
119121
#endif /* _ASM_X86_KPROBES_H */

‎arch/x86/include/asm/traps.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ dotraplinkage void do_segment_not_present(struct pt_regs *, long);
6868
dotraplinkage void do_stack_segment(struct pt_regs *, long);
6969
#ifdef CONFIG_X86_64
7070
dotraplinkage void do_double_fault(struct pt_regs *, long);
71-
asmlinkage __kprobes struct pt_regs *sync_regs(struct pt_regs *);
71+
asmlinkage struct pt_regs *sync_regs(struct pt_regs *);
7272
#endif
7373
dotraplinkage void do_general_protection(struct pt_regs *, long);
7474
dotraplinkage void do_page_fault(struct pt_regs *, unsigned long);
@@ -103,7 +103,6 @@ static inline int get_si_code(unsigned long condition)
103103

104104
extern int panic_on_unrecovered_nmi;
105105

106-
void math_error(struct pt_regs *, int, int);
107106
void math_emulate(struct math_emu_info *);
108107
#ifndef CONFIG_X86_32
109108
asmlinkage void smp_thermal_interrupt(void);

‎arch/x86/include/asm/uprobes.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,18 @@ struct arch_uprobe {
4141
u8 ixol[MAX_UINSN_BYTES];
4242
};
4343

44-
u16 fixups;
4544
const struct uprobe_xol_ops *ops;
4645

4746
union {
48-
#ifdef CONFIG_X86_64
49-
unsigned long rip_rela_target_address;
50-
#endif
5147
struct {
5248
s32 offs;
5349
u8 ilen;
5450
u8 opc1;
55-
} branch;
51+
} branch;
52+
struct {
53+
u8 fixups;
54+
u8 ilen;
55+
} defparam;
5656
};
5757
};
5858

‎arch/x86/kernel/alternative.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include <linux/mutex.h>
66
#include <linux/list.h>
77
#include <linux/stringify.h>
8-
#include <linux/kprobes.h>
98
#include <linux/mm.h>
109
#include <linux/vmalloc.h>
1110
#include <linux/memory.h>
@@ -551,7 +550,7 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
551550
*
552551
* Note: Must be called under text_mutex.
553552
*/
554-
void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
553+
void *text_poke(void *addr, const void *opcode, size_t len)
555554
{
556555
unsigned long flags;
557556
char *vaddr;

‎arch/x86/kernel/apic/hw_nmi.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void arch_trigger_all_cpu_backtrace(void)
6060
smp_mb__after_atomic();
6161
}
6262

63-
static int __kprobes
63+
static int
6464
arch_trigger_all_cpu_backtrace_handler(unsigned int cmd, struct pt_regs *regs)
6565
{
6666
int cpu;
@@ -80,6 +80,7 @@ arch_trigger_all_cpu_backtrace_handler(unsigned int cmd, struct pt_regs *regs)
8080

8181
return NMI_DONE;
8282
}
83+
NOKPROBE_SYMBOL(arch_trigger_all_cpu_backtrace_handler);
8384

8485
static int __init register_trigger_all_cpu_backtrace(void)
8586
{

‎arch/x86/kernel/cpu/common.c‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/delay.h>
99
#include <linux/sched.h>
1010
#include <linux/init.h>
11+
#include <linux/kprobes.h>
1112
#include <linux/kgdb.h>
1213
#include <linux/smp.h>
1314
#include <linux/io.h>
@@ -1193,6 +1194,7 @@ int is_debug_stack(unsigned long addr)
11931194
(addr <= __get_cpu_var(debug_stack_addr) &&
11941195
addr > (__get_cpu_var(debug_stack_addr) - DEBUG_STKSZ));
11951196
}
1197+
NOKPROBE_SYMBOL(is_debug_stack);
11961198

11971199
DEFINE_PER_CPU(u32, debug_idt_ctr);
11981200

@@ -1201,6 +1203,7 @@ void debug_stack_set_zero(void)
12011203
this_cpu_inc(debug_idt_ctr);
12021204
load_current_idt();
12031205
}
1206+
NOKPROBE_SYMBOL(debug_stack_set_zero);
12041207

12051208
void debug_stack_reset(void)
12061209
{
@@ -1209,6 +1212,7 @@ void debug_stack_reset(void)
12091212
if (this_cpu_dec_return(debug_idt_ctr) == 0)
12101213
load_current_idt();
12111214
}
1215+
NOKPROBE_SYMBOL(debug_stack_reset);
12121216

12131217
#else /* CONFIG_X86_64 */
12141218

0 commit comments

Comments
 (0)