mbox series

[bpf-next,0/5] bpf: fix stackmap on perf_events with PEBS

Message ID 20200711012639.3429622-1-songliubraving@fb.com
Headers show
Series bpf: fix stackmap on perf_events with PEBS | expand

Message

Song Liu July 11, 2020, 1:26 a.m. UTC
Calling get_perf_callchain() on perf_events from PEBS entries may cause
unwinder errors. To fix this issue, perf subsystem fetches callchain early,
and marks perf_events are marked with __PERF_SAMPLE_CALLCHAIN_EARLY.
Similar issue exists when BPF program calls get_perf_callchain() via
helper functions. For more information about this issue, please refer to
discussions in [1].

This set provides a solution for this problem.

1/5 blocks ioctl(PERF_EVENT_IOC_SET_BPF) attaching BPF program that calls
    get_perf_callchain() to perf events with PEBS entries.
2/5 exposes callchain fetched by perf subsystem to BPF program.
3/5 introduces bpf_get_callchain_stackid(), which is alternative to
    bpf_get_stackid() for perf_event with PEBS.
4/5 adds selftests for 1/5.
5/5 adds selftests for 2/5 and 3/5.

[1] https://lore.kernel.org/lkml/ED7B9430-6489-4260-B3C5-9CFA2E3AA87A@fb.com/

Song Liu (5):
  bpf: block bpf_get_[stack|stackid] on perf_event with PEBS entries
  bpf: add callchain to bpf_perf_event_data
  bpf: introduce bpf_get_callchain_stackid
  selftests/bpf: add get_stackid_cannot_attach
  selftests/bpf: add callchain_stackid

 include/linux/bpf.h                           |  1 +
 include/linux/filter.h                        |  3 +-
 include/linux/perf_event.h                    |  5 --
 include/linux/trace_events.h                  |  5 ++
 include/uapi/linux/bpf.h                      | 43 +++++++++++++
 include/uapi/linux/bpf_perf_event.h           |  7 +++
 kernel/bpf/btf.c                              |  5 ++
 kernel/bpf/stackmap.c                         | 63 ++++++++++++++-----
 kernel/bpf/verifier.c                         |  7 ++-
 kernel/events/core.c                          | 10 +++
 kernel/trace/bpf_trace.c                      | 29 +++++++++
 scripts/bpf_helpers_doc.py                    |  2 +
 tools/include/uapi/linux/bpf.h                | 43 +++++++++++++
 tools/include/uapi/linux/bpf_perf_event.h     |  8 +++
 .../bpf/prog_tests/callchain_stackid.c        | 61 ++++++++++++++++++
 .../prog_tests/get_stackid_cannot_attach.c    | 57 +++++++++++++++++
 .../selftests/bpf/progs/callchain_stackid.c   | 37 +++++++++++
 17 files changed, 364 insertions(+), 22 deletions(-)
 create mode 100644 tools/testing/selftests/bpf/prog_tests/callchain_stackid.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/get_stackid_cannot_attach.c
 create mode 100644 tools/testing/selftests/bpf/progs/callchain_stackid.c

--
2.24.1