Skip to content

Commit f4e2298

Browse files
yonghong-songborkmann
authored andcommitted
bpf/tracing: fix kernel/events/core.c compilation error
Commit f371b30 ("bpf/tracing: allow user space to query prog array on the same tp") introduced a perf ioctl command to query prog array attached to the same perf tracepoint. The commit introduced a compilation error under certain config conditions, e.g., (1). CONFIG_BPF_SYSCALL is not defined, or (2). CONFIG_TRACING is defined but neither CONFIG_UPROBE_EVENTS nor CONFIG_KPROBE_EVENTS is defined. Error message: kernel/events/core.o: In function `perf_ioctl': core.c:(.text+0x98c4): undefined reference to `bpf_event_query_prog_array' This patch fixed this error by guarding the real definition under CONFIG_BPF_EVENTS and provided static inline dummy function if CONFIG_BPF_EVENTS was not defined. It renamed the function from bpf_event_query_prog_array to perf_event_query_prog_array and moved the definition from linux/bpf.h to linux/trace_events.h so the definition is in proximity to other prog_array related functions. Fixes: f371b30 ("bpf/tracing: allow user space to query prog array on the same tp") Reported-by: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Yonghong Song <yhs@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
1 parent 553a8f2 commit f4e2298

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

include/linux/bpf.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ typedef unsigned long (*bpf_ctx_copy_t)(void *dst, const void *src,
254254

255255
u64 bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
256256
void *ctx, u64 ctx_size, bpf_ctx_copy_t ctx_copy);
257-
int bpf_event_query_prog_array(struct perf_event *event, void __user *info);
258257

259258
int bpf_prog_test_run_xdp(struct bpf_prog *prog, const union bpf_attr *kattr,
260259
union bpf_attr __user *uattr);

include/linux/trace_events.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ trace_trigger_soft_disabled(struct trace_event_file *file)
467467
unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx);
468468
int perf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog);
469469
void perf_event_detach_bpf_prog(struct perf_event *event);
470+
int perf_event_query_prog_array(struct perf_event *event, void __user *info);
470471
#else
471472
static inline unsigned int trace_call_bpf(struct trace_event_call *call, void *ctx)
472473
{
@@ -481,6 +482,11 @@ perf_event_attach_bpf_prog(struct perf_event *event, struct bpf_prog *prog)
481482

482483
static inline void perf_event_detach_bpf_prog(struct perf_event *event) { }
483484

485+
static inline int
486+
perf_event_query_prog_array(struct perf_event *event, void __user *info)
487+
{
488+
return -EOPNOTSUPP;
489+
}
484490
#endif
485491

486492
enum {

kernel/events/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4725,7 +4725,7 @@ static long _perf_ioctl(struct perf_event *event, unsigned int cmd, unsigned lon
47254725
}
47264726

47274727
case PERF_EVENT_IOC_QUERY_BPF:
4728-
return bpf_event_query_prog_array(event, (void __user *)arg);
4728+
return perf_event_query_prog_array(event, (void __user *)arg);
47294729
default:
47304730
return -ENOTTY;
47314731
}

kernel/trace/bpf_trace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ void perf_event_detach_bpf_prog(struct perf_event *event)
856856
mutex_unlock(&bpf_event_mutex);
857857
}
858858

859-
int bpf_event_query_prog_array(struct perf_event *event, void __user *info)
859+
int perf_event_query_prog_array(struct perf_event *event, void __user *info)
860860
{
861861
struct perf_event_query_bpf __user *uquery = info;
862862
struct perf_event_query_bpf query = {};

0 commit comments

Comments
 (0)