From 45ce950feda732e773bdeebeb6d6450989a8d48d Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Mon, 13 Apr 2020 15:13:06 -0400 Subject: [PATCH] callstack context: use GPL-exported symbols --- lttng-context-callstack-legacy-impl.h | 35 +++----------- lttng-context-callstack-stackwalk-impl.h | 59 +----------------------- lttng-context-callstack.c | 4 -- 3 files changed, 8 insertions(+), 90 deletions(-) diff --git a/lttng-context-callstack-legacy-impl.h b/lttng-context-callstack-legacy-impl.h index 8d78fb95..adcb0842 100644 --- a/lttng-context-callstack-legacy-impl.h +++ b/lttng-context-callstack-legacy-impl.h @@ -37,22 +37,16 @@ struct field_data { struct lttng_cs_type { const char *name; const char *length_name; - const char *save_func_name; - void (*save_func)(struct stack_trace *trace); }; static struct lttng_cs_type cs_types[] = { { .name = "callstack_kernel", .length_name = "_callstack_kernel_length", - .save_func_name = "save_stack_trace", - .save_func = NULL, }, { .name = "callstack_user", .length_name = "_callstack_user_length", - .save_func_name = "save_stack_trace_user", - .save_func = NULL, }, }; @@ -68,23 +62,6 @@ const char *lttng_cs_ctx_mode_length_name(enum lttng_cs_ctx_modes mode) return cs_types[mode].length_name; } -static -int init_type(enum lttng_cs_ctx_modes mode) -{ - unsigned long func; - - if (cs_types[mode].save_func) - return 0; - func = kallsyms_lookup_funcptr(cs_types[mode].save_func_name); - if (!func) { - printk(KERN_WARNING "LTTng: symbol lookup failed: %s\n", - cs_types[mode].save_func_name); - return -EINVAL; - } - cs_types[mode].save_func = (void *) func; - return 0; -} - static void lttng_cs_set_init(struct lttng_cs __percpu *cs_set) { @@ -174,14 +151,14 @@ size_t lttng_callstack_sequence_get_size(size_t offset, struct lttng_ctx_field * /* reset stack trace, no need to clear memory */ trace->nr_entries = 0; - if (fdata->mode == CALLSTACK_USER) + if (fdata->mode == CALLSTACK_USER) { ++per_cpu(callstack_user_nesting, ctx->cpu); - - /* do the real work and reserve space */ - cs_types[fdata->mode].save_func(trace); - - if (fdata->mode == CALLSTACK_USER) + /* do the real work and reserve space */ + save_stack_trace_user(trace); per_cpu(callstack_user_nesting, ctx->cpu)--; + } else { + save_stack_trace(trace); + } /* * Remove final ULONG_MAX delimiter. If we cannot find it, add diff --git a/lttng-context-callstack-stackwalk-impl.h b/lttng-context-callstack-stackwalk-impl.h index 42f4273d..c227efb2 100644 --- a/lttng-context-callstack-stackwalk-impl.h +++ b/lttng-context-callstack-stackwalk-impl.h @@ -34,12 +34,6 @@ struct field_data { enum lttng_cs_ctx_modes mode; }; -static -unsigned int (*save_func_kernel)(unsigned long *store, unsigned int size, - unsigned int skipnr); -static -unsigned int (*save_func_user)(unsigned long *store, unsigned int size); - static const char *lttng_cs_ctx_mode_name(enum lttng_cs_ctx_modes mode) { @@ -66,55 +60,6 @@ const char *lttng_cs_ctx_mode_length_name(enum lttng_cs_ctx_modes mode) } } -static -int init_type_callstack_kernel(void) -{ - unsigned long func; - const char *func_name = "stack_trace_save"; - - if (save_func_kernel) - return 0; - func = kallsyms_lookup_funcptr(func_name); - if (!func) { - printk(KERN_WARNING "LTTng: symbol lookup failed: %s\n", - func_name); - return -EINVAL; - } - save_func_kernel = (void *) func; - return 0; -} - -static -int init_type_callstack_user(void) -{ - unsigned long func; - const char *func_name = "stack_trace_save_user"; - - if (save_func_user) - return 0; - func = kallsyms_lookup_funcptr(func_name); - if (!func) { - printk(KERN_WARNING "LTTng: symbol lookup failed: %s\n", - func_name); - return -EINVAL; - } - save_func_user = (void *) func; - return 0; -} - -static -int init_type(enum lttng_cs_ctx_modes mode) -{ - switch (mode) { - case CALLSTACK_KERNEL: - return init_type_callstack_kernel(); - case CALLSTACK_USER: - return init_type_callstack_user(); - default: - return -EINVAL; - } -} - static void lttng_cs_set_init(struct lttng_cs __percpu *cs_set) { @@ -193,13 +138,13 @@ size_t lttng_callstack_sequence_get_size(size_t offset, struct lttng_ctx_field * switch (fdata->mode) { case CALLSTACK_KERNEL: /* do the real work and reserve space */ - trace->nr_entries = save_func_kernel(trace->entries, + trace->nr_entries = stack_trace_save(trace->entries, MAX_ENTRIES, 0); break; case CALLSTACK_USER: ++per_cpu(callstack_user_nesting, ctx->cpu); /* do the real work and reserve space */ - trace->nr_entries = save_func_user(trace->entries, + trace->nr_entries = stack_trace_save_user(trace->entries, MAX_ENTRIES); per_cpu(callstack_user_nesting, ctx->cpu)--; break; diff --git a/lttng-context-callstack.c b/lttng-context-callstack.c index e97b1db2..801ddd60 100644 --- a/lttng-context-callstack.c +++ b/lttng-context-callstack.c @@ -46,7 +46,6 @@ #include "lttng-events.h" #include "wrapper/ringbuffer/backend.h" #include "wrapper/ringbuffer/frontend.h" -#include "wrapper/kallsyms.h" #include "lttng-tracer.h" #include "lttng-endian.h" @@ -109,9 +108,6 @@ int __lttng_add_callstack_generic(struct lttng_ctx **ctx, struct field_data *fdata; int ret; - ret = init_type(mode); - if (ret) - return ret; length_field = lttng_append_context(ctx); if (!length_field) return -ENOMEM; -- 2.34.1