Re: [PATCH V2 03/13] kprobes: Add symbols for kprobe insn pages

From: Jiri Olsa
Date: Wed Feb 26 2020 - 10:22:08 EST


On Wed, Feb 12, 2020 at 02:49:39PM +0200, Adrian Hunter wrote:
> Symbols are needed for tools to describe instruction addresses. Pages
> allocated for kprobe's purposes need symbols to be created for them.
> Add such symbols to be visible via /proc/kallsyms.
>
> Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>

SNIP

> @@ -272,6 +273,8 @@ static inline bool is_kprobe_##__name##_slot(unsigned long addr) \
> { \
> return __is_insn_slot_addr(&kprobe_##__name##_slots, addr); \
> }
> +#define KPROBE_INSN_PAGE_SYM "kprobe_insn_page"
> +#define KPROBE_OPTINSN_PAGE_SYM "kprobe_optinsn_page"
> #else /* __ARCH_WANT_KPROBES_INSN_SLOT */
> #define DEFINE_INSN_CACHE_OPS(__name) \
> static inline bool is_kprobe_##__name##_slot(unsigned long addr) \
> @@ -373,6 +376,13 @@ void dump_kprobe(struct kprobe *kp);
> void *alloc_insn_page(void);
> void free_insn_page(void *page);
>
> +int kprobe_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
> + char *sym);
> +int kprobe_cache_get_kallsym(struct kprobe_insn_cache *c, unsigned int *symnum,
> + unsigned long *value, char *type, char *sym);
> +
> +int arch_kprobe_get_kallsym(unsigned int *symnum, unsigned long *value,
> + char *type, char *sym);
> #else /* !CONFIG_KPROBES: */
>
> static inline int kprobes_built_in(void)
> @@ -435,6 +445,24 @@ static inline bool within_kprobe_blacklist(unsigned long addr)
> {
> return true;
> }
> +static inline int kprobe_get_kallsym(unsigned int symnum, unsigned long *value,
> + char *type, char *sym)
> +{
> + return 0;
> +}
> +static inline int kprobe_cache_get_kallsym(struct kprobe_insn_cache *c,
> + unsigned int *symnum,
> + unsigned long *value, char *type,
> + char *sym)
> +{
> + return 0;
> +}
> +static inline int arch_kprobe_get_kallsym(unsigned int *symnum,
> + unsigned long *value, char *type,
> + char *sym)
> +{
> + return 0;
> +}

there's another arch_kprobe_get_kallsym marked as __weak,
is above function superfluous?

jirka

SNIP

> +int __weak arch_kprobe_get_kallsym(unsigned int *symnum, unsigned long *value,
> + char *type, char *sym)
> +{
> + return -ERANGE;
> +}
> +
> +int kprobe_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
> + char *sym)
> +{
> +#ifdef __ARCH_WANT_KPROBES_INSN_SLOT
> + if (!kprobe_cache_get_kallsym(&kprobe_insn_slots, &symnum, value, type, sym))
> + return 0;
> +#ifdef CONFIG_OPTPROBES
> + if (!kprobe_cache_get_kallsym(&kprobe_optinsn_slots, &symnum, value, type, sym))
> + return 0;
> +#endif
> +#endif
> + if (!arch_kprobe_get_kallsym(&symnum, value, type, sym))
> + return 0;
> + return -ERANGE;
> +}
> +
> int __init __weak arch_populate_kprobe_blacklist(void)
> {
> return 0;
> --
> 2.17.1
>