Introduce lazy system call event creation
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 Nov 2020 20:30:30 +0000 (15:30 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Wed, 25 Nov 2020 20:31:59 +0000 (15:31 -0500)
Introduce lazy system call event creation. If only specific system call
events are enabled, only create the metadata for those.

Align implementation of system call event probes for recording events
with their notifier counterpart.

This is part of the background work required for a future feature (trace
hit counters and map support) which brings benefits on its own.

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/lttng/events.h
src/lttng-events.c
src/lttng-syscalls.c

index b4c5372ae1f9266e9e851992f33059d7544bea90..7fa41ac18d1664b7d409cd287d7202cd6af53418 100644 (file)
@@ -338,6 +338,7 @@ struct lttng_event {
                struct {
                        enum lttng_syscall_entryexit entryexit;
                        enum lttng_syscall_abi abi;
+                       struct hlist_node node;                 /* chain registered syscall event */
                } syscall;
        } u;
        struct list_head list;          /* Event list in session */
@@ -578,18 +579,19 @@ struct lttng_channel {
        struct list_head list;          /* Channel list */
        struct lttng_channel_ops *ops;
        struct lttng_transport *transport;
-       struct lttng_event **sc_table;  /* for syscall tracing */
-       struct lttng_event **compat_sc_table;
-       struct lttng_event **sc_exit_table;     /* for syscall exit tracing */
-       struct lttng_event **compat_sc_exit_table;
-       struct lttng_event *sc_unknown; /* for unknown syscalls */
-       struct lttng_event *sc_compat_unknown;
-       struct lttng_event *sc_exit_unknown;
-       struct lttng_event *compat_sc_exit_unknown;
+       struct hlist_head *sc_table;    /* for syscall tracing */
+       struct hlist_head *compat_sc_table;
+       struct hlist_head *sc_exit_table;       /* for syscall exit tracing */
+       struct hlist_head *compat_sc_exit_table;
+       struct hlist_head sc_unknown;   /* for unknown syscalls */
+       struct hlist_head sc_compat_unknown;
+       struct hlist_head sc_exit_unknown;
+       struct hlist_head compat_sc_exit_unknown;
        struct lttng_syscall_filter *sc_filter;
        int header_type;                /* 0: unset, 1: compact, 2: large */
        enum channel_type channel_type;
-       int syscall_all;
+       int syscall_all_entry;
+       int syscall_all_exit;
        unsigned int metadata_dumped:1,
                sys_enter_registered:1,
                sys_exit_registered:1,
@@ -887,8 +889,8 @@ int lttng_desc_match_enabler(const struct lttng_event_desc *desc,
                struct lttng_enabler *enabler);
 
 #if defined(CONFIG_HAVE_SYSCALL_TRACEPOINTS)
-int lttng_syscalls_register_event(struct lttng_channel *chan, void *filter);
-int lttng_syscalls_unregister_event(struct lttng_channel *chan);
+int lttng_syscalls_register_event(struct lttng_event_enabler *event_enabler, void *filter);
+int lttng_syscalls_unregister_channel(struct lttng_channel *chan);
 int lttng_syscalls_destroy_event(struct lttng_channel *chan);
 int lttng_syscall_filter_enable_event(
                struct lttng_channel *chan,
@@ -905,17 +907,17 @@ int lttng_syscalls_register_event_notifier(
                void *filter);
 int lttng_syscals_create_matching_event_notifiers(
                struct lttng_event_notifier_enabler *event_notifier_enabler, void *filter);
-int lttng_syscalls_unregister_event_notifier(struct lttng_event_notifier_group *group);
+int lttng_syscalls_unregister_event_notifier_group(struct lttng_event_notifier_group *group);
 int lttng_syscall_filter_enable_event_notifier(struct lttng_event_notifier *event_notifier);
 int lttng_syscall_filter_disable_event_notifier(struct lttng_event_notifier *event_notifier);
 #else
 static inline int lttng_syscalls_register_event(
-               struct lttng_channel *chan, void *filter)
+               struct lttng_event_enabler *event_enabler, void *filter)
 {
        return -ENOSYS;
 }
 
-static inline int lttng_syscalls_unregister_event(struct lttng_channel *chan)
+static inline int lttng_syscalls_unregister_channel(struct lttng_channel *chan)
 {
        return 0;
 }
@@ -949,7 +951,7 @@ static inline int lttng_syscalls_register_event_notifier(
        return -ENOSYS;
 }
 
-static inline int lttng_syscalls_unregister_event_notifier(
+static inline int lttng_syscalls_unregister_event_notifier_group(
                struct lttng_event_notifier_group *group)
 {
        return 0;
index 9f683db18f2274badbaeb37288d4843fc7c246e0..3f9d0f9a91fdf7b50b7a647d1aea55413d8412b0 100644 (file)
@@ -337,7 +337,7 @@ void lttng_session_destroy(struct lttng_session *session)
        mutex_lock(&sessions_mutex);
        WRITE_ONCE(session->active, 0);
        list_for_each_entry(chan, &session->chan, list) {
-               ret = lttng_syscalls_unregister_event(chan);
+               ret = lttng_syscalls_unregister_channel(chan);
                WARN_ON(ret);
        }
        list_for_each_entry(event, &session->events, list) {
@@ -386,7 +386,7 @@ void lttng_event_notifier_group_destroy(
 
        mutex_lock(&sessions_mutex);
 
-       ret = lttng_syscalls_unregister_event_notifier(event_notifier_group);
+       ret = lttng_syscalls_unregister_event_notifier_group(event_notifier_group);
        WARN_ON(ret);
 
        list_for_each_entry_safe(event_notifier, tmpevent_notifier,
@@ -2065,7 +2065,7 @@ void lttng_create_syscall_event_if_missing(struct lttng_event_enabler *event_ena
 {
        int ret;
 
-       ret = lttng_syscalls_register_event(event_enabler->chan, NULL);
+       ret = lttng_syscalls_register_event(event_enabler, NULL);
        WARN_ON_ONCE(ret);
 }
 
@@ -2115,14 +2115,17 @@ int lttng_event_enabler_ref_events(struct lttng_event_enabler *event_enabler)
        struct lttng_event *event;
 
        if (base_enabler->event_param.instrumentation == LTTNG_KERNEL_SYSCALL &&
-                       base_enabler->event_param.u.syscall.entryexit == LTTNG_KERNEL_SYSCALL_ENTRYEXIT &&
                        base_enabler->event_param.u.syscall.abi == LTTNG_KERNEL_SYSCALL_ABI_ALL &&
                        base_enabler->event_param.u.syscall.match == LTTNG_KERNEL_SYSCALL_MATCH_NAME &&
                        !strcmp(base_enabler->event_param.name, "*")) {
-               if (base_enabler->enabled)
-                       WRITE_ONCE(chan->syscall_all, 1);
-               else
-                       WRITE_ONCE(chan->syscall_all, 0);
+               int enabled = base_enabler->enabled;
+               enum lttng_kernel_syscall_entryexit entryexit = base_enabler->event_param.u.syscall.entryexit;
+
+               if (entryexit == LTTNG_KERNEL_SYSCALL_ENTRY || entryexit == LTTNG_KERNEL_SYSCALL_ENTRYEXIT)
+                       WRITE_ONCE(chan->syscall_all_entry, enabled);
+
+               if (entryexit == LTTNG_KERNEL_SYSCALL_EXIT || entryexit == LTTNG_KERNEL_SYSCALL_ENTRYEXIT)
+                       WRITE_ONCE(chan->syscall_all_exit, enabled);
        }
 
        /* First ensure that probe events are created for this enabler. */
index 41e10be07ab513f68c397463b29fbb0ba80cf3b0..c5be18051191bbb6dd0ac335389e27c469662bba 100644 (file)
@@ -388,16 +388,19 @@ struct lttng_syscall_filter {
        DECLARE_BITMAP(sc_compat_exit, NR_compat_syscalls);
 };
 
-static void syscall_entry_event_unknown(struct lttng_event *event,
+static void syscall_entry_event_unknown(struct hlist_head *unknown_action_list_head,
        struct pt_regs *regs, long id)
 {
        unsigned long args[LTTNG_SYSCALL_NR_ARGS];
+       struct lttng_event *event;
 
        lttng_syscall_get_arguments(current, regs, args);
-       if (unlikely(in_compat_syscall()))
-               __event_probe__compat_syscall_entry_unknown(event, id, args);
-       else
-               __event_probe__syscall_entry_unknown(event, id, args);
+       hlist_for_each_entry_rcu(event, unknown_action_list_head, u.syscall.node) {
+               if (unlikely(in_compat_syscall()))
+                       __event_probe__compat_syscall_entry_unknown(event, id, args);
+               else
+                       __event_probe__syscall_entry_unknown(event, id, args);
+       }
 }
 
 static void syscall_entry_event_notifier_unknown(
@@ -433,15 +436,19 @@ static void syscall_exit_event_notifier_unknown(
 }
 
 static __always_inline
-void syscall_entry_call_func(void *func, unsigned int nrargs, void *data,
+void syscall_entry_call_func(struct hlist_head *action_list,
+               void *func, unsigned int nrargs,
                struct pt_regs *regs)
 {
+       struct lttng_event *event;
+
        switch (nrargs) {
        case 0:
        {
                void (*fptr)(void *__data) = func;
 
-               fptr(data);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event);
                break;
        }
        case 1:
@@ -450,7 +457,8 @@ void syscall_entry_call_func(void *func, unsigned int nrargs, void *data,
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(data, args[0]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, args[0]);
                break;
        }
        case 2:
@@ -461,7 +469,8 @@ void syscall_entry_call_func(void *func, unsigned int nrargs, void *data,
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(data, args[0], args[1]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, args[0], args[1]);
                break;
        }
        case 3:
@@ -473,7 +482,8 @@ void syscall_entry_call_func(void *func, unsigned int nrargs, void *data,
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(data, args[0], args[1], args[2]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, args[0], args[1], args[2]);
                break;
        }
        case 4:
@@ -486,7 +496,8 @@ void syscall_entry_call_func(void *func, unsigned int nrargs, void *data,
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(data, args[0], args[1], args[2], args[3]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, args[0], args[1], args[2], args[3]);
                break;
        }
        case 5:
@@ -500,7 +511,8 @@ void syscall_entry_call_func(void *func, unsigned int nrargs, void *data,
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(data, args[0], args[1], args[2], args[3], args[4]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, args[0], args[1], args[2], args[3], args[4]);
                break;
        }
        case 6:
@@ -515,8 +527,9 @@ void syscall_entry_call_func(void *func, unsigned int nrargs, void *data,
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(data, args[0], args[1], args[2],
-                       args[3], args[4], args[5]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, args[0], args[1], args[2],
+                            args[3], args[4], args[5]);
                break;
        }
        default:
@@ -627,7 +640,7 @@ void syscall_entry_event_notifier_call_func(struct hlist_head *dispatch_list,
 void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id)
 {
        struct lttng_channel *chan = __data;
-       struct lttng_event *event, *unknown_event;
+       struct hlist_head *action_list, *unknown_action_list;
        const struct trace_syscall_entry *table, *entry;
        size_t table_len;
 
@@ -635,40 +648,45 @@ void syscall_entry_event_probe(void *__data, struct pt_regs *regs, long id)
                struct lttng_syscall_filter *filter = chan->sc_filter;
 
                if (id < 0 || id >= NR_compat_syscalls
-                       || (!READ_ONCE(chan->syscall_all) && !test_bit(id, filter->sc_compat_entry))) {
+                       || (!READ_ONCE(chan->syscall_all_entry) && !test_bit(id, filter->sc_compat_entry))) {
                        /* System call filtered out. */
                        return;
                }
                table = compat_sc_table;
                table_len = ARRAY_SIZE(compat_sc_table);
-               unknown_event = chan->sc_compat_unknown;
+               unknown_action_list = &chan->sc_compat_unknown;
        } else {
                struct lttng_syscall_filter *filter = chan->sc_filter;
 
                if (id < 0 || id >= NR_syscalls
-                       || (!READ_ONCE(chan->syscall_all) && !test_bit(id, filter->sc_entry))) {
+                       || (!READ_ONCE(chan->syscall_all_entry) && !test_bit(id, filter->sc_entry))) {
                        /* System call filtered out. */
                        return;
                }
                table = sc_table;
                table_len = ARRAY_SIZE(sc_table);
-               unknown_event = chan->sc_unknown;
+               unknown_action_list = &chan->sc_unknown;
        }
        if (unlikely(id < 0 || id >= table_len)) {
-               syscall_entry_event_unknown(unknown_event, regs, id);
+               syscall_entry_event_unknown(unknown_action_list, regs, id);
                return;
        }
-       if (unlikely(in_compat_syscall()))
-               event = chan->compat_sc_table[id];
-       else
-               event = chan->sc_table[id];
-       if (unlikely(!event)) {
-               syscall_entry_event_unknown(unknown_event, regs, id);
+
+       entry = &table[id];
+       if (!entry->event_func) {
+               syscall_entry_event_unknown(unknown_action_list, regs, id);
                return;
        }
-       entry = &table[id];
-       WARN_ON_ONCE(!entry->event_func);
-       syscall_entry_call_func(entry->event_func, entry->nrargs, event, regs);
+
+       if (unlikely(in_compat_syscall())) {
+               action_list = &chan->compat_sc_table[id];
+       } else {
+               action_list = &chan->sc_table[id];
+       }
+       if (unlikely(hlist_empty(action_list)))
+               return;
+
+       syscall_entry_call_func(action_list, entry->event_func, entry->nrargs, regs);
 }
 
 void syscall_entry_event_notifier_probe(void *__data, struct pt_regs *regs,
@@ -730,83 +748,48 @@ void syscall_entry_event_notifier_probe(void *__data, struct pt_regs *regs,
                        entry->event_notifier_func, entry->nrargs, regs);
 }
 
-static void syscall_exit_event_unknown(struct lttng_event *event,
+static void syscall_exit_event_unknown(struct hlist_head *unknown_action_list_head,
        struct pt_regs *regs, long id, long ret)
 {
        unsigned long args[LTTNG_SYSCALL_NR_ARGS];
+       struct lttng_event *event;
 
        lttng_syscall_get_arguments(current, regs, args);
-       if (unlikely(in_compat_syscall()))
-               __event_probe__compat_syscall_exit_unknown(event, id, ret,
-                       args);
-       else
-               __event_probe__syscall_exit_unknown(event, id, ret, args);
+       hlist_for_each_entry_rcu(event, unknown_action_list_head, u.syscall.node) {
+               if (unlikely(in_compat_syscall()))
+                       __event_probe__compat_syscall_exit_unknown(event, id, ret,
+                               args);
+               else
+                       __event_probe__syscall_exit_unknown(event, id, ret, args);
+       }
 }
 
-void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret)
+static __always_inline
+void syscall_exit_call_func(struct hlist_head *action_list,
+               void *func, unsigned int nrargs,
+               struct pt_regs *regs, long ret)
 {
-       struct lttng_channel *chan = __data;
-       struct lttng_event *event, *unknown_event;
-       const struct trace_syscall_entry *table, *entry;
-       size_t table_len;
-       long id;
-
-       id = syscall_get_nr(current, regs);
-       if (unlikely(in_compat_syscall())) {
-               struct lttng_syscall_filter *filter = chan->sc_filter;
-
-               if (id < 0 || id >= NR_compat_syscalls
-                       || (!READ_ONCE(chan->syscall_all) && !test_bit(id, filter->sc_compat_exit))) {
-                       /* System call filtered out. */
-                       return;
-               }
-               table = compat_sc_exit_table;
-               table_len = ARRAY_SIZE(compat_sc_exit_table);
-               unknown_event = chan->compat_sc_exit_unknown;
-       } else {
-               struct lttng_syscall_filter *filter = chan->sc_filter;
+       struct lttng_event *event;
 
-               if (id < 0 || id >= NR_syscalls
-                       || (!READ_ONCE(chan->syscall_all) && !test_bit(id, filter->sc_exit))) {
-                       /* System call filtered out. */
-                       return;
-               }
-               table = sc_exit_table;
-               table_len = ARRAY_SIZE(sc_exit_table);
-               unknown_event = chan->sc_exit_unknown;
-       }
-       if (unlikely(id < 0 || id >= table_len)) {
-               syscall_exit_event_unknown(unknown_event, regs, id, ret);
-               return;
-       }
-       if (unlikely(in_compat_syscall()))
-               event = chan->compat_sc_exit_table[id];
-       else
-               event = chan->sc_exit_table[id];
-       if (unlikely(!event)) {
-               syscall_exit_event_unknown(unknown_event, regs, id, ret);
-               return;
-       }
-       entry = &table[id];
-       WARN_ON_ONCE(!entry->event_func);
-
-       switch (entry->nrargs) {
+       switch (nrargs) {
        case 0:
        {
-               void (*fptr)(void *__data, long ret) = entry->event_func;
+               void (*fptr)(void *__data, long ret) = func;
 
-               fptr(event, ret);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, ret);
                break;
        }
        case 1:
        {
                void (*fptr)(void *__data,
                        long ret,
-                       unsigned long arg0) = entry->event_func;
+                       unsigned long arg0) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, ret, args[0]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, ret, args[0]);
                break;
        }
        case 2:
@@ -814,11 +797,12 @@ void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret)
                void (*fptr)(void *__data,
                        long ret,
                        unsigned long arg0,
-                       unsigned long arg1) = entry->event_func;
+                       unsigned long arg1) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, ret, args[0], args[1]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, ret, args[0], args[1]);
                break;
        }
        case 3:
@@ -827,11 +811,12 @@ void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret)
                        long ret,
                        unsigned long arg0,
                        unsigned long arg1,
-                       unsigned long arg2) = entry->event_func;
+                       unsigned long arg2) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, ret, args[0], args[1], args[2]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, ret, args[0], args[1], args[2]);
                break;
        }
        case 4:
@@ -841,11 +826,12 @@ void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret)
                        unsigned long arg0,
                        unsigned long arg1,
                        unsigned long arg2,
-                       unsigned long arg3) = entry->event_func;
+                       unsigned long arg3) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, ret, args[0], args[1], args[2], args[3]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, ret, args[0], args[1], args[2], args[3]);
                break;
        }
        case 5:
