1 /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only)
5 * Holds LTTng per-session event registry.
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #ifndef _LTTNG_EVENTS_H
11 #define _LTTNG_EVENTS_H
13 #include <lttng/kernel-version.h>
14 #include <linux/list.h>
15 #include <linux/kprobes.h>
16 #include <linux/kref.h>
17 #include <linux/uuid.h>
18 #include <linux/irq_work.h>
19 #include <wrapper/uprobes.h>
20 #include <lttng/cpuhotplug.h>
21 #include <lttng/tracer.h>
22 #include <lttng/abi.h>
23 #include <lttng/abi-old.h>
24 #include <lttng/endian.h>
26 #define lttng_is_signed_type(type) (((type) -1) < (type) 1)
29 struct lttng_kernel_session
;
30 struct lttng_metadata_cache
;
31 struct lttng_kernel_ring_buffer_ctx
;
33 struct perf_event_attr
;
34 struct lib_ring_buffer_config
;
36 /* Type description */
38 enum lttng_kernel_type
{
39 lttng_kernel_type_integer
,
40 lttng_kernel_type_string
,
41 lttng_kernel_type_enum
,
42 lttng_kernel_type_array
,
43 lttng_kernel_type_sequence
,
44 lttng_kernel_type_struct
,
45 lttng_kernel_type_variant
,
46 NR_LTTNG_KERNEL_TYPES
,
49 enum lttng_kernel_string_encoding
{
50 lttng_kernel_string_encoding_none
= 0,
51 lttng_kernel_string_encoding_UTF8
= 1,
52 lttng_kernel_string_encoding_ASCII
= 2,
53 NR_LTTNG_KERNEL_STRING_ENCODING
,
61 struct lttng_kernel_enum_value
{
62 unsigned long long value
;
63 unsigned int signedness
:1;
66 struct lttng_kernel_enum_entry
{
67 struct lttng_kernel_enum_value start
, end
; /* start and end are inclusive */
70 unsigned int is_auto
:1;
75 * struct lttng_kernel_type_common is fixed-size. Its children inherits
76 * from it by embedding struct lttng_kernel_type_common as its first field.
78 struct lttng_kernel_type_common
{
79 enum lttng_kernel_type type
;
82 struct lttng_kernel_type_integer
{
83 struct lttng_kernel_type_common parent
;
84 unsigned int size
; /* in bits */
85 unsigned short alignment
; /* in bits */
86 unsigned int signedness
:1,
88 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
91 struct lttng_kernel_type_string
{
92 struct lttng_kernel_type_common parent
;
93 enum lttng_kernel_string_encoding encoding
;
96 struct lttng_kernel_type_enum
{
97 struct lttng_kernel_type_common parent
;
98 const struct lttng_kernel_enum_desc
*desc
; /* Enumeration mapping */
99 const struct lttng_kernel_type_common
*container_type
;
102 struct lttng_kernel_type_array
{
103 struct lttng_kernel_type_common parent
;
104 const struct lttng_kernel_type_common
*elem_type
;
105 unsigned int length
; /* Num. elems. */
106 unsigned int alignment
;
107 enum lttng_kernel_string_encoding encoding
;
110 struct lttng_kernel_type_sequence
{
111 struct lttng_kernel_type_common parent
;
112 const char *length_name
; /* Length field name. If NULL, use previous field. */
113 const struct lttng_kernel_type_common
*elem_type
;
114 unsigned int alignment
; /* Alignment before elements. */
115 enum lttng_kernel_string_encoding encoding
;
118 struct lttng_kernel_type_struct
{
119 struct lttng_kernel_type_common parent
;
120 unsigned int nr_fields
;
121 const struct lttng_kernel_event_field
**fields
; /* Array of pointers to fields. */
122 unsigned int alignment
;
125 struct lttng_kernel_type_variant
{
126 struct lttng_kernel_type_common parent
;
127 const char *tag_name
; /* Tag field name. If NULL, use previous field. */
128 const struct lttng_kernel_event_field
**choices
; /* Array of pointers to fields. */
129 unsigned int nr_choices
;
130 unsigned int alignment
;
133 struct lttng_kernel_enum_desc
{
135 const struct lttng_kernel_enum_entry
**entries
;
136 unsigned int nr_entries
;
139 /* Event field description */
141 struct lttng_kernel_event_field
{
143 const struct lttng_kernel_type_common
*type
;
144 unsigned int nowrite
:1, /* do not write into trace */
145 user
:1, /* fetch from user-space */
146 nofilter
:1; /* do not consider for filter */
149 #define lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \
150 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_integer, { \
152 .type = lttng_kernel_type_integer, \
155 .alignment = (_alignment), \
156 .signedness = (_signedness), \
157 .reverse_byte_order = (_byte_order) != __BYTE_ORDER, \
161 #define lttng_kernel_static_type_integer_from_type(_type, _byte_order, _base) \
162 lttng_kernel_static_type_integer(sizeof(_type) * CHAR_BIT, \
163 lttng_alignof(_type) * CHAR_BIT, \
164 lttng_is_signed_type(_type), \
168 #define lttng_kernel_static_type_enum(_desc, _container_type) \
169 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_enum, { \
171 .type = lttng_kernel_type_enum, \
174 .container_type = (_container_type), \
177 #define lttng_kernel_static_type_array(_length, _elem_type, _alignment, _encoding) \
178 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_array, { \
180 .type = lttng_kernel_type_array, \
182 .length = (_length), \
183 .alignment = (_alignment), \
184 .encoding = lttng_kernel_string_encoding_##_encoding, \
185 .elem_type = (_elem_type), \
188 #define lttng_kernel_static_type_array_text(_length) \
189 lttng_kernel_static_type_array(_length, \
190 lttng_kernel_static_type_integer(sizeof(char) * CHAR_BIT, \
191 lttng_alignof(char) * CHAR_BIT, lttng_is_signed_type(char), \
195 #define lttng_kernel_static_type_sequence(_length_name, _elem_type, _alignment, _encoding) \
196 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_sequence, { \
198 .type = lttng_kernel_type_sequence, \
200 .length_name = (_length_name), \
201 .alignment = (_alignment), \
202 .encoding = lttng_kernel_string_encoding_##_encoding, \
203 .elem_type = (_elem_type), \
206 #define lttng_kernel_static_type_string(_encoding) \
207 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_string, { \
209 .type = lttng_kernel_type_string, \
211 .encoding = lttng_kernel_string_encoding_##_encoding, \
214 #define lttng_kernel_static_type_struct(_nr_fields, _fields, _alignment) \
215 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_struct, { \
217 .type = lttng_kernel_type_struct, \
219 .nr_fields = (_nr_fields), \
221 .alignment = (_alignment), \
224 #define lttng_kernel_static_type_variant(_nr_choices, _choices, _tag_name, _alignment) \
225 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_variant, { \
227 .type = lttng_kernel_type_variant, \
229 .tag_name = (_tag_name), \
230 .choices = _choices, \
231 .nr_choices = (_nr_choices), \
232 .alignment = (_alignment), \
235 #define lttng_kernel_static_event_field(_name, _type, _nowrite, _user, _nofilter) \
236 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field, { \
239 .nowrite = (_nowrite), \
241 .nofilter = (_nofilter), \
244 #define lttng_kernel_static_event_field_array(_fields...) \
245 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field *, \
249 #define lttng_kernel_static_enum_entry_value(_string, _value) \
250 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
252 .signedness = lttng_is_signed_type(__typeof__(_value)), \
253 .value = lttng_is_signed_type(__typeof__(_value)) ? \
254 (long long) (_value) : (_value), \
257 .signedness = lttng_is_signed_type(__typeof__(_value)), \
258 .value = lttng_is_signed_type(__typeof__(_value)) ? \
259 (long long) (_value) : (_value), \
261 .string = (_string), \
264 #define lttng_kernel_static_enum_entry_range(_string, _range_start, _range_end) \
265 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
267 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
268 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
269 (long long) (_range_start) : (_range_start), \
272 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
273 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
274 (long long) (_range_end) : (_range_end), \
276 .string = (_string), \
279 #define lttng_kernel_static_enum_entry_auto(_string) \
280 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
289 .string = (_string), \
295 struct lttng_kernel_probe_ctx
{
296 struct lttng_kernel_event_common
*event
;
297 uint8_t interruptible
;
300 struct lttng_kernel_event_desc
{
301 const char *event_name
; /* lttng-modules name */
302 const char *event_kname
; /* Linux kernel name (tracepoints) */
303 const struct lttng_kernel_probe_desc
*probe_desc
;
304 void (*probe_callback
)(void);
305 const struct lttng_kernel_event_field
**fields
; /* event payload */
306 unsigned int nr_fields
;
307 struct module
*owner
;
310 struct lttng_kernel_probe_desc
{
311 const char *provider_name
;
312 const struct lttng_kernel_event_desc
**event_desc
;
313 unsigned int nr_events
;
314 struct list_head head
; /* chain registered probes */
315 struct list_head lazy_init_head
;
316 int lazy
; /* lazy registration */
320 * Result of the run_filter() callback.
322 enum lttng_kernel_event_filter_result
{
323 LTTNG_KERNEL_EVENT_FILTER_ACCEPT
= 0,
324 LTTNG_KERNEL_EVENT_FILTER_REJECT
= 1,
327 struct lttng_kernel_event_common_private
;
329 enum lttng_kernel_event_type
{
330 LTTNG_KERNEL_EVENT_TYPE_RECORDER
= 0,
331 LTTNG_KERNEL_EVENT_TYPE_NOTIFIER
= 1,
334 struct lttng_kernel_event_common
{
335 struct lttng_kernel_event_common_private
*priv
; /* Private event interface */
337 enum lttng_kernel_event_type type
;
338 /* Get child with container_of(). */
341 int eval_filter
; /* Need to evaluate filters */
342 int (*run_filter
)(const struct lttng_kernel_event_common
*event
,
343 const char *stack_data
,
344 struct lttng_kernel_probe_ctx
*probe_ctx
,
348 struct lttng_kernel_event_recorder_private
;
350 struct lttng_kernel_event_recorder
{
351 struct lttng_kernel_event_common parent
;
352 struct lttng_kernel_event_recorder_private
*priv
; /* Private event record interface */
354 struct lttng_channel
*chan
;
357 struct lttng_kernel_notification_ctx
{
358 int eval_capture
; /* Capture evaluation available. */
361 struct lttng_kernel_event_notifier_private
;
363 struct lttng_kernel_event_notifier
{
364 struct lttng_kernel_event_common parent
;
365 struct lttng_kernel_event_notifier_private
*priv
; /* Private event notifier interface */
367 int eval_capture
; /* Need to evaluate capture */
368 void (*notification_send
)(struct lttng_kernel_event_notifier
*event_notifier
,
369 const char *stack_data
,
370 struct lttng_kernel_probe_ctx
*probe_ctx
,
371 struct lttng_kernel_notification_ctx
*notif_ctx
);
374 struct lttng_kernel_channel_buffer_ops
{
375 struct lttng_kernel_channel_buffer_ops_private
*priv
; /* Private channel buffer ops interface. */
377 int (*event_reserve
)(struct lttng_kernel_ring_buffer_ctx
*ctx
);
378 void (*event_commit
)(struct lttng_kernel_ring_buffer_ctx
*ctx
);
379 void (*event_write
)(struct lttng_kernel_ring_buffer_ctx
*ctx
, const void *src
,
381 void (*event_write_from_user
)(struct lttng_kernel_ring_buffer_ctx
*ctx
,
382 const void *src
, size_t len
);
383 void (*event_memset
)(struct lttng_kernel_ring_buffer_ctx
*ctx
,
385 void (*event_strcpy
)(struct lttng_kernel_ring_buffer_ctx
*ctx
, const char *src
,
387 void (*event_strcpy_from_user
)(struct lttng_kernel_ring_buffer_ctx
*ctx
,
388 const char __user
*src
, size_t len
);
391 #define LTTNG_EVENT_HT_BITS 12
392 #define LTTNG_EVENT_HT_SIZE (1U << LTTNG_EVENT_HT_BITS)
394 struct lttng_event_ht
{
395 struct hlist_head table
[LTTNG_EVENT_HT_SIZE
];
398 #define LTTNG_EVENT_NOTIFIER_HT_BITS 12
399 #define LTTNG_EVENT_NOTIFIER_HT_SIZE (1U << LTTNG_EVENT_NOTIFIER_HT_BITS)
401 struct lttng_event_notifier_ht
{
402 struct hlist_head table
[LTTNG_EVENT_NOTIFIER_HT_SIZE
];
405 struct lttng_channel
{
407 struct channel
*chan
; /* Channel buffers */
409 struct lttng_kernel_ctx
*ctx
;
410 /* Event ID management */
411 struct lttng_kernel_session
*session
;
412 struct file
*file
; /* File associated to channel */
413 unsigned int free_event_id
; /* Next event ID to allocate */
414 struct list_head list
; /* Channel list */
415 struct lttng_kernel_channel_buffer_ops
*ops
;
416 struct lttng_transport
*transport
;
417 struct hlist_head
*sc_table
; /* for syscall tracing */
418 struct hlist_head
*compat_sc_table
;
419 struct hlist_head
*sc_exit_table
; /* for syscall exit tracing */
420 struct hlist_head
*compat_sc_exit_table
;
421 struct hlist_head sc_unknown
; /* for unknown syscalls */
422 struct hlist_head sc_compat_unknown
;
423 struct hlist_head sc_exit_unknown
;
424 struct hlist_head compat_sc_exit_unknown
;
425 struct lttng_syscall_filter
*sc_filter
;
426 int header_type
; /* 0: unset, 1: compact, 2: large */
427 enum channel_type channel_type
;
428 int syscall_all_entry
;
429 int syscall_all_exit
;
430 unsigned int metadata_dumped
:1,
431 sys_enter_registered
:1,
432 sys_exit_registered
:1,
433 tstate
:1; /* Transient enable state */
436 #define LTTNG_DYNAMIC_LEN_STACK_SIZE 128
438 struct lttng_dynamic_len_stack
{
439 size_t stack
[LTTNG_DYNAMIC_LEN_STACK_SIZE
];
443 DECLARE_PER_CPU(struct lttng_dynamic_len_stack
, lttng_dynamic_len_stack
);
446 * struct lttng_kernel_id_tracker declared in header due to deferencing of *v
447 * in RCU_INITIALIZER(v).
449 #define LTTNG_ID_HASH_BITS 6
450 #define LTTNG_ID_TABLE_SIZE (1 << LTTNG_ID_HASH_BITS)
452 struct lttng_kernel_id_tracker_rcu
{
453 struct hlist_head id_hash
[LTTNG_ID_TABLE_SIZE
];
456 struct lttng_kernel_id_tracker
{
457 struct lttng_kernel_id_tracker_private
*priv
; /* Private API */
459 struct lttng_kernel_id_tracker_rcu
*p
; /* RCU dereferenced. */
462 struct lttng_kernel_session_private
;
464 struct lttng_kernel_session
{
465 struct lttng_kernel_session_private
*priv
; /* Private session interface */
467 int active
; /* Is trace session active ? */
469 struct lttng_kernel_id_tracker pid_tracker
;
470 struct lttng_kernel_id_tracker vpid_tracker
;
471 struct lttng_kernel_id_tracker uid_tracker
;
472 struct lttng_kernel_id_tracker vuid_tracker
;
473 struct lttng_kernel_id_tracker gid_tracker
;
474 struct lttng_kernel_id_tracker vgid_tracker
;
477 int lttng_kernel_probe_register(struct lttng_kernel_probe_desc
*desc
);
478 void lttng_kernel_probe_unregister(struct lttng_kernel_probe_desc
*desc
);
480 bool lttng_id_tracker_lookup(struct lttng_kernel_id_tracker_rcu
*p
, int id
);
482 #endif /* _LTTNG_EVENTS_H */