Skip to content

Commit 09bb885

Browse files
committed
Merge tag 'trace-v5.18-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace
Pull more tracing updates from Steven Rostedt: - Rename the staging files to give them some meaning. Just stage1,stag2,etc, does not show what they are for - Check for NULL from allocation in bootconfig - Hold event mutex for dyn_event call in user events - Mark user events to broken (to work on the API) - Remove eBPF updates from user events - Remove user events from uapi header to keep it from being installed. - Move ftrace_graph_is_dead() into inline as it is called from hot paths and also convert it into a static branch. * tag 'trace-v5.18-2' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace: tracing: Move user_events.h temporarily out of include/uapi ftrace: Make ftrace_graph_is_dead() a static branch tracing: Set user_events to BROKEN tracing/user_events: Remove eBPF interfaces tracing/user_events: Hold event_mutex during dyn_event_add proc: bootconfig: Add null pointer check tracing: Rename the staging files for trace_events
2 parents 34a53ff + 5cfff56 commit 09bb885

15 files changed

+44
-167
lines changed

Documentation/trace/user_events.rst

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ user_events: User-based Event Tracing
77
Overview
88
--------
99
User based trace events allow user processes to create events and trace data
10-
that can be viewed via existing tools, such as ftrace, perf and eBPF.
10+
that can be viewed via existing tools, such as ftrace and perf.
1111
To enable this feature, build your kernel with CONFIG_USER_EVENTS=y.
1212

1313
Programs can view status of the events via
@@ -67,8 +67,7 @@ The command string format is as follows::
6767

6868
Supported Flags
6969
^^^^^^^^^^^^^^^
70-
**BPF_ITER** - EBPF programs attached to this event will get the raw iovec
71-
struct instead of any data copies for max performance.
70+
None yet
7271

7372
Field Format
7473
^^^^^^^^^^^^
@@ -160,7 +159,7 @@ The following values are defined to aid in checking what has been attached:
160159

161160
**EVENT_STATUS_FTRACE** - Bit set if ftrace has been attached (Bit 0).
162161

163-
**EVENT_STATUS_PERF** - Bit set if perf/eBPF has been attached (Bit 1).
162+
**EVENT_STATUS_PERF** - Bit set if perf has been attached (Bit 1).
164163

165164
Writing Data
166165
------------
@@ -204,13 +203,6 @@ It's advised for user programs to do the following::
204203

205204
**NOTE:** *The write_index is not emitted out into the trace being recorded.*
206205

207-
EBPF
208-
----
209-
EBPF programs that attach to a user-based event tracepoint are given a pointer
210-
to a struct user_bpf_context. The bpf context contains the data type (which can
211-
be a user or kernel buffer, or can be a pointer to the iovec) and the data
212-
length that was emitted (minus the write_index).
213-
214206
Example Code
215207
------------
216208
See sample code in samples/user_events.

fs/proc/bootconfig.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ static int __init copy_xbc_key_value_list(char *dst, size_t size)
3232
int ret = 0;
3333

3434
key = kzalloc(XBC_KEYLEN_MAX, GFP_KERNEL);
35+
if (!key)
36+
return -ENOMEM;
3537