@@ -856,11 +842,12 @@ void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret)
                        unsigned long arg1,
                        unsigned long arg2,
                        unsigned long arg3,
-                       unsigned long arg4) = entry->event_func;
+                       unsigned long arg4) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, ret, args[0], args[1], args[2], args[3], args[4]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, ret, args[0], args[1], args[2], args[3], args[4]);
                break;
        }
        case 6:
@@ -872,12 +859,13 @@ void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret)
                        unsigned long arg2,
                        unsigned long arg3,
                        unsigned long arg4,
-                       unsigned long arg5) = entry->event_func;
+                       unsigned long arg5) = func;
                unsigned long args[LTTNG_SYSCALL_NR_ARGS];
 
                lttng_syscall_get_arguments(current, regs, args);
-               fptr(event, ret, args[0], args[1], args[2],
-                       args[3], args[4], args[5]);
+               hlist_for_each_entry_rcu(event, action_list, u.syscall.node)
+                       fptr(event, ret, args[0], args[1], args[2],
+                            args[3], args[4], args[5]);
                break;
        }
        default:
@@ -885,6 +873,62 @@ void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret)
        }
 }
 
+void syscall_exit_event_probe(void *__data, struct pt_regs *regs, long ret)
+{
+       struct lttng_channel *chan = __data;
+       struct hlist_head *action_list, *unknown_action_list;
+       const struct trace_syscall_entry *table, *entry;
+       size_t table_len;
+       long id;
+
+       id = syscall_get_nr(current, regs);
+
+       if (unlikely(in_compat_syscall())) {
+               struct lttng_syscall_filter *filter = chan->sc_filter;
+
+               if (id < 0 || id >= NR_compat_syscalls
+                       || (!READ_ONCE(chan->syscall_all_exit) && !test_bit(id, filter->sc_compat_exit))) {
+                       /* System call filtered out. */
+                       return;
+               }
+               table = compat_sc_exit_table;
+               table_len = ARRAY_SIZE(compat_sc_exit_table);
+               unknown_action_list = &chan->compat_sc_exit_unknown;
+       } else {
+               struct lttng_syscall_filter *filter = chan->sc_filter;
+
+               if (id < 0 || id >= NR_syscalls
+                       || (!READ_ONCE(chan->syscall_all_exit) && !test_bit(id, filter->sc_exit))) {
+                       /* System call filtered out. */
+                       return;
+               }
+               table = sc_exit_table;
+               table_len = ARRAY_SIZE(sc_exit_table);
+               unknown_action_list = &chan->sc_exit_unknown;
+       }
+       if (unlikely(id < 0 || id >= table_len)) {
+               syscall_exit_event_unknown(unknown_action_list, regs, id, ret);
+               return;
+       }
+
+       entry = &table[id];
+       if (!entry->event_func) {
+               syscall_exit_event_unknown(unknown_action_list, regs, id, ret);
+               return;
+       }
+
+       if (unlikely(in_compat_syscall())) {
+               action_list = &chan->compat_sc_exit_table[id];
+       } else {
+               action_list = &chan->sc_exit_table[id];
+       }
+       if (unlikely(hlist_empty(action_list)))
+               return;
+
+       syscall_exit_call_func(action_list, entry->event_func, entry->nrargs,
+                              regs, ret);
+}
+
 static __always_inline
 void syscall_exit_event_notifier_call_func(struct hlist_head *dispatch_list,
                void *func, unsigned int nrargs, struct pt_regs *regs, long ret)
