Skip to content

Commit

Permalink
kprobes: move kprobe declarations to asm-generic/kprobes.h
Browse files Browse the repository at this point in the history
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.

[[email protected]: fix arm64 build]
  Link: http://lkml.kernel.org/r/CAB=NE6X1WMByuARS4mZ1g9+W=LuVBnMDnh_5zyN0CLADaVh=Jw@mail.gmail.com
[[email protected]: fixup for kprobes declarations moving]
  Link: http://lkml.kernel.org/r/[email protected]
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Luis R. Rodriguez <[email protected]>
Signed-off-by: Stephen Rothwell <[email protected]>
Acked-by: Masami Hiramatsu <[email protected]>
Cc: Arnd Bergmann <[email protected]>
Cc: Masami Hiramatsu <[email protected]>
Cc: Ananth N Mavinakayanahalli <[email protected]>
Cc: Anil S Keshavamurthy <[email protected]>
Cc: David S. Miller <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Thomas Gleixner <[email protected]>
Cc: H. Peter Anvin <[email protected]>
Cc: Andy Lutomirski <[email protected]>
Cc: Steven Rostedt <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
mcgrof authored and torvalds committed Feb 28, 2017
1 parent fd5bb66 commit 7d134b2
Show file tree
Hide file tree
Showing 40 changed files with 125 additions and 38 deletions.
1 change: 1 addition & 0 deletions MAINTAINERS
Original file line number Diff line number Diff line change
Expand Up @@ -7286,6 +7286,7 @@ M: Masami Hiramatsu <[email protected]>
S: Maintained
F: Documentation/kprobes.txt
F: include/linux/kprobes.h
F: include/asm-generic/kprobes.h
F: kernel/kprobes.c

KS0108 LCD CONTROLLER DRIVER
Expand Down
1 change: 1 addition & 0 deletions arch/alpha/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ generic-y += preempt.h
generic-y += sections.h
generic-y += trace_clock.h
generic-y += current.h
generic-y += kprobes.h
6 changes: 4 additions & 2 deletions arch/arc/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#ifndef _ARC_KPROBES_H
#define _ARC_KPROBES_H

#include <asm-generic/kprobes.h>

#ifdef CONFIG_KPROBES

typedef u16 kprobe_opcode_t;
Expand Down Expand Up @@ -55,6 +57,6 @@ void trap_is_kprobe(unsigned long address, struct pt_regs *regs);
static void trap_is_kprobe(unsigned long address, struct pt_regs *regs)
{
}
#endif
#endif /* CONFIG_KPROBES */

#endif
#endif /* _ARC_KPROBES_H */
4 changes: 4 additions & 0 deletions arch/arm/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#ifndef _ARM_KPROBES_H
#define _ARM_KPROBES_H

#include <asm-generic/kprobes.h>

#ifdef CONFIG_KPROBES
#include <linux/types.h>
#include <linux/ptrace.h>
#include <linux/notifier.h>
Expand Down Expand Up @@ -83,4 +86,5 @@ struct arch_optimized_insn {
*/
};

#endif /* CONFIG_KPROBES */
#endif /* _ARM_KPROBES_H */
1 change: 1 addition & 0 deletions arch/arm/probes/decode.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <linux/types.h>
#include <linux/stddef.h>
#include <asm/probes.h>
#include <asm/kprobes.h>

void __init arm_probes_decode_init(void);

Expand Down
4 changes: 4 additions & 0 deletions arch/arm64/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
#ifndef _ARM_KPROBES_H
#define _ARM_KPROBES_H

#include <asm-generic/kprobes.h>

#ifdef CONFIG_KPROBES
#include <linux/types.h>
#include <linux/ptrace.h>
#include <linux/percpu.h>
Expand Down Expand Up @@ -57,4 +60,5 @@ int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr);
void kretprobe_trampoline(void);
void __kprobes *trampoline_probe_handler(struct pt_regs *regs);

#endif /* CONFIG_KPROBES */
#endif /* _ARM_KPROBES_H */
1 change: 1 addition & 0 deletions arch/arm64/kernel/armv8_deprecated.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <asm/sysreg.h>
#include <asm/system_misc.h>
#include <asm/traps.h>
#include <asm/kprobes.h>
#include <linux/uaccess.h>
#include <asm/cpufeature.h>

Expand Down
1 change: 1 addition & 0 deletions arch/arm64/kernel/insn.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <asm/debug-monitors.h>
#include <asm/fixmap.h>
#include <asm/insn.h>
#include <asm/kprobes.h>

#define AARCH64_INSN_SF_BIT BIT(31)
#define AARCH64_INSN_N_BIT BIT(22)
Expand Down
2 changes: 2 additions & 0 deletions arch/arm64/kernel/probes/decode-insn.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#ifndef _ARM_KERNEL_KPROBES_ARM64_H
#define _ARM_KERNEL_KPROBES_ARM64_H

#include <asm/kprobes.h>

