[PATCH]Kprobes: fix kprobes reentrancy

Chuck Ebbert 76306.1226@compuserve.com
Wed Dec 13 10:43:00 GMT 2006


In-Reply-To: <20061212222517.GA17627@bambi.jf.intel.com>

On Tue, 12 Dec 2006 14:25:17 -0800, Keshavamurthy, Anil S wrote:

> --- 2.6.19-git19.orig/include/linux/kprobes.h
> +++ 2.6.19-git19/include/linux/kprobes.h
> @@ -188,6 +188,28 @@ static inline struct kprobe_ctlblk *get_
>       return (&__get_cpu_var(kprobe_ctlblk));
>  }
>  
> +/* Per-CPU area for storing the previous kprobe information
> + * in case of reentrancy.
> + */
> +#define PREV_KPROBE_SIZE 4
> +DECLARE_PER_CPU(atomic_t, prev_kprobe_index);
> +DECLARE_PER_CPU(struct prev_kprobe [PREV_KPROBE_SIZE], prev_kprobe_blk);
> +
> +static inline struct prev_kprobe *get_prev_kprobe(void)
> +{
> +     unsigned int i;
> +     i = atomic_add_return(1, &(__get_cpu_var(prev_kprobe_index)));
> +     BUG_ON(i > PREV_KPROBE_SIZE);

Can't you make it fail gracefully instead of going BUG() if this happens
(i.e. skip the kprobe or something?)

> +     return (&__get_cpu_var(prev_kprobe_blk)[i-1]);
> +}
> +
> +static inline struct prev_kprobe *restore_prev_kprobe(void)
> +{
> +     unsigned int i;
> +     i = atomic_sub_return(1, &(__get_cpu_var(prev_kprobe_index)));

And this needs a BUG_ON() or Bad Things could happen on underflow.

> +     return (&__get_cpu_var(prev_kprobe_blk)[i]);
> +}
> +

-- 
MBTI: IXTP



More information about the Systemtap mailing list