Commit 8533bbe9 authored by Masami Hiramatsu's avatar Masami Hiramatsu Committed by Ingo Molnar

x86: prepare kprobes code for x86 unification

This patch cleanup kprobes code on x86 for unification.
This patch is based on Arjan's previous work.

- Remove spurious whitespace changes
- Add harmless includes
- Make the 32/64 files more identical
 - Generalize structure fields' and local variable name.
 - Wrap accessing to stack address by macros.
 - Modify bitmap making macro.
 - Merge fixup code into is_riprel() and change its name to fix_riprel().
 - Set MAX_INSN_SIZE to 16 on both arch.
 - Use u32 for bitmaps on both architectures.
 - Clarify some comments.
Signed-off-by: default avatarMasami Hiramatsu <mhiramat@redhat.com>
Signed-off-by: default avatarArjan van de Ven <arjan@infradead.org>
Signed-off-by: default avatarJim Keniston <jkenisto@us.ibm.com>
Signed-off-by: default avatarIngo Molnar <mingo@elte.hu>
Signed-off-by: default avatarThomas Gleixner <tglx@linutronix.de>
parent da07ab03
This diff is collapsed.
This diff is collapsed.
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/kdebug.h> #include <linux/kdebug.h>
#include <linux/kprobes.h>
#include <asm/system.h> #include <asm/system.h>
#include <asm/desc.h> #include <asm/desc.h>
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
#include <linux/kprobes.h> #include <linux/kprobes.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <linux/kdebug.h> #include <linux/kdebug.h>
#include <linux/kprobes.h>
#include <asm/system.h> #include <asm/system.h>
#include <asm/pgalloc.h> #include <asm/pgalloc.h>
......
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#define _ASM_KPROBES_H #define _ASM_KPROBES_H
/* /*
* Kernel Probes (KProbes) * Kernel Probes (KProbes)
* include/asm-i386/kprobes.h
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -23,14 +22,17 @@ ...@@ -23,14 +22,17 @@
* 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel * 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
* Probes initial implementation ( includes suggestions from * Probes initial implementation ( includes suggestions from
* Rusty Russell). * Rusty Russell).
* 2004-Oct Prasanna S Panchamukhi <prasanna@in.ibm.com> and Jim Keniston
* kenistoj@us.ibm.com adopted from i386.
*/ */
#include <linux/types.h> #include <linux/types.h>
#include <linux/ptrace.h> #include <linux/ptrace.h>
#include <linux/percpu.h>
#define __ARCH_WANT_KPROBES_INSN_SLOT #define __ARCH_WANT_KPROBES_INSN_SLOT
struct kprobe;
struct pt_regs; struct pt_regs;
struct kprobe;
typedef u8 kprobe_opcode_t; typedef u8 kprobe_opcode_t;
#define BREAKPOINT_INSTRUCTION 0xcc #define BREAKPOINT_INSTRUCTION 0xcc
...@@ -38,9 +40,11 @@ typedef u8 kprobe_opcode_t; ...@@ -38,9 +40,11 @@ typedef u8 kprobe_opcode_t;
#define MAX_INSN_SIZE 16 #define MAX_INSN_SIZE 16
#define MAX_STACK_SIZE 64 #define MAX_STACK_SIZE 64
#define MIN_STACK_SIZE(ADDR) (((MAX_STACK_SIZE) < \ #define MIN_STACK_SIZE(ADDR) (((MAX_STACK_SIZE) < \
(((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR))) \ (((unsigned long)current_thread_info()) + THREAD_SIZE \
- (unsigned long)(ADDR))) \
? (MAX_STACK_SIZE) \ ? (MAX_STACK_SIZE) \
: (((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR))) : (((unsigned long)current_thread_info()) + THREAD_SIZE \
- (unsigned long)(ADDR)))
#define ARCH_SUPPORTS_KRETPROBES #define ARCH_SUPPORTS_KRETPROBES
#define flush_insn_slot(p) do { } while (0) #define flush_insn_slot(p) do { } while (0)
...@@ -55,8 +59,12 @@ struct arch_specific_insn { ...@@ -55,8 +59,12 @@ struct arch_specific_insn {
/* copy of the original instruction */ /* copy of the original instruction */
kprobe_opcode_t *insn; kprobe_opcode_t *insn;
/* /*
* If this flag is not 0, this kprobe can be boost when its * boostable = -1: This instruction type is not boostable.
* post_handler and break_handler is not set. * boostable = 0: This instruction type is boostable.
* boostable = 1: This instruction has been boosted: we have
* added a relative jump after the instruction copy in insn,
* so no single-step and fixup are needed (unless there's
* a post_handler or break_handler).
*/ */
int boostable; int boostable;
}; };
...@@ -64,16 +72,16 @@ struct arch_specific_insn { ...@@ -64,16 +72,16 @@ struct arch_specific_insn {
struct prev_kprobe { struct prev_kprobe {
struct kprobe *kp; struct kprobe *kp;
unsigned long status; unsigned long status;
unsigned long old_eflags; unsigned long old_flags;
unsigned long saved_eflags; unsigned long saved_flags;
}; };
/* per-cpu kprobe control block */ /* per-cpu kprobe control block */
struct kprobe_ctlblk { struct kprobe_ctlblk {
unsigned long kprobe_status; unsigned long kprobe_status;
unsigned long kprobe_old_eflags; unsigned long kprobe_old_flags;
unsigned long kprobe_saved_eflags; unsigned long kprobe_saved_flags;
unsigned long *jprobe_saved_esp; unsigned long *jprobe_saved_sp;
struct pt_regs jprobe_saved_regs; struct pt_regs jprobe_saved_regs;
kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE]; kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE];
struct prev_kprobe prev_kprobe; struct prev_kprobe prev_kprobe;
...@@ -88,7 +96,7 @@ static inline void restore_interrupts(struct pt_regs *regs) ...@@ -88,7 +96,7 @@ static inline void restore_interrupts(struct pt_regs *regs)
local_irq_enable(); local_irq_enable();
} }
extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
extern int kprobe_exceptions_notify(struct notifier_block *self, extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data); unsigned long val, void *data);
extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
#endif /* _ASM_KPROBES_H */ #endif /* _ASM_KPROBES_H */
...@@ -2,7 +2,6 @@ ...@@ -2,7 +2,6 @@
#define _ASM_KPROBES_H #define _ASM_KPROBES_H
/* /*
* Kernel Probes (KProbes) * Kernel Probes (KProbes)
* include/asm-x86_64/kprobes.h
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
...@@ -20,6 +19,9 @@ ...@@ -20,6 +19,9 @@
* *
* Copyright (C) IBM Corporation, 2002, 2004 * Copyright (C) IBM Corporation, 2002, 2004
* *
* 2002-Oct Created by Vamsi Krishna S <vamsi_krishna@in.ibm.com> Kernel
* Probes initial implementation ( includes suggestions from
* Rusty Russell).
* 2004-Oct Prasanna S Panchamukhi <prasanna@in.ibm.com> and Jim Keniston * 2004-Oct Prasanna S Panchamukhi <prasanna@in.ibm.com> and Jim Keniston
* kenistoj@us.ibm.com adopted from i386. * kenistoj@us.ibm.com adopted from i386.
*/ */
...@@ -35,19 +37,22 @@ struct kprobe; ...@@ -35,19 +37,22 @@ struct kprobe;
typedef u8 kprobe_opcode_t; typedef u8 kprobe_opcode_t;
#define BREAKPOINT_INSTRUCTION 0xcc #define BREAKPOINT_INSTRUCTION 0xcc
#define RELATIVEJUMP_INSTRUCTION 0xe9 #define RELATIVEJUMP_INSTRUCTION 0xe9
#define MAX_INSN_SIZE 15 #define MAX_INSN_SIZE 16
#define MAX_STACK_SIZE 64 #define MAX_STACK_SIZE 64
#define MIN_STACK_SIZE(ADDR) (((MAX_STACK_SIZE) < \ #define MIN_STACK_SIZE(ADDR) (((MAX_STACK_SIZE) < \
(((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR))) \ (((unsigned long)current_thread_info()) + THREAD_SIZE \
- (unsigned long)(ADDR))) \
? (MAX_STACK_SIZE) \ ? (MAX_STACK_SIZE) \
: (((unsigned long)current_thread_info()) + THREAD_SIZE - (ADDR))) : (((unsigned long)current_thread_info()) + THREAD_SIZE \
- (unsigned long)(ADDR)))
#define ARCH_SUPPORTS_KRETPROBES #define ARCH_SUPPORTS_KRETPROBES
#define flush_insn_slot(p) do { } while (0)
extern const int kretprobe_blacklist_size; extern const int kretprobe_blacklist_size;
void arch_remove_kprobe(struct kprobe *p);
void kretprobe_trampoline(void); void kretprobe_trampoline(void);
extern void arch_remove_kprobe(struct kprobe *p);
#define flush_insn_slot(p) do { } while (0)
/* Architecture specific copy of original instruction*/ /* Architecture specific copy of original instruction*/
struct arch_specific_insn { struct arch_specific_insn {
...@@ -67,16 +72,16 @@ struct arch_specific_insn { ...@@ -67,16 +72,16 @@ struct arch_specific_insn {
struct prev_kprobe { struct prev_kprobe {
struct kprobe *kp; struct kprobe *kp;
unsigned long status; unsigned long status;
unsigned long old_rflags; unsigned long old_flags;
unsigned long saved_rflags; unsigned long saved_flags;
}; };
/* per-cpu kprobe control block */ /* per-cpu kprobe control block */
struct kprobe_ctlblk { struct kprobe_ctlblk {
unsigned long kprobe_status; unsigned long kprobe_status;
unsigned long kprobe_old_rflags; unsigned long kprobe_old_flags;
unsigned long kprobe_saved_rflags; unsigned long kprobe_saved_flags;
unsigned long *jprobe_saved_rsp; unsigned long *jprobe_saved_sp;
struct pt_regs jprobe_saved_regs; struct pt_regs jprobe_saved_regs;
kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE]; kprobe_opcode_t jprobes_stack[MAX_STACK_SIZE];
struct prev_kprobe prev_kprobe; struct prev_kprobe prev_kprobe;
...@@ -91,10 +96,7 @@ static inline void restore_interrupts(struct pt_regs *regs) ...@@ -91,10 +96,7 @@ static inline void restore_interrupts(struct pt_regs *regs)
local_irq_enable(); local_irq_enable();
} }
extern int post_kprobe_handler(struct pt_regs *regs);
extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr); extern int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
extern int kprobe_handler(struct pt_regs *regs);
extern int kprobe_exceptions_notify(struct notifier_block *self, extern int kprobe_exceptions_notify(struct notifier_block *self,
unsigned long val, void *data); unsigned long val, void *data);
#endif /* _ASM_KPROBES_H */ #endif /* _ASM_KPROBES_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment