Refactoring: syscalls: combine syscalls register event for notifier/recorder
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Nov 2021 16:31:08 +0000 (12:31 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Nov 2021 16:31:08 +0000 (12:31 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I907ac0397d0fdf421702d50ee382eb5e79827921

include/lttng/events-internal.h
src/lttng-events.c
src/lttng-syscalls.c

index aceabbe4324bc6b397dc983d66a49f2347212440..4b5883ed12bc2264a0321dc7efaeae42b44c7fbf 100644 (file)
@@ -809,7 +809,7 @@ void lttng_enabler_link_bytecode(const struct lttng_kernel_event_desc *event_des
                struct list_head *enabler_bytecode_runtime_head);
 
 #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
                struct list_head *enabler_bytecode_runtime_head);
 
 #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
-int lttng_syscalls_register_event_recorder(struct lttng_event_recorder_enabler *event_enabler);
+int lttng_syscalls_register_event(struct lttng_event_enabler_common *event_enabler);
 int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common *event);
 int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common *event);
 
 int lttng_syscall_filter_enable_event(struct lttng_kernel_event_common *event);
 int lttng_syscall_filter_disable_event(struct lttng_kernel_event_common *event);
 
@@ -819,12 +819,10 @@ int lttng_syscalls_destroy_syscall_table(struct lttng_kernel_syscall_table *sysc
 long lttng_channel_syscall_mask(struct lttng_kernel_channel_buffer *channel,
                struct lttng_kernel_abi_syscall_mask __user *usyscall_mask);
 
 long lttng_channel_syscall_mask(struct lttng_kernel_channel_buffer *channel,
                struct lttng_kernel_abi_syscall_mask __user *usyscall_mask);
 
-int lttng_syscalls_register_event_notifier(
-               struct lttng_event_notifier_enabler *event_notifier_enabler);
 int lttng_syscalls_create_matching_event_notifiers(
                struct lttng_event_notifier_enabler *event_notifier_enabler);
 #else
 int lttng_syscalls_create_matching_event_notifiers(
                struct lttng_event_notifier_enabler *event_notifier_enabler);
 #else
-static inline int lttng_syscalls_register_event_recorder(struct lttng_event_recorder_enabler *event_enabler)
+static inline int lttng_syscalls_register_event(struct lttng_event_enabler_common *event_enabler)
 {
        return -ENOSYS;
 }
 {
        return -ENOSYS;
 }
@@ -855,12 +853,6 @@ static inline long lttng_channel_syscall_mask(struct lttng_kernel_channel_buffer
        return -ENOSYS;
 }
 
        return -ENOSYS;
 }
 
-static inline int lttng_syscalls_register_event_notifier(
-               struct lttng_event_notifier_group *group)
-{
-       return -ENOSYS;
-}
-
 static inline int lttng_syscalls_create_matching_event_notifiers(struct lttng_event_notifier_enabler *event_notifier_enabler)
 {
        return -ENOSYS;
 static inline int lttng_syscalls_create_matching_event_notifiers(struct lttng_event_notifier_enabler *event_notifier_enabler)
 {
        return -ENOSYS;
index 270ee57309fb6fa1ead3a9ab7f8701514eb78902..7181f0fbaf6cb5d3461eb48af469cc1098402041 100644 (file)
@@ -2243,7 +2243,7 @@ void lttng_create_syscall_event_if_missing(struct lttng_event_recorder_enabler *
 {
        int ret;
 
 {
        int ret;
 
-       ret = lttng_syscalls_register_event_recorder(event_enabler);
+       ret = lttng_syscalls_register_event(&event_enabler->parent);
        WARN_ON_ONCE(ret);
 }
 
        WARN_ON_ONCE(ret);
 }
 
@@ -2252,7 +2252,7 @@ void lttng_create_syscall_event_notifier_if_missing(struct lttng_event_notifier_
 {
        int ret;
 
 {
        int ret;
 
-       ret = lttng_syscalls_register_event_notifier(event_notifier_enabler);
+       ret = lttng_syscalls_register_event(&event_notifier_enabler->parent);
        WARN_ON_ONCE(ret);
        ret = lttng_syscalls_create_matching_event_notifiers(event_notifier_enabler);
        WARN_ON_ONCE(ret);
        WARN_ON_ONCE(ret);
        ret = lttng_syscalls_create_matching_event_notifiers(event_notifier_enabler);
        WARN_ON_ONCE(ret);
index f72afbe2c6eeffdab3b513316dd8006f677808f4..1194b95d24ab71b2b88ce940ad393febec032341 100644 (file)
@@ -613,46 +613,20 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl
        return 0;
 }
 
        return 0;
 }
 
-/*
- * Should be called with sessions lock held.
- */
-int lttng_syscalls_register_event_recorder(struct lttng_event_recorder_enabler *syscall_event_enabler)
+static
+int lttng_syscalls_populate_events(struct lttng_event_enabler_common *syscall_event_enabler)
 {
 {
-       struct lttng_kernel_syscall_table *syscall_table = get_syscall_table_from_enabler(&syscall_event_enabler->parent);
+       struct lttng_kernel_syscall_table *syscall_table = get_syscall_table_from_enabler(syscall_event_enabler);
+       struct lttng_event_recorder_enabler *event_recorder_enabler;
+       struct lttng_kernel_channel_buffer *chan;
        struct lttng_kernel_abi_event ev;
        int ret;
 
        struct lttng_kernel_abi_event ev;
        int ret;
 
-       wrapper_vmalloc_sync_mappings();
-
-       if (!syscall_table->syscall_dispatch) {
-               /* create syscall table mapping syscall to events */
-               syscall_table->syscall_dispatch = kzalloc(sizeof(struct hlist_head) * sc_table.len, GFP_KERNEL);
-               if (!syscall_table->syscall_dispatch)
-                       return -ENOMEM;
-       }
-       if (!syscall_table->syscall_exit_dispatch) {
-               /* create syscall table mapping syscall to events */
-               syscall_table->syscall_exit_dispatch = kzalloc(sizeof(struct hlist_head) * sc_exit_table.len, GFP_KERNEL);
-               if (!syscall_table->syscall_exit_dispatch)
-                       return -ENOMEM;
-       }
-
-
-#ifdef CONFIG_COMPAT
-       if (!syscall_table->compat_syscall_dispatch) {
-               /* create syscall table mapping compat syscall to events */
-               syscall_table->compat_syscall_dispatch = kzalloc(sizeof(struct hlist_head) * compat_sc_table.len, GFP_KERNEL);
-               if (!syscall_table->compat_syscall_dispatch)
-                       return -ENOMEM;
-       }
+       if (syscall_event_enabler->enabler_type != LTTNG_EVENT_ENABLER_TYPE_RECORDER)
+               return 0;
+       event_recorder_enabler = container_of(syscall_event_enabler, struct lttng_event_recorder_enabler, parent);
+       chan = event_recorder_enabler->chan;
 
 
-       if (!syscall_table->compat_syscall_exit_dispatch) {
-               /* create syscall table mapping compat syscall to events */
-               syscall_table->compat_syscall_exit_dispatch = kzalloc(sizeof(struct hlist_head) * compat_sc_exit_table.len, GFP_KERNEL);
-               if (!syscall_table->compat_syscall_exit_dispatch)
-                       return -ENOMEM;
-       }
-#endif
        if (hlist_empty(&syscall_table->unknown_syscall_dispatch)) {
                const struct lttng_kernel_event_desc *desc =
                        &__event_desc___syscall_entry_unknown;
        if (hlist_empty(&syscall_table->unknown_syscall_dispatch)) {
                const struct lttng_kernel_event_desc *desc =
                        &__event_desc___syscall_entry_unknown;
@@ -665,7 +639,7 @@ int lttng_syscalls_register_event_recorder(struct lttng_event_recorder_enabler *
                ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_ENTRY;
                ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_NATIVE;
                ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_ENTRY;
                ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_NATIVE;
-               event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, syscall_event_enabler->chan);
+               event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, chan);
                if (!event_enabler) {
                        return -ENOMEM;
                }
                if (!event_enabler) {
                        return -ENOMEM;
                }
@@ -690,7 +664,7 @@ int lttng_syscalls_register_event_recorder(struct lttng_event_recorder_enabler *
                ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_ENTRY;
                ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_COMPAT;
                ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_ENTRY;
                ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_COMPAT;
-               event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, syscall_event_enabler->chan);
+               event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, chan);
                if (!event_enabler) {
                        return -ENOMEM;
                }
                if (!event_enabler) {
                        return -ENOMEM;
                }
@@ -715,7 +689,7 @@ int lttng_syscalls_register_event_recorder(struct lttng_event_recorder_enabler *
                ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_EXIT;
                ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_COMPAT;
                ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_EXIT;
                ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_COMPAT;
-               event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, syscall_event_enabler->chan);
+               event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, chan);
                if (!event_enabler) {
                        return -ENOMEM;
                }
                if (!event_enabler) {
                        return -ENOMEM;
                }
@@ -740,7 +714,7 @@ int lttng_syscalls_register_event_recorder(struct lttng_event_recorder_enabler *
                ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_EXIT;
                ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_NATIVE;
                ev.instrumentation = LTTNG_KERNEL_ABI_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_ABI_SYSCALL_EXIT;
                ev.u.syscall.abi = LTTNG_KERNEL_ABI_SYSCALL_ABI_NATIVE;
-               event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, syscall_event_enabler->chan);
+               event_enabler = lttng_event_recorder_enabler_create(LTTNG_ENABLER_FORMAT_NAME, &ev, chan);
                if (!event_enabler) {
                        return -ENOMEM;
                }
                if (!event_enabler) {
                        return -ENOMEM;
                }
@@ -754,96 +728,64 @@ int lttng_syscalls_register_event_recorder(struct lttng_event_recorder_enabler *
        }
 
        ret = lttng_create_syscall_event_if_missing(sc_table.table, sc_table.len,
        }
 
        ret = lttng_create_syscall_event_if_missing(sc_table.table, sc_table.len,
-                       syscall_table->syscall_dispatch, syscall_event_enabler, SC_TYPE_ENTRY);
+                       syscall_table->syscall_dispatch, event_recorder_enabler, SC_TYPE_ENTRY);
        if (ret)
                return ret;
        ret = lttng_create_syscall_event_if_missing(sc_exit_table.table, sc_exit_table.len,
        if (ret)
                return ret;
        ret = lttng_create_syscall_event_if_missing(sc_exit_table.table, sc_exit_table.len,
-                       syscall_table->syscall_exit_dispatch, syscall_event_enabler, SC_TYPE_EXIT);
+                       syscall_table->syscall_exit_dispatch, event_recorder_enabler, SC_TYPE_EXIT);
        if (ret)
                return ret;
 
 #ifdef CONFIG_COMPAT
        ret = lttng_create_syscall_event_if_missing(compat_sc_table.table, compat_sc_table.len,
        if (ret)
                return ret;
 
 #ifdef CONFIG_COMPAT
        ret = lttng_create_syscall_event_if_missing(compat_sc_table.table, compat_sc_table.len,
-                       syscall_table->compat_syscall_dispatch, syscall_event_enabler, SC_TYPE_COMPAT_ENTRY);
+                       syscall_table->compat_syscall_dispatch, event_recorder_enabler, SC_TYPE_COMPAT_ENTRY);
        if (ret)
                return ret;
        ret = lttng_create_syscall_event_if_missing(compat_sc_exit_table.table, compat_sc_exit_table.len,
        if (ret)
                return ret;
        ret = lttng_create_syscall_event_if_missing(compat_sc_exit_table.table, compat_sc_exit_table.len,
-                       syscall_table->compat_syscall_exit_dispatch, syscall_event_enabler, SC_TYPE_COMPAT_EXIT);
+                       syscall_table->compat_syscall_exit_dispatch, event_recorder_enabler, SC_TYPE_COMPAT_EXIT);
        if (ret)
                return ret;
 #endif
        if (ret)
                return ret;
 #endif
-
-       if (!syscall_table->sc_filter) {
-               syscall_table->sc_filter = kzalloc(sizeof(struct lttng_syscall_filter),
-                               GFP_KERNEL);
-               if (!syscall_table->sc_filter)
-                       return -ENOMEM;
-       }
-
-       if (!syscall_table->sys_enter_registered) {
-               ret = lttng_wrapper_tracepoint_probe_register("sys_enter",
-                               (void *) syscall_entry_event_probe, syscall_table);
-               if (ret)
-                       return ret;
-               syscall_table->sys_enter_registered = 1;
-       }
-       /*
-        * We change the name of sys_exit tracepoint due to namespace
-        * conflict with sys_exit syscall entry.
-        */
-       if (!syscall_table->sys_exit_registered) {
-               ret = lttng_wrapper_tracepoint_probe_register("sys_exit",
-                               (void *) syscall_exit_event_probe, syscall_table);
-               if (ret) {
-                       WARN_ON_ONCE(lttng_wrapper_tracepoint_probe_unregister("sys_enter",
-                               (void *) syscall_entry_event_probe, syscall_table));
-                       return ret;
-               }
-               syscall_table->sys_exit_registered = 1;
-       }
        return ret;
 }
 
 /*
  * Should be called with sessions lock held.
  */
        return ret;
 }
 
 /*
  * Should be called with sessions lock held.
  */
-int lttng_syscalls_register_event_notifier(
-               struct lttng_event_notifier_enabler *event_notifier_enabler)
+int lttng_syscalls_register_event(struct lttng_event_enabler_common *syscall_event_enabler)
 {
 {
-       struct lttng_event_notifier_group *group = event_notifier_enabler->group;
-       struct lttng_kernel_syscall_table *syscall_table = &group->syscall_table;
-       int ret = 0;
-
-       wrapper_vmalloc_sync_mappings();
+       struct lttng_kernel_syscall_table *syscall_table = get_syscall_table_from_enabler(syscall_event_enabler);
+       int ret;
 
        if (!syscall_table->syscall_dispatch) {
 
        if (!syscall_table->syscall_dispatch) {
+               /* create syscall table mapping syscall to events */
                syscall_table->syscall_dispatch = kzalloc(sizeof(struct hlist_head) * sc_table.len, GFP_KERNEL);
                if (!syscall_table->syscall_dispatch)
                        return -ENOMEM;
        }
                syscall_table->syscall_dispatch = kzalloc(sizeof(struct hlist_head) * sc_table.len, GFP_KERNEL);
                if (!syscall_table->syscall_dispatch)
                        return -ENOMEM;
        }
-
        if (!syscall_table->syscall_exit_dispatch) {
        if (!syscall_table->syscall_exit_dispatch) {
-               syscall_table->syscall_exit_dispatch = kzalloc(sizeof(struct hlist_head) * sc_table.len, GFP_KERNEL);
+               /* create syscall table mapping syscall to events */
+               syscall_table->syscall_exit_dispatch = kzalloc(sizeof(struct hlist_head) * sc_exit_table.len, GFP_KERNEL);
                if (!syscall_table->syscall_exit_dispatch)
                        return -ENOMEM;
        }
 
                if (!syscall_table->syscall_exit_dispatch)
                        return -ENOMEM;
        }
 
+
 #ifdef CONFIG_COMPAT
        if (!syscall_table->compat_syscall_dispatch) {
 #ifdef CONFIG_COMPAT
        if (!syscall_table->compat_syscall_dispatch) {
+               /* create syscall table mapping compat syscall to events */
                syscall_table->compat_syscall_dispatch = kzalloc(sizeof(struct hlist_head) * compat_sc_table.len, GFP_KERNEL);
                if (!syscall_table->compat_syscall_dispatch)
                        return -ENOMEM;
        }
 
        if (!syscall_table->compat_syscall_exit_dispatch) {
                syscall_table->compat_syscall_dispatch = kzalloc(sizeof(struct hlist_head) * compat_sc_table.len, GFP_KERNEL);
                if (!syscall_table->compat_syscall_dispatch)
                        return -ENOMEM;
        }
 
        if (!syscall_table->compat_syscall_exit_dispatch) {
-               syscall_table->compat_syscall_exit_dispatch =
-                               kzalloc(sizeof(struct hlist_head) * compat_sc_exit_table.len,
-                                       GFP_KERNEL);
+               /* create syscall table mapping compat syscall to events */
+               syscall_table->compat_syscall_exit_dispatch = kzalloc(sizeof(struct hlist_head) * compat_sc_exit_table.len, GFP_KERNEL);
                if (!syscall_table->compat_syscall_exit_dispatch)
                        return -ENOMEM;
        }
 #endif
                if (!syscall_table->compat_syscall_exit_dispatch)
                        return -ENOMEM;
        }
 #endif
-
        if (!syscall_table->sc_filter) {
                syscall_table->sc_filter = kzalloc(sizeof(struct lttng_syscall_filter),
                                GFP_KERNEL);
        if (!syscall_table->sc_filter) {
                syscall_table->sc_filter = kzalloc(sizeof(struct lttng_syscall_filter),
                                GFP_KERNEL);
@@ -851,6 +793,12 @@ int lttng_syscalls_register_event_notifier(
                        return -ENOMEM;
        }
 
                        return -ENOMEM;
        }
 
+       ret = lttng_syscalls_populate_events(syscall_event_enabler);
+       if (ret)
+               return ret;
+
+       wrapper_vmalloc_sync_mappings();
+
        if (!syscall_table->sys_enter_registered) {
                ret = lttng_wrapper_tracepoint_probe_register("sys_enter",
                                (void *) syscall_entry_event_probe, syscall_table);
        if (!syscall_table->sys_enter_registered) {
                ret = lttng_wrapper_tracepoint_probe_register("sys_enter",
                                (void *) syscall_entry_event_probe, syscall_table);
@@ -858,7 +806,6 @@ int lttng_syscalls_register_event_notifier(
                        return ret;
                syscall_table->sys_enter_registered = 1;
        }
                        return ret;
                syscall_table->sys_enter_registered = 1;
        }
-
        if (!syscall_table->sys_exit_registered) {
                ret = lttng_wrapper_tracepoint_probe_register("sys_exit",
                                (void *) syscall_exit_event_probe, syscall_table);
        if (!syscall_table->sys_exit_registered) {
                ret = lttng_wrapper_tracepoint_probe_register("sys_exit",
                                (void *) syscall_exit_event_probe, syscall_table);
@@ -869,7 +816,6 @@ int lttng_syscalls_register_event_notifier(
                }
                syscall_table->sys_exit_registered = 1;
        }
                }
                syscall_table->sys_exit_registered = 1;
        }
-
        return ret;
 }
 
        return ret;
 }
 
This page took 0.033121 seconds and 4 git commands to generate.