3638
xbc_for_each_key_value(leaf, val) {
3739
ret = xbc_node_compose_key(leaf, key, XBC_KEYLEN_MAX);

include/linux/ftrace.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
#include <linux/trace_recursion.h>
1111
#include <linux/trace_clock.h>
12+
#include <linux/jump_label.h>
1213
#include <linux/kallsyms.h>
1314
#include <linux/linkage.h>
1415
#include <linux/bitops.h>
@@ -1018,7 +1019,20 @@ unsigned long ftrace_graph_ret_addr(struct task_struct *task, int *idx,
10181019
extern int register_ftrace_graph(struct fgraph_ops *ops);
10191020
extern void unregister_ftrace_graph(struct fgraph_ops *ops);
10201021

1021-
extern bool ftrace_graph_is_dead(void);
1022+
/**
1023+
* ftrace_graph_is_dead - returns true if ftrace_graph_stop() was called
1024+
*
1025+
* ftrace_graph_stop() is called when a severe error is detected in
1026+
* the function graph tracing. This function is called by the critical
1027+
* paths of function graph to keep those paths from doing any more harm.
1028+
*/
1029+
DECLARE_STATIC_KEY_FALSE(kill_ftrace_graph);
1030+
1031+
static inline bool ftrace_graph_is_dead(void)
1032+
{
1033+
return static_branch_unlikely(&kill_ftrace_graph);
1034+
}
1035+
10221036
extern void ftrace_graph_stop(void);
10231037

10241038
/* The current handlers in use */

include/linux/user_events.h

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
/* Create dynamic location entry within a 32-bit value */
3333
#define DYN_LOC(offset, size) ((size) << 16 | (offset))
3434

35-
/* Use raw iterator for attached BPF program(s), no affect on ftrace/perf */
36-
#define FLAG_BPF_ITER (1 << 0)
37-
3835
/*
3936
* Describes an event registration and stores the results of the registration.
4037
* This structure is passed to the DIAG_IOCSREG ioctl, callers at a minimum
@@ -63,54 +60,4 @@ struct user_reg {
6360
/* Requests to delete a user_event */
6461
#define DIAG_IOCSDEL _IOW(DIAG_IOC_MAGIC, 1, char*)
6562

66-
/* Data type that was passed to the BPF program */
67-
enum {
68-
/* Data resides in kernel space */
69-
USER_BPF_DATA_KERNEL,
70-
71-
/* Data resides in user space */
72-
USER_BPF_DATA_USER,
73-
74-
/* Data is a pointer to a user_bpf_iter structure */
75-
USER_BPF_DATA_ITER,
76-
};
77-
78-
/*
79-
* Describes an iovec iterator that BPF programs can use to access data for
80-
* a given user_event write() / writev() call.
81-
*/
82-
struct user_bpf_iter {
83-
84-
/* Offset of the data within the first iovec */
85-
__u32 iov_offset;
86-
87-
/* Number of iovec structures */
88-
__u32 nr_segs;
89-
90-
/* Pointer to iovec structures */
91-
const struct iovec *iov;
92-
};
93-
94-
/* Context that BPF programs receive when attached to a user_event */
95-
struct user_bpf_context {
96-
97-
/* Data type being passed (see union below) */
98-
__u32 data_type;
99-
100-
/* Length of the data */
101-
__u32 data_len;
102-
103-
/* Pointer to data, varies by data type */
104-
union {
105-
/* Kernel data (data_type == USER_BPF_DATA_KERNEL) */
106-
void *kdata;
107-
108-
/* User data (data_type == USER_BPF_DATA_USER) */
109-
void *udata;
110-
111-
/* Direct iovec (data_type == USER_BPF_DATA_ITER) */
112-
struct user_bpf_iter *iter;
113-
};
114-
};
115-
11663
#endif /* _UAPI_LINUX_USER_EVENTS_H */

include/trace/trace_custom_events.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
/* Stage 1 creates the structure of the recorded event layout */
3737

38-
#include "stages/stage1_defines.h"
38+
#include "stages/stage1_struct_define.h"
3939

4040
#undef DECLARE_CUSTOM_EVENT_CLASS
4141
#define DECLARE_CUSTOM_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
@@ -56,7 +56,7 @@
5656

5757
/* Stage 2 creates the custom class */
5858

59-
#include "stages/stage2_defines.h"
59+
#include "stages/stage2_data_offsets.h"
6060

6161
#undef DECLARE_CUSTOM_EVENT_CLASS
6262
#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -71,7 +71,7 @@
7171

7272
/* Stage 3 create the way to print the custom event */
7373

74-
#include "stages/stage3_defines.h"
74+
#include "stages/stage3_trace_output.h"
7575

7676
#undef DECLARE_CUSTOM_EVENT_CLASS
7777
#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -102,7 +102,7 @@ static struct trace_event_functions trace_custom_event_type_funcs_##call = { \
102102

103103
/* Stage 4 creates the offset layout for the fields */
104104

105-
#include "stages/stage4_defines.h"
105+
#include "stages/stage4_event_fields.h"
106106

107107
#undef DECLARE_CUSTOM_EVENT_CLASS
108108
#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, func, print) \
@@ -114,7 +114,7 @@ static struct trace_event_fields trace_custom_event_fields_##call[] = { \
114114

115115
/* Stage 5 creates the helper function for dynamic fields */
116116

117-
#include "stages/stage5_defines.h"
117+
#include "stages/stage5_get_offsets.h"
118118

119119
#undef DECLARE_CUSTOM_EVENT_CLASS
120120
#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -134,7 +134,7 @@ static inline notrace int trace_custom_event_get_offsets_##call( \
134134

135135
/* Stage 6 creates the probe function that records the event */
136136

137-
#include "stages/stage6_defines.h"
137+
#include "stages/stage6_event_callback.h"
138138

139139
#undef DECLARE_CUSTOM_EVENT_CLASS
140140
#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -182,7 +182,7 @@ static inline void ftrace_test_custom_probe_##call(void) \
182182

183183
/* Stage 7 creates the actual class and event structure for the custom event */
184184

185-
#include "stages/stage7_defines.h"
185+
#include "stages/stage7_class_define.h"
186186

187187
#undef DECLARE_CUSTOM_EVENT_CLASS
188188
#define DECLARE_CUSTOM_EVENT_CLASS(call, proto, args, tstruct, assign, print) \

include/trace/trace_events.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
PARAMS(print)); \
4646
DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
4747

48-
#include "stages/stage1_defines.h"
48+
#include "stages/stage1_struct_define.h"
4949

5050
#undef DECLARE_EVENT_CLASS
5151
#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
@@ -109,7 +109,7 @@
109109
* The size of an array is also encoded, in the higher 16 bits of <item>.
110110
*/
111111

112-
#include "stages/stage2_defines.h"
112+
#include "stages/stage2_data_offsets.h"
113113

114114
#undef DECLARE_EVENT_CLASS
115115
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -181,7 +181,7 @@
181181
* in binary.
182182
*/
183183

184-
#include "stages/stage3_defines.h"
184+
#include "stages/stage3_trace_output.h"
185185

186186
#undef DECLARE_EVENT_CLASS
187187
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -236,7 +236,7 @@ static struct trace_event_functions trace_event_type_funcs_##call = { \
236236

237237
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
238238

239-
#include "stages/stage4_defines.h"
239+
#include "stages/stage4_event_fields.h"
240240

241241
#undef DECLARE_EVENT_CLASS
242242
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
@@ -249,7 +249,7 @@ static struct trace_event_fields trace_event_fields_##call[] = { \
249249

250250
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
251251

252-
#include "stages/stage5_defines.h"
252+
#include "stages/stage5_get_offsets.h"
253253

254254
#undef DECLARE_EVENT_CLASS
255255
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -372,7 +372,7 @@ static inline notrace int trace_event_get_offsets_##call( \
372372
#define _TRACE_PERF_INIT(call)
373373
#endif /* CONFIG_PERF_EVENTS */
374374

375-
#include "stages/stage6_defines.h"
375+
#include "stages/stage6_event_callback.h"
376376

377377
#undef DECLARE_EVENT_CLASS
378378
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
@@ -418,7 +418,7 @@ static inline void ftrace_test_probe_##call(void) \
418418

419419
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
420420

421-
#include "stages/stage7_defines.h"
421+
#include "stages/stage7_class_define.h"
422422

423423
#undef DECLARE_EVENT_CLASS
424424
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \

kernel/trace/fgraph.c

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* Highly modified by Steven Rostedt (VMware).
99
*/
10+
#include <linux/jump_label.h>
1011
#include <linux/suspend.h>
1112
#include <linux/ftrace.h>
1213
#include <linux/slab.h>
@@ -23,24 +24,12 @@
2324
#define ASSIGN_OPS_HASH(opsname, val)
2425
#endif
2526

26-
static bool kill_ftrace_graph;
27+
DEFINE_STATIC_KEY_FALSE(kill_ftrace_graph);
2728
int ftrace_graph_active;
2829

2930
/* Both enabled by default (can be cleared by function_graph tracer flags */
3031
static bool fgraph_sleep_time = true;
3132

32-
/**
33-
* ftrace_graph_is_dead - returns true if ftrace_graph_stop() was called
34-
*
35-
* ftrace_graph_stop() is called when a severe error is detected in
36-
* the function graph tracing. This function is called by the critical
37-
* paths of function graph to keep those paths from doing any more harm.
38-
*/
39-
bool ftrace_graph_is_dead(void)
40-
{
41-
return kill_ftrace_graph;
42-
}
43-
4433
/**
4534
* ftrace_graph_stop - set to permanently disable function graph tracing
4635
*
@@ -51,7 +40,7 @@ bool ftrace_graph_is_dead(void)
5140
*/
5241
void ftrace_graph_stop(void)
5342
{
54-
kill_ftrace_graph = true;
43+
static_branch_enable(&kill_ftrace_graph);
5544
}
5645

5746
/* Add a function return address to the trace stack on thread info.*/

0 commit comments

Comments
 (0)