Record event as soon as one filter evaluates to TRUE
[lttng-modules.git] / probes / lttng-tracepoint-event-impl.h
index 0fee61aea756b677ca99d12be76328316b3f7f58..34561243b01502b79db9db6892c2add87f38047c 100644 (file)
@@ -1,22 +1,9 @@
-/*
+/* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
+ *
  * lttng-tracepoint-event-impl.h
  *
  * Copyright (C) 2009 Steven Rostedt <rostedt@goodmis.org>
  * Copyright (C) 2009-2014 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
  */
 
 #include <linux/uaccess.h>
@@ -32,6 +19,7 @@
 #include <wrapper/ringbuffer/frontend_types.h>
 #include <wrapper/ringbuffer/backend.h>
 #include <wrapper/rcu.h>
+#include <wrapper/user_namespace.h>
 #include <lttng-events.h>
 #include <lttng-tracer-core.h>
 #include <lttng-tp-mempool.h>
@@ -1140,7 +1128,7 @@ static void __event_probe__##_name(void *__data, _proto)                \
        struct probe_local_vars __tp_locvar;                                  \
        struct probe_local_vars *tp_locvar __attribute__((unused)) =          \
                        &__tp_locvar;                                         \
-       struct lttng_pid_tracker *__lpf;                                      \
+       struct lttng_id_tracker_rcu *__lf;                                    \
                                                                              \
        if (!_TP_SESSION_CHECK(session, __session))                           \
                return;                                                       \
@@ -1150,8 +1138,27 @@ static void __event_probe__##_name(void *__data, _proto)               \
                return;                                                       \
        if (unlikely(!READ_ONCE(__event->enabled)))                           \
                return;                                                       \
-       __lpf = lttng_rcu_dereference(__session->pid_tracker);                \
-       if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->tgid))) \
+       __lf = lttng_rcu_dereference(__session->pid_tracker.p);               \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid)))    \
+               return;                                                       \
+       __lf = lttng_rcu_dereference(__session->vpid_tracker.p);              \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \
+               return;                                                       \
+       __lf = lttng_rcu_dereference(__session->uid_tracker.p);               \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf,                     \
+                       lttng_current_uid())))                                \
+               return;                                                       \
+       __lf = lttng_rcu_dereference(__session->vuid_tracker.p);              \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf,                     \
+                       lttng_current_vuid())))                               \
+               return;                                                       \
+       __lf = lttng_rcu_dereference(__session->gid_tracker.p);               \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf,                     \
+                       lttng_current_gid())))                                \
+               return;                                                       \
+       __lf = lttng_rcu_dereference(__session->vgid_tracker.p);              \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf,                     \
+                       lttng_current_vgid())))                               \
                return;                                                       \
        __orig_dynamic_len_offset = this_cpu_ptr(&lttng_dynamic_len_stack)->offset; \
        __dynamic_len_idx = __orig_dynamic_len_offset;                        \
@@ -1164,8 +1171,10 @@ static void __event_probe__##_name(void *__data, _proto)               \
                                tp_locvar, _args);                                    \
                lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
                        if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx,       \
-                                       __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
+                                       __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
                                __filter_record = 1;                          \
+                               break;                                        \
+                       }                                                     \
                }                                                             \
                if (likely(!__filter_record))                                 \
                        goto __post;                                          \
@@ -1214,7 +1223,7 @@ static void __event_probe__##_name(void *__data)                        \
        struct probe_local_vars __tp_locvar;                                  \
        struct probe_local_vars *tp_locvar __attribute__((unused)) =          \
                        &__tp_locvar;                                         \
-       struct lttng_pid_tracker *__lpf;                                      \
+       struct lttng_id_tracker_rcu *__lf;                                    \
                                                                              \
        if (!_TP_SESSION_CHECK(session, __session))                           \
                return;                                                       \
@@ -1224,8 +1233,27 @@ static void __event_probe__##_name(void *__data)                       \
                return;                                                       \
        if (unlikely(!READ_ONCE(__event->enabled)))                           \
                return;                                                       \
-       __lpf = lttng_rcu_dereference(__session->pid_tracker);                \
-       if (__lpf && likely(!lttng_pid_tracker_lookup(__lpf, current->tgid)))  \
+       __lf = lttng_rcu_dereference(__session->pid_tracker.p);               \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf, current->tgid)))    \
+               return;                                                       \
+       __lf = lttng_rcu_dereference(__session->vpid_tracker.p);              \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf, task_tgid_vnr(current)))) \
+               return;                                                       \
+       __lf = lttng_rcu_dereference(__session->uid_tracker.p);               \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf,                     \
+                       lttng_current_uid())))                                \
+               return;                                                       \
+       __lf = lttng_rcu_dereference(__session->vuid_tracker.p);              \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf,                     \
+                       lttng_current_vuid())))                               \
+               return;                                                       \
+       __lf = lttng_rcu_dereference(__session->gid_tracker.p);               \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf,                     \
+                       lttng_current_gid())))                                \
+               return;                                                       \
+       __lf = lttng_rcu_dereference(__session->vgid_tracker.p);              \
+       if (__lf && likely(!lttng_id_tracker_lookup(__lf,                     \
+                       lttng_current_vgid())))                               \
                return;                                                       \
        __orig_dynamic_len_offset = this_cpu_ptr(&lttng_dynamic_len_stack)->offset; \
        __dynamic_len_idx = __orig_dynamic_len_offset;                        \
@@ -1238,8 +1266,10 @@ static void __event_probe__##_name(void *__data)                       \
                                tp_locvar);                                   \
                lttng_list_for_each_entry_rcu(bc_runtime, &__event->bytecode_runtime_head, node) { \
                        if (unlikely(bc_runtime->filter(bc_runtime, &__lttng_probe_ctx, \
-                                       __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
+                                       __stackvar.__filter_stack_data) & LTTNG_FILTER_RECORD_FLAG)) \
                                __filter_record = 1;                          \
+                               break;                                        \
+                       }                                                     \
                }                                                             \
                if (likely(!__filter_record))                                 \
                        goto __post;                                          \
This page took 0.024675 seconds and 4 git commands to generate.