From: Mathieu Desnoyers Date: Tue, 2 Nov 2021 16:31:08 +0000 (-0400) Subject: Refactoring: syscalls: combine syscalls register event for notifier/recorder X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=d26015f62c573e6d544f05caa25f0b0f645ef20c;p=lttng-modules.git Refactoring: syscalls: combine syscalls register event for notifier/recorder Signed-off-by: Mathieu Desnoyers Change-Id: I907ac0397d0fdf421702d50ee382eb5e79827921 --- diff --git a/include/lttng/events-internal.h b/include/lttng/events-internal.h index aceabbe4..4b5883ed 100644 --- a/include/lttng/events-internal.h +++ b/include/lttng/events-internal.h @@ -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) -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); @@ -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); -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 -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; } @@ -855,12 +853,6 @@ static inline long lttng_channel_syscall_mask(struct lttng_kernel_channel_buffer 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; diff --git a/src/lttng-events.c b/src/lttng-events.c index 270ee573..7181f0fb 100644 --- a/src/lttng-events.c +++ b/src/lttng-events.c @@ -2243,7 +2243,7 @@ void lttng_create_syscall_event_if_missing(struct lttng_event_recorder_enabler * { int ret; - ret = lttng_syscalls_register_event_recorder(event_enabler); + ret = lttng_syscalls_register_event(&event_enabler->parent); WARN_ON_ONCE(ret); } @@ -2252,7 +2252,7 @@ void lttng_create_syscall_event_notifier_if_missing(struct lttng_event_notifier_ { 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); diff --git a/src/lttng-syscalls.c b/src/lttng-syscalls.c index f72afbe2..1194b95d 100644 --- a/src/lttng-syscalls.c +++ b/src/lttng-syscalls.c @@ -613,46 +613,20 @@ int lttng_create_syscall_event_if_missing(const struct trace_syscall_entry *tabl 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; - 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; @@ -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; - 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; } @@ -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; - 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; } @@ -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; - 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; } @@ -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; - 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; } @@ -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, - 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, - 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, - 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, - 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 (!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. */ -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) { + /* 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) { - 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; } + #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_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->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; } + 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); @@ -858,7 +806,6 @@ int lttng_syscalls_register_event_notifier( 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); @@ -869,7 +816,6 @@ int lttng_syscalls_register_event_notifier( } syscall_table->sys_exit_registered = 1; } - return ret; }