Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

kprobes: move kprobe declarations to asm-generic/kprobes.h

Often all is needed is these small helpers, instead of compiler.h or a
full kprobes.h. This is important for asm helpers, in fact even some
asm/kprobes.h make use of these helpers... instead just keep a generic
asm file with helpers useful for asm code with the least amount of
clutter as possible.

Likewise we need now to also address what to do about this file for both
when architectures have CONFIG_HAVE_KPROBES, and when they do not. Then
for when architectures have CONFIG_HAVE_KPROBES but have disabled
CONFIG_KPROBES.

Right now most asm/kprobes.h do not have guards against CONFIG_KPROBES,
this means most architecture code cannot include asm/kprobes.h safely.
Correct this and add guards for architectures missing them.
Additionally provide architectures that not have kprobes support with
the default asm-generic solution. This lets us force asm/kprobes.h on
the header include/linux/kprobes.h always, but most importantly we can
now safely include just asm/kprobes.h on architecture code without
bringing the full kitchen sink of header files.

Two architectures already provided a guard against CONFIG_KPROBES on its
kprobes.h: sh, arch. The rest of the architectures needed gaurds added.
We avoid including any not-needed headers on asm/kprobes.h unless
kprobes have been enabled.

In a subsequent atomic change we can try now to remove compiler.h from
include/linux/kprobes.h.

During this sweep I've also identified a few architectures defining a
common macro needed for both kprobes and ftrace, that of the definition
of the breakput instruction up. Some refer to this as
BREAKPOINT_INSTRUCTION. This must be kept outside of the #ifdef
CONFIG_KPROBES guard.

[mcgrof@kernel.org: fix arm64 build]
Link: http://lkml.kernel.org/r/CAB=NE6X1WMByuARS4mZ1g9+W=LuVBnMDnh_5zyN0CLADaVh=Jw@mail.gmail.com
[sfr@canb.auug.org.au: fixup for kprobes declarations moving]
Link: http://lkml.kernel.org/r/20170214165933.13ebd4f4@canb.auug.org.au
Link: http://lkml.kernel.org/r/20170203233139.32682-1-mcgrof@kernel.org
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Acked-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Masami Hiramatsu <mhiramat@kernel.org>
Cc: Ananth N Mavinakayanahalli <ananth@linux.vnet.ibm.com>
Cc: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: H. Peter Anvin <hpa@zytor.com>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Steven Rostedt <rostedt@goodmis.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Luis R. Rodriguez and committed by
Linus Torvalds
7d134b2c fd5bb66c

