Skip to content

Commit

Permalink
[IA64] fix Kprobes reentrancy
Browse files Browse the repository at this point in the history
In case of reentrance i.e when a probe handler calls a functions which
inturn has a probe, we save a previous kprobe information and just single
step the reentrant probe without calling the actual probe handler.  During
this reentracy period, if an interrupt occurs and if probe happens to
trigger in the inturrupt path, then we were corrupting the previous kprobe(
as we were overriding the previous kprobe info) info their by crashing the
system.  This patch fixes this issues by having a an array of previous
kprobe info struct(with the array size of 2).

This similar technique is not needed on i386 and x86_64 because by default
interrupts are turn off in the break/int3 exception handler.

Signed-off-by: Anil S Keshavamurthy <anil.s.keshavamurthy@intel.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Tony Luck <tony.luck@intel.com>
  • Loading branch information
Anil S Keshavamurthy authored and Tony Luck committed May 11, 2007
1 parent 25d6157 commit cdc7dbd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
12 changes: 8 additions & 4 deletions arch/ia64/kernel/kprobes.c
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,18 @@ static int __kprobes valid_kprobe_addr(int template, int slot,

static void __kprobes save_previous_kprobe(struct kprobe_ctlblk *kcb)
{
kcb->prev_kprobe.kp = kprobe_running();
kcb->prev_kprobe.status = kcb->kprobe_status;
unsigned int i;
i = atomic_add_return(1, &kcb->prev_kprobe_index);
kcb->prev_kprobe[i-1].kp = kprobe_running();
kcb->prev_kprobe[i-1].status = kcb->kprobe_status;
}

static void __kprobes restore_previous_kprobe(struct kprobe_ctlblk *kcb)
{
__get_cpu_var(current_kprobe) = kcb->prev_kprobe.kp;
kcb->kprobe_status = kcb->prev_kprobe.status;
unsigned int i;
i = atomic_sub_return(1, &kcb->prev_kprobe_index);
__get_cpu_var(current_kprobe) = kcb->prev_kprobe[i].kp;
kcb->kprobe_status = kcb->prev_kprobe[i].status;
}

static void __kprobes set_current_kprobe(struct kprobe *p,
Expand Down
4 changes: 3 additions & 1 deletion include/asm-ia64/kprobes.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@ struct prev_kprobe {

#define MAX_PARAM_RSE_SIZE (0x60+0x60/0x3f)
/* per-cpu kprobe control block */
#define ARCH_PREV_KPROBE_SZ 2
struct kprobe_ctlblk {
unsigned long kprobe_status;
struct pt_regs jprobe_saved_regs;
unsigned long jprobes_saved_stacked_regs[MAX_PARAM_RSE_SIZE];
unsigned long *bsp;
unsigned long cfm;
struct prev_kprobe prev_kprobe;
atomic_t prev_kprobe_index;
struct prev_kprobe prev_kprobe[ARCH_PREV_KPROBE_SZ];
};

#define JPROBE_ENTRY(pentry) (kprobe_opcode_t *)pentry
Expand Down

0 comments on commit cdc7dbd

Please sign in to comment.