Skip to content

Commit 768c1e7

Browse files
beaubelgraverostedt
authored andcommitted
tracing/user_events: Remove eBPF interfaces
Remove eBPF interfaces within user_events to ensure they are fully reviewed. Link: https://lore.kernel.org/all/20220329165718.GA10381@kbox/ Link: https://lkml.kernel.org/r/[email protected] Suggested-by: Alexei Starovoitov <[email protected]> Signed-off-by: Beau Belgrave <[email protected]> Signed-off-by: Steven Rostedt (Google) <[email protected]>
1 parent efe34e9 commit 768c1e7

File tree

3 files changed

+4
-136
lines changed

3 files changed

+4
-136
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.

include/uapi/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 */

kernel/trace/trace_events_user.c

Lines changed: 1 addition & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@
4242
#define MAX_FIELD_ARRAY_SIZE 1024
4343
#define MAX_FIELD_ARG_NAME 256
4444

45-
#define MAX_BPF_COPY_SIZE PAGE_SIZE
46-
#define MAX_STACK_BPF_DATA 512
47-
4845
static char *register_page_data;
4946

5047
static DEFINE_MUTEX(reg_mutex);
@@ -405,19 +402,6 @@ static int user_event_parse_field(char *field, struct user_event *user,
405402
type[0] != 'u', FILTER_OTHER);
406403
}
407404

408-
static void user_event_parse_flags(struct user_event *user, char *flags)
409-
{
410-
char *flag;
411-
412-
if (flags == NULL)
413-
return;
414-
415-
while ((flag = strsep(&flags, ",")) != NULL) {
416-
if (strcmp(flag, "BPF_ITER") == 0)
417-
user->flags |= FLAG_BPF_ITER;
418-
}
419-
}
420-
421405
static int user_event_parse_fields(struct user_event *user, char *args)
422406
{
423407
char *field;
@@ -713,64 +697,14 @@ static void user_event_ftrace(struct user_event *user, struct iov_iter *i,
713697
}
714698

715699
#ifdef CONFIG_PERF_EVENTS
716-
static void user_event_bpf(struct user_event *user, struct iov_iter *i)
717-
{
718-
struct user_bpf_context context;
719-
struct user_bpf_iter bpf_i;
720-
char fast_data[MAX_STACK_BPF_DATA];
721-
void *temp = NULL;
722-
723-
if ((user->flags & FLAG_BPF_ITER) && iter_is_iovec(i)) {
724-
/* Raw iterator */
725-
context.data_type = USER_BPF_DATA_ITER;
726-
context.data_len = i->count;
727-
context.iter = &bpf_i;
728-
729-
bpf_i.iov_offset = i->iov_offset;
730-
bpf_i.iov = i->iov;
731-
bpf_i.nr_segs = i->nr_segs;
732-
} else if (i->nr_segs == 1 && iter_is_iovec(i)) {
733-
/* Single buffer from user */
734-
context.data_type = USER_BPF_DATA_USER;
735-
context.data_len = i->count;
736-
context.udata = i->iov->iov_base + i->iov_offset;
737-
} else {
738-
/* Multi buffer from user */
739-
struct iov_iter copy = *i;
740-
size_t copy_size = min_t(size_t, i->count, MAX_BPF_COPY_SIZE);
741-
742-
context.data_type = USER_BPF_DATA_KERNEL;
743-
context.kdata = fast_data;
744-
745-
if (unlikely(copy_size > sizeof(fast_data))) {
746-
temp = kmalloc(copy_size, GFP_NOWAIT);
747-
748-
if (temp)
749-
context.kdata = temp;
750-
else
751-
copy_size = sizeof(fast_data);
752-
}
753-
754-
context.data_len = copy_nofault(context.kdata,
755-
copy_size, &copy);
756-
}
757-
758-
trace_call_bpf(&user->call, &context);
759-
760-
kfree(temp);
761-
}
762-
763700
/*
764-
* Writes the user supplied payload out to perf ring buffer or eBPF program.
701+
* Writes the user supplied payload out to perf ring buffer.
765702
*/
766703
static void user_event_perf(struct user_event *user, struct iov_iter *i,
767704
void *tpdata, bool *faulted)
768705
{
769706
struct hlist_head *perf_head;
770707

771-
if (bpf_prog_array_valid(&user->call))
772-
user_event_bpf(user, i);
773-
774708
perf_head = this_cpu_ptr(user->call.perf_events);
775709

776710
if (perf_head && !hlist_empty(perf_head)) {
@@ -1136,8 +1070,6 @@ static int user_event_parse(char *name, char *args, char *flags,
11361070

11371071
user->tracepoint.name = name;
11381072

1139-
user_event_parse_flags(user, flags);
1140-
11411073
ret = user_event_parse_fields(user, args);
11421074

11431075
if (ret)
@@ -1579,9 +1511,6 @@ static int user_seq_show(struct seq_file *m, void *p)
15791511
busy++;
15801512
}
15811513

1582-
if (flags & FLAG_BPF_ITER)
1583-
seq_puts(m, " FLAG:BPF_ITER");
1584-
15851514
seq_puts(m, "\n");
15861515
active++;
15871516
}

0 commit comments

Comments
 (0)