From: Mathieu Desnoyers Date: Thu, 10 Feb 2022 20:40:25 +0000 (-0500) Subject: kretprobes: implement counter support X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=327374656ed97ef208450d0ae51ec475e4efeb49;p=lttng-modules.git kretprobes: implement counter support Signed-off-by: Mathieu Desnoyers Change-Id: I8e64712455b2812305250a45311b5b023281a1fe --- diff --git a/src/probes/lttng-kretprobes.c b/src/probes/lttng-kretprobes.c index 410e5f79..55866a82 100644 --- a/src/probes/lttng-kretprobes.c +++ b/src/probes/lttng-kretprobes.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -40,6 +41,7 @@ int _lttng_kretprobes_handler(struct kretprobe_instance *krpi, struct lttng_krp *lttng_krp = container_of(lttng_get_kretprobe(krpi), struct lttng_krp, krp); struct lttng_kernel_event_common *event = lttng_krp->event[type]; + struct lttng_kernel_channel_common *chan_common; struct lttng_kernel_probe_ctx lttng_probe_ctx = { .event = event, .interruptible = !lttng_regs_irqs_disabled(regs), @@ -49,27 +51,37 @@ int _lttng_kretprobes_handler(struct kretprobe_instance *krpi, unsigned long parent_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: - lttng_fallthrough; - 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: @@ -92,11 +104,20 @@ int _lttng_kretprobes_handler(struct kretprobe_instance *krpi, chan->ops->event_commit(&ctx); break; } + case LTTNG_KERNEL_EVENT_TYPE_COUNTER: + { + struct lttng_kernel_event_counter *event_counter = + container_of(event, struct lttng_kernel_event_counter, parent); + + (void) event_counter->chan->ops->event_counter_add(event_counter, 1); + break; + } case LTTNG_KERNEL_EVENT_TYPE_NOTIFIER: lttng_fallthrough; default: WARN_ON_ONCE(1); } +end: return 0; }