Drop support for kernels < 3.0 from skb instrumentation
[lttng-modules.git] / lttng-events.c
index c1f00ff5c9000ac8d6c32026a00b17baa773cad5..566080a3a4c1be92ea01e9e6b2af497fd040d007 100644 (file)
@@ -1,23 +1,10 @@
-/*
+/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
+ *
  * lttng-events.c
  *
  * Holds LTTng per-session event registry.
  *
  * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; only
- * version 2.1 of the License.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /*
@@ -40,8 +27,8 @@
 #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/random.h>
 #include <wrapper/tracepoint.h>
@@ -53,7 +40,6 @@
 #include <lttng-abi-old.h>
 #include <lttng-endian.h>
 #include <lttng-string-utils.h>
-#include <wrapper/vzalloc.h>
 #include <wrapper/ringbuffer/backend.h>
 #include <wrapper/ringbuffer/frontend.h>
 
@@ -143,7 +129,7 @@ struct lttng_session *lttng_session_create(void)
                        GFP_KERNEL);
        if (!metadata_cache)
                goto err_free_session;
-       metadata_cache->data = lttng_vzalloc(METADATA_CACHE_DEFAULT_SIZE);
+       metadata_cache->data = vzalloc(METADATA_CACHE_DEFAULT_SIZE);
        if (!metadata_cache->data)
                goto err_free_cache;
        metadata_cache->cache_alloc = METADATA_CACHE_DEFAULT_SIZE;
@@ -239,6 +225,9 @@ int lttng_session_enable(struct lttng_session *session)
        /* Set transient enabler state to "enabled" */
        session->tstate = 1;
 
+       /* We need to sync enablers with session before activation. */
+       lttng_session_sync_enablers(session);
+
        /*
         * Snapshot the number of events per channel to know the type of header
         * we need to use.
@@ -252,9 +241,6 @@ int lttng_session_enable(struct lttng_session *session)
                        chan->header_type = 2;  /* large */
        }
 
-       /* We need to sync enablers with session before activation. */
-       lttng_session_sync_enablers(session);
-
        /* Clear each stream's quiescent state. */
        list_for_each_entry(chan, &session->chan, list) {
                if (chan->channel_type != METADATA_CHANNEL)
@@ -408,6 +394,7 @@ int lttng_event_enable(struct lttng_event *event)
                break;
        case LTTNG_KERNEL_KPROBE:
        case LTTNG_KERNEL_FUNCTION:
+       case LTTNG_KERNEL_UPROBE:
        case LTTNG_KERNEL_NOOP:
                WRITE_ONCE(event->enabled, 1);
                break;
@@ -443,6 +430,7 @@ int lttng_event_disable(struct lttng_event *event)
                break;
        case LTTNG_KERNEL_KPROBE:
        case LTTNG_KERNEL_FUNCTION:
+       case LTTNG_KERNEL_UPROBE:
        case LTTNG_KERNEL_NOOP:
                WRITE_ONCE(event->enabled, 0);
                break;
@@ -589,6 +577,7 @@ struct lttng_event *_lttng_event_create(struct lttng_channel *chan,
                event_name = event_desc->name;
                break;
        case LTTNG_KERNEL_KPROBE:
+       case LTTNG_KERNEL_UPROBE:
        case LTTNG_KERNEL_KRETPROBE:
        case LTTNG_KERNEL_FUNCTION:
        case LTTNG_KERNEL_NOOP:
@@ -752,6 +741,28 @@ struct lttng_event *_lttng_event_create(struct lttng_channel *chan,
                        goto register_error;
                }
                break;
+       case LTTNG_KERNEL_UPROBE:
+               /*
+                * 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_uprobes_register(event_param->name,
+                               event_param->u.uprobe.fd,
+                               event);
+               if (ret)
+                       goto register_error;
+               ret = try_module_get(event->desc->owner);
+               WARN_ON_ONCE(!ret);
+               break;
        default:
                WARN_ON_ONCE(1);
                ret = -EINVAL;
@@ -814,6 +825,7 @@ void register_event(struct lttng_event *event)
                        desc->name);
                break;
        case LTTNG_KERNEL_KPROBE:
+       case LTTNG_KERNEL_UPROBE:
        case LTTNG_KERNEL_KRETPROBE:
        case LTTNG_KERNEL_FUNCTION:
        case LTTNG_KERNEL_NOOP:
@@ -863,6 +875,10 @@ int _lttng_event_unregister(struct lttng_event *event)
        case LTTNG_KERNEL_NOOP:
                ret = 0;
                break;
+       case LTTNG_KERNEL_UPROBE:
+               lttng_uprobes_unregister(event);
+               ret = 0;
+               break;
        default:
                WARN_ON_ONCE(1);
        }
@@ -896,6 +912,10 @@ void _lttng_event_destroy(struct lttng_event *event)
        case LTTNG_KERNEL_NOOP:
        case LTTNG_KERNEL_SYSCALL:
                break;
+       case LTTNG_KERNEL_UPROBE:
+               module_put(event->desc->owner);
+               lttng_uprobes_destroy_private(event);
+               break;
        default:
                WARN_ON_ONCE(1);
        }
@@ -1445,6 +1465,18 @@ error_free:
        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)
 {
@@ -1659,7 +1691,7 @@ int lttng_metadata_printf(struct lttng_session *session,
                tmp_cache_alloc_size = max_t(unsigned int,
                                session->metadata_cache->cache_alloc + len,
                                session->metadata_cache->cache_alloc << 1);
-               tmp_cache_realloc = lttng_vzalloc(tmp_cache_alloc_size);
+               tmp_cache_realloc = vzalloc(tmp_cache_alloc_size);
                if (!tmp_cache_realloc)
                        goto err;
                if (session->metadata_cache->data) {
@@ -2899,7 +2931,7 @@ MODULE_INFO(extra_version_name, LTTNG_EXTRA_VERSION_NAME);
 #endif
 MODULE_LICENSE("GPL and additional rights");
 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
-MODULE_DESCRIPTION("LTTng Events");
+MODULE_DESCRIPTION("LTTng tracer");
 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
        __stringify(LTTNG_MODULES_MINOR_VERSION) "."
        __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
This page took 0.026345 seconds and 4 git commands to generate.