Commit | Line | Data |
---|---|---|
b7cdc182 | 1 | /* SPDX-License-Identifier: (GPL-2.0-only or LGPL-2.1-only) |
a6cf40a4 MJ |
2 | * |
3 | * lttng-context-ipc-ns.c | |
4 | * | |
5 | * LTTng ipc namespace context. | |
6 | * | |
7 | * Copyright (C) 2009-2012 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
8 | * 2019 Michael Jeanson <mjeanson@efficios.com> | |
9 | * | |
10 | */ | |
11 | ||
455d6bcc MJ |
12 | #ifdef CONFIG_IPC_NS |
13 | ||
a6cf40a4 MJ |
14 | #include <linux/module.h> |
15 | #include <linux/slab.h> | |
16 | #include <linux/sched.h> | |
17 | #include <linux/ipc_namespace.h> | |
2df37e95 | 18 | #include <lttng/events.h> |
0fe45627 | 19 | #include <lttng/events-internal.h> |
24591303 | 20 | #include <ringbuffer/frontend_types.h> |
a6cf40a4 | 21 | #include <wrapper/vmalloc.h> |
2df37e95 | 22 | #include <lttng/tracer.h> |
a6cf40a4 | 23 | |
a6cf40a4 | 24 | static |
a92e844e | 25 | size_t ipc_ns_get_size(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, size_t offset) |
a6cf40a4 MJ |
26 | { |
27 | size_t size = 0; | |
28 | ||
29 | size += lib_ring_buffer_align(offset, lttng_alignof(unsigned int)); | |
30 | size += sizeof(unsigned int); | |
31 | return size; | |
32 | } | |
33 | ||
34 | static | |
a92e844e | 35 | void ipc_ns_record(void *priv, struct lttng_kernel_probe_ctx *probe_ctx, |
8a57ec02 | 36 | struct lttng_kernel_ring_buffer_ctx *ctx, |
f7d06400 | 37 | struct lttng_kernel_channel_buffer *chan) |
a6cf40a4 MJ |
38 | { |
39 | unsigned int ipc_ns_inum = 0; | |
40 | ||
41 | /* | |
42 | * nsproxy can be NULL when scheduled out of exit. | |
43 | * | |
44 | * As documented in 'linux/nsproxy.h' namespaces access rules, no | |
45 | * precautions should be taken when accessing the current task's | |
46 | * namespaces, just dereference the pointers. | |
47 | */ | |
48 | if (current->nsproxy) | |
93e5bcec | 49 | ipc_ns_inum = current->nsproxy->ipc_ns->ns.inum; |
a6cf40a4 | 50 | |
f5ffbd77 | 51 | chan->ops->event_write(ctx, &ipc_ns_inum, sizeof(ipc_ns_inum), lttng_alignof(ipc_ns_inum)); |
a6cf40a4 MJ |
52 | } |
53 | ||
54 | static | |
2dc781e0 | 55 | void ipc_ns_get_value(void *priv, |
a92e844e | 56 | struct lttng_kernel_probe_ctx *lttng_probe_ctx, |
2dc781e0 | 57 | struct lttng_ctx_value *value) |
a6cf40a4 MJ |
58 | { |
59 | unsigned int ipc_ns_inum = 0; | |
60 | ||
61 | /* | |
62 | * nsproxy can be NULL when scheduled out of exit. | |
63 | * | |
64 | * As documented in 'linux/nsproxy.h' namespaces access rules, no | |
65 | * precautions should be taken when accessing the current task's | |
66 | * namespaces, just dereference the pointers. | |
67 | */ | |
68 | if (current->nsproxy) | |
93e5bcec | 69 | ipc_ns_inum = current->nsproxy->ipc_ns->ns.inum; |
a6cf40a4 | 70 | |
2dc781e0 | 71 | value->u.s64 = ipc_ns_inum; |
a6cf40a4 MJ |
72 | } |
73 | ||
437d5aa5 MD |
74 | static const struct lttng_kernel_ctx_field *ctx_field = lttng_kernel_static_ctx_field( |
75 | lttng_kernel_static_event_field("ipc_ns", | |
76 | lttng_kernel_static_type_integer_from_type(unsigned int, __BYTE_ORDER, 10), | |
4697aac7 | 77 | false, false), |
437d5aa5 | 78 | ipc_ns_get_size, |
437d5aa5 MD |
79 | ipc_ns_record, |
80 | ipc_ns_get_value, | |
81 | NULL, NULL); | |
82 | ||
83 | int lttng_add_ipc_ns_to_ctx(struct lttng_kernel_ctx **ctx) | |
a6cf40a4 | 84 | { |
437d5aa5 | 85 | int ret; |
a6cf40a4 | 86 | |
437d5aa5 | 87 | if (lttng_kernel_find_context(*ctx, ctx_field->event_field->name)) |
a6cf40a4 | 88 | return -EEXIST; |
437d5aa5 | 89 | ret = lttng_kernel_context_append(ctx, ctx_field); |
263b6c88 | 90 | wrapper_vmalloc_sync_mappings(); |
437d5aa5 | 91 | return ret; |
a6cf40a4 MJ |
92 | } |
93 | EXPORT_SYMBOL_GPL(lttng_add_ipc_ns_to_ctx); | |
94 | ||
95 | #endif |