@@ -1057,28 +1101,44 @@ void syscall_exit_event_notifier_probe(void *__data, struct pt_regs *regs,
  * Should be called with sessions lock held.
  */
 static
-int fill_event_table(const struct trace_syscall_entry *table, size_t table_len,
-       struct lttng_event **chan_table, struct lttng_channel *chan,
+int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *table, size_t table_len,
+       struct hlist_head *chan_table, struct lttng_event_enabler *event_enabler,
        void *filter, enum sc_type type)
 {
-       const struct lttng_event_desc *desc;
+       struct lttng_channel *chan = event_enabler->chan;
+       struct lttng_session *session = chan->session;
        unsigned int i;
 
-       /* Allocate events for each syscall, insert into table */
+       /* Allocate events for each syscall matching enabler, insert into table */
        for (i = 0; i < table_len; i++) {
+               const struct lttng_event_desc *desc = table[i].desc;
                struct lttng_kernel_event ev;
-               desc = table[i].desc;
+               struct lttng_event *event;
+               struct hlist_head *head;
+               bool found = false;
 
                if (!desc) {
                        /* Unknown syscall */
                        continue;
                }
+               if (lttng_desc_match_enabler(desc,
+                               lttng_event_enabler_as_enabler(event_enabler)) <= 0)
+                       continue;
                /*
-                * Skip those already populated by previous failed
-                * register for this channel.
+                * Check if already created.
                 */
-               if (chan_table[i])
+               head = utils_borrow_hash_table_bucket(
+                       session->events_ht.table, LTTNG_EVENT_HT_SIZE,
+                       desc->name);
+               lttng_hlist_for_each_entry(event, head, hlist) {
+                       if (event->desc == desc
+                               && event->chan == event_enabler->chan)
+                               found = true;
+               }
+               if (found)
                        continue;
+
+               /* We need to create an event for this syscall/enabler. */
                memset(&ev, 0, sizeof(ev));
                switch (type) {
                case SC_TYPE_ENTRY:
@@ -1101,18 +1161,19 @@ int fill_event_table(const struct trace_syscall_entry *table, size_t table_len,
                strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN - 1);
                ev.name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
                ev.instrumentation = LTTNG_KERNEL_SYSCALL;
-               chan_table[i] = _lttng_event_create(chan, &ev, filter,
-                                               desc, ev.instrumentation);
-               WARN_ON_ONCE(!chan_table[i]);
-               if (IS_ERR(chan_table[i])) {
+               event = _lttng_event_create(chan, &ev, filter,
+                                           desc, ev.instrumentation);
+               WARN_ON_ONCE(!event);
+               if (IS_ERR(event)) {
                        /*
                         * If something goes wrong in event registration
                         * after the first one, we have no choice but to
                         * leave the previous events in there, until
                         * deleted by session teardown.
                         */
-                       return PTR_ERR(chan_table[i]);
+                       return PTR_ERR(event);
                }
+               hlist_add_head(&event->u.syscall.node, &chan_table[i]);
        }
        return 0;
 }
@@ -1120,8 +1181,9 @@ int fill_event_table(const struct trace_syscall_entry *table, size_t table_len,
 /*
  * Should be called with sessions lock held.
  */
-int lttng_syscalls_register_event(struct lttng_channel *chan, void *filter)
+int lttng_syscalls_register_event(struct lttng_event_enabler *event_enabler, void *filter)
 {
+       struct lttng_channel *chan = event_enabler->chan;
        struct lttng_kernel_event ev;
        int ret;
 
@@ -1160,9 +1222,10 @@ int lttng_syscalls_register_event(struct lttng_channel *chan, void *filter)
                        return -ENOMEM;
        }
 #endif
-       if (!chan->sc_unknown) {
+       if (hlist_empty(&chan->sc_unknown)) {
                const struct lttng_event_desc *desc =
                        &__event_desc___syscall_entry_unknown;
+               struct lttng_event *event;
 
                memset(&ev, 0, sizeof(ev));
                strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
@@ -1170,18 +1233,19 @@ int lttng_syscalls_register_event(struct lttng_channel *chan, void *filter)
                ev.instrumentation = LTTNG_KERNEL_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_SYSCALL_ENTRY;
                ev.u.syscall.abi = LTTNG_KERNEL_SYSCALL_ABI_NATIVE;
-               chan->sc_unknown = _lttng_event_create(chan, &ev, filter,
-                                               desc,
-                                               ev.instrumentation);
-               WARN_ON_ONCE(!chan->sc_unknown);
-               if (IS_ERR(chan->sc_unknown)) {
-                       return PTR_ERR(chan->sc_unknown);
+               event = _lttng_event_create(chan, &ev, filter, desc,
+                                           ev.instrumentation);
+               WARN_ON_ONCE(!event);
+               if (IS_ERR(event)) {
+                       return PTR_ERR(event);
                }
+               hlist_add_head(&event->u.syscall.node, &chan->sc_unknown);
        }
 
-       if (!chan->sc_compat_unknown) {
+       if (hlist_empty(&chan->sc_compat_unknown)) {
                const struct lttng_event_desc *desc =
                        &__event_desc___compat_syscall_entry_unknown;
+               struct lttng_event *event;
 
                memset(&ev, 0, sizeof(ev));
                strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
@@ -1189,18 +1253,19 @@ int lttng_syscalls_register_event(struct lttng_channel *chan, void *filter)
                ev.instrumentation = LTTNG_KERNEL_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_SYSCALL_ENTRY;
                ev.u.syscall.abi = LTTNG_KERNEL_SYSCALL_ABI_COMPAT;
-               chan->sc_compat_unknown = _lttng_event_create(chan, &ev, filter,
-                                               desc,
-                                               ev.instrumentation);
-               WARN_ON_ONCE(!chan->sc_unknown);
-               if (IS_ERR(chan->sc_compat_unknown)) {
-                       return PTR_ERR(chan->sc_compat_unknown);
+               event = _lttng_event_create(chan, &ev, filter, desc,
+                                           ev.instrumentation);
+               WARN_ON_ONCE(!event);
+               if (IS_ERR(event)) {
+                       return PTR_ERR(event);
                }
+               hlist_add_head(&event->u.syscall.node, &chan->sc_compat_unknown);
        }
 
-       if (!chan->compat_sc_exit_unknown) {
+       if (hlist_empty(&chan->compat_sc_exit_unknown)) {
                const struct lttng_event_desc *desc =
                        &__event_desc___compat_syscall_exit_unknown;
+               struct lttng_event *event;
 
                memset(&ev, 0, sizeof(ev));
                strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
@@ -1208,18 +1273,19 @@ int lttng_syscalls_register_event(struct lttng_channel *chan, void *filter)
                ev.instrumentation = LTTNG_KERNEL_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_SYSCALL_EXIT;
                ev.u.syscall.abi = LTTNG_KERNEL_SYSCALL_ABI_COMPAT;
-               chan->compat_sc_exit_unknown = _lttng_event_create(chan, &ev,
-                                               filter, desc,
-                                               ev.instrumentation);
-               WARN_ON_ONCE(!chan->compat_sc_exit_unknown);
-               if (IS_ERR(chan->compat_sc_exit_unknown)) {
-                       return PTR_ERR(chan->compat_sc_exit_unknown);
+               event = _lttng_event_create(chan, &ev, filter, desc,
+                                           ev.instrumentation);
+               WARN_ON_ONCE(!event);
+               if (IS_ERR(event)) {
+                       return PTR_ERR(event);
                }
+               hlist_add_head(&event->u.syscall.node, &chan->compat_sc_exit_unknown);
        }
 
-       if (!chan->sc_exit_unknown) {
+       if (hlist_empty(&chan->sc_exit_unknown)) {
                const struct lttng_event_desc *desc =
                        &__event_desc___syscall_exit_unknown;
+               struct lttng_event *event;
 
                memset(&ev, 0, sizeof(ev));
                strncpy(ev.name, desc->name, LTTNG_KERNEL_SYM_NAME_LEN);
@@ -1227,31 +1293,32 @@ int lttng_syscalls_register_event(struct lttng_channel *chan, void *filter)
                ev.instrumentation = LTTNG_KERNEL_SYSCALL;
                ev.u.syscall.entryexit = LTTNG_KERNEL_SYSCALL_EXIT;
                ev.u.syscall.abi = LTTNG_KERNEL_SYSCALL_ABI_NATIVE;
-               chan->sc_exit_unknown = _lttng_event_create(chan, &ev, filter,
-                                               desc, ev.instrumentation);
-               WARN_ON_ONCE(!chan->sc_exit_unknown);
-               if (IS_ERR(chan->sc_exit_unknown)) {
-                       return PTR_ERR(chan->sc_exit_unknown);
+               event = _lttng_event_create(chan, &ev, filter, desc,
+                                           ev.instrumentation);
+               WARN_ON_ONCE(!event);
+               if (IS_ERR(event)) {
+                       return PTR_ERR(event);
                }
+               hlist_add_head(&event->u.syscall.node, &chan->sc_exit_unknown);
        }
 
-       ret = fill_event_table(sc_table, ARRAY_SIZE(sc_table),
-                       chan->sc_table, chan, filter, SC_TYPE_ENTRY);
+       ret = lttng_create_syscall_event_if_missing(sc_table, ARRAY_SIZE(sc_table),
+                       chan->sc_table, event_enabler, filter, SC_TYPE_ENTRY);
        if (ret)
                return ret;
-       ret = fill_event_table(sc_exit_table, ARRAY_SIZE(sc_exit_table),
-                       chan->sc_exit_table, chan, filter, SC_TYPE_EXIT);
+       ret = lttng_create_syscall_event_if_missing(sc_exit_table, ARRAY_SIZE(sc_exit_table),
+                       chan->sc_exit_table, event_enabler, filter, SC_TYPE_EXIT);
        if (ret)
                return ret;
 
 #ifdef CONFIG_COMPAT
-       ret = fill_event_table(compat_sc_table, ARRAY_SIZE(compat_sc_table),
-                       chan->compat_sc_table, chan, filter,
+       ret = lttng_create_syscall_event_if_missing(compat_sc_table, ARRAY_SIZE(compat_sc_table),
+                       chan->compat_sc_table, event_enabler, filter,
                        SC_TYPE_COMPAT_ENTRY);
        if (ret)
                return ret;
-       ret = fill_event_table(compat_sc_exit_table, ARRAY_SIZE(compat_sc_exit_table),
-                       chan->compat_sc_exit_table, chan, filter,
+       ret = lttng_create_syscall_event_if_missing(compat_sc_exit_table, ARRAY_SIZE(compat_sc_exit_table),
+                       chan->compat_sc_exit_table, event_enabler, filter,
                        SC_TYPE_COMPAT_EXIT);
        if (ret)
                return ret;
@@ -1628,7 +1695,7 @@ end:
 /*
  * Unregister the syscall event_notifier probes from the callsites.
  */
-int lttng_syscalls_unregister_event_notifier(
+int lttng_syscalls_unregister_event_notifier_group(
                struct lttng_event_notifier_group *event_notifier_group)
 {
        int ret;
@@ -1662,7 +1729,7 @@ int lttng_syscalls_unregister_event_notifier(
        return 0;
 }
 
-int lttng_syscalls_unregister_event(struct lttng_channel *chan)
+int lttng_syscalls_unregister_channel(struct lttng_channel *chan)
 {
        int ret;
 
@@ -2125,7 +2192,8 @@ long lttng_channel_syscall_mask(struct lttng_channel *channel,
                char state;
 
                if (channel->sc_table) {
-                       if (!READ_ONCE(channel->syscall_all) && filter)
+                       if (!(READ_ONCE(channel->syscall_all_entry)
+                                       || READ_ONCE(channel->syscall_all_exit)) && filter)
                                state = test_bit(bit, filter->sc_entry)
                                        || test_bit(bit, filter->sc_exit);
                        else
@@ -2139,7 +2207,8 @@ long lttng_channel_syscall_mask(struct lttng_channel *channel,
                char state;
 
                if (channel->compat_sc_table) {
-                       if (!READ_ONCE(channel->syscall_all) && filter)
+                       if (!(READ_ONCE(channel->syscall_all_entry)
+                                       || READ_ONCE(channel->syscall_all_exit)) && filter)
                                state = test_bit(bit - ARRAY_SIZE(sc_table),
                                                filter->sc_compat_entry)
                                        || test_bit(bit - ARRAY_SIZE(sc_table),
This page took 0.038729 seconds and 5 git commands to generate.