From: Francis Deslauriers Date: Tue, 14 Jan 2020 20:34:54 +0000 (-0500) Subject: Namespace kprobe functions relating to events X-Git-Tag: v2.13.0-rc1~134 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=8bf17deb525927d1191c59a1765d5b11b37c4320;p=lttng-modules.git Namespace kprobe functions relating to events The event notifier support for kprobe will soon be introduce and kprobe code will be reused. Signed-off-by: Francis Deslauriers Signed-off-by: Mathieu Desnoyers Change-Id: Ia44aea762c158e922c1fafed381fca6919bea188 --- diff --git a/include/lttng/events.h b/include/lttng/events.h index 5fb7a780..f89fe1d0 100644 --- a/include/lttng/events.h +++ b/include/lttng/events.h @@ -276,6 +276,11 @@ struct lttng_uprobe_handler { struct list_head node; }; +struct lttng_kprobe { + struct kprobe kp; + char *symbol_name; +}; + enum lttng_syscall_entryexit { LTTNG_SYSCALL_ENTRY, LTTNG_SYSCALL_EXIT, @@ -300,10 +305,7 @@ struct lttng_event { struct lttng_ctx *ctx; enum lttng_kernel_instrumentation instrumentation; union { - struct { - struct kprobe kp; - char *symbol_name; - } kprobe; + struct lttng_kprobe kprobe; struct { struct lttng_krp *lttng_krp; char *symbol_name; @@ -1007,16 +1009,16 @@ void lttng_logger_exit(void); extern int lttng_statedump_start(struct lttng_session *session); #ifdef CONFIG_KPROBES -int lttng_kprobes_register(const char *name, +int lttng_kprobes_register_event(const char *name, const char *symbol_name, uint64_t offset, uint64_t addr, struct lttng_event *event); -void lttng_kprobes_unregister(struct lttng_event *event); -void lttng_kprobes_destroy_private(struct lttng_event *event); +void lttng_kprobes_unregister_event(struct lttng_event *event); +void lttng_kprobes_destroy_event_private(struct lttng_event *event); #else static inline -int lttng_kprobes_register(const char *name, +int lttng_kprobes_register_event(const char *name, const char *symbol_name, uint64_t offset, uint64_t addr, @@ -1026,7 +1028,12 @@ int lttng_kprobes_register(const char *name, } static inline -void lttng_kprobes_unregister(struct lttng_event *event) +void lttng_kprobes_unregister_event(struct lttng_event *event) +{ +} + +static inline +void lttng_kprobes_destroy_event_private(struct lttng_event *event) { } diff --git a/src/lttng-events.c b/src/lttng-events.c index 1338f129..41bbd709 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -838,7 +838,7 @@ struct lttng_event *_lttng_event_create(struct lttng_channel *chan, * registration. */ smp_wmb(); - ret = lttng_kprobes_register(event_name, + ret = lttng_kprobes_register_event(event_name, event_param->u.kprobe.symbol_name, event_param->u.kprobe.offset, event_param->u.kprobe.addr, @@ -1163,7 +1163,7 @@ int _lttng_event_unregister(struct lttng_event *event) event); break; case LTTNG_KERNEL_KPROBE: - lttng_kprobes_unregister(event); + lttng_kprobes_unregister_event(event); ret = 0; break; case LTTNG_KERNEL_KRETPROBE: @@ -1262,7 +1262,7 @@ void _lttng_event_destroy(struct lttng_event *event) break; case LTTNG_KERNEL_KPROBE: module_put(event->desc->owner); - lttng_kprobes_destroy_private(event); + lttng_kprobes_destroy_event_private(event); break; case LTTNG_KERNEL_KRETPROBE: module_put(event->desc->owner); diff --git a/src/probes/lttng-kprobes.c b/src/probes/lttng-kprobes.c index e127d72f..3f9b0235 100644 --- a/src/probes/lttng-kprobes.c +++ b/src/probes/lttng-kprobes.c @@ -18,7 +18,7 @@ #include static -int lttng_kprobes_handler_pre(struct kprobe *p, struct pt_regs *regs) +int lttng_kprobes_event_handler_pre(struct kprobe *p, struct pt_regs *regs) { struct lttng_event *event = container_of(p, struct lttng_event, u.kprobe.kp); @@ -94,11 +94,12 @@ error_str: return ret; } -int lttng_kprobes_register(const char *name, - const char *symbol_name, +static +int _lttng_kprobes_register(const char *symbol_name, uint64_t offset, uint64_t addr, - struct lttng_event *event) + struct lttng_kprobe *lttng_kp, + kprobe_pre_handler_t pre_handler) { int ret; @@ -106,26 +107,24 @@ int lttng_kprobes_register(const char *name, if (symbol_name[0] == '\0') symbol_name = NULL; - ret = lttng_create_kprobe_event(name, event); - if (ret) - goto error; - memset(&event->u.kprobe.kp, 0, sizeof(event->u.kprobe.kp)); - event->u.kprobe.kp.pre_handler = lttng_kprobes_handler_pre; + memset(<tng_kp->kp, 0, sizeof(lttng_kp->kp)); + lttng_kp->kp.pre_handler = pre_handler; + if (symbol_name) { - event->u.kprobe.symbol_name = + lttng_kp->symbol_name = kzalloc(LTTNG_KERNEL_SYM_NAME_LEN * sizeof(char), GFP_KERNEL); - if (!event->u.kprobe.symbol_name) { + if (!lttng_kp->symbol_name) { ret = -ENOMEM; goto name_error; } - memcpy(event->u.kprobe.symbol_name, symbol_name, + memcpy(lttng_kp->symbol_name, symbol_name, LTTNG_KERNEL_SYM_NAME_LEN * sizeof(char)); - event->u.kprobe.kp.symbol_name = - event->u.kprobe.symbol_name; + lttng_kp->kp.symbol_name = lttng_kp->symbol_name; } - event->u.kprobe.kp.offset = offset; - event->u.kprobe.kp.addr = (void *) (unsigned long) addr; + + lttng_kp->kp.offset = offset; + lttng_kp->kp.addr = (void *) (unsigned long) addr; /* * Ensure the memory we just allocated don't trigger page faults. @@ -134,36 +133,60 @@ int lttng_kprobes_register(const char *name, */ wrapper_vmalloc_sync_mappings(); - ret = register_kprobe(&event->u.kprobe.kp); + ret = register_kprobe(<tng_kp->kp); if (ret) goto register_error; + return 0; register_error: - kfree(event->u.kprobe.symbol_name); + kfree(lttng_kp->symbol_name); name_error: + return ret; +} + +int lttng_kprobes_register_event(const char *name, + const char *symbol_name, + uint64_t offset, + uint64_t addr, + struct lttng_event *event) +{ + int ret; + + ret = lttng_create_kprobe_event(name, event); + if (ret) + goto error; + + ret = _lttng_kprobes_register(symbol_name, offset, addr, + &event->u.kprobe, lttng_kprobes_event_handler_pre); + if (ret) + goto register_error; + + return 0; + +register_error: kfree(event->desc->fields); kfree(event->desc->name); kfree(event->desc); error: return ret; } -EXPORT_SYMBOL_GPL(lttng_kprobes_register); +EXPORT_SYMBOL_GPL(lttng_kprobes_register_event); -void lttng_kprobes_unregister(struct lttng_event *event) +void lttng_kprobes_unregister_event(struct lttng_event *event) { unregister_kprobe(&event->u.kprobe.kp); } -EXPORT_SYMBOL_GPL(lttng_kprobes_unregister); +EXPORT_SYMBOL_GPL(lttng_kprobes_unregister_event); -void lttng_kprobes_destroy_private(struct lttng_event *event) +void lttng_kprobes_destroy_event_private(struct lttng_event *event) { kfree(event->u.kprobe.symbol_name); kfree(event->desc->fields); kfree(event->desc->name); kfree(event->desc); } -EXPORT_SYMBOL_GPL(lttng_kprobes_destroy_private); +EXPORT_SYMBOL_GPL(lttng_kprobes_destroy_event_private); MODULE_LICENSE("GPL and additional rights"); MODULE_AUTHOR("Mathieu Desnoyers ");