Skip to content

Commit ae0a457

Browse files
etsalAlexei Starovoitov
authored andcommitted
bpf: Make perf_event_read_output accessible in all program types.
The perf_event_read_event_output helper is currently only available to tracing protrams, but is useful for other BPF programs like sched_ext schedulers. When the helper is available, provide its bpf_func_proto directly from the bpf base_proto. Signed-off-by: Emil Tsalapatis (Meta) <emil@etsalapatis.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Link: https://lore.kernel.org/r/20250318030753.10949-1-emil@etsalapatis.com Signed-off-by: Alexei Starovoitov <ast@kernel.org>
1 parent f3f8649 commit ae0a457

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

include/linux/bpf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,8 @@ int bpf_prog_calc_tag(struct bpf_prog *fp);
20592059
const struct bpf_func_proto *bpf_get_trace_printk_proto(void);
20602060
const struct bpf_func_proto *bpf_get_trace_vprintk_proto(void);
20612061

2062+
const struct bpf_func_proto *bpf_get_perf_event_read_value_proto(void);
2063+
20622064
typedef unsigned long (*bpf_ctx_copy_t)(void *dst, const void *src,
20632065
unsigned long off, unsigned long len);
20642066
typedef u32 (*bpf_convert_ctx_access_t)(enum bpf_access_type type,

kernel/bpf/core.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2972,6 +2972,11 @@ const struct bpf_func_proto * __weak bpf_get_trace_vprintk_proto(void)
29722972
return NULL;
29732973
}
29742974

2975+
const struct bpf_func_proto * __weak bpf_get_perf_event_read_value_proto(void)
2976+
{
2977+
return NULL;
2978+
}
2979+
29752980
u64 __weak
29762981
bpf_event_output(struct bpf_map *map, u64 flags, void *meta, u64 meta_size,
29772982
void *ctx, u64 ctx_size, bpf_ctx_copy_t ctx_copy)

kernel/bpf/helpers.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2056,6 +2056,8 @@ bpf_base_func_proto(enum bpf_func_id func_id, const struct bpf_prog *prog)
20562056
return &bpf_task_pt_regs_proto;
20572057
case BPF_FUNC_trace_vprintk:
20582058
return bpf_get_trace_vprintk_proto();
2059+
case BPF_FUNC_perf_event_read_value:
2060+
return bpf_get_perf_event_read_value_proto();
20592061
default:
20602062
return NULL;
20612063
}

kernel/trace/bpf_trace.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,11 @@ static const struct bpf_func_proto bpf_perf_event_read_value_proto = {
607607
.arg4_type = ARG_CONST_SIZE,
608608
};
609609

610+
const struct bpf_func_proto *bpf_get_perf_event_read_value_proto(void)
611+
{
612+
return &bpf_perf_event_read_value_proto;
613+
}
614+
610615
static __always_inline u64
611616
__bpf_perf_event_output(struct pt_regs *regs, struct bpf_map *map,
612617
u64 flags, struct perf_raw_record *raw,

0 commit comments

Comments
 (0)