Fix: lttng-tracepoint module notifier should return NOTIFY_OK
[lttng-modules.git] / lttng-events.c
1 /* SPDX-License-Identifier: (GPL-2.0 or LGPL-2.1)
2 *
3 * lttng-events.c
4 *
5 * Holds LTTng per-session event registry.
6 *
7 * Copyright (C) 2010-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
8 */
9
10 /*
11 * This page_alloc.h wrapper needs to be included before gfpflags.h because it
12 * overrides a function with a define.
13 */
14 #include "wrapper/page_alloc.h"
15
16 #include <linux/module.h>
17 #include <linux/mutex.h>
18 #include <linux/sched.h>
19 #include <linux/slab.h>
20 #include <linux/jiffies.h>
21 #include <linux/utsname.h>
22 #include <linux/err.h>
23 #include <linux/seq_file.h>
24 #include <linux/file.h>
25 #include <linux/anon_inodes.h>
26 #include <wrapper/file.h>
27 #include <linux/jhash.h>
28 #include <linux/uaccess.h>
29 #include <linux/vmalloc.h>
30 #include <linux/uuid.h>
31
32 #include <wrapper/vmalloc.h> /* for wrapper_vmalloc_sync_all() */
33 #include <wrapper/random.h>
34 #include <wrapper/tracepoint.h>
35 #include <wrapper/list.h>
36 #include <wrapper/types.h>
37 #include <lttng-kernel-version.h>
38 #include <lttng-events.h>
39 #include <lttng-tracer.h>
40 #include <lttng-abi-old.h>
41 #include <lttng-endian.h>
42 #include <lttng-string-utils.h>
43 #include <wrapper/ringbuffer/backend.h>
44 #include <wrapper/ringbuffer/frontend.h>
45
46 #define METADATA_CACHE_DEFAULT_SIZE 4096
47
48 static LIST_HEAD(sessions);
49 static LIST_HEAD(lttng_transport_list);
50 /*
51 * Protect the sessions and metadata caches.
52 */
53 static DEFINE_MUTEX(sessions_mutex);
54 static struct kmem_cache *event_cache;
55
56 static void lttng_session_lazy_sync_enablers(struct lttng_session *session);
57 static void lttng_session_sync_enablers(struct lttng_session *session);
58 static void lttng_enabler_destroy(struct lttng_enabler *enabler);
59
60 static void _lttng_event_destroy(struct lttng_event *event);
61 static void _lttng_channel_destroy(struct lttng_channel *chan);
62 static int _lttng_event_unregister(struct lttng_event *event);
63 static
64 int _lttng_event_metadata_statedump(struct lttng_session *session,
65 struct lttng_channel *chan,
66 struct lttng_event *event);
67 static
68 int _lttng_session_metadata_statedump(struct lttng_session *session);
69 static
70 void _lttng_metadata_channel_hangup(struct lttng_metadata_stream *stream);
71 static
72 int _lttng_field_statedump(struct lttng_session *session,
73 const struct lttng_event_field *field,
74 size_t nesting);
75
76 void synchronize_trace(void)
77 {
78 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5,1,0))
79 synchronize_rcu();
80 #else
81 synchronize_sched();
82 #endif
83
84 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0))
85 #ifdef CONFIG_PREEMPT_RT_FULL
86 synchronize_rcu();
87 #endif
88 #else /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */
89 #ifdef CONFIG_PREEMPT_RT
90 synchronize_rcu();
91 #endif
92 #endif /* (LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)) */
93 }
94
95 void lttng_lock_sessions(void)
96 {
97 mutex_lock(&sessions_mutex);
98 }
99
100 void lttng_unlock_sessions(void)
101 {
102 mutex_unlock(&sessions_mutex);
103 }
104
105 /*
106 * Called with sessions lock held.
107 */
108 int lttng_session_active(void)
109 {
110 struct lttng_session *iter;
111
112 list_for_each_entry(iter, &sessions, list) {
113 if (iter->active)
114 return 1;
115 }
116 return 0;
117 }
118
119 struct lttng_session *lttng_session_create(void)
120 {
121 struct lttng_session *session;
122 struct lttng_metadata_cache *metadata_cache;
123 int i;
124
125 mutex_lock(&sessions_mutex);
126 session = lttng_kvzalloc(sizeof(struct lttng_session), GFP_KERNEL);
127 if (!session)
128 goto err;
129 INIT_LIST_HEAD(&session->chan);
130 INIT_LIST_HEAD(&session->events);
131 uuid_le_gen(&session->uuid);
132
133 metadata_cache = kzalloc(sizeof(struct lttng_metadata_cache),
134 GFP_KERNEL);
135 if (!metadata_cache)
136 goto err_free_session;
137 metadata_cache->data = vzalloc(METADATA_CACHE_DEFAULT_SIZE);
138 if (!metadata_cache->data)
139 goto err_free_cache;
140 metadata_cache->cache_alloc = METADATA_CACHE_DEFAULT_SIZE;
141 kref_init(&metadata_cache->refcount);
142 mutex_init(&metadata_cache->lock);
143 session->metadata_cache = metadata_cache;
144 INIT_LIST_HEAD(&metadata_cache->metadata_stream);
145 memcpy(&metadata_cache->uuid, &session->uuid,
146 sizeof(metadata_cache->uuid));
147 INIT_LIST_HEAD(&session->enablers_head);
148 for (i = 0; i < LTTNG_EVENT_HT_SIZE; i++)
149 INIT_HLIST_HEAD(&session->events_ht.table[i]);
150 list_add(&session->list, &sessions);
151 mutex_unlock(&sessions_mutex);
152 return session;
153
154 err_free_cache:
155 kfree(metadata_cache);
156 err_free_session:
157 lttng_kvfree(session);
158 err:
159 mutex_unlock(&sessions_mutex);
160 return NULL;
161 }
162
163 void metadata_cache_destroy(struct kref *kref)
164 {
165 struct lttng_metadata_cache *cache =
166 container_of(kref, struct lttng_metadata_cache, refcount);
167 vfree(cache->data);
168 kfree(cache);
169 }
170
171 void lttng_session_destroy(struct lttng_session *session)
172 {
173 struct lttng_channel *chan, *tmpchan;
174 struct lttng_event *event, *tmpevent;
175 struct lttng_metadata_stream *metadata_stream;
176 struct lttng_enabler *enabler, *tmpenabler;
177 int ret;
178
179 mutex_lock(&sessions_mutex);
180 WRITE_ONCE(session->active, 0);
181 list_for_each_entry(chan, &session->chan, list) {
182 ret = lttng_syscalls_unregister(chan);
183 WARN_ON(ret);
184 }
185 list_for_each_entry(event, &session->events, list) {
186 ret = _lttng_event_unregister(event);
187 WARN_ON(ret);
188 }
189 synchronize_trace(); /* Wait for in-flight events to complete */
190 list_for_each_entry_safe(enabler, tmpenabler,
191 &session->enablers_head, node)
192 lttng_enabler_destroy(enabler);
193 list_for_each_entry_safe(event, tmpevent, &session->events, list)
194 _lttng_event_destroy(event);
195 list_for_each_entry_safe(chan, tmpchan, &session->chan, list) {
196 BUG_ON(chan->channel_type == METADATA_CHANNEL);
197 _lttng_channel_destroy(chan);
198 }
199 list_for_each_entry(metadata_stream, &session->metadata_cache->metadata_stream, list)
200 _lttng_metadata_channel_hangup(metadata_stream);
201 if (session->pid_tracker)
202 lttng_pid_tracker_destroy(session->pid_tracker);
203 kref_put(&session->metadata_cache->refcount, metadata_cache_destroy);
204 list_del(&session->list);
205 mutex_unlock(&sessions_mutex);
206 lttng_kvfree(session);
207 }
208
209 int lttng_session_statedump(struct lttng_session *session)
210 {
211 int ret;
212
213 mutex_lock(&sessions_mutex);
214 ret = lttng_statedump_start(session);
215 mutex_unlock(&sessions_mutex);
216 return ret;
217 }
218
219 int lttng_session_enable(struct lttng_session *session)
220 {
221 int ret = 0;
222 struct lttng_channel *chan;
223
224 mutex_lock(&sessions_mutex);
225 if (session->active) {
226 ret = -EBUSY;
227 goto end;
228 }
229
230 /* Set transient enabler state to "enabled" */
231 session->tstate = 1;
232
233 /* We need to sync enablers with session before activation. */
234 lttng_session_sync_enablers(session);
235
236 /*
237 * Snapshot the number of events per channel to know the type of header
238 * we need to use.
239 */
240 list_for_each_entry(chan, &session->chan, list) {
241 if (chan->header_type)
242 continue; /* don't change it if session stop/restart */
243 if (chan->free_event_id < 31)
244 chan->header_type = 1; /* compact */
245 else
246 chan->header_type = 2; /* large */
247 }
248
249 /* Clear each stream's quiescent state. */
250 list_for_each_entry(chan, &session->chan, list) {
251 if (chan->channel_type != METADATA_CHANNEL)
252 lib_ring_buffer_clear_quiescent_channel(chan->chan);
253 }
254
255 WRITE_ONCE(session->active, 1);
256 WRITE_ONCE(session->been_active, 1);
257 ret = _lttng_session_metadata_statedump(session);
258 if (ret) {
259 WRITE_ONCE(session->active, 0);
260 goto end;
261 }
262 ret = lttng_statedump_start(session);
263 if (ret)
264 WRITE_ONCE(session->active, 0);
265 end:
266 mutex_unlock(&sessions_mutex);
267 return ret;
268 }
269
270 int lttng_session_disable(struct lttng_session *session)
271 {
272 int ret = 0;
273 struct lttng_channel *chan;
274
275 mutex_lock(&sessions_mutex);
276 if (!session->active) {
277 ret = -EBUSY;
278 goto end;
279 }
280 WRITE_ONCE(session->active, 0);
281
282 /* Set transient enabler state to "disabled" */
283 session->tstate = 0;
284 lttng_session_sync_enablers(session);
285
286 /* Set each stream's quiescent state. */
287 list_for_each_entry(chan, &session->chan, list) {
288 if (chan->channel_type != METADATA_CHANNEL)
289 lib_ring_buffer_set_quiescent_channel(chan->chan);
290 }
291 end:
292 mutex_unlock(&sessions_mutex);
293 return ret;
294 }
295
296 int lttng_session_metadata_regenerate(struct lttng_session *session)
297 {
298 int ret = 0;
299 struct lttng_channel *chan;
300 struct lttng_event *event;
301 struct lttng_metadata_cache *cache = session->metadata_cache;
302 struct lttng_metadata_stream *stream;
303
304 mutex_lock(&sessions_mutex);
305 if (!session->active) {
306 ret = -EBUSY;
307 goto end;
308 }
309
310 mutex_lock(&cache->lock);
311 memset(cache->data, 0, cache->cache_alloc);
312 cache->metadata_written = 0;
313 cache->version++;
314 list_for_each_entry(stream, &session->metadata_cache->metadata_stream, list) {
315 stream->metadata_out = 0;
316 stream->metadata_in = 0;
317 }
318 mutex_unlock(&cache->lock);
319
320 session->metadata_dumped = 0;
321 list_for_each_entry(chan, &session->chan, list) {
322 chan->metadata_dumped = 0;
323 }
324
325 list_for_each_entry(event, &session->events, list) {
326 event->metadata_dumped = 0;
327 }
328
329 ret = _lttng_session_metadata_statedump(session);
330
331 end:
332 mutex_unlock(&sessions_mutex);
333 return ret;
334 }
335
336 int lttng_channel_enable(struct lttng_channel *channel)
337 {
338 int ret = 0;
339
340 mutex_lock(&sessions_mutex);
341 if (channel->channel_type == METADATA_CHANNEL) {
342 ret = -EPERM;
343 goto end;
344 }
345 if (channel->enabled) {
346 ret = -EEXIST;
347 goto end;
348 }
349 /* Set transient enabler state to "enabled" */
350 channel->tstate = 1;
351 lttng_session_sync_enablers(channel->session);
352 /* Set atomically the state to "enabled" */
353 WRITE_ONCE(channel->enabled, 1);
354 end:
355 mutex_unlock(&sessions_mutex);
356 return ret;
357 }
358
359 int lttng_channel_disable(struct lttng_channel *channel)
360 {
361 int ret = 0;
362
363 mutex_lock(&sessions_mutex);
364 if (channel->channel_type == METADATA_CHANNEL) {
365 ret = -EPERM;
366 goto end;
367 }
368 if (!channel->enabled) {
369 ret = -EEXIST;
370 goto end;
371 }
372 /* Set atomically the state to "disabled" */
373 WRITE_ONCE(channel->enabled, 0);
374 /* Set transient enabler state to "enabled" */
375 channel->tstate = 0;
376 lttng_session_sync_enablers(channel->session);
377 end:
378 mutex_unlock(&sessions_mutex);
379 return ret;
380 }
381
382 int lttng_event_enable(struct lttng_event *event)
383 {
384 int ret = 0;
385
386 mutex_lock(&sessions_mutex);
387 if (event->chan->channel_type == METADATA_CHANNEL) {
388 ret = -EPERM;
389 goto end;
390 }
391 if (event->enabled) {
392 ret = -EEXIST;
393 goto end;
394 }
395 switch (event->instrumentation) {
396 case LTTNG_KERNEL_TRACEPOINT:
397 case LTTNG_KERNEL_SYSCALL:
398 ret = -EINVAL;
399 break;
400 case LTTNG_KERNEL_KPROBE:
401 case LTTNG_KERNEL_FUNCTION:
402 case LTTNG_KERNEL_UPROBE:
403 case LTTNG_KERNEL_NOOP:
404 WRITE_ONCE(event->enabled, 1);
405 break;
406 case LTTNG_KERNEL_KRETPROBE:
407 ret = lttng_kretprobes_event_enable_state(event, 1);
408 break;
409 default:
410 WARN_ON_ONCE(1);
411 ret = -EINVAL;
412 }
413 end:
414 mutex_unlock(&sessions_mutex);
415 return ret;
416 }
417
418 int lttng_event_disable(struct lttng_event *event)
419 {
420 int ret = 0;
421
422 mutex_lock(&sessions_mutex);
423 if (event->chan->channel_type == METADATA_CHANNEL) {
424 ret = -EPERM;
425 goto end;
426 }
427 if (!event->enabled) {
428 ret = -EEXIST;
429 goto end;
430 }
431 switch (event->instrumentation) {
432 case LTTNG_KERNEL_TRACEPOINT:
433 case LTTNG_KERNEL_SYSCALL:
434 ret = -EINVAL;
435 break;
436 case LTTNG_KERNEL_KPROBE:
437 case LTTNG_KERNEL_FUNCTION:
438 case LTTNG_KERNEL_UPROBE:
439 case LTTNG_KERNEL_NOOP:
440 WRITE_ONCE(event->enabled, 0);
441 break;
442 case LTTNG_KERNEL_KRETPROBE:
443 ret = lttng_kretprobes_event_enable_state(event, 0);
444 break;
445 default:
446 WARN_ON_ONCE(1);
447 ret = -EINVAL;
448 }
449 end:
450 mutex_unlock(&sessions_mutex);
451 return ret;
452 }
453
454 static struct lttng_transport *lttng_transport_find(const char *name)
455 {
456 struct lttng_transport *transport;
457
458 list_for_each_entry(transport, &lttng_transport_list, node) {
459 if (!strcmp(transport->name, name))
460 return transport;
461 }
462 return NULL;
463 }
464
465 struct lttng_channel *lttng_channel_create(struct lttng_session *session,
466 const char *transport_name,
467 void *buf_addr,
468 size_t subbuf_size, size_t num_subbuf,
469 unsigned int switch_timer_interval,
470 unsigned int read_timer_interval,
471 enum channel_type channel_type)
472 {
473 struct lttng_channel *chan;
474 struct lttng_transport *transport = NULL;
475
476 mutex_lock(&sessions_mutex);
477 if (session->been_active && channel_type != METADATA_CHANNEL)
478 goto active; /* Refuse to add channel to active session */
479 transport = lttng_transport_find(transport_name);
480 if (!transport) {
481 printk(KERN_WARNING "LTTng transport %s not found\n",
482 transport_name);
483 goto notransport;
484 }
485 if (!try_module_get(transport->owner)) {
486 printk(KERN_WARNING "LTT : Can't lock transport module.\n");
487 goto notransport;
488 }
489 chan = kzalloc(sizeof(struct lttng_channel), GFP_KERNEL);
490 if (!chan)
491 goto nomem;
492 chan->session = session;
493 chan->id = session->free_chan_id++;
494 chan->ops = &transport->ops;
495 /*
496 * Note: the channel creation op already writes into the packet
497 * headers. Therefore the "chan" information used as input
498 * should be already accessible.
499 */
500 chan->chan = transport->ops.channel_create(transport_name,
501 chan, buf_addr, subbuf_size, num_subbuf,
502 switch_timer_interval, read_timer_interval);
503 if (!chan->chan)
504 goto create_error;
505 chan->tstate = 1;
506 chan->enabled = 1;
507 chan->transport = transport;
508 chan->channel_type = channel_type;
509 list_add(&chan->list, &session->chan);
510 mutex_unlock(&sessions_mutex);
511 return chan;
512
513 create_error:
514 kfree(chan);
515 nomem:
516 if (transport)
517 module_put(transport->owner);
518 notransport:
519 active:
520 mutex_unlock(&sessions_mutex);
521 return NULL;
522 }
523
524 /*
525 * Only used internally at session destruction for per-cpu channels, and
526 * when metadata channel is released.
527 * Needs to be called with sessions mutex held.
528 */
529 static
530 void _lttng_channel_destroy(struct lttng_channel *chan)
531 {
532 chan->ops->channel_destroy(chan->chan);
533 module_put(chan->transport->owner);
534 list_del(&chan->list);
535 lttng_destroy_context(chan->ctx);
536 kfree(chan);
537 }
538
539 void lttng_metadata_channel_destroy(struct lttng_channel *chan)
540 {
541 BUG_ON(chan->channel_type != METADATA_CHANNEL);
542
543 /* Protect the metadata cache with the sessions_mutex. */
544 mutex_lock(&sessions_mutex);
545 _lttng_channel_destroy(chan);
546 mutex_unlock(&sessions_mutex);
547 }
548 EXPORT_SYMBOL_GPL(lttng_metadata_channel_destroy);
549
550 static
551 void _lttng_metadata_channel_hangup(struct lttng_metadata_stream *stream)
552 {
553 stream->finalized = 1;
554 wake_up_interruptible(&stream->read_wait);
555 }
556
557 /*
558 * Supports event creation while tracing session is active.
559 * Needs to be called with sessions mutex held.
560 */
561 struct lttng_event *_lttng_event_create(struct lttng_channel *chan,
562 struct lttng_kernel_event *event_param,
563 void *filter,
564 const struct lttng_event_desc *event_desc,
565 enum lttng_kernel_instrumentation itype)
566 {
567 struct lttng_session *session = chan->session;
568 struct lttng_event *event;
569 const char *event_name;
570 struct hlist_head *head;
571 size_t name_len;
572 uint32_t hash;
573 int ret;
574
575 if (chan->free_event_id == -1U) {
576 ret = -EMFILE;
577 goto full;
578 }
579
580 switch (itype) {
581 case LTTNG_KERNEL_TRACEPOINT:
582 event_name = event_desc->name;
583 break;
584 case LTTNG_KERNEL_KPROBE:
585 case LTTNG_KERNEL_UPROBE:
586 case LTTNG_KERNEL_KRETPROBE:
587 case LTTNG_KERNEL_FUNCTION:
588 case LTTNG_KERNEL_NOOP:
589 case LTTNG_KERNEL_SYSCALL:
590 event_name = event_param->name;
591 break;
592 default:
593 WARN_ON_ONCE(1);
594 ret = -EINVAL;
595 goto type_error;
596 }
597 name_len = strlen(event_name);
598 hash = jhash(event_name, name_len, 0);
599 head = &session->events_ht.table[hash & (LTTNG_EVENT_HT_SIZE - 1)];
600 lttng_hlist_for_each_entry(event, head, hlist) {
601 WARN_ON_ONCE(!event->desc);
602 if (!strncmp(event->desc->name, event_name,
603 LTTNG_KERNEL_SYM_NAME_LEN - 1)
604 && chan == event->chan) {
605 ret = -EEXIST;
606 goto exist;
607 }
608 }
609
610 event = kmem_cache_zalloc(event_cache, GFP_KERNEL);
611 if (!event) {
612 ret = -ENOMEM;
613 goto cache_error;
614 }
615 event->chan = chan;
616 event->filter = filter;
617 event->id = chan->free_event_id++;
618 event->instrumentation = itype;
619 event->evtype = LTTNG_TYPE_EVENT;
620 INIT_LIST_HEAD(&event->bytecode_runtime_head);
621 INIT_LIST_HEAD(&event->enablers_ref_head);
622
623 switch (itype) {
624 case LTTNG_KERNEL_TRACEPOINT:
625 /* Event will be enabled by enabler sync. */
626 event->enabled = 0;
627 event->registered = 0;
628 event->desc = lttng_event_get(event_name);
629 if (!event->desc) {
630 ret = -ENOENT;
631 goto register_error;
632 }
633 /* Populate lttng_event structure before event registration. */
634 smp_wmb();
635 break;
636 case LTTNG_KERNEL_KPROBE:
637 /*
638 * Needs to be explicitly enabled after creation, since
639 * we may want to apply filters.
640 */
641 event->enabled = 0;
642 event->registered = 1;
643 /*
644 * Populate lttng_event structure before event
645 * registration.
646 */
647 smp_wmb();
648 ret = lttng_kprobes_register(event_name,
649 event_param->u.kprobe.symbol_name,
650 event_param->u.kprobe.offset,
651 event_param->u.kprobe.addr,
652 event);
653 if (ret) {
654 ret = -EINVAL;
655 goto register_error;
656 }
657 ret = try_module_get(event->desc->owner);
658 WARN_ON_ONCE(!ret);
659 break;
660 case LTTNG_KERNEL_KRETPROBE:
661 {
662 struct lttng_event *event_return;
663
664 /* kretprobe defines 2 events */
665 /*
666 * Needs to be explicitly enabled after creation, since
667 * we may want to apply filters.
668 */
669 event->enabled = 0;
670 event->registered = 1;
671 event_return =
672 kmem_cache_zalloc(event_cache, GFP_KERNEL);
673 if (!event_return) {
674 ret = -ENOMEM;
675 goto register_error;
676 }
677 event_return->chan = chan;
678 event_return->filter = filter;
679 event_return->id = chan->free_event_id++;
680 event_return->enabled = 0;
681 event_return->registered = 1;
682 event_return->instrumentation = itype;
683 /*
684 * Populate lttng_event structure before kretprobe registration.
685 */
686 smp_wmb();
687 ret = lttng_kretprobes_register(event_name,
688 event_param->u.kretprobe.symbol_name,
689 event_param->u.kretprobe.offset,
690 event_param->u.kretprobe.addr,
691 event, event_return);
692 if (ret) {
693 kmem_cache_free(event_cache, event_return);
694 ret = -EINVAL;
695 goto register_error;
696 }
697 /* Take 2 refs on the module: one per event. */
698 ret = try_module_get(event->desc->owner);
699 WARN_ON_ONCE(!ret);
700 ret = try_module_get(event->desc->owner);
701 WARN_ON_ONCE(!ret);
702 ret = _lttng_event_metadata_statedump(chan->session, chan,
703 event_return);
704 WARN_ON_ONCE(ret > 0);
705 if (ret) {
706 kmem_cache_free(event_cache, event_return);
707 module_put(event->desc->owner);
708 module_put(event->desc->owner);
709 goto statedump_error;
710 }
711 list_add(&event_return->list, &chan->session->events);
712 break;
713 }
714 case LTTNG_KERNEL_FUNCTION:
715 /*
716 * Needs to be explicitly enabled after creation, since
717 * we may want to apply filters.
718 */
719 event->enabled = 0;
720 event->registered = 1;
721 /*
722 * Populate lttng_event structure before event
723 * registration.
724 */
725 smp_wmb();
726 ret = lttng_ftrace_register(event_name,
727 event_param->u.ftrace.symbol_name,
728 event);
729 if (ret) {
730 goto register_error;
731 }
732 ret = try_module_get(event->desc->owner);
733 WARN_ON_ONCE(!ret);
734 break;
735 case LTTNG_KERNEL_NOOP:
736 case LTTNG_KERNEL_SYSCALL:
737 /*
738 * Needs to be explicitly enabled after creation, since
739 * we may want to apply filters.
740 */
741 event->enabled = 0;
742 event->registered = 0;
743 event->desc = event_desc;
744 if (!event->desc) {
745 ret = -EINVAL;
746 goto register_error;
747 }
748 break;
749 case LTTNG_KERNEL_UPROBE:
750 /*
751 * Needs to be explicitly enabled after creation, since
752 * we may want to apply filters.
753 */
754 event->enabled = 0;
755 event->registered = 1;
756
757 /*
758 * Populate lttng_event structure before event
759 * registration.
760 */
761 smp_wmb();
762
763 ret = lttng_uprobes_register(event_param->name,
764 event_param->u.uprobe.fd,
765 event);
766 if (ret)
767 goto register_error;
768 ret = try_module_get(event->desc->owner);
769 WARN_ON_ONCE(!ret);
770 break;
771 default:
772 WARN_ON_ONCE(1);
773 ret = -EINVAL;
774 goto register_error;
775 }
776 ret = _lttng_event_metadata_statedump(chan->session, chan, event);
777 WARN_ON_ONCE(ret > 0);
778 if (ret) {
779 goto statedump_error;
780 }
781 hlist_add_head(&event->hlist, head);
782 list_add(&event->list, &chan->session->events);
783 return event;
784
785 statedump_error:
786 /* If a statedump error occurs, events will not be readable. */
787 register_error:
788 kmem_cache_free(event_cache, event);
789 cache_error:
790 exist:
791 type_error:
792 full:
793 return ERR_PTR(ret);
794 }
795
796 struct lttng_event *lttng_event_create(struct lttng_channel *chan,
797 struct lttng_kernel_event *event_param,
798 void *filter,
799 const struct lttng_event_desc *event_desc,
800 enum lttng_kernel_instrumentation itype)
801 {
802 struct lttng_event *event;
803
804 mutex_lock(&sessions_mutex);
805 event = _lttng_event_create(chan, event_param, filter, event_desc,
806 itype);
807 mutex_unlock(&sessions_mutex);
808 return event;
809 }
810
811 /* Only used for tracepoints for now. */
812 static
813 void register_event(struct lttng_event *event)
814 {
815 const struct lttng_event_desc *desc;
816 int ret = -EINVAL;
817
818 if (event->registered)
819 return;
820
821 desc = event->desc;
822 switch (event->instrumentation) {
823 case LTTNG_KERNEL_TRACEPOINT:
824 ret = lttng_wrapper_tracepoint_probe_register(desc->kname,
825 desc->probe_callback,
826 event);
827 break;
828 case LTTNG_KERNEL_SYSCALL:
829 ret = lttng_syscall_filter_enable(event->chan,
830 desc->name);
831 break;
832 case LTTNG_KERNEL_KPROBE:
833 case LTTNG_KERNEL_UPROBE:
834 case LTTNG_KERNEL_KRETPROBE:
835 case LTTNG_KERNEL_FUNCTION:
836 case LTTNG_KERNEL_NOOP:
837 ret = 0;
838 break;
839 default:
840 WARN_ON_ONCE(1);
841 }
842 if (!ret)
843 event->registered = 1;
844 }
845
846 /*
847 * Only used internally at session destruction.
848 */
849 int _lttng_event_unregister(struct lttng_event *event)
850 {
851 const struct lttng_event_desc *desc;
852 int ret = -EINVAL;
853
854 if (!event->registered)
855 return 0;
856
857 desc = event->desc;
858 switch (event->instrumentation) {
859 case LTTNG_KERNEL_TRACEPOINT:
860 ret = lttng_wrapper_tracepoint_probe_unregister(event->desc->kname,
861 event->desc->probe_callback,
862 event);
863 break;
864 case LTTNG_KERNEL_KPROBE:
865 lttng_kprobes_unregister(event);
866 ret = 0;
867 break;
868 case LTTNG_KERNEL_KRETPROBE:
869 lttng_kretprobes_unregister(event);
870 ret = 0;
871 break;
872 case LTTNG_KERNEL_FUNCTION:
873 lttng_ftrace_unregister(event);
874 ret = 0;
875 break;
876 case LTTNG_KERNEL_SYSCALL:
877 ret = lttng_syscall_filter_disable(event->chan,
878 desc->name);
879 break;
880 case LTTNG_KERNEL_NOOP:
881 ret = 0;
882 break;
883 case LTTNG_KERNEL_UPROBE:
884 lttng_uprobes_unregister(event);
885 ret = 0;
886 break;
887 default:
888 WARN_ON_ONCE(1);
889 }
890 if (!ret)
891 event->registered = 0;
892 return ret;
893 }
894
895 /*
896 * Only used internally at session destruction.
897 */
898 static
899 void _lttng_event_destroy(struct lttng_event *event)
900 {
901 switch (event->instrumentation) {
902 case LTTNG_KERNEL_TRACEPOINT:
903 lttng_event_put(event->desc);
904 break;
905 case LTTNG_KERNEL_KPROBE:
906 module_put(event->desc->owner);
907 lttng_kprobes_destroy_private(event);
908 break;
909 case LTTNG_KERNEL_KRETPROBE:
910 module_put(event->desc->owner);
911 lttng_kretprobes_destroy_private(event);
912 break;
913 case LTTNG_KERNEL_FUNCTION:
914 module_put(event->desc->owner);
915 lttng_ftrace_destroy_private(event);
916 break;
917 case LTTNG_KERNEL_NOOP:
918 case LTTNG_KERNEL_SYSCALL:
919 break;
920 case LTTNG_KERNEL_UPROBE:
921 module_put(event->desc->owner);
922 lttng_uprobes_destroy_private(event);
923 break;
924 default:
925 WARN_ON_ONCE(1);
926 }
927 list_del(&event->list);
928 lttng_destroy_context(event->ctx);
929 kmem_cache_free(event_cache, event);
930 }
931
932 int lttng_session_track_pid(struct lttng_session *session, int pid)
933 {
934 int ret;
935
936 if (pid < -1)
937 return -EINVAL;
938 mutex_lock(&sessions_mutex);
939 if (pid == -1) {
940 /* track all pids: destroy tracker. */
941 if (session->pid_tracker) {
942 struct lttng_pid_tracker *lpf;
943
944 lpf = session->pid_tracker;
945 rcu_assign_pointer(session->pid_tracker, NULL);
946 synchronize_trace();
947 lttng_pid_tracker_destroy(lpf);
948 }
949 ret = 0;
950 } else {
951 if (!session->pid_tracker) {
952 struct lttng_pid_tracker *lpf;
953
954 lpf = lttng_pid_tracker_create();
955 if (!lpf) {
956 ret = -ENOMEM;
957 goto unlock;
958 }
959 ret = lttng_pid_tracker_add(lpf, pid);
960 rcu_assign_pointer(session->pid_tracker, lpf);
961 } else {
962 ret = lttng_pid_tracker_add(session->pid_tracker, pid);
963 }
964 }
965 unlock:
966 mutex_unlock(&sessions_mutex);
967 return ret;
968 }
969
970 int lttng_session_untrack_pid(struct lttng_session *session, int pid)
971 {
972 int ret;
973
974 if (pid < -1)
975 return -EINVAL;
976 mutex_lock(&sessions_mutex);
977 if (pid == -1) {
978 /* untrack all pids: replace by empty tracker. */
979 struct lttng_pid_tracker *old_lpf = session->pid_tracker;
980 struct lttng_pid_tracker *lpf;
981
982 lpf = lttng_pid_tracker_create();
983 if (!lpf) {
984 ret = -ENOMEM;
985 goto unlock;
986 }
987 rcu_assign_pointer(session->pid_tracker, lpf);
988 synchronize_trace();
989 if (old_lpf)
990 lttng_pid_tracker_destroy(old_lpf);
991 ret = 0;
992 } else {
993 if (!session->pid_tracker) {
994 ret = -ENOENT;
995 goto unlock;
996 }
997 ret = lttng_pid_tracker_del(session->pid_tracker, pid);
998 }
999 unlock:
1000 mutex_unlock(&sessions_mutex);
1001 return ret;
1002 }
1003
1004 static
1005 void *pid_list_start(struct seq_file *m, loff_t *pos)
1006 {
1007 struct lttng_session *session = m->private;
1008 struct lttng_pid_tracker *lpf;
1009 struct lttng_pid_hash_node *e;
1010 int iter = 0, i;
1011
1012 mutex_lock(&sessions_mutex);
1013 lpf = session->pid_tracker;
1014 if (lpf) {
1015 for (i = 0; i < LTTNG_PID_TABLE_SIZE; i++) {
1016 struct hlist_head *head = &lpf->pid_hash[i];
1017
1018 lttng_hlist_for_each_entry(e, head, hlist) {
1019 if (iter++ >= *pos)
1020 return e;
1021 }
1022 }
1023 } else {
1024 /* PID tracker disabled. */
1025 if (iter >= *pos && iter == 0) {
1026 return session; /* empty tracker */
1027 }
1028 iter++;
1029 }
1030 /* End of list */
1031 return NULL;
1032 }
1033
1034 /* Called with sessions_mutex held. */
1035 static
1036 void *pid_list_next(struct seq_file *m, void *p, loff_t *ppos)
1037 {
1038 struct lttng_session *session = m->private;
1039 struct lttng_pid_tracker *lpf;
1040 struct lttng_pid_hash_node *e;
1041 int iter = 0, i;
1042
1043 (*ppos)++;
1044 lpf = session->pid_tracker;
1045 if (lpf) {
1046 for (i = 0; i < LTTNG_PID_TABLE_SIZE; i++) {
1047 struct hlist_head *head = &lpf->pid_hash[i];
1048
1049 lttng_hlist_for_each_entry(e, head, hlist) {
1050 if (iter++ >= *ppos)
1051 return e;
1052 }
1053 }
1054 } else {
1055 /* PID tracker disabled. */
1056 if (iter >= *ppos && iter == 0)
1057 return session; /* empty tracker */
1058 iter++;
1059 }
1060
1061 /* End of list */
1062 return NULL;
1063 }
1064
1065 static
1066 void pid_list_stop(struct seq_file *m, void *p)
1067 {
1068 mutex_unlock(&sessions_mutex);
1069 }
1070
1071 static
1072 int pid_list_show(struct seq_file *m, void *p)
1073 {
1074 int pid;
1075
1076 if (p == m->private) {
1077 /* Tracker disabled. */
1078 pid = -1;
1079 } else {
1080 const struct lttng_pid_hash_node *e = p;
1081
1082 pid = lttng_pid_tracker_get_node_pid(e);
1083 }
1084 seq_printf(m, "process { pid = %d; };\n", pid);
1085 return 0;
1086 }
1087
1088 static
1089 const struct seq_operations lttng_tracker_pids_list_seq_ops = {
1090 .start = pid_list_start,
1091 .next = pid_list_next,
1092 .stop = pid_list_stop,
1093 .show = pid_list_show,
1094 };
1095
1096 static
1097 int lttng_tracker_pids_list_open(struct inode *inode, struct file *file)
1098 {
1099 return seq_open(file, &lttng_tracker_pids_list_seq_ops);
1100 }
1101
1102 static
1103 int lttng_tracker_pids_list_release(struct inode *inode, struct file *file)
1104 {
1105 struct seq_file *m = file->private_data;
1106 struct lttng_session *session = m->private;
1107 int ret;
1108
1109 WARN_ON_ONCE(!session);
1110 ret = seq_release(inode, file);
1111 if (!ret && session)
1112 fput(session->file);
1113 return ret;
1114 }
1115
1116 const struct file_operations lttng_tracker_pids_list_fops = {
1117 .owner = THIS_MODULE,
1118 .open = lttng_tracker_pids_list_open,
1119 .read = seq_read,
1120 .llseek = seq_lseek,
1121 .release = lttng_tracker_pids_list_release,
1122 };
1123
1124 int lttng_session_list_tracker_pids(struct lttng_session *session)
1125 {
1126 struct file *tracker_pids_list_file;
1127 struct seq_file *m;
1128 int file_fd, ret;
1129
1130 file_fd = lttng_get_unused_fd();
1131 if (file_fd < 0) {
1132 ret = file_fd;
1133 goto fd_error;
1134 }
1135
1136 tracker_pids_list_file = anon_inode_getfile("[lttng_tracker_pids_list]",
1137 &lttng_tracker_pids_list_fops,
1138 NULL, O_RDWR);
1139 if (IS_ERR(tracker_pids_list_file)) {
1140 ret = PTR_ERR(tracker_pids_list_file);
1141 goto file_error;
1142 }
1143 if (!atomic_long_add_unless(&session->file->f_count, 1, LONG_MAX)) {
1144 ret = -EOVERFLOW;
1145 goto refcount_error;
1146 }
1147 ret = lttng_tracker_pids_list_fops.open(NULL, tracker_pids_list_file);
1148 if (ret < 0)
1149 goto open_error;
1150 m = tracker_pids_list_file->private_data;
1151 m->private = session;
1152 fd_install(file_fd, tracker_pids_list_file);
1153
1154 return file_fd;
1155
1156 open_error:
1157 atomic_long_dec(&session->file->f_count);
1158 refcount_error:
1159 fput(tracker_pids_list_file);
1160 file_error:
1161 put_unused_fd(file_fd);
1162 fd_error:
1163 return ret;
1164 }
1165
1166 /*
1167 * Enabler management.
1168 */
1169 static
1170 int lttng_match_enabler_star_glob(const char *desc_name,
1171 const char *pattern)
1172 {
1173 if (!strutils_star_glob_match(pattern, LTTNG_SIZE_MAX,
1174 desc_name, LTTNG_SIZE_MAX))
1175 return 0;
1176 return 1;
1177 }
1178
1179 static
1180 int lttng_match_enabler_name(const char *desc_name,
1181 const char *name)
1182 {
1183 if (strcmp(desc_name, name))
1184 return 0;
1185 return 1;
1186 }
1187
1188 static
1189 int lttng_desc_match_enabler(const struct lttng_event_desc *desc,
1190 struct lttng_enabler *enabler)
1191 {
1192 const char *desc_name, *enabler_name;
1193
1194 enabler_name = enabler->event_param.name;
1195 switch (enabler->event_param.instrumentation) {
1196 case LTTNG_KERNEL_TRACEPOINT:
1197 desc_name = desc->name;
1198 break;
1199 case LTTNG_KERNEL_SYSCALL:
1200 desc_name = desc->name;
1201 if (!strncmp(desc_name, "compat_", strlen("compat_")))
1202 desc_name += strlen("compat_");
1203 if (!strncmp(desc_name, "syscall_exit_",
1204 strlen("syscall_exit_"))) {
1205 desc_name += strlen("syscall_exit_");
1206 } else if (!strncmp(desc_name, "syscall_entry_",
1207 strlen("syscall_entry_"))) {
1208 desc_name += strlen("syscall_entry_");
1209 } else {
1210 WARN_ON_ONCE(1);
1211 return -EINVAL;
1212 }
1213 break;
1214 default:
1215 WARN_ON_ONCE(1);
1216 return -EINVAL;
1217 }
1218 switch (enabler->type) {
1219 case LTTNG_ENABLER_STAR_GLOB:
1220 return lttng_match_enabler_star_glob(desc_name, enabler_name);
1221 case LTTNG_ENABLER_NAME:
1222 return lttng_match_enabler_name(desc_name, enabler_name);
1223 default:
1224 return -EINVAL;
1225 }
1226 }
1227
1228 static
1229 int lttng_event_match_enabler(struct lttng_event *event,
1230 struct lttng_enabler *enabler)
1231 {
1232 if (enabler->event_param.instrumentation != event->instrumentation)
1233 return 0;
1234 if (lttng_desc_match_enabler(event->desc, enabler)
1235 && event->chan == enabler->chan)
1236 return 1;
1237 else
1238 return 0;
1239 }
1240
1241 static
1242 struct lttng_enabler_ref *lttng_event_enabler_ref(struct lttng_event *event,
1243 struct lttng_enabler *enabler)
1244 {
1245 struct lttng_enabler_ref *enabler_ref;
1246
1247 list_for_each_entry(enabler_ref,
1248 &event->enablers_ref_head, node) {
1249 if (enabler_ref->ref == enabler)
1250 return enabler_ref;
1251 }
1252 return NULL;
1253 }
1254
1255 static
1256 void lttng_create_tracepoint_if_missing(struct lttng_enabler *enabler)
1257 {
1258 struct lttng_session *session = enabler->chan->session;
1259 struct lttng_probe_desc *probe_desc;
1260 const struct lttng_event_desc *desc;
1261 int i;
1262 struct list_head *probe_list;
1263
1264 probe_list = lttng_get_probe_list_head();
1265 /*
1266 * For each probe event, if we find that a probe event matches
1267 * our enabler, create an associated lttng_event if not
1268 * already present.
1269 */
1270 list_for_each_entry(probe_desc, probe_list, head) {
1271 for (i = 0; i < probe_desc->nr_events; i++) {
1272 int found = 0;
1273 struct hlist_head *head;
1274 const char *event_name;
1275 size_t name_len;
1276 uint32_t hash;
1277 struct lttng_event *event;
1278
1279 desc = probe_desc->event_desc[i];
1280 if (!lttng_desc_match_enabler(desc, enabler))
1281 continue;
1282 event_name = desc->name;
1283 name_len = strlen(event_name);
1284
1285 /*
1286 * Check if already created.
1287 */
1288 hash = jhash(event_name, name_len, 0);
1289 head = &session->events_ht.table[hash & (LTTNG_EVENT_HT_SIZE - 1)];
1290 lttng_hlist_for_each_entry(event, head, hlist) {
1291 if (event->desc == desc
1292 && event->chan == enabler->chan)
1293 found = 1;
1294 }
1295 if (found)
1296 continue;
1297
1298 /*
1299 * We need to create an event for this
1300 * event probe.
1301 */
1302 event = _lttng_event_create(enabler->chan,
1303 NULL, NULL, desc,
1304 LTTNG_KERNEL_TRACEPOINT);
1305 if (!event) {
1306 printk(KERN_INFO "Unable to create event %s\n",
1307 probe_desc->event_desc[i]->name);
1308 }
1309 }
1310 }
1311 }
1312
1313 static
1314 void lttng_create_syscall_if_missing(struct lttng_enabler *enabler)
1315 {
1316 int ret;
1317
1318 ret = lttng_syscalls_register(enabler->chan, NULL);
1319 WARN_ON_ONCE(ret);
1320 }
1321
1322 /*
1323 * Create struct lttng_event if it is missing and present in the list of
1324 * tracepoint probes.
1325 * Should be called with sessions mutex held.
1326 */
1327 static
1328 void lttng_create_event_if_missing(struct lttng_enabler *enabler)
1329 {
1330 switch (enabler->event_param.instrumentation) {
1331 case LTTNG_KERNEL_TRACEPOINT:
1332 lttng_create_tracepoint_if_missing(enabler);
1333 break;
1334 case LTTNG_KERNEL_SYSCALL:
1335 lttng_create_syscall_if_missing(enabler);
1336 break;
1337 default:
1338 WARN_ON_ONCE(1);
1339 break;
1340 }
1341 }
1342
1343 /*
1344 * Create events associated with an enabler (if not already present),
1345 * and add backward reference from the event to the enabler.
1346 * Should be called with sessions mutex held.
1347 */
1348 static
1349 int lttng_enabler_ref_events(struct lttng_enabler *enabler)
1350 {
1351 struct lttng_session *session = enabler->chan->session;
1352 struct lttng_event *event;
1353
1354 /* First ensure that probe events are created for this enabler. */
1355 lttng_create_event_if_missing(enabler);
1356
1357 /* For each event matching enabler in session event list. */
1358 list_for_each_entry(event, &session->events, list) {
1359 struct lttng_enabler_ref *enabler_ref;
1360
1361 if (!lttng_event_match_enabler(event, enabler))
1362 continue;
1363 enabler_ref = lttng_event_enabler_ref(event, enabler);
1364 if (!enabler_ref) {
1365 /*
1366 * If no backward ref, create it.
1367 * Add backward ref from event to enabler.
1368 */
1369 enabler_ref = kzalloc(sizeof(*enabler_ref), GFP_KERNEL);
1370 if (!enabler_ref)
1371 return -ENOMEM;
1372 enabler_ref->ref = enabler;
1373 list_add(&enabler_ref->node,
1374 &event->enablers_ref_head);
1375 }
1376
1377 /*
1378 * Link filter bytecodes if not linked yet.
1379 */
1380 lttng_enabler_event_link_bytecode(event, enabler);
1381
1382 /* TODO: merge event context. */
1383 }
1384 return 0;
1385 }
1386
1387 /*
1388 * Called at module load: connect the probe on all enablers matching
1389 * this event.
1390 * Called with sessions lock held.
1391 */
1392 int lttng_fix_pending_events(void)
1393 {
1394 struct lttng_session *session;
1395
1396 list_for_each_entry(session, &sessions, list)
1397 lttng_session_lazy_sync_enablers(session);
1398 return 0;
1399 }
1400
1401 struct lttng_enabler *lttng_enabler_create(enum lttng_enabler_type type,
1402 struct lttng_kernel_event *event_param,
1403 struct lttng_channel *chan)
1404 {
1405 struct lttng_enabler *enabler;
1406
1407 enabler = kzalloc(sizeof(*enabler), GFP_KERNEL);
1408 if (!enabler)
1409 return NULL;
1410 enabler->type = type;
1411 INIT_LIST_HEAD(&enabler->filter_bytecode_head);
1412 memcpy(&enabler->event_param, event_param,
1413 sizeof(enabler->event_param));
1414 enabler->chan = chan;
1415 /* ctx left NULL */
1416 enabler->enabled = 0;
1417 enabler->evtype = LTTNG_TYPE_ENABLER;
1418 mutex_lock(&sessions_mutex);
1419 list_add(&enabler->node, &enabler->chan->session->enablers_head);
1420 lttng_session_lazy_sync_enablers(enabler->chan->session);
1421 mutex_unlock(&sessions_mutex);
1422 return enabler;
1423 }
1424
1425 int lttng_enabler_enable(struct lttng_enabler *enabler)
1426 {
1427 mutex_lock(&sessions_mutex);
1428 enabler->enabled = 1;
1429 lttng_session_lazy_sync_enablers(enabler->chan->session);
1430 mutex_unlock(&sessions_mutex);
1431 return 0;
1432 }
1433
1434 int lttng_enabler_disable(struct lttng_enabler *enabler)
1435 {
1436 mutex_lock(&sessions_mutex);
1437 enabler->enabled = 0;
1438 lttng_session_lazy_sync_enablers(enabler->chan->session);
1439 mutex_unlock(&sessions_mutex);
1440 return 0;
1441 }
1442
1443 int lttng_enabler_attach_bytecode(struct lttng_enabler *enabler,
1444 struct lttng_kernel_filter_bytecode __user *bytecode)
1445 {
1446 struct lttng_filter_bytecode_node *bytecode_node;
1447 uint32_t bytecode_len;
1448 int ret;
1449
1450 ret = get_user(bytecode_len, &bytecode->len);
1451 if (ret)
1452 return ret;
1453 bytecode_node = kzalloc(sizeof(*bytecode_node) + bytecode_len,
1454 GFP_KERNEL);
1455 if (!bytecode_node)
1456 return -ENOMEM;
1457 ret = copy_from_user(&bytecode_node->bc, bytecode,
1458 sizeof(*bytecode) + bytecode_len);
1459 if (ret)
1460 goto error_free;
1461 bytecode_node->enabler = enabler;
1462 /* Enforce length based on allocated size */
1463 bytecode_node->bc.len = bytecode_len;
1464 list_add_tail(&bytecode_node->node, &enabler->filter_bytecode_head);
1465 lttng_session_lazy_sync_enablers(enabler->chan->session);
1466 return 0;
1467
1468 error_free:
1469 kfree(bytecode_node);
1470 return ret;
1471 }
1472
1473 int lttng_event_add_callsite(struct lttng_event *event,
1474 struct lttng_kernel_event_callsite __user *callsite)
1475 {
1476
1477 switch (event->instrumentation) {
1478 case LTTNG_KERNEL_UPROBE:
1479 return lttng_uprobes_add_callsite(event, callsite);
1480 default:
1481 return -EINVAL;
1482 }
1483 }
1484
1485 int lttng_enabler_attach_context(struct lttng_enabler *enabler,
1486 struct lttng_kernel_context *context_param)
1487 {
1488 return -ENOSYS;
1489 }
1490
1491 static
1492 void lttng_enabler_destroy(struct lttng_enabler *enabler)
1493 {
1494 struct lttng_filter_bytecode_node *filter_node, *tmp_filter_node;
1495
1496 /* Destroy filter bytecode */
1497 list_for_each_entry_safe(filter_node, tmp_filter_node,
1498 &enabler->filter_bytecode_head, node) {
1499 kfree(filter_node);
1500 }
1501
1502 /* Destroy contexts */
1503 lttng_destroy_context(enabler->ctx);
1504
1505 list_del(&enabler->node);
1506 kfree(enabler);
1507 }
1508
1509 /*
1510 * lttng_session_sync_enablers should be called just before starting a
1511 * session.
1512 * Should be called with sessions mutex held.
1513 */
1514 static
1515 void lttng_session_sync_enablers(struct lttng_session *session)
1516 {
1517 struct lttng_enabler *enabler;
1518 struct lttng_event *event;
1519
1520 list_for_each_entry(enabler, &session->enablers_head, node)
1521 lttng_enabler_ref_events(enabler);
1522 /*
1523 * For each event, if at least one of its enablers is enabled,
1524 * and its channel and session transient states are enabled, we
1525 * enable the event, else we disable it.
1526 */
1527 list_for_each_entry(event, &session->events, list) {
1528 struct lttng_enabler_ref *enabler_ref;
1529 struct lttng_bytecode_runtime *runtime;
1530 int enabled = 0, has_enablers_without_bytecode = 0;
1531
1532 switch (event->instrumentation) {
1533 case LTTNG_KERNEL_TRACEPOINT:
1534 case LTTNG_KERNEL_SYSCALL:
1535 /* Enable events */
1536 list_for_each_entry(enabler_ref,
1537 &event->enablers_ref_head, node) {
1538 if (enabler_ref->ref->enabled) {
1539 enabled = 1;
1540 break;
1541 }
1542 }
1543 break;
1544 default:
1545 /* Not handled with lazy sync. */
1546 continue;
1547 }
1548 /*
1549 * Enabled state is based on union of enablers, with
1550 * intesection of session and channel transient enable
1551 * states.
1552 */
1553 enabled = enabled && session->tstate && event->chan->tstate;
1554
1555 WRITE_ONCE(event->enabled, enabled);
1556 /*
1557 * Sync tracepoint registration with event enabled
1558 * state.
1559 */
1560 if (enabled) {
1561 register_event(event);
1562 } else {
1563 _lttng_event_unregister(event);
1564 }
1565
1566 /* Check if has enablers without bytecode enabled */
1567 list_for_each_entry(enabler_ref,
1568 &event->enablers_ref_head, node) {
1569 if (enabler_ref->ref->enabled
1570 && list_empty(&enabler_ref->ref->filter_bytecode_head)) {
1571 has_enablers_without_bytecode = 1;
1572 break;
1573 }
1574 }
1575 event->has_enablers_without_bytecode =
1576 has_enablers_without_bytecode;
1577
1578 /* Enable filters */
1579 list_for_each_entry(runtime,
1580 &event->bytecode_runtime_head, node)
1581 lttng_filter_sync_state(runtime);
1582 }
1583 }
1584
1585 /*
1586 * Apply enablers to session events, adding events to session if need
1587 * be. It is required after each modification applied to an active
1588 * session, and right before session "start".
1589 * "lazy" sync means we only sync if required.
1590 * Should be called with sessions mutex held.
1591 */
1592 static
1593 void lttng_session_lazy_sync_enablers(struct lttng_session *session)
1594 {
1595 /* We can skip if session is not active */
1596 if (!session->active)
1597 return;
1598 lttng_session_sync_enablers(session);
1599 }
1600
1601 /*
1602 * Serialize at most one packet worth of metadata into a metadata
1603 * channel.
1604 * We grab the metadata cache mutex to get exclusive access to our metadata
1605 * buffer and to the metadata cache. Exclusive access to the metadata buffer
1606 * allows us to do racy operations such as looking for remaining space left in
1607 * packet and write, since mutual exclusion protects us from concurrent writes.
1608 * Mutual exclusion on the metadata cache allow us to read the cache content
1609 * without racing against reallocation of the cache by updates.
1610 * Returns the number of bytes written in the channel, 0 if no data
1611 * was written and a negative value on error.
1612 */
1613 int lttng_metadata_output_channel(struct lttng_metadata_stream *stream,
1614 struct channel *chan)
1615 {
1616 struct lib_ring_buffer_ctx ctx;
1617 int ret = 0;
1618 size_t len, reserve_len;
1619
1620 /*
1621 * Ensure we support mutiple get_next / put sequences followed by
1622 * put_next. The metadata cache lock protects reading the metadata
1623 * cache. It can indeed be read concurrently by "get_next_subbuf" and
1624 * "flush" operations on the buffer invoked by different processes.
1625 * Moreover, since the metadata cache memory can be reallocated, we
1626 * need to have exclusive access against updates even though we only
1627 * read it.
1628 */
1629 mutex_lock(&stream->metadata_cache->lock);
1630 WARN_ON(stream->metadata_in < stream->metadata_out);
1631 if (stream->metadata_in != stream->metadata_out)
1632 goto end;
1633
1634 /* Metadata regenerated, change the version. */
1635 if (stream->metadata_cache->version != stream->version)
1636 stream->version = stream->metadata_cache->version;
1637
1638 len = stream->metadata_cache->metadata_written -
1639 stream->metadata_in;
1640 if (!len)
1641 goto end;
1642 reserve_len = min_t(size_t,
1643 stream->transport->ops.packet_avail_size(chan),
1644 len);
1645 lib_ring_buffer_ctx_init(&ctx, chan, NULL, reserve_len,
1646 sizeof(char), -1);
1647 /*
1648 * If reservation failed, return an error to the caller.
1649 */
1650 ret = stream->transport->ops.event_reserve(&ctx, 0);
1651 if (ret != 0) {
1652 printk(KERN_WARNING "LTTng: Metadata event reservation failed\n");
1653 goto end;
1654 }
1655 stream->transport->ops.event_write(&ctx,
1656 stream->metadata_cache->data + stream->metadata_in,
1657 reserve_len);
1658 stream->transport->ops.event_commit(&ctx);
1659 stream->metadata_in += reserve_len;
1660 ret = reserve_len;
1661
1662 end:
1663 mutex_unlock(&stream->metadata_cache->lock);
1664 return ret;
1665 }
1666
1667 /*
1668 * Write the metadata to the metadata cache.
1669 * Must be called with sessions_mutex held.
1670 * The metadata cache lock protects us from concurrent read access from
1671 * thread outputting metadata content to ring buffer.
1672 */
1673 int lttng_metadata_printf(struct lttng_session *session,
1674 const char *fmt, ...)
1675 {
1676 char *str;
1677 size_t len;
1678 va_list ap;
1679 struct lttng_metadata_stream *stream;
1680
1681 WARN_ON_ONCE(!READ_ONCE(session->active));
1682
1683 va_start(ap, fmt);
1684 str = kvasprintf(GFP_KERNEL, fmt, ap);
1685 va_end(ap);
1686 if (!str)
1687 return -ENOMEM;
1688
1689 len = strlen(str);
1690 mutex_lock(&session->metadata_cache->lock);
1691 if (session->metadata_cache->metadata_written + len >
1692 session->metadata_cache->cache_alloc) {
1693 char *tmp_cache_realloc;
1694 unsigned int tmp_cache_alloc_size;
1695
1696 tmp_cache_alloc_size = max_t(unsigned int,
1697 session->metadata_cache->cache_alloc + len,
1698 session->metadata_cache->cache_alloc << 1);
1699 tmp_cache_realloc = vzalloc(tmp_cache_alloc_size);
1700 if (!tmp_cache_realloc)
1701 goto err;
1702 if (session->metadata_cache->data) {
1703 memcpy(tmp_cache_realloc,
1704 session->metadata_cache->data,
1705 session->metadata_cache->cache_alloc);
1706 vfree(session->metadata_cache->data);
1707 }
1708
1709 session->metadata_cache->cache_alloc = tmp_cache_alloc_size;
1710 session->metadata_cache->data = tmp_cache_realloc;
1711 }
1712 memcpy(session->metadata_cache->data +
1713 session->metadata_cache->metadata_written,
1714 str, len);
1715 session->metadata_cache->metadata_written += len;
1716 mutex_unlock(&session->metadata_cache->lock);
1717 kfree(str);
1718
1719 list_for_each_entry(stream, &session->metadata_cache->metadata_stream, list)
1720 wake_up_interruptible(&stream->read_wait);
1721
1722 return 0;
1723
1724 err:
1725 mutex_unlock(&session->metadata_cache->lock);
1726 kfree(str);
1727 return -ENOMEM;
1728 }
1729
1730 static
1731 int print_tabs(struct lttng_session *session, size_t nesting)
1732 {
1733 size_t i;
1734
1735 for (i = 0; i < nesting; i++) {
1736 int ret;
1737
1738 ret = lttng_metadata_printf(session, " ");
1739 if (ret) {
1740 return ret;
1741 }
1742 }
1743 return 0;
1744 }
1745
1746 /*
1747 * Must be called with sessions_mutex held.
1748 */
1749 static
1750 int _lttng_struct_type_statedump(struct lttng_session *session,
1751 const struct lttng_type *type,
1752 size_t nesting)
1753 {
1754 int ret;
1755 uint32_t i, nr_fields;
1756
1757 ret = print_tabs(session, nesting);
1758 if (ret)
1759 return ret;
1760 ret = lttng_metadata_printf(session,
1761 "struct {\n");
1762 if (ret)
1763 return ret;
1764 nr_fields = type->u._struct.nr_fields;
1765 for (i = 0; i < nr_fields; i++) {
1766 const struct lttng_event_field *iter_field;
1767
1768 iter_field = &type->u._struct.fields[i];
1769 ret = _lttng_field_statedump(session, iter_field, nesting + 1);
1770 if (ret)
1771 return ret;
1772 }
1773 ret = print_tabs(session, nesting);
1774 if (ret)
1775 return ret;
1776 ret = lttng_metadata_printf(session,
1777 "}");
1778 return ret;
1779 }
1780
1781 /*
1782 * Must be called with sessions_mutex held.
1783 */
1784 static
1785 int _lttng_struct_statedump(struct lttng_session *session,
1786 const struct lttng_event_field *field,
1787 size_t nesting)
1788 {
1789 int ret;
1790
1791 ret = _lttng_struct_type_statedump(session,
1792 &field->type, nesting);
1793 if (ret)
1794 return ret;
1795 ret = lttng_metadata_printf(session,
1796 "_%s;\n",
1797 field->name);
1798 return ret;
1799 }
1800
1801 /*
1802 * Must be called with sessions_mutex held.
1803 */
1804 static
1805 int _lttng_variant_type_statedump(struct lttng_session *session,
1806 const struct lttng_type *type,
1807 size_t nesting)
1808 {
1809 int ret;
1810 uint32_t i, nr_choices;
1811
1812 ret = print_tabs(session, nesting);
1813 if (ret)
1814 return ret;
1815 ret = lttng_metadata_printf(session,
1816 "variant <_%s> {\n",
1817 type->u.variant.tag_name);
1818 if (ret)
1819 return ret;
1820 nr_choices = type->u.variant.nr_choices;
1821 for (i = 0; i < nr_choices; i++) {
1822 const struct lttng_event_field *iter_field;
1823
1824 iter_field = &type->u.variant.choices[i];
1825 ret = _lttng_field_statedump(session, iter_field, nesting + 1);
1826 if (ret)
1827 return ret;
1828 }
1829 ret = print_tabs(session, nesting);
1830 if (ret)
1831 return ret;
1832 ret = lttng_metadata_printf(session,
1833 "}");
1834 return ret;
1835 }
1836
1837 /*
1838 * Must be called with sessions_mutex held.
1839 */
1840 static
1841 int _lttng_variant_statedump(struct lttng_session *session,
1842 const struct lttng_event_field *field,
1843 size_t nesting)
1844 {
1845 int ret;
1846
1847 ret = _lttng_variant_type_statedump(session,
1848 &field->type, nesting);
1849 if (ret)
1850 return ret;
1851 ret = lttng_metadata_printf(session,
1852 "_%s;\n",
1853 field->name);
1854 return ret;
1855 }
1856
1857 /*
1858 * Must be called with sessions_mutex held.
1859 */
1860 static
1861 int _lttng_array_compound_statedump(struct lttng_session *session,
1862 const struct lttng_event_field *field,
1863 size_t nesting)
1864 {
1865 int ret;
1866 const struct lttng_type *elem_type;
1867
1868 /* Only array of structures and variants are currently supported. */
1869 elem_type = field->type.u.array_compound.elem_type;
1870 switch (elem_type->atype) {
1871 case atype_struct:
1872 ret = _lttng_struct_type_statedump(session, elem_type, nesting);
1873 if (ret)
1874 return ret;
1875 break;
1876 case atype_variant:
1877 ret = _lttng_variant_type_statedump(session, elem_type, nesting);
1878 if (ret)
1879 return ret;
1880 break;
1881 default:
1882 return -EINVAL;
1883 }
1884 ret = lttng_metadata_printf(session,
1885 " _%s[%u];\n",
1886 field->name,
1887 field->type.u.array_compound.length);
1888 return ret;
1889 }
1890
1891 /*
1892 * Must be called with sessions_mutex held.
1893 */
1894 static
1895 int _lttng_sequence_compound_statedump(struct lttng_session *session,
1896 const struct lttng_event_field *field,
1897 size_t nesting)
1898 {
1899 int ret;
1900 const char *length_name;
1901 const struct lttng_type *elem_type;
1902
1903 length_name = field->type.u.sequence_compound.length_name;
1904
1905 /* Only array of structures and variants are currently supported. */
1906 elem_type = field->type.u.sequence_compound.elem_type;
1907 switch (elem_type->atype) {
1908 case atype_struct:
1909 ret = _lttng_struct_type_statedump(session, elem_type, nesting);
1910 if (ret)
1911 return ret;
1912 break;
1913 case atype_variant:
1914 ret = _lttng_variant_type_statedump(session, elem_type, nesting);
1915 if (ret)
1916 return ret;
1917 break;
1918 default:
1919 return -EINVAL;
1920 }
1921 ret = lttng_metadata_printf(session,
1922 " _%s[ _%s ];\n",
1923 field->name,
1924 length_name);
1925 return ret;
1926 }
1927
1928 /*
1929 * Must be called with sessions_mutex held.
1930 */
1931 static
1932 int _lttng_enum_statedump(struct lttng_session *session,
1933 const struct lttng_event_field *field,
1934 size_t nesting)
1935 {
1936 const struct lttng_enum_desc *enum_desc;
1937 const struct lttng_integer_type *container_type;
1938 int ret;
1939 unsigned int i, nr_entries;
1940
1941 enum_desc = field->type.u.basic.enumeration.desc;
1942 container_type = &field->type.u.basic.enumeration.container_type;
1943 nr_entries = enum_desc->nr_entries;
1944
1945 ret = print_tabs(session, nesting);
1946 if (ret)
1947 goto end;
1948 ret = lttng_metadata_printf(session,
1949 "enum : integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } {\n",
1950 container_type->size,
1951 container_type->alignment,
1952 container_type->signedness,
1953 (container_type->encoding == lttng_encode_none)
1954 ? "none"
1955 : (container_type->encoding == lttng_encode_UTF8)
1956 ? "UTF8"
1957 : "ASCII",
1958 container_type->base,
1959 #if __BYTE_ORDER == __BIG_ENDIAN
1960 container_type->reverse_byte_order ? " byte_order = le;" : ""
1961 #else
1962 container_type->reverse_byte_order ? " byte_order = be;" : ""
1963 #endif
1964 );
1965 if (ret)
1966 goto end;
1967 /* Dump all entries */
1968 for (i = 0; i < nr_entries; i++) {
1969 const struct lttng_enum_entry *entry = &enum_desc->entries[i];
1970 int j, len;
1971
1972 ret = print_tabs(session, nesting + 1);
1973 if (ret)
1974 goto end;
1975 ret = lttng_metadata_printf(session,
1976 "\"");
1977 if (ret)
1978 goto end;
1979 len = strlen(entry->string);
1980 /* Escape the character '"' */
1981 for (j = 0; j < len; j++) {
1982 char c = entry->string[j];
1983
1984 switch (c) {
1985 case '"':
1986 ret = lttng_metadata_printf(session,
1987 "\\\"");
1988 break;
1989 case '\\':
1990 ret = lttng_metadata_printf(session,
1991 "\\\\");
1992 break;
1993 default:
1994 ret = lttng_metadata_printf(session,
1995 "%c", c);
1996 break;
1997 }
1998 if (ret)
1999 goto end;
2000 }
2001 ret = lttng_metadata_printf(session, "\"");
2002 if (ret)
2003 goto end;
2004
2005 if (entry->options.is_auto) {
2006 ret = lttng_metadata_printf(session, ",\n");
2007 if (ret)
2008 goto end;
2009 } else {
2010 ret = lttng_metadata_printf(session,
2011 " = ");
2012 if (ret)
2013 goto end;
2014 if (entry->start.signedness)
2015 ret = lttng_metadata_printf(session,
2016 "%lld", (long long) entry->start.value);
2017 else
2018 ret = lttng_metadata_printf(session,
2019 "%llu", entry->start.value);
2020 if (ret)
2021 goto end;
2022 if (entry->start.signedness == entry->end.signedness &&
2023 entry->start.value
2024 == entry->end.value) {
2025 ret = lttng_metadata_printf(session,
2026 ",\n");
2027 } else {
2028 if (entry->end.signedness) {
2029 ret = lttng_metadata_printf(session,
2030 " ... %lld,\n",
2031 (long long) entry->end.value);
2032 } else {
2033 ret = lttng_metadata_printf(session,
2034 " ... %llu,\n",
2035 entry->end.value);
2036 }
2037 }
2038 if (ret)
2039 goto end;
2040 }
2041 }
2042 ret = print_tabs(session, nesting);
2043 if (ret)
2044 goto end;
2045 ret = lttng_metadata_printf(session, "} _%s;\n",
2046 field->name);
2047 end:
2048 return ret;
2049 }
2050
2051 /*
2052 * Must be called with sessions_mutex held.
2053 */
2054 static
2055 int _lttng_field_statedump(struct lttng_session *session,
2056 const struct lttng_event_field *field,
2057 size_t nesting)
2058 {
2059 int ret = 0;
2060
2061 switch (field->type.atype) {
2062 case atype_integer:
2063 ret = print_tabs(session, nesting);
2064 if (ret)
2065 return ret;
2066 ret = lttng_metadata_printf(session,
2067 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s;\n",
2068 field->type.u.basic.integer.size,
2069 field->type.u.basic.integer.alignment,
2070 field->type.u.basic.integer.signedness,
2071 (field->type.u.basic.integer.encoding == lttng_encode_none)
2072 ? "none"
2073 : (field->type.u.basic.integer.encoding == lttng_encode_UTF8)
2074 ? "UTF8"
2075 : "ASCII",
2076 field->type.u.basic.integer.base,
2077 #if __BYTE_ORDER == __BIG_ENDIAN
2078 field->type.u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
2079 #else
2080 field->type.u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
2081 #endif
2082 field->name);
2083 break;
2084 case atype_enum:
2085 ret = _lttng_enum_statedump(session, field, nesting);
2086 break;
2087 case atype_array:
2088 case atype_array_bitfield:
2089 {
2090 const struct lttng_basic_type *elem_type;
2091
2092 elem_type = &field->type.u.array.elem_type;
2093 if (field->type.u.array.elem_alignment) {
2094 ret = print_tabs(session, nesting);
2095 if (ret)
2096 return ret;
2097 ret = lttng_metadata_printf(session,
2098 "struct { } align(%u) _%s_padding;\n",
2099 field->type.u.array.elem_alignment * CHAR_BIT,
2100 field->name);
2101 if (ret)
2102 return ret;
2103 }
2104 ret = print_tabs(session, nesting);
2105 if (ret)
2106 return ret;
2107 ret = lttng_metadata_printf(session,
2108 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[%u];\n",
2109 elem_type->u.basic.integer.size,
2110 elem_type->u.basic.integer.alignment,
2111 elem_type->u.basic.integer.signedness,
2112 (elem_type->u.basic.integer.encoding == lttng_encode_none)
2113 ? "none"
2114 : (elem_type->u.basic.integer.encoding == lttng_encode_UTF8)
2115 ? "UTF8"
2116 : "ASCII",
2117 elem_type->u.basic.integer.base,
2118 #if __BYTE_ORDER == __BIG_ENDIAN
2119 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
2120 #else
2121 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
2122 #endif
2123 field->name, field->type.u.array.length);
2124 break;
2125 }
2126 case atype_sequence:
2127 case atype_sequence_bitfield:
2128 {
2129 const struct lttng_basic_type *elem_type;
2130 const struct lttng_basic_type *length_type;
2131
2132 elem_type = &field->type.u.sequence.elem_type;
2133 length_type = &field->type.u.sequence.length_type;
2134 ret = print_tabs(session, nesting);
2135 if (ret)
2136 return ret;
2137 ret = lttng_metadata_printf(session,
2138 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } __%s_length;\n",
2139 length_type->u.basic.integer.size,
2140 (unsigned int) length_type->u.basic.integer.alignment,
2141 length_type->u.basic.integer.signedness,
2142 (length_type->u.basic.integer.encoding == lttng_encode_none)
2143 ? "none"
2144 : ((length_type->u.basic.integer.encoding == lttng_encode_UTF8)
2145 ? "UTF8"
2146 : "ASCII"),
2147 length_type->u.basic.integer.base,
2148 #if __BYTE_ORDER == __BIG_ENDIAN
2149 length_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
2150 #else
2151 length_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
2152 #endif
2153 field->name);
2154 if (ret)
2155 return ret;
2156
2157 if (field->type.u.sequence.elem_alignment) {
2158 ret = print_tabs(session, nesting);
2159 if (ret)
2160 return ret;
2161 ret = lttng_metadata_printf(session,
2162 "struct { } align(%u) _%s_padding;\n",
2163 field->type.u.sequence.elem_alignment * CHAR_BIT,
2164 field->name);
2165 if (ret)
2166 return ret;
2167 }
2168 ret = print_tabs(session, nesting);
2169 if (ret)
2170 return ret;
2171 ret = lttng_metadata_printf(session,
2172 "integer { size = %u; align = %u; signed = %u; encoding = %s; base = %u;%s } _%s[ __%s_length ];\n",
2173 elem_type->u.basic.integer.size,
2174 (unsigned int) elem_type->u.basic.integer.alignment,
2175 elem_type->u.basic.integer.signedness,
2176 (elem_type->u.basic.integer.encoding == lttng_encode_none)
2177 ? "none"
2178 : ((elem_type->u.basic.integer.encoding == lttng_encode_UTF8)
2179 ? "UTF8"
2180 : "ASCII"),
2181 elem_type->u.basic.integer.base,
2182 #if __BYTE_ORDER == __BIG_ENDIAN
2183 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = le;" : "",
2184 #else
2185 elem_type->u.basic.integer.reverse_byte_order ? " byte_order = be;" : "",
2186 #endif
2187 field->name,
2188 field->name);
2189 break;
2190 }
2191
2192 case atype_string:
2193 /* Default encoding is UTF8 */
2194 ret = print_tabs(session, nesting);
2195 if (ret)
2196 return ret;
2197 ret = lttng_metadata_printf(session,
2198 "string%s _%s;\n",
2199 field->type.u.basic.string.encoding == lttng_encode_ASCII ?
2200 " { encoding = ASCII; }" : "",
2201 field->name);
2202 break;
2203 case atype_struct:
2204 ret = _lttng_struct_statedump(session, field, nesting);
2205 break;
2206 case atype_array_compound:
2207 ret = _lttng_array_compound_statedump(session, field, nesting);
2208 break;
2209 case atype_sequence_compound:
2210 ret = _lttng_sequence_compound_statedump(session, field, nesting);
2211 break;
2212 case atype_variant:
2213 ret = _lttng_variant_statedump(session, field, nesting);
2214 break;
2215
2216 default:
2217 WARN_ON_ONCE(1);
2218 return -EINVAL;
2219 }
2220 return ret;
2221 }
2222
2223 static
2224 int _lttng_context_metadata_statedump(struct lttng_session *session,
2225 struct lttng_ctx *ctx)
2226 {
2227 int ret = 0;
2228 int i;
2229
2230 if (!ctx)
2231 return 0;
2232 for (i = 0; i < ctx->nr_fields; i++) {
2233 const struct lttng_ctx_field *field = &ctx->fields[i];
2234
2235 ret = _lttng_field_statedump(session, &field->event_field, 2);
2236 if (ret)
2237 return ret;
2238 }
2239 return ret;
2240 }
2241
2242 static
2243 int _lttng_fields_metadata_statedump(struct lttng_session *session,
2244 struct lttng_event *event)
2245 {
2246 const struct lttng_event_desc *desc = event->desc;
2247 int ret = 0;
2248 int i;
2249
2250 for (i = 0; i < desc->nr_fields; i++) {
2251 const struct lttng_event_field *field = &desc->fields[i];
2252
2253 ret = _lttng_field_statedump(session, field, 2);
2254 if (ret)
2255 return ret;
2256 }
2257 return ret;
2258 }
2259
2260 /*
2261 * Must be called with sessions_mutex held.
2262 */
2263 static
2264 int _lttng_event_metadata_statedump(struct lttng_session *session,
2265 struct lttng_channel *chan,
2266 struct lttng_event *event)
2267 {
2268 int ret = 0;
2269
2270 if (event->metadata_dumped || !READ_ONCE(session->active))
2271 return 0;
2272 if (chan->channel_type == METADATA_CHANNEL)
2273 return 0;
2274
2275 ret = lttng_metadata_printf(session,
2276 "event {\n"
2277 " name = \"%s\";\n"
2278 " id = %u;\n"
2279 " stream_id = %u;\n",
2280 event->desc->name,
2281 event->id,
2282 event->chan->id);
2283 if (ret)
2284 goto end;
2285
2286 if (event->ctx) {
2287 ret = lttng_metadata_printf(session,
2288 " context := struct {\n");
2289 if (ret)
2290 goto end;
2291 }
2292 ret = _lttng_context_metadata_statedump(session, event->ctx);
2293 if (ret)
2294 goto end;
2295 if (event->ctx) {
2296 ret = lttng_metadata_printf(session,
2297 " };\n");
2298 if (ret)
2299 goto end;
2300 }
2301
2302 ret = lttng_metadata_printf(session,
2303 " fields := struct {\n"
2304 );
2305 if (ret)
2306 goto end;
2307
2308 ret = _lttng_fields_metadata_statedump(session, event);
2309 if (ret)
2310 goto end;
2311
2312 /*
2313 * LTTng space reservation can only reserve multiples of the
2314 * byte size.
2315 */
2316 ret = lttng_metadata_printf(session,
2317 " };\n"
2318 "};\n\n");
2319 if (ret)
2320 goto end;
2321
2322 event->metadata_dumped = 1;
2323 end:
2324 return ret;
2325
2326 }
2327
2328 /*
2329 * Must be called with sessions_mutex held.
2330 */
2331 static
2332 int _lttng_channel_metadata_statedump(struct lttng_session *session,
2333 struct lttng_channel *chan)
2334 {
2335 int ret = 0;
2336
2337 if (chan->metadata_dumped || !READ_ONCE(session->active))
2338 return 0;
2339
2340 if (chan->channel_type == METADATA_CHANNEL)
2341 return 0;
2342
2343 WARN_ON_ONCE(!chan->header_type);
2344 ret = lttng_metadata_printf(session,
2345 "stream {\n"
2346 " id = %u;\n"
2347 " event.header := %s;\n"
2348 " packet.context := struct packet_context;\n",
2349 chan->id,
2350 chan->header_type == 1 ? "struct event_header_compact" :
2351 "struct event_header_large");
2352 if (ret)
2353 goto end;
2354
2355 if (chan->ctx) {
2356 ret = lttng_metadata_printf(session,
2357 " event.context := struct {\n");
2358 if (ret)
2359 goto end;
2360 }
2361 ret = _lttng_context_metadata_statedump(session, chan->ctx);
2362 if (ret)
2363 goto end;
2364 if (chan->ctx) {
2365 ret = lttng_metadata_printf(session,
2366 " };\n");
2367 if (ret)
2368 goto end;
2369 }
2370
2371 ret = lttng_metadata_printf(session,
2372 "};\n\n");
2373
2374 chan->metadata_dumped = 1;
2375 end:
2376 return ret;
2377 }
2378
2379 /*
2380 * Must be called with sessions_mutex held.
2381 */
2382 static
2383 int _lttng_stream_packet_context_declare(struct lttng_session *session)
2384 {
2385 return lttng_metadata_printf(session,
2386 "struct packet_context {\n"
2387 " uint64_clock_monotonic_t timestamp_begin;\n"
2388 " uint64_clock_monotonic_t timestamp_end;\n"
2389 " uint64_t content_size;\n"
2390 " uint64_t packet_size;\n"
2391 " uint64_t packet_seq_num;\n"
2392 " unsigned long events_discarded;\n"
2393 " uint32_t cpu_id;\n"
2394 "};\n\n"
2395 );
2396 }
2397
2398 /*
2399 * Compact header:
2400 * id: range: 0 - 30.
2401 * id 31 is reserved to indicate an extended header.
2402 *
2403 * Large header:
2404 * id: range: 0 - 65534.
2405 * id 65535 is reserved to indicate an extended header.
2406 *
2407 * Must be called with sessions_mutex held.
2408 */
2409 static
2410 int _lttng_event_header_declare(struct lttng_session *session)
2411 {
2412 return lttng_metadata_printf(session,
2413 "struct event_header_compact {\n"
2414 " enum : uint5_t { compact = 0 ... 30, extended = 31 } id;\n"
2415 " variant <id> {\n"
2416 " struct {\n"
2417 " uint27_clock_monotonic_t timestamp;\n"
2418 " } compact;\n"
2419 " struct {\n"
2420 " uint32_t id;\n"
2421 " uint64_clock_monotonic_t timestamp;\n"
2422 " } extended;\n"
2423 " } v;\n"
2424 "} align(%u);\n"
2425 "\n"
2426 "struct event_header_large {\n"
2427 " enum : uint16_t { compact = 0 ... 65534, extended = 65535 } id;\n"
2428 " variant <id> {\n"
2429 " struct {\n"
2430 " uint32_clock_monotonic_t timestamp;\n"
2431 " } compact;\n"
2432 " struct {\n"
2433 " uint32_t id;\n"
2434 " uint64_clock_monotonic_t timestamp;\n"
2435 " } extended;\n"
2436 " } v;\n"
2437 "} align(%u);\n\n",
2438 lttng_alignof(uint32_t) * CHAR_BIT,
2439 lttng_alignof(uint16_t) * CHAR_BIT
2440 );
2441 }
2442
2443 /*
2444 * Approximation of NTP time of day to clock monotonic correlation,
2445 * taken at start of trace.
2446 * Yes, this is only an approximation. Yes, we can (and will) do better
2447 * in future versions.
2448 * This function may return a negative offset. It may happen if the
2449 * system sets the REALTIME clock to 0 after boot.
2450 */
2451 static
2452 int64_t measure_clock_offset(void)
2453 {
2454 uint64_t monotonic_avg, monotonic[2], realtime;
2455 uint64_t tcf = trace_clock_freq();
2456 int64_t offset;
2457 struct timespec rts = { 0, 0 };
2458 unsigned long flags;
2459
2460 /* Disable interrupts to increase correlation precision. */
2461 local_irq_save(flags);
2462 monotonic[0] = trace_clock_read64();
2463 getnstimeofday(&rts);
2464 monotonic[1] = trace_clock_read64();
2465 local_irq_restore(flags);
2466
2467 monotonic_avg = (monotonic[0] + monotonic[1]) >> 1;
2468 realtime = (uint64_t) rts.tv_sec * tcf;
2469 if (tcf == NSEC_PER_SEC) {
2470 realtime += rts.tv_nsec;
2471 } else {
2472 uint64_t n = rts.tv_nsec * tcf;
2473
2474 do_div(n, NSEC_PER_SEC);
2475 realtime += n;
2476 }
2477 offset = (int64_t) realtime - monotonic_avg;
2478 return offset;
2479 }
2480
2481 /*
2482 * Output metadata into this session's metadata buffers.
2483 * Must be called with sessions_mutex held.
2484 */
2485 static
2486 int _lttng_session_metadata_statedump(struct lttng_session *session)
2487 {
2488 unsigned char *uuid_c = session->uuid.b;
2489 unsigned char uuid_s[37], clock_uuid_s[BOOT_ID_LEN];
2490 struct lttng_channel *chan;
2491 struct lttng_event *event;
2492 int ret = 0;
2493
2494 if (!READ_ONCE(session->active))
2495 return 0;
2496 if (session->metadata_dumped)
2497 goto skip_session;
2498
2499 snprintf(uuid_s, sizeof(uuid_s),
2500 "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
2501 uuid_c[0], uuid_c[1], uuid_c[2], uuid_c[3],
2502 uuid_c[4], uuid_c[5], uuid_c[6], uuid_c[7],
2503 uuid_c[8], uuid_c[9], uuid_c[10], uuid_c[11],
2504 uuid_c[12], uuid_c[13], uuid_c[14], uuid_c[15]);
2505
2506 ret = lttng_metadata_printf(session,
2507 "typealias integer { size = 8; align = %u; signed = false; } := uint8_t;\n"
2508 "typealias integer { size = 16; align = %u; signed = false; } := uint16_t;\n"
2509 "typealias integer { size = 32; align = %u; signed = false; } := uint32_t;\n"
2510 "typealias integer { size = 64; align = %u; signed = false; } := uint64_t;\n"
2511 "typealias integer { size = %u; align = %u; signed = false; } := unsigned long;\n"
2512 "typealias integer { size = 5; align = 1; signed = false; } := uint5_t;\n"
2513 "typealias integer { size = 27; align = 1; signed = false; } := uint27_t;\n"
2514 "\n"
2515 "trace {\n"
2516 " major = %u;\n"
2517 " minor = %u;\n"
2518 " uuid = \"%s\";\n"
2519 " byte_order = %s;\n"
2520 " packet.header := struct {\n"
2521 " uint32_t magic;\n"
2522 " uint8_t uuid[16];\n"
2523 " uint32_t stream_id;\n"
2524 " uint64_t stream_instance_id;\n"
2525 " };\n"
2526 "};\n\n",
2527 lttng_alignof(uint8_t) * CHAR_BIT,
2528 lttng_alignof(uint16_t) * CHAR_BIT,
2529 lttng_alignof(uint32_t) * CHAR_BIT,
2530 lttng_alignof(uint64_t) * CHAR_BIT,
2531 sizeof(unsigned long) * CHAR_BIT,
2532 lttng_alignof(unsigned long) * CHAR_BIT,
2533 CTF_SPEC_MAJOR,
2534 CTF_SPEC_MINOR,
2535 uuid_s,
2536 #if __BYTE_ORDER == __BIG_ENDIAN
2537 "be"
2538 #else
2539 "le"
2540 #endif
2541 );
2542 if (ret)
2543 goto end;
2544
2545 ret = lttng_metadata_printf(session,
2546 "env {\n"
2547 " hostname = \"%s\";\n"
2548 " domain = \"kernel\";\n"
2549 " sysname = \"%s\";\n"
2550 " kernel_release = \"%s\";\n"
2551 " kernel_version = \"%s\";\n"
2552 " tracer_name = \"lttng-modules\";\n"
2553 " tracer_major = %d;\n"
2554 " tracer_minor = %d;\n"
2555 " tracer_patchlevel = %d;\n"
2556 "};\n\n",
2557 current->nsproxy->uts_ns->name.nodename,
2558 utsname()->sysname,
2559 utsname()->release,
2560 utsname()->version,
2561 LTTNG_MODULES_MAJOR_VERSION,
2562 LTTNG_MODULES_MINOR_VERSION,
2563 LTTNG_MODULES_PATCHLEVEL_VERSION
2564 );
2565 if (ret)
2566 goto end;
2567
2568 ret = lttng_metadata_printf(session,
2569 "clock {\n"
2570 " name = \"%s\";\n",
2571 trace_clock_name()
2572 );
2573 if (ret)
2574 goto end;
2575
2576 if (!trace_clock_uuid(clock_uuid_s)) {
2577 ret = lttng_metadata_printf(session,
2578 " uuid = \"%s\";\n",
2579 clock_uuid_s
2580 );
2581 if (ret)
2582 goto end;
2583 }
2584
2585 ret = lttng_metadata_printf(session,
2586 " description = \"%s\";\n"
2587 " freq = %llu; /* Frequency, in Hz */\n"
2588 " /* clock value offset from Epoch is: offset * (1/freq) */\n"
2589 " offset = %lld;\n"
2590 "};\n\n",
2591 trace_clock_description(),
2592 (unsigned long long) trace_clock_freq(),
2593 (long long) measure_clock_offset()
2594 );
2595 if (ret)
2596 goto end;
2597
2598 ret = lttng_metadata_printf(session,
2599 "typealias integer {\n"
2600 " size = 27; align = 1; signed = false;\n"
2601 " map = clock.%s.value;\n"
2602 "} := uint27_clock_monotonic_t;\n"
2603 "\n"
2604 "typealias integer {\n"
2605 " size = 32; align = %u; signed = false;\n"
2606 " map = clock.%s.value;\n"
2607 "} := uint32_clock_monotonic_t;\n"
2608 "\n"
2609 "typealias integer {\n"
2610 " size = 64; align = %u; signed = false;\n"
2611 " map = clock.%s.value;\n"
2612 "} := uint64_clock_monotonic_t;\n\n",
2613 trace_clock_name(),
2614 lttng_alignof(uint32_t) * CHAR_BIT,
2615 trace_clock_name(),
2616 lttng_alignof(uint64_t) * CHAR_BIT,
2617 trace_clock_name()
2618 );
2619 if (ret)
2620 goto end;
2621
2622 ret = _lttng_stream_packet_context_declare(session);
2623 if (ret)
2624 goto end;
2625
2626 ret = _lttng_event_header_declare(session);
2627 if (ret)
2628 goto end;
2629
2630 skip_session:
2631 list_for_each_entry(chan, &session->chan, list) {
2632 ret = _lttng_channel_metadata_statedump(session, chan);
2633 if (ret)
2634 goto end;
2635 }
2636
2637 list_for_each_entry(event, &session->events, list) {
2638 ret = _lttng_event_metadata_statedump(session, event->chan, event);
2639 if (ret)
2640 goto end;
2641 }
2642 session->metadata_dumped = 1;
2643 end:
2644 return ret;
2645 }
2646
2647 /**
2648 * lttng_transport_register - LTT transport registration
2649 * @transport: transport structure
2650 *
2651 * Registers a transport which can be used as output to extract the data out of
2652 * LTTng. The module calling this registration function must ensure that no
2653 * trap-inducing code will be executed by the transport functions. E.g.
2654 * vmalloc_sync_all() must be called between a vmalloc and the moment the memory
2655 * is made visible to the transport function. This registration acts as a
2656 * vmalloc_sync_all. Therefore, only if the module allocates virtual memory
2657 * after its registration must it synchronize the TLBs.
2658 */
2659 void lttng_transport_register(struct lttng_transport *transport)
2660 {
2661 /*
2662 * Make sure no page fault can be triggered by the module about to be
2663 * registered. We deal with this here so we don't have to call
2664 * vmalloc_sync_all() in each module's init.
2665 */
2666 wrapper_vmalloc_sync_all();
2667
2668 mutex_lock(&sessions_mutex);
2669 list_add_tail(&transport->node, &lttng_transport_list);
2670 mutex_unlock(&sessions_mutex);
2671 }
2672 EXPORT_SYMBOL_GPL(lttng_transport_register);
2673
2674 /**
2675 * lttng_transport_unregister - LTT transport unregistration
2676 * @transport: transport structure
2677 */
2678 void lttng_transport_unregister(struct lttng_transport *transport)
2679 {
2680 mutex_lock(&sessions_mutex);
2681 list_del(&transport->node);
2682 mutex_unlock(&sessions_mutex);
2683 }
2684 EXPORT_SYMBOL_GPL(lttng_transport_unregister);
2685
2686 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0))
2687
2688 enum cpuhp_state lttng_hp_prepare;
2689 enum cpuhp_state lttng_hp_online;
2690
2691 static int lttng_hotplug_prepare(unsigned int cpu, struct hlist_node *node)
2692 {
2693 struct lttng_cpuhp_node *lttng_node;
2694
2695 lttng_node = container_of(node, struct lttng_cpuhp_node, node);
2696 switch (lttng_node->component) {
2697 case LTTNG_RING_BUFFER_FRONTEND:
2698 return 0;
2699 case LTTNG_RING_BUFFER_BACKEND:
2700 return lttng_cpuhp_rb_backend_prepare(cpu, lttng_node);
2701 case LTTNG_RING_BUFFER_ITER:
2702 return 0;
2703 case LTTNG_CONTEXT_PERF_COUNTERS:
2704 return 0;
2705 default:
2706 return -EINVAL;
2707 }
2708 }
2709
2710 static int lttng_hotplug_dead(unsigned int cpu, struct hlist_node *node)
2711 {
2712 struct lttng_cpuhp_node *lttng_node;
2713
2714 lttng_node = container_of(node, struct lttng_cpuhp_node, node);
2715 switch (lttng_node->component) {
2716 case LTTNG_RING_BUFFER_FRONTEND:
2717 return lttng_cpuhp_rb_frontend_dead(cpu, lttng_node);
2718 case LTTNG_RING_BUFFER_BACKEND:
2719 return 0;
2720 case LTTNG_RING_BUFFER_ITER:
2721 return 0;
2722 case LTTNG_CONTEXT_PERF_COUNTERS:
2723 return lttng_cpuhp_perf_counter_dead(cpu, lttng_node);
2724 default:
2725 return -EINVAL;
2726 }
2727 }
2728
2729 static int lttng_hotplug_online(unsigned int cpu, struct hlist_node *node)
2730 {
2731 struct lttng_cpuhp_node *lttng_node;
2732
2733 lttng_node = container_of(node, struct lttng_cpuhp_node, node);
2734 switch (lttng_node->component) {
2735 case LTTNG_RING_BUFFER_FRONTEND:
2736 return lttng_cpuhp_rb_frontend_online(cpu, lttng_node);
2737 case LTTNG_RING_BUFFER_BACKEND:
2738 return 0;
2739 case LTTNG_RING_BUFFER_ITER:
2740 return lttng_cpuhp_rb_iter_online(cpu, lttng_node);
2741 case LTTNG_CONTEXT_PERF_COUNTERS:
2742 return lttng_cpuhp_perf_counter_online(cpu, lttng_node);
2743 default:
2744 return -EINVAL;
2745 }
2746 }
2747
2748 static int lttng_hotplug_offline(unsigned int cpu, struct hlist_node *node)
2749 {
2750 struct lttng_cpuhp_node *lttng_node;
2751
2752 lttng_node = container_of(node, struct lttng_cpuhp_node, node);
2753 switch (lttng_node->component) {
2754 case LTTNG_RING_BUFFER_FRONTEND:
2755 return lttng_cpuhp_rb_frontend_offline(cpu, lttng_node);
2756 case LTTNG_RING_BUFFER_BACKEND:
2757 return 0;
2758 case LTTNG_RING_BUFFER_ITER:
2759 return 0;
2760 case LTTNG_CONTEXT_PERF_COUNTERS:
2761 return 0;
2762 default:
2763 return -EINVAL;
2764 }
2765 }
2766
2767 static int __init lttng_init_cpu_hotplug(void)
2768 {
2769 int ret;
2770
2771 ret = cpuhp_setup_state_multi(CPUHP_BP_PREPARE_DYN, "lttng:prepare",
2772 lttng_hotplug_prepare,
2773 lttng_hotplug_dead);
2774 if (ret < 0) {
2775 return ret;
2776 }
2777 lttng_hp_prepare = ret;
2778 lttng_rb_set_hp_prepare(ret);
2779
2780 ret = cpuhp_setup_state_multi(CPUHP_AP_ONLINE_DYN, "lttng:online",
2781 lttng_hotplug_online,
2782 lttng_hotplug_offline);
2783 if (ret < 0) {
2784 cpuhp_remove_multi_state(lttng_hp_prepare);
2785 lttng_hp_prepare = 0;
2786 return ret;
2787 }
2788 lttng_hp_online = ret;
2789 lttng_rb_set_hp_online(ret);
2790
2791 return 0;
2792 }
2793
2794 static void __exit lttng_exit_cpu_hotplug(void)
2795 {
2796 lttng_rb_set_hp_online(0);
2797 cpuhp_remove_multi_state(lttng_hp_online);
2798 lttng_rb_set_hp_prepare(0);
2799 cpuhp_remove_multi_state(lttng_hp_prepare);
2800 }
2801
2802 #else /* #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
2803 static int lttng_init_cpu_hotplug(void)
2804 {
2805 return 0;
2806 }
2807 static void lttng_exit_cpu_hotplug(void)
2808 {
2809 }
2810 #endif /* #else #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4,10,0)) */
2811
2812
2813 static int __init lttng_events_init(void)
2814 {
2815 int ret;
2816
2817 ret = wrapper_lttng_fixup_sig(THIS_MODULE);
2818 if (ret)
2819 return ret;
2820 ret = wrapper_get_pfnblock_flags_mask_init();
2821 if (ret)
2822 return ret;
2823 ret = wrapper_get_pageblock_flags_mask_init();
2824 if (ret)
2825 return ret;
2826 ret = lttng_probes_init();
2827 if (ret)
2828 return ret;
2829 ret = lttng_context_init();
2830 if (ret)
2831 return ret;
2832 ret = lttng_tracepoint_init();
2833 if (ret)
2834 goto error_tp;
2835 event_cache = KMEM_CACHE(lttng_event, 0);
2836 if (!event_cache) {
2837 ret = -ENOMEM;
2838 goto error_kmem;
2839 }
2840 ret = lttng_abi_init();
2841 if (ret)
2842 goto error_abi;
2843 ret = lttng_logger_init();
2844 if (ret)
2845 goto error_logger;
2846 ret = lttng_init_cpu_hotplug();
2847 if (ret)
2848 goto error_hotplug;
2849 printk(KERN_NOTICE "LTTng: Loaded modules v%s.%s.%s%s (%s)%s%s\n",
2850 __stringify(LTTNG_MODULES_MAJOR_VERSION),
2851 __stringify(LTTNG_MODULES_MINOR_VERSION),
2852 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
2853 LTTNG_MODULES_EXTRAVERSION,
2854 LTTNG_VERSION_NAME,
2855 #ifdef LTTNG_EXTRA_VERSION_GIT
2856 LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT,
2857 #else
2858 "",
2859 #endif
2860 #ifdef LTTNG_EXTRA_VERSION_NAME
2861 LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME);
2862 #else
2863 "");
2864 #endif
2865 return 0;
2866
2867 error_hotplug:
2868 lttng_logger_exit();
2869 error_logger:
2870 lttng_abi_exit();
2871 error_abi:
2872 kmem_cache_destroy(event_cache);
2873 error_kmem:
2874 lttng_tracepoint_exit();
2875 error_tp:
2876 lttng_context_exit();
2877 printk(KERN_NOTICE "LTTng: Failed to load modules v%s.%s.%s%s (%s)%s%s\n",
2878 __stringify(LTTNG_MODULES_MAJOR_VERSION),
2879 __stringify(LTTNG_MODULES_MINOR_VERSION),
2880 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
2881 LTTNG_MODULES_EXTRAVERSION,
2882 LTTNG_VERSION_NAME,
2883 #ifdef LTTNG_EXTRA_VERSION_GIT
2884 LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT,
2885 #else
2886 "",
2887 #endif
2888 #ifdef LTTNG_EXTRA_VERSION_NAME
2889 LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME);
2890 #else
2891 "");
2892 #endif
2893 return ret;
2894 }
2895
2896 module_init(lttng_events_init);
2897
2898 static void __exit lttng_events_exit(void)
2899 {
2900 struct lttng_session *session, *tmpsession;
2901
2902 lttng_exit_cpu_hotplug();
2903 lttng_logger_exit();
2904 lttng_abi_exit();
2905 list_for_each_entry_safe(session, tmpsession, &sessions, list)
2906 lttng_session_destroy(session);
2907 kmem_cache_destroy(event_cache);
2908 lttng_tracepoint_exit();
2909 lttng_context_exit();
2910 printk(KERN_NOTICE "LTTng: Unloaded modules v%s.%s.%s%s (%s)%s%s\n",
2911 __stringify(LTTNG_MODULES_MAJOR_VERSION),
2912 __stringify(LTTNG_MODULES_MINOR_VERSION),
2913 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION),
2914 LTTNG_MODULES_EXTRAVERSION,
2915 LTTNG_VERSION_NAME,
2916 #ifdef LTTNG_EXTRA_VERSION_GIT
2917 LTTNG_EXTRA_VERSION_GIT[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_GIT,
2918 #else
2919 "",
2920 #endif
2921 #ifdef LTTNG_EXTRA_VERSION_NAME
2922 LTTNG_EXTRA_VERSION_NAME[0] == '\0' ? "" : " - " LTTNG_EXTRA_VERSION_NAME);
2923 #else
2924 "");
2925 #endif
2926 }
2927
2928 module_exit(lttng_events_exit);
2929
2930 #include "extra_version/patches.i"
2931 #ifdef LTTNG_EXTRA_VERSION_GIT
2932 MODULE_INFO(extra_version_git, LTTNG_EXTRA_VERSION_GIT);
2933 #endif
2934 #ifdef LTTNG_EXTRA_VERSION_NAME
2935 MODULE_INFO(extra_version_name, LTTNG_EXTRA_VERSION_NAME);
2936 #endif
2937 MODULE_LICENSE("GPL and additional rights");
2938 MODULE_AUTHOR("Mathieu Desnoyers <mathieu.desnoyers@efficios.com>");
2939 MODULE_DESCRIPTION("LTTng tracer");
2940 MODULE_VERSION(__stringify(LTTNG_MODULES_MAJOR_VERSION) "."
2941 __stringify(LTTNG_MODULES_MINOR_VERSION) "."
2942 __stringify(LTTNG_MODULES_PATCHLEVEL_VERSION)
2943 LTTNG_MODULES_EXTRAVERSION);
This page took 0.144901 seconds and 4 git commands to generate.