#include <linux/jhash.h>
#include <linux/uaccess.h>
#include <linux/vmalloc.h>
+#include <linux/uuid.h>
#include <wrapper/uuid.h>
-#include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
+#include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_mappings() */
#include <wrapper/random.h>
#include <wrapper/tracepoint.h>
#include <wrapper/list.h>
#include <wrapper/vzalloc.h>
#include <wrapper/ringbuffer/backend.h>
#include <wrapper/ringbuffer/frontend.h>
+#include <wrapper/time.h>
#define METADATA_CACHE_DEFAULT_SIZE 4096
void synchronize_trace(void)
{
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0))
+ synchronize_rcu();
+#else
synchronize_sched();
+#endif
+
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
#ifdef CONFIG_PREEMPT_RT_FULL
synchronize_rcu();
goto err;
INIT_LIST_HEAD(&session->chan);
INIT_LIST_HEAD(&session->events);
- uuid_le_gen(&session->uuid);
+ lttng_guid_gen(&session->uuid);
metadata_cache = kzalloc(sizeof(struct lttng_metadata_cache),
GFP_KERNEL);
ret = -EINVAL;
break;
case LTTNG_KERNEL_KPROBE:
- case LTTNG_KERNEL_FUNCTION:
case LTTNG_KERNEL_UPROBE:
case LTTNG_KERNEL_NOOP:
WRITE_ONCE(event->enabled, 1);
case LTTNG_KERNEL_KRETPROBE:
ret = lttng_kretprobes_event_enable_state(event, 1);
break;
+ case LTTNG_KERNEL_FUNCTION: /* Fall-through. */
default:
WARN_ON_ONCE(1);
ret = -EINVAL;
ret = -EINVAL;
break;
case LTTNG_KERNEL_KPROBE:
- case LTTNG_KERNEL_FUNCTION:
case LTTNG_KERNEL_UPROBE:
case LTTNG_KERNEL_NOOP:
WRITE_ONCE(event->enabled, 0);
case LTTNG_KERNEL_KRETPROBE:
ret = lttng_kretprobes_event_enable_state(event, 0);
break;
+ case LTTNG_KERNEL_FUNCTION: /* Fall-through. */
default:
WARN_ON_ONCE(1);
ret = -EINVAL;
case LTTNG_KERNEL_KPROBE:
case LTTNG_KERNEL_UPROBE:
case LTTNG_KERNEL_KRETPROBE:
- case LTTNG_KERNEL_FUNCTION:
case LTTNG_KERNEL_NOOP:
case LTTNG_KERNEL_SYSCALL:
event_name = event_param->name;
break;
+ case LTTNG_KERNEL_FUNCTION: /* Fall-through. */
default:
WARN_ON_ONCE(1);
ret = -EINVAL;
list_add(&event_return->list, &chan->session->events);
break;
}
- case LTTNG_KERNEL_FUNCTION:
- /*
- * Needs to be explicitly enabled after creation, since
- * we may want to apply filters.
- */
- event->enabled = 0;
- event->registered = 1;
- /*
- * Populate lttng_event structure before event
- * registration.
- */
- smp_wmb();
- ret = lttng_ftrace_register(event_name,
- event_param->u.ftrace.symbol_name,
- event);
- if (ret) {
- goto register_error;
- }
- ret = try_module_get(event->desc->owner);
- WARN_ON_ONCE(!ret);
- break;
case LTTNG_KERNEL_NOOP:
case LTTNG_KERNEL_SYSCALL:
/*
*/
event->enabled = 0;
event->registered = 1;
+
/*
* Populate lttng_event structure before event
* registration.
ret = lttng_uprobes_register(event_param->name,
event_param->u.uprobe.fd,
- event_param->u.uprobe.offset,
event);
if (ret)
goto register_error;
ret = try_module_get(event->desc->owner);
WARN_ON_ONCE(!ret);
break;
+ case LTTNG_KERNEL_FUNCTION: /* Fall-through */
default:
WARN_ON_ONCE(1);
ret = -EINVAL;
case LTTNG_KERNEL_KPROBE:
case LTTNG_KERNEL_UPROBE:
case LTTNG_KERNEL_KRETPROBE:
- case LTTNG_KERNEL_FUNCTION:
case LTTNG_KERNEL_NOOP:
ret = 0;
break;
+ case LTTNG_KERNEL_FUNCTION: /* Fall-through */
default:
WARN_ON_ONCE(1);
}
lttng_kretprobes_unregister(event);
ret = 0;
break;
- case LTTNG_KERNEL_FUNCTION:
- lttng_ftrace_unregister(event);
- ret = 0;
- break;
case LTTNG_KERNEL_SYSCALL:
ret = lttng_syscall_filter_disable(event->chan,
desc->name);
lttng_uprobes_unregister(event);
ret = 0;
break;
+ case LTTNG_KERNEL_FUNCTION: /* Fall-through */
default:
WARN_ON_ONCE(1);
}
module_put(event->desc->owner);
lttng_kretprobes_destroy_private(event);
break;
- case LTTNG_KERNEL_FUNCTION:
- module_put(event->desc->owner);
- lttng_ftrace_destroy_private(event);
- break;
case LTTNG_KERNEL_NOOP:
case LTTNG_KERNEL_SYSCALL:
break;
module_put(event->desc->owner);
lttng_uprobes_destroy_private(event);
break;
+ case LTTNG_KERNEL_FUNCTION: /* Fall-through */
default:
WARN_ON_ONCE(1);
}
ret = PTR_ERR(tracker_pids_list_file);
goto file_error;
}
- if (atomic_long_add_unless(&session->file->f_count,
- 1, INT_MAX) == INT_MAX) {
+ if (!atomic_long_add_unless(&session->file->f_count, 1, LONG_MAX)) {
+ ret = -EOVERFLOW;
goto refcount_error;
}
ret = lttng_tracker_pids_list_fops.open(NULL, tracker_pids_list_file);
return ret;
}
+int lttng_event_add_callsite(struct lttng_event *event,
+ struct lttng_kernel_event_callsite __user *callsite)
+{
+
+ switch (event->instrumentation) {
+ case LTTNG_KERNEL_UPROBE:
+ return lttng_uprobes_add_callsite(event, callsite);
+ default:
+ return -EINVAL;
+ }
+}
+
int lttng_enabler_attach_context(struct lttng_enabler *enabler,
struct lttng_kernel_context *context_param)
{
* in future versions.
* This function may return a negative offset. It may happen if the
* system sets the REALTIME clock to 0 after boot.
+ *
+ * Use 64bit timespec on kernels that have it, this makes 32bit arch
+ * y2038 compliant.
*/
static
int64_t measure_clock_offset(void)
uint64_t monotonic_avg, monotonic[2], realtime;
uint64_t tcf = trace_clock_freq();
int64_t offset;
- struct timespec rts = { 0, 0 };
unsigned long flags;
+#ifdef LTTNG_KERNEL_HAS_TIMESPEC64
+ struct timespec64 rts = { 0, 0 };
+#else
+ struct timespec rts = { 0, 0 };
+#endif
/* Disable interrupts to increase correlation precision. */
local_irq_save(flags);
monotonic[0] = trace_clock_read64();
+#ifdef LTTNG_KERNEL_HAS_TIMESPEC64
+ ktime_get_real_ts64(&rts);
+#else
getnstimeofday(&rts);
+#endif
monotonic[1] = trace_clock_read64();
local_irq_restore(flags);
return offset;
}
+static
+int print_escaped_ctf_string(struct lttng_session *session, const char *string)
+{
+ int ret;
+ size_t i;
+ char cur;
+
+ i = 0;
+ cur = string[i];
+ while (cur != '\0') {
+ switch (cur) {
+ case '\n':
+ ret = lttng_metadata_printf(session, "%s", "\\n");
+ break;
+ case '\\':
+ case '"':
+ ret = lttng_metadata_printf(session, "%c", '\\');
+ if (ret)
+ goto error;
+ /* We still print the current char */
+ /* Fallthrough */
+ default:
+ ret = lttng_metadata_printf(session, "%c", cur);
+ break;
+ }
+
+ if (ret)
+ goto error;
+
+ cur = string[++i];
+ }
+error:
+ return ret;
+}
+
+static
+int print_metadata_escaped_field(struct lttng_session *session, const char *field,
+ const char *field_value)
+{
+ int ret;
+
+ ret = lttng_metadata_printf(session, " %s = \"", field);
+ if (ret)
+ goto error;
+
+ ret = print_escaped_ctf_string(session, field_value);
+ if (ret)
+ goto error;
+
+ ret = lttng_metadata_printf(session, "\";\n");
+
+error:
+ return ret;
+}
+
/*
* Output metadata into this session's metadata buffers.
* Must be called with sessions_mutex held.
" tracer_major = %d;\n"
" tracer_minor = %d;\n"
" tracer_patchlevel = %d;\n"
- "};\n\n",
+ " trace_buffering_scheme = \"global\";\n",
current->nsproxy->uts_ns->name.nodename,
utsname()->sysname,
utsname()->release,
if (ret)
goto end;
+ ret = print_metadata_escaped_field(session, "trace_name", session->name);
+ if (ret)
+ goto end;
+ ret = print_metadata_escaped_field(session, "trace_creation_datetime",
+ session->creation_time);
+ if (ret)
+ goto end;
+
+ /* Close env */
+ ret = lttng_metadata_printf(session, "};\n\n");
+ if (ret)
+ goto end;
+
ret = lttng_metadata_printf(session,
"clock {\n"
" name = \"%s\";\n",
* Registers a transport which can be used as output to extract the data out of
* LTTng. The module calling this registration function must ensure that no
* trap-inducing code will be executed by the transport functions. E.g.
- * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
+ * vmalloc_sync_mappings() must be called between a vmalloc and the moment the memory
* is made visible to the transport function. This registration acts as a
- * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
+ * vmalloc_sync_mappings. Therefore, only if the module allocates virtual memory
* after its registration must it synchronize the TLBs.
*/
void lttng_transport_register(struct lttng_transport *transport)
/*
* Make sure no page fault can be triggered by the module about to be
* registered. We deal with this here so we don't have to call
- * vmalloc_sync_all() in each module's init.
+ * vmalloc_sync_mappings() in each module's init.
*/
- wrapper_vmalloc_sync_all();
+ wrapper_vmalloc_sync_mappings();
mutex_lock(&sessions_mutex);
list_add_tail(&transport->node, <tng_transport_list);