uprobe: implement counter support
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Thu, 10 Feb 2022 20:41:58 +0000 (15:41 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 15 Jul 2024 20:58:48 +0000 (16:58 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Change-Id: I46909ecc57a15d5f0c6b58e1f2f254219e55e01d

src/probes/lttng-uprobes.c

index 5463251aae982847e441afbbf790565bf9c3501b..bf4305f37fe77b1753ef3bb38551b9514b4b6e77 100644 (file)
@@ -22,6 +22,7 @@
 #include <lttng/events-internal.h>
 #include <lttng/tracer.h>
 #include <wrapper/irqflags.h>
+#include <wrapper/rcu.h>
 #include <ringbuffer/frontend_types.h>
 #include <wrapper/vmalloc.h>
 
@@ -31,6 +32,7 @@ int lttng_uprobes_event_handler_pre(struct uprobe_consumer *uc, struct pt_regs *
        struct lttng_uprobe_handler *uprobe_handler =
                container_of(uc, struct lttng_uprobe_handler, up_consumer);
        struct lttng_kernel_event_common *event = uprobe_handler->event;
+       struct lttng_kernel_channel_common *chan_common;
        struct lttng_kernel_probe_ctx lttng_probe_ctx = {
                .event = event,
                .interruptible = !lttng_regs_irqs_disabled(regs),
@@ -39,28 +41,37 @@ int lttng_uprobes_event_handler_pre(struct uprobe_consumer *uc, struct pt_regs *
                unsigned long ip;
        } payload;
 
-       switch (event->type) {
-       case LTTNG_KERNEL_EVENT_TYPE_RECORDER:
-       {
-               struct lttng_kernel_event_recorder *event_recorder =
-                       container_of(event, struct lttng_kernel_event_recorder, parent);
-               struct lttng_kernel_channel_buffer *chan = event_recorder->chan;
-
-               if (unlikely(!LTTNG_READ_ONCE(chan->parent.session->active)))
-                       return 0;
-               if (unlikely(!LTTNG_READ_ONCE(chan->parent.enabled)))
-                       return 0;
-               break;
-       }
-       case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER:
-               break;
-       default:
-               WARN_ON_ONCE(1);
-       }
-
        if (unlikely(!LTTNG_READ_ONCE(event->enabled)))
-               return 0;
+               goto end;
 
+       chan_common = lttng_kernel_get_chan_common_from_event_common(event);
+       if (chan_common) {
+               struct lttng_kernel_session *session = chan_common->session;
+               struct lttng_kernel_id_tracker_rcu *lf;
+
+               if (unlikely(!LTTNG_READ_ONCE(session->active)))
+                       goto end;
+               if (unlikely(!LTTNG_READ_ONCE(chan_common->enabled)))
+                       goto end;
+               lf = lttng_rcu_dereference(session->pid_tracker.p);
+               if (lf && likely(!lttng_id_tracker_lookup(lf, current->tgid)))
+                       goto end;
+               lf = lttng_rcu_dereference(session->vpid_tracker.p);
+               if (lf && likely(!lttng_id_tracker_lookup(lf, task_tgid_vnr(current))))
+                       goto end;
+               lf = lttng_rcu_dereference(session->uid_tracker.p);
+               if (lf && likely(!lttng_id_tracker_lookup(lf, from_kuid_munged(&init_user_ns, current_uid()))))
+                       goto end;
+               lf = lttng_rcu_dereference(session->vuid_tracker.p);
+               if (lf && likely(!lttng_id_tracker_lookup(lf, from_kuid_munged(current_user_ns(), current_uid()))))
+                       goto end;
+               lf = lttng_rcu_dereference(session->gid_tracker.p);
+               if (lf && likely(!lttng_id_tracker_lookup(lf, from_kgid_munged(&init_user_ns, current_gid()))))
+                       goto end;
+               lf = lttng_rcu_dereference(session->vgid_tracker.p);
+               if (lf && likely(!lttng_id_tracker_lookup(lf, from_kgid_munged(current_user_ns(), current_gid()))))
+                       goto end;
+       }
        switch (event->type) {
        case LTTNG_KERNEL_EVENT_TYPE_RECORDER:
        {
@@ -94,9 +105,21 @@ int lttng_uprobes_event_handler_pre(struct uprobe_consumer *uc, struct pt_regs *
                event_notifier->notification_send(event_notifier, NULL, NULL, &notif_ctx);
                break;
        }
+       case LTTNG_KERNEL_EVENT_TYPE_COUNTER:
+       {
+               struct lttng_kernel_event_counter *event_counter =
+                       container_of(event, struct lttng_kernel_event_counter, parent);
+
+               /* uprobes is invoked with preemption enabled. */
+               rcu_read_lock_sched_notrace();
+               (void) event_counter->chan->ops->event_counter_add(event_counter, 1);
+               rcu_read_unlock_sched_notrace();
+               break;
+       }
        default:
                WARN_ON_ONCE(1);
        }
+end:
        return 0;
 }
 
This page took 0.028764 seconds and 4 git commands to generate.