From: wangnan0@huawei.com (Wang Nan)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 07/11] kprobes: introduces macros for allocing early kprobe resources.
Date: Wed, 7 Jan 2015 18:45:40 +0800 [thread overview]
Message-ID: <54AD0E54.9060900@huawei.com> (raw)
In-Reply-To: <1420616151-43023-1-git-send-email-wangnan0@huawei.com>
On 2015/1/7 15:35, Wang Nan wrote:
> Introduces macros to genearte common early kprobe related resource
> allocator.
>
> All early kprobe related resources are statically allocated during
> linking for each early kprobe slot. For each type of resource, a bitmap
> is used to track allocation. __DEFINE_EKPROBE_ALLOC_OPS defines alloc
> and free handler for them. The range of the resource and the bitmap
> should be provided for allocaing and freeing. DEFINE_EKPROBE_ALLOC_OPS
> defines bitmap and the array used by it.
>
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> ---
> include/linux/kprobes.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 69 insertions(+)
>
> diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
> index b0265f9..9a18188 100644
> --- a/include/linux/kprobes.h
> +++ b/include/linux/kprobes.h
> @@ -270,6 +270,75 @@ extern void show_registers(struct pt_regs *regs);
> extern void kprobes_inc_nmissed_count(struct kprobe *p);
> extern bool arch_within_kprobe_blacklist(unsigned long addr);
>
> +#ifdef CONFIG_EARLY_KPROBES
> +
> +#define NR_EARLY_KPROBES_SLOTS CONFIG_NR_EARLY_KPROBES_SLOTS
> +#define ALIGN_UP(v, a) (((v) + ((a) - 1)) & ~((a) - 1))
> +#define EARLY_KPROBES_BITMAP_SZ ALIGN_UP(NR_EARLY_KPROBES_SLOTS, BITS_PER_LONG)
> +
> +#define __ek_in_range(v, s, e) (((v) >= (s)) && ((v) < (e)))
> +#define __ek_buf_sz(s, e) ((void *)(e) - (void *)(s))
> +#define __ek_elem_sz_b(s, e) (__ek_buf_sz(s, e) / NR_EARLY_KPROBES_SLOTS)
> +#define __ek_elem_sz(s, e) (__ek_elem_sz_b(s, e) / sizeof(s[0]))
> +#define __ek_elem_idx(v, s, e) (__ek_buf_sz(s, v) / __ek_elem_sz_b(s, e))
> +#define __ek_get_elem(i, s, e) (&((s)[__ek_elem_sz(s, e) * (i)]))
> +#define __DEFINE_EKPROBE_ALLOC_OPS(__t, __name) \
> +static inline __t *__ek_alloc_##__name(__t *__s, __t *__e, unsigned long *__b)\
> +{ \
> + int __i = find_next_zero_bit(__b, NR_EARLY_KPROBES_SLOTS, 0); \
> + if (__i >= NR_EARLY_KPROBES_SLOTS) \
> + return NULL; \
> + set_bit(__i, __b); \
> + return __ek_get_elem(__i, __s, __e); \
> +} \
> +static inline int __ek_free_##__name(__t *__v, __t *__s, __t *__e, unsigned long *__b) \
> +{ \
> + if (!__ek_in_range(__v, __s, __e)) \
> + return 0; \
> + clear_bit(__ek_elem_idx(__v, __s, __e), __b); \
> + return 1; \
> +}
> +
> +#define DEFINE_EKPROBE_ALLOC_OPS(__t, __name, __static) \
> +__static __t __ek_##__name##_slots[NR_EARLY_KPROBES_SLOTS]; \
> +__static unsigned long __ek_##__name##_bitmap[EARLY_KPROBES_BITMAP_SZ]; \
> +__DEFINE_EKPROBE_ALLOC_OPS(__t, __name) \
> +static inline __t *ek_alloc_##__name(void) \
> +{ \
> + return __ek_alloc_##__name(&((__ek_##__name##_slots)[0]), \
> + &((__ek_##__name##_slots)[NR_EARLY_KPROBES_SLOTS]),\
> + (__ek_##__name##_bitmap)); \
> +} \
> +static inline int ek_free_##__name(__t *__s) \
> +{ \
> + return __ek_free_##__name(__s, &((__ek_##__name##_slots)[0]), \
> + &((__ek_##__name##_slots)[NR_EARLY_KPROBES_SLOTS]),\
> + (__ek_##__name##_bitmap)); \
> +}
> +
> +
> +#else
> +#define __DEFINE_EKPROBE_ALLOC_OPS(__t, __name) \
> +static inline __t *__ek_alloc_##__name(__t *__s, __t *__e, unsigned long *__b)\
> +{ \
> + return NULL; \
> +} \
> +static inline int __ek_free_##__name(__t *__v, __t *__s, __t *__e, unsigned long *__b)\
> +{ \
> + return 0; \
> +}
> +
> +#define DEFINE_EKPROBE_ALLOC_OPS(__t, __name, __static) \
> +static inline __t *ek_alloc_##__name(void) \
> +{ \
> + return NULL; \
> +} \
> +static inline void ek_free_##__name(__t *__s) \
> +{ \
> +}
> +
Sorry, here is a small problem. Should be:
static inline int ek_free_##__name(__t *__s) \
{ \
return 0; \
}
> +#endif
> +
> struct kprobe_insn_cache {
> struct mutex mutex;
> void *(*alloc)(void); /* allocate insn page */
>
WARNING: multiple messages have this Message-ID (diff)
From: Wang Nan <wangnan0@huawei.com>
To: Hillf Danton <hillf.zj@alibaba-inc.com>
Cc: <linux@arm.linux.org.uk>, <mingo@redhat.com>, <x86@kernel.org>,
<masami.hiramatsu.pt@hitachi.com>,
<anil.s.keshavamurthy@intel.com>, <davem@davemloft.net>,
<ananth@in.ibm.com>, <dave.long@linaro.org>, <tixy@linaro.org>,
<lizefan@huawei.com>, <linux-arm-kernel@lists.infradead.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH 07/11] kprobes: introduces macros for allocing early kprobe resources.
Date: Wed, 7 Jan 2015 18:45:40 +0800 [thread overview]
Message-ID: <54AD0E54.9060900@huawei.com> (raw)
In-Reply-To: <1420616151-43023-1-git-send-email-wangnan0@huawei.com>
On 2015/1/7 15:35, Wang Nan wrote:
> Introduces macros to genearte common early kprobe related resource
> allocator.
>
> All early kprobe related resources are statically allocated during
> linking for each early kprobe slot. For each type of resource, a bitmap
> is used to track allocation. __DEFINE_EKPROBE_ALLOC_OPS defines alloc
> and free handler for them. The range of the resource and the bitmap
> should be provided for allocaing and freeing. DEFINE_EKPROBE_ALLOC_OPS
> defines bitmap and the array used by it.
>
> Signed-off-by: Wang Nan <wangnan0@huawei.com>
> ---
> include/linux/kprobes.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 69 insertions(+)
>
> diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
> index b0265f9..9a18188 100644
> --- a/include/linux/kprobes.h
> +++ b/include/linux/kprobes.h
> @@ -270,6 +270,75 @@ extern void show_registers(struct pt_regs *regs);
> extern void kprobes_inc_nmissed_count(struct kprobe *p);
> extern bool arch_within_kprobe_blacklist(unsigned long addr);
>
> +#ifdef CONFIG_EARLY_KPROBES
> +
> +#define NR_EARLY_KPROBES_SLOTS CONFIG_NR_EARLY_KPROBES_SLOTS
> +#define ALIGN_UP(v, a) (((v) + ((a) - 1)) & ~((a) - 1))
> +#define EARLY_KPROBES_BITMAP_SZ ALIGN_UP(NR_EARLY_KPROBES_SLOTS, BITS_PER_LONG)
> +
> +#define __ek_in_range(v, s, e) (((v) >= (s)) && ((v) < (e)))
> +#define __ek_buf_sz(s, e) ((void *)(e) - (void *)(s))
> +#define __ek_elem_sz_b(s, e) (__ek_buf_sz(s, e) / NR_EARLY_KPROBES_SLOTS)
> +#define __ek_elem_sz(s, e) (__ek_elem_sz_b(s, e) / sizeof(s[0]))
> +#define __ek_elem_idx(v, s, e) (__ek_buf_sz(s, v) / __ek_elem_sz_b(s, e))
> +#define __ek_get_elem(i, s, e) (&((s)[__ek_elem_sz(s, e) * (i)]))
> +#define __DEFINE_EKPROBE_ALLOC_OPS(__t, __name) \
> +static inline __t *__ek_alloc_##__name(__t *__s, __t *__e, unsigned long *__b)\
> +{ \
> + int __i = find_next_zero_bit(__b, NR_EARLY_KPROBES_SLOTS, 0); \
> + if (__i >= NR_EARLY_KPROBES_SLOTS) \
> + return NULL; \
> + set_bit(__i, __b); \
> + return __ek_get_elem(__i, __s, __e); \
> +} \
> +static inline int __ek_free_##__name(__t *__v, __t *__s, __t *__e, unsigned long *__b) \
> +{ \
> + if (!__ek_in_range(__v, __s, __e)) \
> + return 0; \
> + clear_bit(__ek_elem_idx(__v, __s, __e), __b); \
> + return 1; \
> +}
> +
> +#define DEFINE_EKPROBE_ALLOC_OPS(__t, __name, __static) \
> +__static __t __ek_##__name##_slots[NR_EARLY_KPROBES_SLOTS]; \
> +__static unsigned long __ek_##__name##_bitmap[EARLY_KPROBES_BITMAP_SZ]; \
> +__DEFINE_EKPROBE_ALLOC_OPS(__t, __name) \
> +static inline __t *ek_alloc_##__name(void) \
> +{ \
> + return __ek_alloc_##__name(&((__ek_##__name##_slots)[0]), \
> + &((__ek_##__name##_slots)[NR_EARLY_KPROBES_SLOTS]),\
> + (__ek_##__name##_bitmap)); \
> +} \
> +static inline int ek_free_##__name(__t *__s) \
> +{ \
> + return __ek_free_##__name(__s, &((__ek_##__name##_slots)[0]), \
> + &((__ek_##__name##_slots)[NR_EARLY_KPROBES_SLOTS]),\
> + (__ek_##__name##_bitmap)); \
> +}
> +
> +
> +#else
> +#define __DEFINE_EKPROBE_ALLOC_OPS(__t, __name) \
> +static inline __t *__ek_alloc_##__name(__t *__s, __t *__e, unsigned long *__b)\
> +{ \
> + return NULL; \
> +} \
> +static inline int __ek_free_##__name(__t *__v, __t *__s, __t *__e, unsigned long *__b)\
> +{ \
> + return 0; \
> +}
> +
> +#define DEFINE_EKPROBE_ALLOC_OPS(__t, __name, __static) \
> +static inline __t *ek_alloc_##__name(void) \
> +{ \
> + return NULL; \
> +} \
> +static inline void ek_free_##__name(__t *__s) \
> +{ \
> +}
> +
Sorry, here is a small problem. Should be:
static inline int ek_free_##__name(__t *__s) \
{ \
return 0; \
}
> +#endif
> +
> struct kprobe_insn_cache {
> struct mutex mutex;
> void *(*alloc)(void); /* allocate insn page */
>
next prev parent reply other threads:[~2015-01-07 10:45 UTC|newest]
Thread overview: 42+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-01-07 7:34 [RFC PATCH 00/11] Early kprobe: enable kprobes at very early Wang Nan
2015-01-07 7:34 ` Wang Nan
2015-01-07 7:35 ` [RFC PATCH 01/11] ARM: kprobes: directly modify code if kprobe is not initialized Wang Nan
2015-01-07 7:35 ` Wang Nan
2015-01-07 17:15 ` Christopher Covington
2015-01-07 17:15 ` Christopher Covington
2015-01-13 15:34 ` Masami Hiramatsu
2015-01-13 15:34 ` Masami Hiramatsu
2015-01-07 7:35 ` [RFC PATCH 02/11] ARM: kprobes: introduce early kprobes related code area Wang Nan
2015-01-07 7:35 ` Wang Nan
2015-01-07 7:35 ` [RFC PATCH 03/11] x86: kprobes: directly modify code if kprobe is not initialized Wang Nan
2015-01-07 7:35 ` Wang Nan
2015-01-07 7:35 ` [RFC PATCH 04/11] x86: kprobes: introduce early kprobes related code area Wang Nan
2015-01-07 7:35 ` Wang Nan
2015-01-07 7:35 ` [RFC PATCH 05/11] kprobes: Add an KPROBE_FLAG_EARLY for early kprobe Wang Nan
2015-01-07 7:35 ` Wang Nan
2015-01-07 7:35 ` [RFC PATCH 06/11] kprobes: makes kprobes_initialized globally visable Wang Nan
2015-01-07 7:35 ` Wang Nan
2015-01-07 7:35 ` [RFC PATCH 07/11] kprobes: introduces macros for allocing early kprobe resources Wang Nan
2015-01-07 7:35 ` Wang Nan
2015-01-07 10:45 ` Wang Nan [this message]
2015-01-07 10:45 ` Wang Nan
2015-01-07 7:35 ` [RFC PATCH 08/11] kprobes: allows __alloc_insn_slot() from early kprobes slots Wang Nan
2015-01-07 7:35 ` Wang Nan
2015-01-07 7:36 ` [RFC PATCH 09/11] kprobes: core logic of eraly kprobes Wang Nan
2015-01-07 7:36 ` Wang Nan
2015-01-07 7:36 ` [RFC PATCH 10/11] kprobes: enable 'ekprobe=' cmdline option for early kprobes Wang Nan
2015-01-07 7:36 ` Wang Nan
2015-01-07 7:36 ` [RFC PATCH 11/11] kprobes: add CONFIG_EARLY_KPROBES option Wang Nan
2015-01-07 7:36 ` Wang Nan
2015-01-07 7:42 ` Wang Nan
2015-01-07 7:42 ` Wang Nan
2015-01-13 15:58 ` [RFC PATCH 00/11] Early kprobe: enable kprobes at very early Masami Hiramatsu
2015-01-13 15:58 ` Masami Hiramatsu
2015-02-06 10:30 ` [RFC PATCH] x86: kprobes: enable optmize relative call insn Wang Nan
2015-02-06 10:30 ` Wang Nan
2015-02-07 10:08 ` Masami Hiramatsu
2015-02-07 10:08 ` Masami Hiramatsu
2015-02-07 10:42 ` Wang Nan
2015-02-07 10:42 ` Wang Nan
2015-01-16 17:48 ` [RFC PATCH 00/11] Early kprobe: enable kprobes at very early Steven Rostedt
2015-01-16 17:48 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=54AD0E54.9060900@huawei.com \
--to=wangnan0@huawei.com \
--cc=linux-arm-kernel@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.