• Alexei Starovoitov's avatar
    bpf: introduce BPF_PROG_TYPE_PERF_EVENT program type · 0515e599
    Alexei Starovoitov authored
    Introduce BPF_PROG_TYPE_PERF_EVENT programs that can be attached to
    HW and SW perf events (PERF_TYPE_HARDWARE and PERF_TYPE_SOFTWARE
    correspondingly in uapi/linux/perf_event.h)
    
    The program visible context meta structure is
    struct bpf_perf_event_data {
        struct pt_regs regs;
         __u64 sample_period;
    };
    which is accessible directly from the program:
    int bpf_prog(struct bpf_perf_event_data *ctx)
    {
      ... ctx->sample_period ...
      ... ctx->regs.ip ...
    }
    
    The bpf verifier rewrites the accesses into kernel internal
    struct bpf_perf_event_data_kern which allows changing
    struct perf_sample_data without affecting bpf programs.
    New fields can be added to the end of struct bpf_perf_event_data
    in the future.
    Signed-off-by: default avatarAlexei Starovoitov <ast@kernel.org>
    Acked-by: default avatarDaniel Borkmann <daniel@iogearbox.net>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    0515e599
bpf_trace.c 16.1 KB