[PATCH v1] perf bpf-filter: Fix opts declaration on older libbpfs

Ian Rogers posted 1 patch 1 month ago
tools/perf/util/bpf-filter.c | 8 ++++++++
1 file changed, 8 insertions(+)
[PATCH v1] perf bpf-filter: Fix opts declaration on older libbpfs
Posted by Ian Rogers 1 month ago
Building perf with LIBBPF_DYNAMIC (ie not the default static linking
of libbpf with perf) is breaking as the libbpf isn't version 1.7 or
newer, where dont_enable is added to bpf_perf_event_opts. To avoid
this breakage add a compile time version check and don't declare the
variable when not present.

Fixes: 5e2ac8e8571d ("perf bpf-filter: Enable events manually")
Signed-off-by: Ian Rogers <irogers@google.com>
---
 tools/perf/util/bpf-filter.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/tools/perf/util/bpf-filter.c b/tools/perf/util/bpf-filter.c
index a0b11f35395f..92308c38fbb5 100644
--- a/tools/perf/util/bpf-filter.c
+++ b/tools/perf/util/bpf-filter.c
@@ -443,6 +443,10 @@ static int create_idx_hash(struct evsel *evsel, struct perf_bpf_filter_entry *en
 	return -1;
 }
 
+#define LIBBPF_CURRENT_VERSION_GEQ(major, minor)			\
+	(LIBBPF_MAJOR_VERSION > (major) ||				\
+	 (LIBBPF_MAJOR_VERSION == (major) && LIBBPF_MINOR_VERSION >= (minor)))
+
 int perf_bpf_filter__prepare(struct evsel *evsel, struct target *target)
 {
 	int i, x, y, fd, ret;
@@ -451,8 +455,12 @@ int perf_bpf_filter__prepare(struct evsel *evsel, struct target *target)
 	struct bpf_link *link;
 	struct perf_bpf_filter_entry *entry;
 	bool needs_idx_hash = !target__has_cpu(target);
+#if LIBBPF_CURRENT_VERSION_GEQ(1, 7)
 	DECLARE_LIBBPF_OPTS(bpf_perf_event_opts, pe_opts,
 			    .dont_enable = true);
+#else
+	DECLARE_LIBBPF_OPTS(bpf_perf_event_opts, pe_opts);
+#endif
 
 	entry = calloc(MAX_FILTERS, sizeof(*entry));
 	if (entry == NULL)
-- 
2.51.0.318.gd7df087d1a-goog
Re: [PATCH v1] perf bpf-filter: Fix opts declaration on older libbpfs
Posted by Ian Rogers 2 weeks ago
On Fri, Aug 29, 2025 at 10:35 PM Ian Rogers <irogers@google.com> wrote:
>
> Building perf with LIBBPF_DYNAMIC (ie not the default static linking
> of libbpf with perf) is breaking as the libbpf isn't version 1.7 or
> newer, where dont_enable is added to bpf_perf_event_opts. To avoid
> this breakage add a compile time version check and don't declare the
> variable when not present.
>
> Fixes: 5e2ac8e8571d ("perf bpf-filter: Enable events manually")
> Signed-off-by: Ian Rogers <irogers@google.com>

Ping.

Thanks,
Ian

> ---
>  tools/perf/util/bpf-filter.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/tools/perf/util/bpf-filter.c b/tools/perf/util/bpf-filter.c
> index a0b11f35395f..92308c38fbb5 100644
> --- a/tools/perf/util/bpf-filter.c
> +++ b/tools/perf/util/bpf-filter.c
> @@ -443,6 +443,10 @@ static int create_idx_hash(struct evsel *evsel, struct perf_bpf_filter_entry *en
>         return -1;
>  }
>
> +#define LIBBPF_CURRENT_VERSION_GEQ(major, minor)                       \
> +       (LIBBPF_MAJOR_VERSION > (major) ||                              \
> +        (LIBBPF_MAJOR_VERSION == (major) && LIBBPF_MINOR_VERSION >= (minor)))
> +
>  int perf_bpf_filter__prepare(struct evsel *evsel, struct target *target)
>  {
>         int i, x, y, fd, ret;
> @@ -451,8 +455,12 @@ int perf_bpf_filter__prepare(struct evsel *evsel, struct target *target)
>         struct bpf_link *link;
>         struct perf_bpf_filter_entry *entry;
>         bool needs_idx_hash = !target__has_cpu(target);
> +#if LIBBPF_CURRENT_VERSION_GEQ(1, 7)
>         DECLARE_LIBBPF_OPTS(bpf_perf_event_opts, pe_opts,
>                             .dont_enable = true);
> +#else
> +       DECLARE_LIBBPF_OPTS(bpf_perf_event_opts, pe_opts);
> +#endif
>
>         entry = calloc(MAX_FILTERS, sizeof(*entry));
>         if (entry == NULL)
> --
> 2.51.0.318.gd7df087d1a-goog
>