This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH]Kprobes: fix kprobes reentrancy


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]