Namespace kprobe functions relating to events
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Tue, 14 Jan 2020 20:34:54 +0000 (15:34 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 18 Nov 2020 18:14:00 +0000 (13:14 -0500)
The event notifier support for kprobe will soon be introduce and kprobe
code will be reused.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: Ia44aea762c158e922c1fafed381fca6919bea188

include/lttng/events.h
src/lttng-events.c
src/probes/lttng-kprobes.c

index 5fb7a7804a1807ba8d5f22e960c2b31ccae2d5e0..f89fe1d01fcb54c0177ae12dae01a21678d3af9c 100644 (file)
@@ -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)
 {
 }
 
index 1338f1295e268ab6a2a150ec7346c5a59d1cf9ec..41bbd7098ddae75f57c7df7a9ee61bddbc0f1258 100644 (file)
@@ -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);
index e127d72fa4fd654e7f1b34c0abcca16c398eb533..3f9b02356740055f146fcadf6b77004c62e5a096 100644 (file)
@@ -18,7 +18,7 @@
 #include <blacklist/kprobes.h>
 
 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(&lttng_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(&lttng_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 <mathieu.desnoyers@efficios.com>");
This page took 0.031197 seconds and 4 git commands to generate.