2008-02-03 03:00:57

by Harvey Harrison

[permalink] [raw]
Subject: [PATCH 2/2] kprobe: remove preempt_enable/disable from kprobe_handle_fault()

This patch removes the preempt_disable/enable pair around kprobe_running
which was originally added to avoid the assertion from smp_processor_id
which would be hit an asertion if preemption was enabled.

Kprobes can not be running if we are preemptible, so test explicitly
for preemption and bail out before hitting kprobe_running().

Signed-off-by: Harvey Harrison <[email protected]>
---
include/linux/kprobes.h | 19 ++++++++-----------
1 files changed, 8 insertions(+), 11 deletions(-)

diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index e5ecb1e..e099426 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -213,19 +213,16 @@ static inline struct kprobe *kprobe_running(void)
return (__get_cpu_var(current_kprobe));
}

+/*
+ * If it is a kprobe pagefault we can not be preemptible so return before
+ * calling kprobe_running() as it will assert on smp_processor_id if
+ * preemption is enabled.
+ */
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;
+ if (!user_mode(regs) && !preemptible() && kprobe_running())
+ return kprobe_fault_handler(regs, trapnr);
+ return 0;
}

static inline void reset_current_kprobe(void)
--
1.5.4.rc4.1142.gf5a97


2008-02-07 19:13:59

by Masami Hiramatsu

[permalink] [raw]
Subject: Re: [PATCH 2/2] kprobe: remove preempt_enable/disable from kprobe_handle_fault()

Harvey Harrison wrote:
> This patch removes the preempt_disable/enable pair around kprobe_running
> which was originally added to avoid the assertion from smp_processor_id
> which would be hit an asertion if preemption was enabled.
>
> Kprobes can not be running if we are preemptible, so test explicitly
> for preemption and bail out before hitting kprobe_running().
>
> Signed-off-by: Harvey Harrison <[email protected]>

Acked-by: Masami Hiramatsu <[email protected]>


--
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America) Inc.
Software Solutions Division

e-mail: [email protected]