perf bpf-filter: Improve error messages
authorNamhyung Kim <namhyung@kernel.org>
Wed, 4 Jun 2025 17:48:35 +0000 (10:48 -0700)
committerNamhyung Kim <namhyung@kernel.org>
Mon, 9 Jun 2025 18:18:17 +0000 (11:18 -0700)
commit189a977e4dc011b05aa1fee044d1a98cf904341b
treec41aece187514f9f123a4d68b02181638952e9f4
parent19272b37aa4f83ca52bdf9c16d5d81bdd1354494
perf bpf-filter: Improve error messages

The BPF filter needs libbpf/BPF-skeleton support and root privilege.
Add error messages to help users understand the problem easily.

When it's not build with BPF support (make BUILD_BPF_SKEL=0).

  $ sudo perf record -e cycles --filter "pid != 0" true
  Error: BPF filter is requested but perf is not built with BPF.
   Please make sure to build with libbpf and BPF skeleton.

   Usage: perf record [<options>] [<command>]
      or: perf record [<options>] -- <command> [<options>]

          --filter <filter>
                            event filter

When it supports BPF but runs without root or CAP_BPF.  Note that it
also checks pinned BPF filters.

  $ perf record -e cycles --filter "pid != 0" -o /dev/null true
  Error: BPF filter only works for users with the CAP_BPF capability!
   Please run 'perf record --setup-filter pin' as root first.

   Usage: perf record [<options>] [<command>]
      or: perf record [<options>] -- <command> [<options>]

          --filter <filter>
                            event filter

Reviewed-by: Ian Rogers <irogers@google.com>
Link: https://lore.kernel.org/r/20250604174835.1852481-1-namhyung@kernel.org
Signed-off-by: Namhyung Kim <namhyung@kernel.org>
tools/perf/util/bpf-filter.c
tools/perf/util/bpf-filter.h
tools/perf/util/cap.c
tools/perf/util/cap.h