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 <linux/uprobes.h>
21 #include <lttng/cpuhotplug.h>
22 #include <lttng/tracer.h>
23 #include <lttng/abi.h>
24 #include <lttng/abi-old.h>
25 #include <lttng/endian.h>
27 #define lttng_is_signed_type(type) (((type) -1) < (type) 1)
29 struct lttng_kernel_channel_buffer
;
30 struct lttng_kernel_session
;
31 struct lttng_kernel_ring_buffer_ctx
;
33 /* Type description */
35 enum lttng_kernel_type
{
36 lttng_kernel_type_integer
,
37 lttng_kernel_type_string
,
38 lttng_kernel_type_enum
,
39 lttng_kernel_type_array
,
40 lttng_kernel_type_sequence
,
41 lttng_kernel_type_struct
,
42 lttng_kernel_type_variant
,
43 NR_LTTNG_KERNEL_TYPES
,
46 enum lttng_kernel_string_encoding
{
47 lttng_kernel_string_encoding_none
= 0,
48 lttng_kernel_string_encoding_UTF8
= 1,
49 lttng_kernel_string_encoding_ASCII
= 2,
50 NR_LTTNG_KERNEL_STRING_ENCODING
,
53 struct lttng_kernel_enum_value
{
54 unsigned long long value
;
55 unsigned int signedness
:1;
58 struct lttng_kernel_enum_entry
{
59 struct lttng_kernel_enum_value start
, end
; /* start and end are inclusive */
62 unsigned int is_auto
:1;
67 * struct lttng_kernel_type_common is fixed-size. Its children inherits
68 * from it by embedding struct lttng_kernel_type_common as its first field.
70 struct lttng_kernel_type_common
{
71 enum lttng_kernel_type type
;
74 struct lttng_kernel_type_integer
{
75 struct lttng_kernel_type_common parent
;
76 unsigned int size
; /* in bits */
77 unsigned short alignment
; /* in bits */
78 unsigned int signedness
:1,
80 user
:1; /* fetch from user-space */
81 unsigned int base
; /* 2, 8, 10, 16, for pretty print */
84 struct lttng_kernel_type_string
{
85 struct lttng_kernel_type_common parent
;
86 enum lttng_kernel_string_encoding encoding
;
87 unsigned int user
:1; /* fetch from user-space */
90 struct lttng_kernel_type_enum
{
91 struct lttng_kernel_type_common parent
;
92 const struct lttng_kernel_enum_desc
*desc
; /* Enumeration mapping */
93 const struct lttng_kernel_type_common
*container_type
;
96 struct lttng_kernel_type_array
{
97 struct lttng_kernel_type_common parent
;
98 const struct lttng_kernel_type_common
*elem_type
;
99 unsigned int length
; /* Num. elems. */
100 unsigned int alignment
; /* Alignment in bytes before elements. */
101 enum lttng_kernel_string_encoding encoding
;
104 struct lttng_kernel_type_sequence
{
105 struct lttng_kernel_type_common parent
;
106 const char *length_name
; /* Length field name. If NULL, use previous field. */
107 const struct lttng_kernel_type_common
*elem_type
;
108 unsigned int alignment
; /* Alignment in bytes before elements. */
109 enum lttng_kernel_string_encoding encoding
;
112 struct lttng_kernel_type_struct
{
113 struct lttng_kernel_type_common parent
;
114 unsigned int nr_fields
;
115 const struct lttng_kernel_event_field
* const *fields
; /* Array of pointers to fields. */
116 unsigned int alignment
; /* Alignment in bits */
119 struct lttng_kernel_type_variant
{
120 struct lttng_kernel_type_common parent
;
121 const char *tag_name
; /* Tag field name. If NULL, use previous field. */
122 const struct lttng_kernel_event_field
* const *choices
; /* Array of pointers to fields. */
123 unsigned int nr_choices
;
124 unsigned int alignment
; /* Alignment in bytes */
127 struct lttng_kernel_enum_desc
{
129 const struct lttng_kernel_enum_entry
* const *entries
;
130 unsigned int nr_entries
;
131 const struct lttng_kernel_probe_desc
*probe_desc
;
134 /* Event field description */
136 struct lttng_kernel_event_field
{
138 const struct lttng_kernel_type_common
*type
;
139 unsigned int nowrite
:1, /* do not write into trace */
140 nofilter
:1; /* do not consider for filter */
144 #define PARAMS(args...) args
147 #define _lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, _user, _base) \
148 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_integer, { \
150 .type = lttng_kernel_type_integer, \
153 .alignment = (_alignment), \
154 .signedness = (_signedness), \
155 .reverse_byte_order = (_byte_order) != __BYTE_ORDER, \
160 #define lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, _base) \
161 _lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, 0, _base)
163 #define lttng_kernel_static_type_user_integer(_size, _alignment, _signedness, _byte_order, _base) \
164 _lttng_kernel_static_type_integer(_size, _alignment, _signedness, _byte_order, 1, _base)
166 #define _lttng_kernel_static_type_integer_from_type(_type, _byte_order, _user, _base) \
167 _lttng_kernel_static_type_integer(sizeof(_type) * CHAR_BIT, \
168 lttng_alignof(_type) * CHAR_BIT, \
169 lttng_is_signed_type(_type), \
170 _byte_order, _user, _base)
172 #define lttng_kernel_static_type_integer_from_type(_type, _byte_order, _base) \
173 _lttng_kernel_static_type_integer_from_type(_type, _byte_order, 0, _base)
175 #define lttng_kernel_static_type_user_integer_from_type(_type, _byte_order, _base) \
176 _lttng_kernel_static_type_integer_from_type(_type, _byte_order, 1, _base)
178 #define lttng_kernel_static_type_enum(_desc, _container_type) \
179 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_enum, { \
181 .type = lttng_kernel_type_enum, \
184 .container_type = (_container_type), \
187 #define lttng_kernel_static_type_array(_length, _elem_type, _alignment, _encoding) \
188 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_array, { \
190 .type = lttng_kernel_type_array, \
192 .length = (_length), \
193 .alignment = (_alignment), \
194 .encoding = lttng_kernel_string_encoding_##_encoding, \
195 .elem_type = (_elem_type), \
198 #define lttng_kernel_static_type_array_text(_length) \
199 lttng_kernel_static_type_array(_length, \
200 lttng_kernel_static_type_integer(sizeof(char) * CHAR_BIT, \
201 lttng_alignof(char) * CHAR_BIT, lttng_is_signed_type(char), \
205 #define lttng_kernel_static_type_sequence(_length_name, _elem_type, _alignment, _encoding) \
206 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_sequence, { \
208 .type = lttng_kernel_type_sequence, \
210 .length_name = (_length_name), \
211 .alignment = (_alignment), \
212 .encoding = lttng_kernel_string_encoding_##_encoding, \
213 .elem_type = (_elem_type), \
216 #define lttng_kernel_static_type_string(_encoding, _user) \
217 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_string, { \
219 .type = lttng_kernel_type_string, \
221 .encoding = lttng_kernel_string_encoding_##_encoding, \
225 #define lttng_kernel_static_type_struct_init(_nr_fields, _fields, _alignment) \
228 .type = lttng_kernel_type_struct, \
230 .nr_fields = (_nr_fields), \
232 .alignment = (_alignment), \
235 #define lttng_kernel_static_type_struct(_nr_fields, _fields, _alignment) \
236 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_struct, \
237 lttng_kernel_static_type_struct_init(_nr_fields, PARAMS(_fields), _alignment) \
240 #define lttng_kernel_static_type_variant(_nr_choices, _choices, _tag_name, _alignment) \
241 ((const struct lttng_kernel_type_common *) __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_type_variant, { \
243 .type = lttng_kernel_type_variant, \
245 .tag_name = (_tag_name), \
246 .choices = _choices, \
247 .nr_choices = (_nr_choices), \
248 .alignment = (_alignment), \
251 #define lttng_kernel_static_event_field(_name, _type, _nowrite, _nofilter) \
252 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field, { \
255 .nowrite = (_nowrite), \
256 .nofilter = (_nofilter), \
259 #define lttng_kernel_static_event_field_array(_fields...) \
260 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_event_field *, \
264 #define lttng_kernel_static_enum_entry_value(_string, _value) \
265 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
267 .signedness = lttng_is_signed_type(__typeof__(_value)), \
268 .value = lttng_is_signed_type(__typeof__(_value)) ? \
269 (long long) (_value) : (_value), \
272 .signedness = lttng_is_signed_type(__typeof__(_value)), \
273 .value = lttng_is_signed_type(__typeof__(_value)) ? \
274 (long long) (_value) : (_value), \
276 .string = (_string), \
279 #define lttng_kernel_static_enum_entry_range(_string, _range_start, _range_end) \
280 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
282 .signedness = lttng_is_signed_type(__typeof__(_range_start)), \
283 .value = lttng_is_signed_type(__typeof__(_range_start)) ? \
284 (long long) (_range_start) : (_range_start), \
287 .signedness = lttng_is_signed_type(__typeof__(_range_end)), \
288 .value = lttng_is_signed_type(__typeof__(_range_end)) ? \
289 (long long) (_range_end) : (_range_end), \
291 .string = (_string), \
294 #define lttng_kernel_static_enum_entry_auto(_string) \
295 __LTTNG_COMPOUND_LITERAL(const struct lttng_kernel_enum_entry, { \
304 .string = (_string), \
310 struct lttng_kernel_probe_ctx
{
311 struct lttng_kernel_event_common
*event
;
312 uint8_t interruptible
;
315 struct lttng_kernel_tracepoint_class
{
316 void (*probe_callback
)(void);
317 const struct lttng_kernel_event_field
* const *fields
; /* event payload */
318 unsigned int nr_fields
;
319 const struct lttng_kernel_probe_desc
*probe_desc
;
322 struct lttng_kernel_event_desc
{
323 const char *event_name
; /* lttng-modules name */
324 const char *event_kname
; /* Linux kernel name (tracepoints) */
325 const struct lttng_kernel_probe_desc
*probe_desc
;
326 const struct lttng_kernel_tracepoint_class
*tp_class
;
327 struct module
*owner
;
330 struct lttng_kernel_probe_desc
{
331 const char *provider_name
;
332 const struct lttng_kernel_event_desc
* const *event_desc
;
333 unsigned int nr_events
;
334 struct list_head head
; /* chain registered probes */
335 struct list_head lazy_init_head
;
336 int lazy
; /* lazy registration */
340 * Result of the run_filter() callback.
342 enum lttng_kernel_event_filter_result
{
343 LTTNG_KERNEL_EVENT_FILTER_ACCEPT
= 0,
344 LTTNG_KERNEL_EVENT_FILTER_REJECT
= 1,
347 struct lttng_kernel_event_common_private
;
349 enum lttng_kernel_event_type
{
350 LTTNG_KERNEL_EVENT_TYPE_RECORDER
= 0,
351 LTTNG_KERNEL_EVENT_TYPE_NOTIFIER
= 1,
354 struct lttng_kernel_event_common
{
355 struct lttng_kernel_event_common_private
*priv
; /* Private event interface */
357 enum lttng_kernel_event_type type
;
358 /* Get child with container_of(). */
361 int eval_filter
; /* Need to evaluate filters */
362 int (*run_filter
)(const struct lttng_kernel_event_common
*event
,
363 const char *stack_data
,
364 struct lttng_kernel_probe_ctx
*probe_ctx
,
368 struct lttng_kernel_event_recorder_private
;
370 struct lttng_kernel_event_recorder
{
371 struct lttng_kernel_event_common parent
;
372 struct lttng_kernel_event_recorder_private
*priv
; /* Private event record interface */
374 struct lttng_kernel_channel_buffer
*chan
;
377 struct lttng_kernel_notification_ctx
{
378 int eval_capture
; /* Capture evaluation available. */
381 struct lttng_kernel_event_notifier_private
;
383 struct lttng_kernel_event_notifier
{
384 struct lttng_kernel_event_common parent
;
385 struct lttng_kernel_event_notifier_private
*priv
; /* Private event notifier interface */
387 int eval_capture
; /* Need to evaluate capture */
388 void (*notification_send
)(struct lttng_kernel_event_notifier
*event_notifier
,
389 const char *stack_data
,
390 struct lttng_kernel_probe_ctx
*probe_ctx
,
391 struct lttng_kernel_notification_ctx
*notif_ctx
);
394 struct lttng_kernel_channel_buffer_ops
{
395 struct lttng_kernel_channel_buffer_ops_private
*priv
; /* Private channel buffer ops interface. */
397 int (*event_reserve
)(struct lttng_kernel_ring_buffer_ctx
*ctx
);
398 void (*event_commit
)(struct lttng_kernel_ring_buffer_ctx
*ctx
);
399 void (*event_write
)(struct lttng_kernel_ring_buffer_ctx
*ctx
, const void *src
,
400 size_t len
, size_t alignment
);
401 void (*event_write_from_user
)(struct lttng_kernel_ring_buffer_ctx
*ctx
,
402 const void *src
, size_t len
, size_t alignment
);
403 void (*event_memset
)(struct lttng_kernel_ring_buffer_ctx
*ctx
,
405 void (*event_strcpy
)(struct lttng_kernel_ring_buffer_ctx
*ctx
, const char *src
,
407 void (*event_strcpy_from_user
)(struct lttng_kernel_ring_buffer_ctx
*ctx
,
408 const char __user
*src
, size_t len
);
409 void (*event_pstrcpy_pad
)(struct lttng_kernel_ring_buffer_ctx
*ctx
,
410 const char *src
, size_t len
);
411 void (*event_pstrcpy_pad_from_user
)(struct lttng_kernel_ring_buffer_ctx
*ctx
,
412 const char __user
*src
, size_t len
);
413 void (*lost_event_too_big
)(struct lttng_kernel_channel_buffer
*lttng_channel
);
416 enum lttng_kernel_channel_type
{
417 LTTNG_KERNEL_CHANNEL_TYPE_BUFFER
= 0,
420 struct lttng_kernel_channel_common_private
;
422 /* Use container_of() to get child. */
423 struct lttng_kernel_channel_common
{
424 struct lttng_kernel_channel_common_private
*priv
; /* Private channel interface. */
426 enum lttng_kernel_channel_type type
;
429 struct lttng_kernel_session
*session
;
432 struct lttng_kernel_channel_buffer_private
;
434 struct lttng_kernel_channel_buffer
{
435 struct lttng_kernel_channel_common parent
;
436 struct lttng_kernel_channel_buffer_private
*priv
;
438 struct lttng_kernel_channel_buffer_ops
*ops
;
441 #define LTTNG_DYNAMIC_LEN_STACK_SIZE 128
443 struct lttng_dynamic_len_stack
{
444 size_t stack
[LTTNG_DYNAMIC_LEN_STACK_SIZE
];
448 DECLARE_PER_CPU(struct lttng_dynamic_len_stack
, lttng_dynamic_len_stack
);
451 * struct lttng_kernel_id_tracker declared in header due to deferencing of *v
452 * in RCU_INITIALIZER(v).
454 #define LTTNG_ID_HASH_BITS 6
455 #define LTTNG_ID_TABLE_SIZE (1 << LTTNG_ID_HASH_BITS)
457 struct lttng_kernel_id_tracker_rcu
{
458 struct hlist_head id_hash
[LTTNG_ID_TABLE_SIZE
];
461 struct lttng_kernel_id_tracker
{
462 struct lttng_kernel_id_tracker_private
*priv
; /* Private API */
464 struct lttng_kernel_id_tracker_rcu
*p
; /* RCU dereferenced. */
467 struct lttng_kernel_session_private
;
469 struct lttng_kernel_session
{
470 struct lttng_kernel_session_private
*priv
; /* Private session interface */
472 int active
; /* Is trace session active ? */
474 struct lttng_kernel_id_tracker pid_tracker
;
475 struct lttng_kernel_id_tracker vpid_tracker
;
476 struct lttng_kernel_id_tracker uid_tracker
;
477 struct lttng_kernel_id_tracker vuid_tracker
;
478 struct lttng_kernel_id_tracker gid_tracker
;
479 struct lttng_kernel_id_tracker vgid_tracker
;
482 int lttng_kernel_probe_register(struct lttng_kernel_probe_desc
*desc
);
483 void lttng_kernel_probe_unregister(struct lttng_kernel_probe_desc
*desc
);
485 bool lttng_id_tracker_lookup(struct lttng_kernel_id_tracker_rcu
*p
, int id
);
487 #endif /* _LTTNG_EVENTS_H */