LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [PATCH 1/2] kprobes: Introduce kprobe_handle_fault()
@ 2008-02-03 3:00 Harvey Harrison
2008-02-03 11:52 ` Heiko Carstens
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Harvey Harrison @ 2008-02-03 3:00 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-arch, LKML
Use a central kprobe_handle_fault() inline in kprobes.h to remove
all of the arch-dependant, practically identical implementations in
avr32, ia64, powerpc, s390, sparc64, and x86.
avr32 was the only arch without the preempt_disable/enable pair
in its notify_page_fault implementation.
This uncovered a possible bug in the s390 version as that purely
copied the x86 version unconditionally passing 14 as the trapnr
rather than the error_code parameter. s390 is changed to pass
error_code in this patch.
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
Andrew, 1/2 is low risk, 2/2 has been tested on x86-32 and 64,
but the !preemptible invariant seems correct.
arch/arm/mm/fault.c | 25 +------------------------
arch/avr32/mm/fault.c | 21 +--------------------
arch/ia64/mm/fault.c | 24 +-----------------------
arch/powerpc/mm/fault.c | 25 +------------------------
arch/s390/mm/fault.c | 25 +------------------------
arch/sparc64/mm/fault.c | 23 +----------------------
arch/x86/mm/fault.c | 26 ++------------------------
include/linux/kprobes.h | 20 ++++++++++++++++++++
8 files changed, 28 insertions(+), 161 deletions(-)
diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
index 28ad7ab..5def64f 100644
--- a/arch/arm/mm/fault.c
+++ b/arch/arm/mm/fault.c
@@ -21,29 +21,6 @@
#include "fault.h"
-
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr)
-{
- int ret = 0;
-
- if (!user_mode(regs)) {
- /* kprobe_running() needs smp_processor_id() */
- preempt_disable();
- if (kprobe_running() && kprobe_fault_handler(regs, fsr))
- ret = 1;
- preempt_enable();
- }
-
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs, unsigned int fsr)
-{
- return 0;
-}
-#endif
-
/*
* This is useful to dump out the page tables associated with
* 'addr' in mm 'mm'.
@@ -246,7 +223,7 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
struct mm_struct *mm;
int fault, sig, code;
- if (notify_page_fault(regs, fsr))
+ if (handle_kprobe_fault(regs, fsr))
return 0;
tsk = current;
diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
index 6560cb1..e41953e 100644
--- a/arch/avr32/mm/fault.c
+++ b/arch/avr32/mm/fault.c
@@ -20,25 +20,6 @@
#include <asm/tlb.h>
#include <asm/uaccess.h>
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs, int trap)
-{
- int ret = 0;
-
- if (!user_mode(regs)) {
- if (kprobe_running() && kprobe_fault_handler(regs, trap))
- ret = 1;
- }
-
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs, int trap)
-{
- return 0;
-}
-#endif
-
int exception_trace = 1;
/*
@@ -66,7 +47,7 @@ asmlinkage void do_page_fault(unsigned long ecr, struct pt_regs *regs)
int code;
int fault;
- if (notify_page_fault(regs, ecr))
+ if (kprobe_handle_fault(regs, ecr))
return;
address = sysreg_read(TLBEAR);
diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
index 7571076..bfc83e8 100644
--- a/arch/ia64/mm/fault.c
+++ b/arch/ia64/mm/fault.c
@@ -18,28 +18,6 @@
extern void die (char *, struct pt_regs *, long);
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs, int trap)
-{
- int ret = 0;
-
- if (!user_mode(regs)) {
- /* kprobe_running() needs smp_processor_id() */
- preempt_disable();
- if (kprobe_running() && kprobes_fault_handler(regs, trap))
- ret = 1;
- preempt_enable();
- }
-
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs, int trap)
-{
- return 0;
-}
-#endif
-
/*
* Return TRUE if ADDRESS points at a page in the kernel's mapped segment
* (inside region 5, on ia64) and that page is present.
@@ -106,7 +84,7 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
/*
* This is to handle the kprobes on user space access instructions
*/
- if (notify_page_fault(regs, TRAP_BRKPT))
+ if (kprobe_handle_fault(regs, TRAP_BRKPT))
return;
down_read(&mm->mmap_sem);
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 7b25107..3246953 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -39,29 +39,6 @@
#include <asm/tlbflush.h>
#include <asm/siginfo.h>
-
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs)
-{
- int ret = 0;
-
- /* kprobe_running() needs smp_processor_id() */
- if (!user_mode(regs)) {
- preempt_disable();
- if (kprobe_running() && kprobe_fault_handler(regs, 11))
- ret = 1;
- preempt_enable();
- }
-
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs)
-{
- return 0;
-}
-#endif
-
/*
* Check whether the instruction at regs->nip is a store using
* an update addressing form which will update r1.
@@ -164,7 +141,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
is_write = error_code & ESR_DST;
#endif /* CONFIG_4xx || CONFIG_BOOKE */
- if (notify_page_fault(regs))
+ if (kprobe_handle_fault(regs, 11))
return 0;
if (unlikely(debugger_fault_handler(regs)))
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
index 2456b52..5a47295 100644
--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -51,29 +51,6 @@ extern int sysctl_userprocess_debug;
extern void die(const char *,struct pt_regs *,long);
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs, long err)
-{
- int ret = 0;
-
- /* kprobe_running() needs smp_processor_id() */
- if (!user_mode(regs)) {
- preempt_disable();
- if (kprobe_running() && kprobe_fault_handler(regs, 14))
- ret = 1;
- preempt_enable();
- }
-
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs, long err)
-{
- return 0;
-}
-#endif
-
-
/*
* Unlock any spinlocks which will prevent us from getting the
* message out.
@@ -309,7 +286,7 @@ do_exception(struct pt_regs *regs, unsigned long error_code, int write)
int si_code;
int fault;
- if (notify_page_fault(regs, error_code))
+ if (kprobe_handle_fault(regs, error_code))
return;
tsk = current;
diff --git a/arch/sparc64/mm/fault.c b/arch/sparc64/mm/fault.c
index e2027f2..8467dd6 100644
--- a/arch/sparc64/mm/fault.c
+++ b/arch/sparc64/mm/fault.c
@@ -31,27 +31,6 @@
#include <asm/sections.h>
#include <asm/mmu_context.h>
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs)
-{
- int ret = 0;
-
- /* kprobe_running() needs smp_processor_id() */
- if (!user_mode(regs)) {
- preempt_disable();
- if (kprobe_running() && kprobe_fault_handler(regs, 0))
- ret = 1;
- preempt_enable();
- }
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs)
-{
- return 0;
-}
-#endif
-
/*
* To debug kernel to catch accesses to certain virtual/physical addresses.
* Mode = 0 selects physical watchpoints, mode = 1 selects virtual watchpoints.
@@ -280,7 +259,7 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
fault_code = get_thread_fault_code();
- if (notify_page_fault(regs))
+ if (kprobe_handle_fault(regs, 0))
return;
si_code = SEGV_MAPERR;
diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
index 3fff490..f0adbb0 100644
--- a/arch/x86/mm/fault.c
+++ b/arch/x86/mm/fault.c
@@ -49,29 +49,6 @@
#define PF_RSVD (1<<3)
#define PF_INSTR (1<<4)
-static inline int notify_page_fault(struct pt_regs *regs)
-{
-#ifdef CONFIG_KPROBES
- int ret = 0;
-
- /* kprobe_running() needs smp_processor_id() */
-#ifdef CONFIG_X86_32
- if (!user_mode_vm(regs)) {
-#else
- if (!user_mode(regs)) {
-#endif
- preempt_disable();
- if (kprobe_running() && kprobe_fault_handler(regs, 14))
- ret = 1;
- preempt_enable();
- }
-
- return ret;
-#else
- return 0;
-#endif
-}
-
/*
* X86_32
* Sometimes AMD Athlon/Opteron CPUs report invalid exceptions on prefetch.
@@ -589,7 +566,8 @@ void __kprobes do_page_fault(struct pt_regs *regs, unsigned long error_code)
si_code = SEGV_MAPERR;
- if (notify_page_fault(regs))
+ /* Must not try to handle kprobes in v8086 mode */
+ if (!v8086_mode(regs) && kprobe_handle_fault(regs, 14))
return;
/*
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 6168c0a..e5ecb1e 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -36,6 +36,7 @@
#include <linux/spinlock.h>
#include <linux/rcupdate.h>
#include <linux/mutex.h>
+#include <linux/hardirq.h>
#ifdef CONFIG_KPROBES
#include <asm/kprobes.h>
@@ -212,6 +213,21 @@ static inline struct kprobe *kprobe_running(void)
return (__get_cpu_var(current_kprobe));
}
+static inline int kprobe_handle_fault(struct pt_regs *regs, int trapnr)
+{
+ int ret = 0;
+
+ /* kprobe_running() needs smp_processor_id() */
+ if (!user_mode(regs)) {
+ preempt_disable();
+ if (kprobe_running() && kprobe_fault_handler(regs, trapnr))
+ ret = 1;
+ preempt_enable();
+ }
+
+ return ret;
+}
+
static inline void reset_current_kprobe(void)
{
__get_cpu_var(current_kprobe) = NULL;
@@ -247,6 +263,10 @@ static inline struct kprobe *kprobe_running(void)
{
return NULL;
}
+static inline int kprobe_handle_fault(struct pt_regs *regs, int trapnr)
+{
+ return 0;
+}
static inline int register_kprobe(struct kprobe *p)
{
return -ENOSYS;
--
1.5.4.rc4.1142.gf5a97
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] kprobes: Introduce kprobe_handle_fault()
2008-02-03 3:00 [PATCH 1/2] kprobes: Introduce kprobe_handle_fault() Harvey Harrison
@ 2008-02-03 11:52 ` Heiko Carstens
2008-02-07 19:12 ` Masami Hiramatsu
2008-02-29 11:16 ` Andrew Morton
2 siblings, 0 replies; 8+ messages in thread
From: Heiko Carstens @ 2008-02-03 11:52 UTC (permalink / raw)
To: Harvey Harrison; +Cc: Andrew Morton, linux-arch, LKML
On Sat, Feb 02, 2008 at 07:00:23PM -0800, Harvey Harrison wrote:
> Use a central kprobe_handle_fault() inline in kprobes.h to remove
> all of the arch-dependant, practically identical implementations in
> avr32, ia64, powerpc, s390, sparc64, and x86.
>
> avr32 was the only arch without the preempt_disable/enable pair
> in its notify_page_fault implementation.
>
> This uncovered a possible bug in the s390 version as that purely
> copied the x86 version unconditionally passing 14 as the trapnr
> rather than the error_code parameter. s390 is changed to pass
> error_code in this patch.
>
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
for the s390 bits:
Acked-by: Heiko Carstens <heiko.carstens@de.ibm.com>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] kprobes: Introduce kprobe_handle_fault()
2008-02-03 3:00 [PATCH 1/2] kprobes: Introduce kprobe_handle_fault() Harvey Harrison
2008-02-03 11:52 ` Heiko Carstens
@ 2008-02-07 19:12 ` Masami Hiramatsu
2008-02-29 11:16 ` Andrew Morton
2 siblings, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2008-02-07 19:12 UTC (permalink / raw)
To: Harvey Harrison; +Cc: Andrew Morton, linux-arch, LKML
Harvey Harrison wrote:
> Use a central kprobe_handle_fault() inline in kprobes.h to remove
> all of the arch-dependant, practically identical implementations in
> avr32, ia64, powerpc, s390, sparc64, and x86.
>
> avr32 was the only arch without the preempt_disable/enable pair
> in its notify_page_fault implementation.
>
> This uncovered a possible bug in the s390 version as that purely
> copied the x86 version unconditionally passing 14 as the trapnr
> rather than the error_code parameter. s390 is changed to pass
> error_code in this patch.
>
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
Tested on i386/x86-64.
Acked-by: Masami Hiramatsu <mhiramat@redhat.com>
--
Masami Hiramatsu
Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division
e-mail: mhiramat@redhat.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] kprobes: Introduce kprobe_handle_fault()
2008-02-03 3:00 [PATCH 1/2] kprobes: Introduce kprobe_handle_fault() Harvey Harrison
2008-02-03 11:52 ` Heiko Carstens
2008-02-07 19:12 ` Masami Hiramatsu
@ 2008-02-29 11:16 ` Andrew Morton
2008-02-29 16:30 ` Harvey Harrison
2 siblings, 1 reply; 8+ messages in thread
From: Andrew Morton @ 2008-02-29 11:16 UTC (permalink / raw)
To: Harvey Harrison; +Cc: linux-arch, LKML
On Sat, 02 Feb 2008 19:00:23 -0800 Harvey Harrison <harvey.harrison@gmail.com> wrote:
> Use a central kprobe_handle_fault() inline in kprobes.h to remove
> all of the arch-dependant, practically identical implementations in
> avr32, ia64, powerpc, s390, sparc64, and x86.
>
> avr32 was the only arch without the preempt_disable/enable pair
> in its notify_page_fault implementation.
>
> This uncovered a possible bug in the s390 version as that purely
> copied the x86 version unconditionally passing 14 as the trapnr
> rather than the error_code parameter. s390 is changed to pass
> error_code in this patch.
>
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
> ---
> Andrew, 1/2 is low risk, 2/2 has been tested on x86-32 and 64,
> but the !preemptible invariant seems correct.
>
> arch/arm/mm/fault.c | 25 +------------------------
> arch/avr32/mm/fault.c | 21 +--------------------
> arch/ia64/mm/fault.c | 24 +-----------------------
> arch/powerpc/mm/fault.c | 25 +------------------------
> arch/s390/mm/fault.c | 25 +------------------------
> arch/sparc64/mm/fault.c | 23 +----------------------
> arch/x86/mm/fault.c | 26 ++------------------------
> include/linux/kprobes.h | 20 ++++++++++++++++++++
> 8 files changed, 28 insertions(+), 161 deletions(-)
Breaks the ia64 build:
include/linux/kprobes.h: In function `kprobe_handle_fault':
include/linux/kprobes.h:234: error: implicit declaration of function `kprobe_fault_handler'
and ia64 doesn't implement kprobe_fault_handler() so there's no easy fix
here.
There's too much inlining in linux/kprobes.h, btw.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] kprobes: Introduce kprobe_handle_fault()
2008-02-29 11:16 ` Andrew Morton
@ 2008-02-29 16:30 ` Harvey Harrison
0 siblings, 0 replies; 8+ messages in thread
From: Harvey Harrison @ 2008-02-29 16:30 UTC (permalink / raw)
To: Andrew Morton; +Cc: linux-arch, LKML
On Fri, Feb 29, 2008 at 3:16 AM, Andrew Morton
<akpm@linux-foundation.org> wrote:
> On Sat, 02 Feb 2008 19:00:23 -0800 Harvey Harrison <harvey.harrison@gmail.com> wrote:
>
> > Use a central kprobe_handle_fault() inline in kprobes.h to remove
> > all of the arch-dependant, practically identical implementations in
> > avr32, ia64, powerpc, s390, sparc64, and x86.
> >
> > avr32 was the only arch without the preempt_disable/enable pair
> > in its notify_page_fault implementation.
> >
> > This uncovered a possible bug in the s390 version as that purely
> > copied the x86 version unconditionally passing 14 as the trapnr
> > rather than the error_code parameter. s390 is changed to pass
> > error_code in this patch.
> >
> > Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
> > ---
> > Andrew, 1/2 is low risk, 2/2 has been tested on x86-32 and 64,
> > but the !preemptible invariant seems correct.
> >
> > arch/arm/mm/fault.c | 25 +------------------------
> > arch/avr32/mm/fault.c | 21 +--------------------
> > arch/ia64/mm/fault.c | 24 +-----------------------
> > arch/powerpc/mm/fault.c | 25 +------------------------
> > arch/s390/mm/fault.c | 25 +------------------------
> > arch/sparc64/mm/fault.c | 23 +----------------------
> > arch/x86/mm/fault.c | 26 ++------------------------
> > include/linux/kprobes.h | 20 ++++++++++++++++++++
> > 8 files changed, 28 insertions(+), 161 deletions(-)
>
> Breaks the ia64 build:
>
> include/linux/kprobes.h: In function `kprobe_handle_fault':
> include/linux/kprobes.h:234: error: implicit declaration of function `kprobe_fault_handler'
>
> and ia64 doesn't implement kprobe_fault_handler() so there's no easy fix
> here.
Yes there is, ia64 apparently called theirs kprobes_handle_fault, sorry I didn't
notice the extra 's'. Want a new patch, or will you change the three
occurances?
Harvey
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] kprobes: Introduce kprobe_handle_fault()
2008-01-10 0:44 ` [PATCH 1/2] " Harvey Harrison
2008-01-10 3:15 ` Masami Hiramatsu
@ 2008-01-10 12:50 ` Ingo Molnar
1 sibling, 0 replies; 8+ messages in thread
From: Ingo Molnar @ 2008-01-10 12:50 UTC (permalink / raw)
To: Harvey Harrison
Cc: Heiko Carstens, Christoph Hellwig, Andrew Morton, LKML,
Masami Hiramatsu, Ananth N Mavinakayanahalli, David Miller,
hskinnemoen, schwidefsky, tony.luck, Paul Mackerras,
David Wilder, jkenisto
* Harvey Harrison <harvey.harrison@gmail.com> wrote:
> Use a central kprobe_handle_fault() inline in kprobes.h to remove all
> of the arch-dependant, practically identical implementations in avr32,
> ia64, powerpc, s390, sparc64, and x86.
i guess this should be done via -mm, because it changes all
architectures.
Acked-by: Ingo Molnar <mingo@elte.hu>
Ingo
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [PATCH 1/2] kprobes: Introduce kprobe_handle_fault()
2008-01-10 0:44 ` [PATCH 1/2] " Harvey Harrison
@ 2008-01-10 3:15 ` Masami Hiramatsu
2008-01-10 12:50 ` Ingo Molnar
1 sibling, 0 replies; 8+ messages in thread
From: Masami Hiramatsu @ 2008-01-10 3:15 UTC (permalink / raw)
To: Harvey Harrison
Cc: Heiko Carstens, Christoph Hellwig, Andrew Morton, LKML,
Ananth N Mavinakayanahalli, David Miller, hskinnemoen,
schwidefsky, tony.luck, Ingo Molnar, Paul Mackerras,
David Wilder, jkenisto
Harvey Harrison wrote:
> Use a central kprobe_handle_fault() inline in kprobes.h to remove
> all of the arch-dependant, practically identical implementations in
> avr32, ia64, powerpc, s390, sparc64, and x86.
>
> avr32 was the only arch without the preempt_disable/enable pair
> in its notify_page_fault implementation.
>
> This uncovered a possible bug in the s390 version as that purely
> copied the x86 version unconditionally passing 14 as the trapnr
> rather than the error_code parameter. s390 is changed to pass
> error_code in this patch.
>
> Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
I tested it on x86-64.
Acked-by: Masami Hiramatsu <mhiramat@redhat.com>
Thank you!
--
Masami Hiramatsu
Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division
e-mail: mhiramat@redhat.com, masami.hiramatsu.pt@hitachi.com
^ permalink raw reply [flat|nested] 8+ messages in thread
* [PATCH 1/2] kprobes: Introduce kprobe_handle_fault()
2008-01-09 23:16 ` Heiko Carstens
@ 2008-01-10 0:44 ` Harvey Harrison
2008-01-10 3:15 ` Masami Hiramatsu
2008-01-10 12:50 ` Ingo Molnar
0 siblings, 2 replies; 8+ messages in thread
From: Harvey Harrison @ 2008-01-10 0:44 UTC (permalink / raw)
To: Heiko Carstens
Cc: Christoph Hellwig, Andrew Morton, LKML, Masami Hiramatsu,
Ananth N Mavinakayanahalli, David Miller, hskinnemoen,
schwidefsky, tony.luck, Ingo Molnar, Paul Mackerras,
David Wilder, jkenisto
Use a central kprobe_handle_fault() inline in kprobes.h to remove
all of the arch-dependant, practically identical implementations in
avr32, ia64, powerpc, s390, sparc64, and x86.
avr32 was the only arch without the preempt_disable/enable pair
in its notify_page_fault implementation.
This uncovered a possible bug in the s390 version as that purely
copied the x86 version unconditionally passing 14 as the trapnr
rather than the error_code parameter. s390 is changed to pass
error_code in this patch.
Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com>
---
arch/avr32/mm/fault.c | 21 +--------------------
arch/ia64/mm/fault.c | 24 +-----------------------
arch/powerpc/mm/fault.c | 25 +------------------------
arch/s390/mm/fault.c | 25 +------------------------
arch/sparc64/mm/fault.c | 23 +----------------------
arch/x86/mm/fault_64.c | 26 ++------------------------
include/linux/kprobes.h | 20 ++++++++++++++++++++
7 files changed, 27 insertions(+), 137 deletions(-)
diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
index 6560cb1..e41953e 100644
--- a/arch/avr32/mm/fault.c
+++ b/arch/avr32/mm/fault.c
@@ -20,25 +20,6 @@
#include <asm/tlb.h>
#include <asm/uaccess.h>
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs, int trap)
-{
- int ret = 0;
-
- if (!user_mode(regs)) {
- if (kprobe_running() && kprobe_fault_handler(regs, trap))
- ret = 1;
- }
-
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs, int trap)
-{
- return 0;
-}
-#endif
-
int exception_trace = 1;
/*
@@ -66,7 +47,7 @@ asmlinkage void do_page_fault(unsigned long ecr, struct pt_regs *regs)
int code;
int fault;
- if (notify_page_fault(regs, ecr))
+ if (kprobe_handle_fault(regs, ecr))
return;
address = sysreg_read(TLBEAR);
diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
index 7571076..bfc83e8 100644
--- a/arch/ia64/mm/fault.c
+++ b/arch/ia64/mm/fault.c
@@ -18,28 +18,6 @@
extern void die (char *, struct pt_regs *, long);
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs, int trap)
-{
- int ret = 0;
-
- if (!user_mode(regs)) {
- /* kprobe_running() needs smp_processor_id() */
- preempt_disable();
- if (kprobe_running() && kprobes_fault_handler(regs, trap))
- ret = 1;
- preempt_enable();
- }
-
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs, int trap)
-{
- return 0;
-}
-#endif
-
/*
* Return TRUE if ADDRESS points at a page in the kernel's mapped segment
* (inside region 5, on ia64) and that page is present.
@@ -106,7 +84,7 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
/*
* This is to handle the kprobes on user space access instructions
*/
- if (notify_page_fault(regs, TRAP_BRKPT))
+ if (kprobe_handle_fault(regs, TRAP_BRKPT))
return;
down_read(&mm->mmap_sem);
diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
index 8135da0..ff64bd3 100644
--- a/arch/powerpc/mm/fault.c
+++ b/arch/powerpc/mm/fault.c
@@ -39,29 +39,6 @@
#include <asm/tlbflush.h>
#include <asm/siginfo.h>
-
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs)
-{
- int ret = 0;
-
- /* kprobe_running() needs smp_processor_id() */
- if (!user_mode(regs)) {
- preempt_disable();
- if (kprobe_running() && kprobe_fault_handler(regs, 11))
- ret = 1;
- preempt_enable();
- }
-
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs)
-{
- return 0;
-}
-#endif
-
/*
* Check whether the instruction at regs->nip is a store using
* an update addressing form which will update r1.
@@ -164,7 +141,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
is_write = error_code & ESR_DST;
#endif /* CONFIG_4xx || CONFIG_BOOKE */
- if (notify_page_fault(regs))
+ if (kprobe_handle_fault(regs, 11))
return 0;
if (trap == 0x300) {
diff --git a/arch/s390/mm/fault.c b/arch/s390/mm/fault.c
index 2456b52..5a47295 100644
--- a/arch/s390/mm/fault.c
+++ b/arch/s390/mm/fault.c
@@ -51,29 +51,6 @@ extern int sysctl_userprocess_debug;
extern void die(const char *,struct pt_regs *,long);
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs, long err)
-{
- int ret = 0;
-
- /* kprobe_running() needs smp_processor_id() */
- if (!user_mode(regs)) {
- preempt_disable();
- if (kprobe_running() && kprobe_fault_handler(regs, 14))
- ret = 1;
- preempt_enable();
- }
-
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs, long err)
-{
- return 0;
-}
-#endif
-
-
/*
* Unlock any spinlocks which will prevent us from getting the
* message out.
@@ -309,7 +286,7 @@ do_exception(struct pt_regs *regs, unsigned long error_code, int write)
int si_code;
int fault;
- if (notify_page_fault(regs, error_code))
+ if (kprobe_handle_fault(regs, error_code))
return;
tsk = current;
diff --git a/arch/sparc64/mm/fault.c b/arch/sparc64/mm/fault.c
index e2027f2..8467dd6 100644
--- a/arch/sparc64/mm/fault.c
+++ b/arch/sparc64/mm/fault.c
@@ -31,27 +31,6 @@
#include <asm/sections.h>
#include <asm/mmu_context.h>
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs)
-{
- int ret = 0;
-
- /* kprobe_running() needs smp_processor_id() */
- if (!user_mode(regs)) {
- preempt_disable();
- if (kprobe_running() && kprobe_fault_handler(regs, 0))
- ret = 1;
- preempt_enable();
- }
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs)
-{
- return 0;
-}
-#endif
-
/*
* To debug kernel to catch accesses to certain virtual/physical addresses.
* Mode = 0 selects physical watchpoints, mode = 1 selects virtual watchpoints.
@@ -280,7 +259,7 @@ asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
fault_code = get_thread_fault_code();
- if (notify_page_fault(regs))
+ if (kprobe_handle_fault(regs, 0))
return;
si_code = SEGV_MAPERR;
diff --git a/arch/x86/mm/fault_64.c b/arch/x86/mm/fault_64.c
index 0e26230..c29e462 100644
--- a/arch/x86/mm/fault_64.c
+++ b/arch/x86/mm/fault_64.c
@@ -41,28 +41,6 @@
#define PF_RSVD (1<<3)
#define PF_INSTR (1<<4)
-#ifdef CONFIG_KPROBES
-static inline int notify_page_fault(struct pt_regs *regs)
-{
- int ret = 0;
-
- /* kprobe_running() needs smp_processor_id() */
- if (!user_mode(regs)) {
- preempt_disable();
- if (kprobe_running() && kprobe_fault_handler(regs, 14))
- ret = 1;
- preempt_enable();
- }
-
- return ret;
-}
-#else
-static inline int notify_page_fault(struct pt_regs *regs)
-{
- return 0;
-}
-#endif
-
/* Sometimes the CPU reports invalid exceptions on prefetch.
Check that here and ignore.
Opcode checker based on code by Richard Brunner */
@@ -343,7 +321,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
if (vmalloc_fault(address) >= 0)
return;
}
- if (notify_page_fault(regs))
+ if (kprobe_handle_fault(regs, 14))
return;
/*
* Don't take the mm semaphore here. If we fixup a prefetch
@@ -352,7 +330,7 @@ asmlinkage void __kprobes do_page_fault(struct pt_regs *regs,
goto bad_area_nosemaphore;
}
- if (notify_page_fault(regs))
+ if (kprobe_handle_fault(regs, 14))
return;
if (likely(regs->eflags & X86_EFLAGS_IF))
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 8189158..c01e320 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -36,6 +36,7 @@
#include <linux/spinlock.h>
#include <linux/rcupdate.h>
#include <linux/mutex.h>
+#include <linux/hardirq.h>
#ifdef CONFIG_KPROBES
#include <asm/kprobes.h>
@@ -203,6 +204,21 @@ static inline struct kprobe *kprobe_running(void)
return (__get_cpu_var(current_kprobe));
}
+static inline int kprobe_handle_fault(struct pt_regs *regs, int trapnr)
+{
+ int ret = 0;
+
+ /* kprobe_running() needs smp_processor_id() */
+ if (!user_mode(regs)) {
+ preempt_disable();
+ if (kprobe_running() && kprobe_fault_handler(regs, trapnr))
+ ret = 1;
+ preempt_enable();
+ }
+
+ return ret;
+}
+
static inline void reset_current_kprobe(void)
{
__get_cpu_var(current_kprobe) = NULL;
@@ -237,6 +253,10 @@ static inline struct kprobe *kprobe_running(void)
{
return NULL;
}
+static inline int kprobe_handle_fault(struct pt_regs *regs, int trapnr)
+{
+ return 0;
+}
static inline int register_kprobe(struct kprobe *p)
{
return -ENOSYS;
--
1.5.4.rc2.1164.g6451
^ permalink raw reply related [flat|nested] 8+ messages in thread
end of thread, other threads:[~2008-02-29 16:30 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-03 3:00 [PATCH 1/2] kprobes: Introduce kprobe_handle_fault() Harvey Harrison
2008-02-03 11:52 ` Heiko Carstens
2008-02-07 19:12 ` Masami Hiramatsu
2008-02-29 11:16 ` Andrew Morton
2008-02-29 16:30 ` Harvey Harrison
-- strict thread matches above, loose matches on Subject: below --
2008-01-07 20:24 [PATCHv2] kprobes: Introduce is_kprobe_fault() Harvey Harrison
2008-01-08 22:45 ` Paul Mackerras
2008-01-08 23:02 ` Harvey Harrison
2008-01-09 4:19 ` [PATCHv3] kprobes: Introduce kprobe_handle_fault() Harvey Harrison
2008-01-09 6:14 ` Heiko Carstens
2008-01-09 6:22 ` Harvey Harrison
2008-01-09 22:01 ` [PATCHv4] " Harvey Harrison
2008-01-09 23:16 ` Heiko Carstens
2008-01-10 0:44 ` [PATCH 1/2] " Harvey Harrison
2008-01-10 3:15 ` Masami Hiramatsu
2008-01-10 12:50 ` Ingo Molnar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).