/*
* ARM strongly recommends a limit of 128 bytes between LoadExcl and
* StoreExcl instructions in a single thread of execution. So keep the
Expand Down
7 changes: 6 additions & 1 deletion arch/avr32/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
#ifndef __ASM_AVR32_KPROBES_H
#define __ASM_AVR32_KPROBES_H

#include <asm-generic/kprobes.h>

#define BREAKPOINT_INSTRUCTION 0xd673 /* breakpoint */

#ifdef CONFIG_KPROBES
#include <linux/types.h>

typedef u16 kprobe_opcode_t;
#define BREAKPOINT_INSTRUCTION 0xd673 /* breakpoint */
#define MAX_INSN_SIZE 2
#define MAX_STACK_SIZE 64 /* 32 would probably be OK */

Expand Down Expand Up @@ -46,4 +50,5 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,

#define flush_insn_slot(p) do { } while (0)

#endif /* CONFIG_KPROBES */
#endif /* __ASM_AVR32_KPROBES_H */
1 change: 1 addition & 0 deletions arch/blackfin/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,4 @@ generic-y += unaligned.h
generic-y += user.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
1 change: 1 addition & 0 deletions arch/c6x/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ generic-y += user.h
generic-y += vga.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
1 change: 1 addition & 0 deletions arch/cris/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ generic-y += types.h
generic-y += vga.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
1 change: 1 addition & 0 deletions arch/frv/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ generic-y += mm-arch-hooks.h
generic-y += preempt.h
generic-y += trace_clock.h
generic-y += word-at-a-time.h
generic-y += kprobes.h
1 change: 1 addition & 0 deletions arch/h8300/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,4 @@ generic-y += unaligned.h
generic-y += vga.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
1 change: 1 addition & 0 deletions arch/hexagon/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ generic-y += unaligned.h
generic-y += vga.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
12 changes: 9 additions & 3 deletions arch/ia64/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@
* 2005-Apr Rusty Lynch <[email protected]> and Anil S Keshavamurthy
* <[email protected]> adapted from i386
*/
#include <asm-generic/kprobes.h>
#include <asm/break.h>

#define BREAK_INST (long)(__IA64_BREAK_KPROBE << 6)

#ifdef CONFIG_KPROBES

#include <linux/types.h>
#include <linux/ptrace.h>
#include <linux/percpu.h>
#include <asm/break.h>

#define __ARCH_WANT_KPROBES_INSN_SLOT
#define MAX_INSN_SIZE 2 /* last half is for kprobe-booster */
#define BREAK_INST (long)(__IA64_BREAK_KPROBE << 6)
#define NOP_M_INST (long)(1<<27)
#define BRL_INST(i1, i2) ((long)((0xcL << 37) | /* brl */ \
(0x1L << 12) | /* many */ \
Expand Down Expand Up @@ -124,4 +129,5 @@ extern void invalidate_stacked_regs(void);
extern void flush_register_stack(void);
extern void arch_remove_kprobe(struct kprobe *p);

#endif /* _ASM_KPROBES_H */
#endif /* CONFIG_KPROBES */
#endif /* _ASM_KPROBES_H */
1 change: 1 addition & 0 deletions arch/m32r/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ generic-y += preempt.h
generic-y += sections.h
generic-y += trace_clock.h
generic-y += word-at-a-time.h
generic-y += kprobes.h
1 change: 1 addition & 0 deletions arch/m68k/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ generic-y += trace_clock.h
generic-y += types.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
1 change: 1 addition & 0 deletions arch/metag/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@ generic-y += user.h
generic-y += vga.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
1 change: 1 addition & 0 deletions arch/microblaze/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ generic-y += preempt.h
generic-y += syscalls.h
generic-y += trace_clock.h
generic-y += word-at-a-time.h
generic-y += kprobes.h
6 changes: 5 additions & 1 deletion arch/mips/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#ifndef _ASM_KPROBES_H
#define _ASM_KPROBES_H

#include <asm-generic/kprobes.h>

#ifdef CONFIG_KPROBES
#include <linux/ptrace.h>
#include <linux/types.h>

Expand Down Expand Up @@ -94,4 +97,5 @@ struct kprobe_ctlblk {
extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data);

#endif /* _ASM_KPROBES_H */
#endif /* CONFIG_KPROBES */
#endif /* _ASM_KPROBES_H */
7 changes: 6 additions & 1 deletion arch/mn10300/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@
#ifndef _ASM_KPROBES_H
#define _ASM_KPROBES_H

#include <asm-generic/kprobes.h>

#define BREAKPOINT_INSTRUCTION 0xff

#ifdef CONFIG_KPROBES
#include <linux/types.h>
#include <linux/ptrace.h>

struct kprobe;

typedef unsigned char kprobe_opcode_t;
#define BREAKPOINT_INSTRUCTION 0xff
#define MAX_INSN_SIZE 8
#define MAX_STACK_SIZE 128

Expand All @@ -47,4 +51,5 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,

extern void arch_remove_kprobe(struct kprobe *p);

#endif /* CONFIG_KPROBES */
#endif /* _ASM_KPROBES_H */
1 change: 1 addition & 0 deletions arch/nios2/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ generic-y += user.h
generic-y += vga.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
1 change: 1 addition & 0 deletions arch/openrisc/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,4 @@ generic-y += user.h
generic-y += vga.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
1 change: 1 addition & 0 deletions arch/parisc/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ generic-y += user.h
generic-y += vga.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
3 changes: 3 additions & 0 deletions arch/powerpc/include/asm/kprobes.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#ifndef _ASM_POWERPC_KPROBES_H
#define _ASM_POWERPC_KPROBES_H

#include <asm-generic/kprobes.h>

#ifdef __KERNEL__
/*
* Kernel Probes (KProbes)
Expand Down
1 change: 1 addition & 0 deletions arch/powerpc/lib/code-patching.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include <asm/page.h>
#include <asm/code-patching.h>
#include <linux/uaccess.h>
#include <linux/kprobes.h>


int patch_instruction(unsigned int *addr, unsigned int instr)
Expand Down
7 changes: 6 additions & 1 deletion arch/s390/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
* 2005-Dec Used as a template for s390 by Mike Grundy
* <[email protected]>
*/
#include <asm-generic/kprobes.h>

#define BREAKPOINT_INSTRUCTION 0x0002

#ifdef CONFIG_KPROBES
#include <linux/types.h>
#include <linux/ptrace.h>
#include <linux/percpu.h>
Expand All @@ -37,7 +42,6 @@ struct pt_regs;
struct kprobe;

typedef u16 kprobe_opcode_t;
#define BREAKPOINT_INSTRUCTION 0x0002

/* Maximum instruction size is 3 (16bit) halfwords: */
#define MAX_INSN_SIZE 0x0003
Expand Down Expand Up @@ -91,4 +95,5 @@ int probe_is_insn_relative_long(u16 *insn);

#define flush_insn_slot(p) do { } while (0)

#endif /* CONFIG_KPROBES */
#endif /* _ASM_S390_KPROBES_H */
1 change: 1 addition & 0 deletions arch/score/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ generic-y += trace_clock.h
generic-y += xor.h
generic-y += serial.h
generic-y += word-at-a-time.h
generic-y += kprobes.h
5 changes: 4 additions & 1 deletion arch/sh/include/asm/kprobes.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
#ifndef __ASM_SH_KPROBES_H
#define __ASM_SH_KPROBES_H

#include <asm-generic/kprobes.h>

#define BREAKPOINT_INSTRUCTION 0xc33a

#ifdef CONFIG_KPROBES

#include <linux/types.h>
#include <linux/ptrace.h>

typedef insn_size_t kprobe_opcode_t;
#define BREAKPOINT_INSTRUCTION 0xc33a

#define MAX_INSN_SIZE 16
#define MAX_STACK_SIZE 64
Expand Down
10 changes: 8 additions & 2 deletions arch/sparc/include/asm/kprobes.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#ifndef _SPARC64_KPROBES_H
#define _SPARC64_KPROBES_H

#include <asm-generic/kprobes.h>

#define BREAKPOINT_INSTRUCTION 0x91d02070 /* ta 0x70 */
#define BREAKPOINT_INSTRUCTION_2 0x91d02071 /* ta 0x71 */

#ifdef CONFIG_KPROBES
#include <linux/types.h>
#include <linux/percpu.h>

typedef u32 kprobe_opcode_t;

#define BREAKPOINT_INSTRUCTION 0x91d02070 /* ta 0x70 */
#define BREAKPOINT_INSTRUCTION_2 0x91d02071 /* ta 0x71 */
#define MAX_INSN_SIZE 2

#define kretprobe_blacklist_size 0
Expand Down Expand Up @@ -48,4 +52,6 @@ int kprobe_exceptions_notify(struct notifier_block *self,
int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
asmlinkage void __kprobes kprobe_trap(unsigned long trap_level,
struct pt_regs *regs);

#endif /* CONFIG_KPROBES */
#endif /* _SPARC64_KPROBES_H */
6 changes: 5 additions & 1 deletion arch/tile/include/asm/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
#ifndef _ASM_TILE_KPROBES_H
#define _ASM_TILE_KPROBES_H

#include <asm-generic/kprobes.h>

#ifdef CONFIG_KPROBES

#include <linux/types.h>
#include <linux/ptrace.h>
#include <linux/percpu.h>

#include <arch/opcode.h>

#define __ARCH_WANT_KPROBES_INSN_SLOT
Expand Down Expand Up @@ -76,4 +79,5 @@ void arch_remove_kprobe(struct kprobe *);
extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data);

#endif /* CONFIG_KPROBES */
#endif /* _ASM_TILE_KPROBES_H */
1 change: 1 addition & 0 deletions arch/um/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ generic-y += topology.h
generic-y += trace_clock.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
1 change: 1 addition & 0 deletions arch/unicore32/include/asm/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ generic-y += user.h
generic-y += vga.h
generic-y += word-at-a-time.h
generic-y += xor.h
generic-y += kprobes.h
Loading

0 comments on commit 7d134b2

Please sign in to comment.