+125 -38
+1
MAINTAINERS
··· 7286 7286 S: Maintained 7287 7287 F: Documentation/kprobes.txt 7288 7288 F: include/linux/kprobes.h 7289 + F: include/asm-generic/kprobes.h 7289 7290 F: kernel/kprobes.c 7290 7291 7291 7292 KS0108 LCD CONTROLLER DRIVER
+1
arch/alpha/include/asm/Kbuild
··· 10 10 generic-y += sections.h 11 11 generic-y += trace_clock.h 12 12 generic-y += current.h 13 + generic-y += kprobes.h
+4 -2
arch/arc/include/asm/kprobes.h
··· 9 9 #ifndef _ARC_KPROBES_H 10 10 #define _ARC_KPROBES_H 11 11 12 + #include <asm-generic/kprobes.h> 13 + 12 14 #ifdef CONFIG_KPROBES 13 15 14 16 typedef u16 kprobe_opcode_t; ··· 57 55 static void trap_is_kprobe(unsigned long address, struct pt_regs *regs) 58 56 { 59 57 } 60 - #endif 58 + #endif /* CONFIG_KPROBES */ 61 59 62 - #endif 60 + #endif /* _ARC_KPROBES_H */
+4
arch/arm/include/asm/kprobes.h
··· 16 16 #ifndef _ARM_KPROBES_H 17 17 #define _ARM_KPROBES_H 18 18 19 + #include <asm-generic/kprobes.h> 20 + 21 + #ifdef CONFIG_KPROBES 19 22 #include <linux/types.h> 20 23 #include <linux/ptrace.h> 21 24 #include <linux/notifier.h> ··· 86 83 */ 87 84 }; 88 85 86 + #endif /* CONFIG_KPROBES */ 89 87 #endif /* _ARM_KPROBES_H */
+1
arch/arm/probes/decode.h
··· 22 22 #include <linux/types.h> 23 23 #include <linux/stddef.h> 24 24 #include <asm/probes.h> 25 + #include <asm/kprobes.h> 25 26 26 27 void __init arm_probes_decode_init(void); 27 28
+4
arch/arm64/include/asm/kprobes.h
··· 16 16 #ifndef _ARM_KPROBES_H 17 17 #define _ARM_KPROBES_H 18 18 19 + #include <asm-generic/kprobes.h> 20 + 21 + #ifdef CONFIG_KPROBES 19 22 #include <linux/types.h> 20 23 #include <linux/ptrace.h> 21 24 #include <linux/percpu.h> ··· 60 57 void kretprobe_trampoline(void); 61 58 void __kprobes *trampoline_probe_handler(struct pt_regs *regs); 62 59 60 + #endif /* CONFIG_KPROBES */ 63 61 #endif /* _ARM_KPROBES_H */
+1
arch/arm64/kernel/armv8_deprecated.c
··· 19 19 #include <asm/sysreg.h> 20 20 #include <asm/system_misc.h> 21 21 #include <asm/traps.h> 22 + #include <asm/kprobes.h> 22 23 #include <linux/uaccess.h> 23 24 #include <asm/cpufeature.h> 24 25
+1
arch/arm64/kernel/insn.c
··· 31 31 #include <asm/debug-monitors.h> 32 32 #include <asm/fixmap.h> 33 33 #include <asm/insn.h> 34 + #include <asm/kprobes.h> 34 35 35 36 #define AARCH64_INSN_SF_BIT BIT(31) 36 37 #define AARCH64_INSN_N_BIT BIT(22)
+2
arch/arm64/kernel/probes/decode-insn.h
··· 16 16 #ifndef _ARM_KERNEL_KPROBES_ARM64_H 17 17 #define _ARM_KERNEL_KPROBES_ARM64_H 18 18 19 + #include <asm/kprobes.h> 20 + 19 21 /* 20 22 * ARM strongly recommends a limit of 128 bytes between LoadExcl and 21 23 * StoreExcl instructions in a single thread of execution. So keep the
+6 -1
arch/avr32/include/asm/kprobes.h
··· 11 11 #ifndef __ASM_AVR32_KPROBES_H 12 12 #define __ASM_AVR32_KPROBES_H 13 13 14 + #include <asm-generic/kprobes.h> 15 + 16 + #define BREAKPOINT_INSTRUCTION 0xd673 /* breakpoint */ 17 + 18 + #ifdef CONFIG_KPROBES 14 19 #include <linux/types.h> 15 20 16 21 typedef u16 kprobe_opcode_t; 17 - #define BREAKPOINT_INSTRUCTION 0xd673 /* breakpoint */ 18 22 #define MAX_INSN_SIZE 2 19 23 #define MAX_STACK_SIZE 64 /* 32 would probably be OK */ 20 24 ··· 50 46 51 47 #define flush_insn_slot(p) do { } while (0) 52 48 49 + #endif /* CONFIG_KPROBES */ 53 50 #endif /* __ASM_AVR32_KPROBES_H */
+1
arch/blackfin/include/asm/Kbuild
··· 46 46 generic-y += user.h 47 47 generic-y += word-at-a-time.h 48 48 generic-y += xor.h 49 + generic-y += kprobes.h
+1
arch/c6x/include/asm/Kbuild
··· 61 61 generic-y += vga.h 62 62 generic-y += word-at-a-time.h 63 63 generic-y += xor.h 64 + generic-y += kprobes.h
+1
arch/cris/include/asm/Kbuild
··· 45 45 generic-y += vga.h 46 46 generic-y += word-at-a-time.h 47 47 generic-y += xor.h 48 + generic-y += kprobes.h
+1
arch/frv/include/asm/Kbuild
··· 7 7 generic-y += preempt.h 8 8 generic-y += trace_clock.h 9 9 generic-y += word-at-a-time.h 10 + generic-y += kprobes.h
+1
arch/h8300/include/asm/Kbuild
··· 74 74 generic-y += vga.h 75 75 generic-y += word-at-a-time.h 76 76 generic-y += xor.h 77 + generic-y += kprobes.h
+1
arch/hexagon/include/asm/Kbuild
··· 59 59 generic-y += vga.h 60 60 generic-y += word-at-a-time.h 61 61 generic-y += xor.h 62 + generic-y += kprobes.h
+9 -3
arch/ia64/include/asm/kprobes.h
··· 23 23 * 2005-Apr Rusty Lynch <rusty.lynch@intel.com> and Anil S Keshavamurthy 24 24 * <anil.s.keshavamurthy@intel.com> adapted from i386 25 25 */ 26 + #include <asm-generic/kprobes.h> 27 + #include <asm/break.h> 28 + 29 + #define BREAK_INST (long)(__IA64_BREAK_KPROBE << 6) 30 + 31 + #ifdef CONFIG_KPROBES 32 + 26 33 #include <linux/types.h> 27 34 #include <linux/ptrace.h> 28 35 #include <linux/percpu.h> 29 - #include <asm/break.h> 30 36 31 37 #define __ARCH_WANT_KPROBES_INSN_SLOT 32 38 #define MAX_INSN_SIZE 2 /* last half is for kprobe-booster */ 33 - #define BREAK_INST (long)(__IA64_BREAK_KPROBE << 6) 34 39 #define NOP_M_INST (long)(1<<27) 35 40 #define BRL_INST(i1, i2) ((long)((0xcL << 37) | /* brl */ \ 36 41 (0x1L << 12) | /* many */ \ ··· 129 124 extern void flush_register_stack(void); 130 125 extern void arch_remove_kprobe(struct kprobe *p); 131 126 132 - #endif /* _ASM_KPROBES_H */ 127 + #endif /* CONFIG_KPROBES */ 128 + #endif /* _ASM_KPROBES_H */
+1
arch/m32r/include/asm/Kbuild
··· 11 11 generic-y += sections.h 12 12 generic-y += trace_clock.h 13 13 generic-y += word-at-a-time.h 14 + generic-y += kprobes.h
+1
arch/m68k/include/asm/Kbuild
··· 33 33 generic-y += types.h 34 34 generic-y += word-at-a-time.h 35 35 generic-y += xor.h 36 + generic-y += kprobes.h
+1
arch/metag/include/asm/Kbuild
··· 54 54 generic-y += vga.h 55 55 generic-y += word-at-a-time.h 56 56 generic-y += xor.h 57 + generic-y += kprobes.h
+1
arch/microblaze/include/asm/Kbuild
··· 10 10 generic-y += syscalls.h 11 11 generic-y += trace_clock.h 12 12 generic-y += word-at-a-time.h 13 + generic-y += kprobes.h
+5 -1
arch/mips/include/asm/kprobes.h
··· 22 22 #ifndef _ASM_KPROBES_H 23 23 #define _ASM_KPROBES_H 24 24 25 + #include <asm-generic/kprobes.h> 26 + 27 + #ifdef CONFIG_KPROBES 25 28 #include <linux/ptrace.h> 26 29 #include <linux/types.h> 27 30 ··· 97 94 extern int kprobe_exceptions_notify(struct notifier_block *self, 98 95 unsigned long val, void *data); 99 96 100 - #endif /* _ASM_KPROBES_H */ 97 + #endif /* CONFIG_KPROBES */ 98 + #endif /* _ASM_KPROBES_H */
+6 -1
arch/mn10300/include/asm/kprobes.h
··· 21 21 #ifndef _ASM_KPROBES_H 22 22 #define _ASM_KPROBES_H 23 23 24 + #include <asm-generic/kprobes.h> 25 + 26 + #define BREAKPOINT_INSTRUCTION 0xff 27 + 28 + #ifdef CONFIG_KPROBES 24 29 #include <linux/types.h> 25 30 #include <linux/ptrace.h> 26 31 27 32 struct kprobe; 28 33 29 34 typedef unsigned char kprobe_opcode_t; 30 - #define BREAKPOINT_INSTRUCTION 0xff 31 35 #define MAX_INSN_SIZE 8 32 36 #define MAX_STACK_SIZE 128 33 37 ··· 51 47 52 48 extern void arch_remove_kprobe(struct kprobe *p); 53 49 50 + #endif /* CONFIG_KPROBES */ 54 51 #endif /* _ASM_KPROBES_H */
+1
arch/nios2/include/asm/Kbuild
··· 62 62 generic-y += vga.h 63 63 generic-y += word-at-a-time.h 64 64 generic-y += xor.h 65 + generic-y += kprobes.h
+1
arch/openrisc/include/asm/Kbuild
··· 67 67 generic-y += vga.h 68 68 generic-y += word-at-a-time.h 69 69 generic-y += xor.h 70 + generic-y += kprobes.h
+1
arch/parisc/include/asm/Kbuild
··· 28 28 generic-y += vga.h 29 29 generic-y += word-at-a-time.h 30 30 generic-y += xor.h 31 + generic-y += kprobes.h
+3
arch/powerpc/include/asm/kprobes.h
··· 1 1 #ifndef _ASM_POWERPC_KPROBES_H 2 2 #define _ASM_POWERPC_KPROBES_H 3 + 4 + #include <asm-generic/kprobes.h> 5 + 3 6 #ifdef __KERNEL__ 4 7 /* 5 8 * Kernel Probes (KProbes)
+1
arch/powerpc/lib/code-patching.c
··· 14 14 #include <asm/page.h> 15 15 #include <asm/code-patching.h> 16 16 #include <linux/uaccess.h> 17 + #include <linux/kprobes.h> 17 18 18 19 19 20 int patch_instruction(unsigned int *addr, unsigned int instr)
+6 -1
arch/s390/include/asm/kprobes.h
··· 27 27 * 2005-Dec Used as a template for s390 by Mike Grundy 28 28 * <grundym@us.ibm.com> 29 29 */ 30 + #include <asm-generic/kprobes.h> 31 + 32 + #define BREAKPOINT_INSTRUCTION 0x0002 33 + 34 + #ifdef CONFIG_KPROBES 30 35 #include <linux/types.h> 31 36 #include <linux/ptrace.h> 32 37 #include <linux/percpu.h> ··· 42 37 struct kprobe; 43 38 44 39 typedef u16 kprobe_opcode_t; 45 - #define BREAKPOINT_INSTRUCTION 0x0002 46 40 47 41 /* Maximum instruction size is 3 (16bit) halfwords: */ 48 42 #define MAX_INSN_SIZE 0x0003 ··· 95 91 96 92 #define flush_insn_slot(p) do { } while (0) 97 93 94 + #endif /* CONFIG_KPROBES */ 98 95 #endif /* _ASM_S390_KPROBES_H */
+1
arch/score/include/asm/Kbuild
··· 13 13 generic-y += xor.h 14 14 generic-y += serial.h 15 15 generic-y += word-at-a-time.h 16 + generic-y += kprobes.h
+4 -1
arch/sh/include/asm/kprobes.h
··· 1 1 #ifndef __ASM_SH_KPROBES_H 2 2 #define __ASM_SH_KPROBES_H 3 3 4 + #include <asm-generic/kprobes.h> 5 + 6 + #define BREAKPOINT_INSTRUCTION 0xc33a 7 + 4 8 #ifdef CONFIG_KPROBES 5 9 6 10 #include <linux/types.h> 7 11 #include <linux/ptrace.h> 8 12 9 13 typedef insn_size_t kprobe_opcode_t; 10 - #define BREAKPOINT_INSTRUCTION 0xc33a 11 14 12 15 #define MAX_INSN_SIZE 16 13 16 #define MAX_STACK_SIZE 64
+8 -2
arch/sparc/include/asm/kprobes.h
··· 1 1 #ifndef _SPARC64_KPROBES_H 2 2 #define _SPARC64_KPROBES_H 3 3 4 + #include <asm-generic/kprobes.h> 5 + 6 + #define BREAKPOINT_INSTRUCTION 0x91d02070 /* ta 0x70 */ 7 + #define BREAKPOINT_INSTRUCTION_2 0x91d02071 /* ta 0x71 */ 8 + 9 + #ifdef CONFIG_KPROBES 4 10 #include <linux/types.h> 5 11 #include <linux/percpu.h> 6 12 7 13 typedef u32 kprobe_opcode_t; 8 14 9 - #define BREAKPOINT_INSTRUCTION 0x91d02070 /* ta 0x70 */ 10 - #define BREAKPOINT_INSTRUCTION_2 0x91d02071 /* ta 0x71 */ 11 15 #define MAX_INSN_SIZE 2 12 16 13 17 #define kretprobe_blacklist_size 0 ··· 52 48 int kprobe_fault_handler(struct pt_regs *regs, int trapnr); 53 49 asmlinkage void __kprobes kprobe_trap(unsigned long trap_level, 54 50 struct pt_regs *regs); 51 + 52 + #endif /* CONFIG_KPROBES */ 55 53 #endif /* _SPARC64_KPROBES_H */
+5 -1
arch/tile/include/asm/kprobes.h
··· 17 17 #ifndef _ASM_TILE_KPROBES_H 18 18 #define _ASM_TILE_KPROBES_H 19 19 20 + #include <asm-generic/kprobes.h> 21 + 22 + #ifdef CONFIG_KPROBES 23 + 20 24 #include <linux/types.h> 21 25 #include <linux/ptrace.h> 22 26 #include <linux/percpu.h> 23 - 24 27 #include <arch/opcode.h> 25 28 26 29 #define __ARCH_WANT_KPROBES_INSN_SLOT ··· 79 76 extern int kprobe_exceptions_notify(struct notifier_block *self, 80 77 unsigned long val, void *data); 81 78 79 + #endif /* CONFIG_KPROBES */ 82 80 #endif /* _ASM_TILE_KPROBES_H */
+1
arch/um/include/asm/Kbuild
··· 25 25 generic-y += trace_clock.h 26 26 generic-y += word-at-a-time.h 27 27 generic-y += xor.h 28 + generic-y += kprobes.h
+1
arch/unicore32/include/asm/Kbuild
··· 63 63 generic-y += vga.h 64 64 generic-y += word-at-a-time.h 65 65 generic-y += xor.h 66 + generic-y += kprobes.h
+8 -1
arch/x86/include/asm/kprobes.h
··· 21 21 * 22 22 * See arch/x86/kernel/kprobes.c for x86 kprobes history. 23 23 */ 24 + 25 + #include <asm-generic/kprobes.h> 26 + 27 + #define BREAKPOINT_INSTRUCTION 0xcc 28 + 29 + #ifdef CONFIG_KPROBES 24 30 #include <linux/types.h> 25 31 #include <linux/ptrace.h> 26 32 #include <linux/percpu.h> ··· 38 32 struct kprobe; 39 33 40 34 typedef u8 kprobe_opcode_t; 41 - #define BREAKPOINT_INSTRUCTION 0xcc 42 35 #define RELATIVEJUMP_OPCODE 0xe9 43 36 #define RELATIVEJUMP_SIZE 5 44 37 #define RELATIVECALL_OPCODE 0xe8 ··· 121 116 unsigned long val, void *data); 122 117 extern int kprobe_int3_handler(struct pt_regs *regs); 123 118 extern int kprobe_debug_handler(struct pt_regs *regs); 119 + 120 + #endif /* CONFIG_KPROBES */ 124 121 #endif /* _ASM_X86_KPROBES_H */
+1
arch/xtensa/include/asm/Kbuild
··· 31 31 generic-y += trace_clock.h 32 32 generic-y += word-at-a-time.h 33 33 generic-y += xor.h 34 + generic-y += kprobes.h
+25
include/asm-generic/kprobes.h
··· 1 + #ifndef _ASM_GENERIC_KPROBES_H 2 + #define _ASM_GENERIC_KPROBES_H 3 + 4 + #if defined(__KERNEL__) && !defined(__ASSEMBLY__) 5 + #ifdef CONFIG_KPROBES 6 + /* 7 + * Blacklist ganerating macro. Specify functions which is not probed 8 + * by using this macro. 9 + */ 10 + # define __NOKPROBE_SYMBOL(fname) \ 11 + static unsigned long __used \ 12 + __attribute__((__section__("_kprobe_blacklist"))) \ 13 + _kbl_addr_##fname = (unsigned long)fname; 14 + # define NOKPROBE_SYMBOL(fname) __NOKPROBE_SYMBOL(fname) 15 + /* Use this to forbid a kprobes attach on very low level functions */ 16 + # define __kprobes __attribute__((__section__(".kprobes.text"))) 17 + # define nokprobe_inline __always_inline 18 + #else 19 + # define NOKPROBE_SYMBOL(fname) 20 + # define __kprobes 21 + # define nokprobe_inline inline 22 + #endif 23 + #endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */ 24 + 25 + #endif /* _ASM_GENERIC_KPROBES_H */
-8
include/linux/compiler.h
··· 570 570 (_________p1); \ 571 571 }) 572 572 573 - /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */ 574 - #ifdef CONFIG_KPROBES 575 - # define __kprobes __attribute__((__section__(".kprobes.text"))) 576 - # define nokprobe_inline __always_inline 577 - #else 578 - # define __kprobes 579 - # define nokprobe_inline inline 580 - #endif 581 573 #endif /* __LINUX_COMPILER_H */
+3 -16
include/linux/kprobes.h
··· 29 29 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi 30 30 * <prasanna@in.ibm.com> added function-return probes. 31 31 */ 32 - #include <linux/compiler.h> /* for __kprobes */ 32 + #include <linux/compiler.h> 33 33 #include <linux/linkage.h> 34 34 #include <linux/list.h> 35 35 #include <linux/notifier.h> ··· 40 40 #include <linux/rcupdate.h> 41 41 #include <linux/mutex.h> 42 42 #include <linux/ftrace.h> 43 + #include <asm/kprobes.h> 43 44 44 45 #ifdef CONFIG_KPROBES 45 - #include <asm/kprobes.h> 46 46 47 47 /* kprobe_status settings */ 48 48 #define KPROBE_HIT_ACTIVE 0x00000001 ··· 51 51 #define KPROBE_HIT_SSDONE 0x00000008 52 52 53 53 #else /* CONFIG_KPROBES */ 54 + #include <asm-generic/kprobes.h> 54 55 typedef int kprobe_opcode_t; 55 56 struct arch_specific_insn { 56 57 int dummy; ··· 508 507 { 509 508 return false; 510 509 } 511 - #endif 512 - 513 - #ifdef CONFIG_KPROBES 514 - /* 515 - * Blacklist ganerating macro. Specify functions which is not probed 516 - * by using this macro. 517 - */ 518 - #define __NOKPROBE_SYMBOL(fname) \ 519 - static unsigned long __used \ 520 - __attribute__((section("_kprobe_blacklist"))) \ 521 - _kbl_addr_##fname = (unsigned long)fname; 522 - #define NOKPROBE_SYMBOL(fname) __NOKPROBE_SYMBOL(fname) 523 - #else 524 - #define NOKPROBE_SYMBOL(fname) 525 510 #endif 526 511 527 512 #endif /* _LINUX_KPROBES_H */