* [PATCH] perf: write bpf_prog (infos|btfs)_cnt to data file
@ 2025-11-07 17:31 Thomas Falcon
2025-11-11 22:07 ` Ian Rogers
2025-11-11 22:38 ` Namhyung Kim
0 siblings, 2 replies; 5+ messages in thread
From: Thomas Falcon @ 2025-11-07 17:31 UTC (permalink / raw)
To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa,
Ian Rogers, Adrian Hunter
Cc: linux-perf-users, linux-kernel, Thomas Falcon
With commit f0d0f978f3f58 ("perf header: Don't write empty BPF/BTF
info"), the write_bpf_( prog_info() | btf() ) functions exit
without writing anything if env->bpf_prog.(infos| btfs)_cnt is zero.
process_bpf_( prog_info() | btf() ), however, still expect a "count"
value to exist in the data file. If btf information is empty, for
example, process_bpf_btf will read garbage or some other data as the
number of btf nodes in the data file. As a result, the data file will
not be processed correctly.
Instead, write the count to the data file and exit if it is zero.
Fixes: f0d0f978f3f58 ("perf header: Don't write empty BPF/BTF info")
Signed-off-by: Thomas Falcon <thomas.falcon@intel.com>
---
tools/perf/util/header.c | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c
index db2ad19fa50d..54968881481c 100644
--- a/tools/perf/util/header.c
+++ b/tools/perf/util/header.c
@@ -1022,12 +1022,9 @@ static int write_bpf_prog_info(struct feat_fd *ff,
down_read(&env->bpf_progs.lock);
- if (env->bpf_progs.infos_cnt == 0)
- goto out;
-
ret = do_write(ff, &env->bpf_progs.infos_cnt,
sizeof(env->bpf_progs.infos_cnt));
- if (ret < 0)
+ if (ret < 0 || env->bpf_progs.infos_cnt == 0)
goto out;
root = &env->bpf_progs.infos;
@@ -1067,13 +1064,10 @@ static int write_bpf_btf(struct feat_fd *ff,
down_read(&env->bpf_progs.lock);
- if (env->bpf_progs.btfs_cnt == 0)
- goto out;
-
ret = do_write(ff, &env->bpf_progs.btfs_cnt,
sizeof(env->bpf_progs.btfs_cnt));
- if (ret < 0)
+ if (ret < 0 || env->bpf_progs.btfs_cnt == 0)
goto out;
root = &env->bpf_progs.btfs;
--
2.47.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] perf: write bpf_prog (infos|btfs)_cnt to data file 2025-11-07 17:31 [PATCH] perf: write bpf_prog (infos|btfs)_cnt to data file Thomas Falcon @ 2025-11-11 22:07 ` Ian Rogers 2025-11-11 22:38 ` Namhyung Kim 1 sibling, 0 replies; 5+ messages in thread From: Ian Rogers @ 2025-11-11 22:07 UTC (permalink / raw) To: Thomas Falcon Cc: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo, Namhyung Kim, Mark Rutland, Alexander Shishkin, Jiri Olsa, Adrian Hunter, linux-perf-users, linux-kernel On Fri, Nov 7, 2025 at 9:32 AM Thomas Falcon <thomas.falcon@intel.com> wrote: > > With commit f0d0f978f3f58 ("perf header: Don't write empty BPF/BTF > info"), the write_bpf_( prog_info() | btf() ) functions exit > without writing anything if env->bpf_prog.(infos| btfs)_cnt is zero. > > process_bpf_( prog_info() | btf() ), however, still expect a "count" > value to exist in the data file. If btf information is empty, for > example, process_bpf_btf will read garbage or some other data as the > number of btf nodes in the data file. As a result, the data file will > not be processed correctly. > > Instead, write the count to the data file and exit if it is zero. > > Fixes: f0d0f978f3f58 ("perf header: Don't write empty BPF/BTF info") > Signed-off-by: Thomas Falcon <thomas.falcon@intel.com> Reviewed-by: Ian Rogers <irogers@google.com> Thanks! Ian > --- > tools/perf/util/header.c | 10 ++-------- > 1 file changed, 2 insertions(+), 8 deletions(-) > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c > index db2ad19fa50d..54968881481c 100644 > --- a/tools/perf/util/header.c > +++ b/tools/perf/util/header.c > @@ -1022,12 +1022,9 @@ static int write_bpf_prog_info(struct feat_fd *ff, > > down_read(&env->bpf_progs.lock); > > - if (env->bpf_progs.infos_cnt == 0) > - goto out; > - > ret = do_write(ff, &env->bpf_progs.infos_cnt, > sizeof(env->bpf_progs.infos_cnt)); > - if (ret < 0) > + if (ret < 0 || env->bpf_progs.infos_cnt == 0) > goto out; > > root = &env->bpf_progs.infos; > @@ -1067,13 +1064,10 @@ static int write_bpf_btf(struct feat_fd *ff, > > down_read(&env->bpf_progs.lock); > > - if (env->bpf_progs.btfs_cnt == 0) > - goto out; > - > ret = do_write(ff, &env->bpf_progs.btfs_cnt, > sizeof(env->bpf_progs.btfs_cnt)); > > - if (ret < 0) > + if (ret < 0 || env->bpf_progs.btfs_cnt == 0) > goto out; > > root = &env->bpf_progs.btfs; > -- > 2.47.3 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf: write bpf_prog (infos|btfs)_cnt to data file 2025-11-07 17:31 [PATCH] perf: write bpf_prog (infos|btfs)_cnt to data file Thomas Falcon 2025-11-11 22:07 ` Ian Rogers @ 2025-11-11 22:38 ` Namhyung Kim 2025-11-13 12:52 ` Arnaldo Carvalho de Melo 1 sibling, 1 reply; 5+ messages in thread From: Namhyung Kim @ 2025-11-11 22:38 UTC (permalink / raw) To: Thomas Falcon, Arnaldo Carvalho de Melo Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, linux-perf-users, linux-kernel On Fri, Nov 07, 2025 at 11:31:50AM -0600, Thomas Falcon wrote: > With commit f0d0f978f3f58 ("perf header: Don't write empty BPF/BTF > info"), the write_bpf_( prog_info() | btf() ) functions exit > without writing anything if env->bpf_prog.(infos| btfs)_cnt is zero. > > process_bpf_( prog_info() | btf() ), however, still expect a "count" > value to exist in the data file. If btf information is empty, for > example, process_bpf_btf will read garbage or some other data as the > number of btf nodes in the data file. As a result, the data file will > not be processed correctly. > > Instead, write the count to the data file and exit if it is zero. Oh, I'm afraid it'd create a compatibility problem. But I think this is a right behavior and it's should be fine if it goes to the stable soon. Arnaldo, can you please take this into perf-tools tree for v6.18? Thanks, Namhyung > > Fixes: f0d0f978f3f58 ("perf header: Don't write empty BPF/BTF info") > Signed-off-by: Thomas Falcon <thomas.falcon@intel.com> > --- > tools/perf/util/header.c | 10 ++-------- > 1 file changed, 2 insertions(+), 8 deletions(-) > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c > index db2ad19fa50d..54968881481c 100644 > --- a/tools/perf/util/header.c > +++ b/tools/perf/util/header.c > @@ -1022,12 +1022,9 @@ static int write_bpf_prog_info(struct feat_fd *ff, > > down_read(&env->bpf_progs.lock); > > - if (env->bpf_progs.infos_cnt == 0) > - goto out; > - > ret = do_write(ff, &env->bpf_progs.infos_cnt, > sizeof(env->bpf_progs.infos_cnt)); > - if (ret < 0) > + if (ret < 0 || env->bpf_progs.infos_cnt == 0) > goto out; > > root = &env->bpf_progs.infos; > @@ -1067,13 +1064,10 @@ static int write_bpf_btf(struct feat_fd *ff, > > down_read(&env->bpf_progs.lock); > > - if (env->bpf_progs.btfs_cnt == 0) > - goto out; > - > ret = do_write(ff, &env->bpf_progs.btfs_cnt, > sizeof(env->bpf_progs.btfs_cnt)); > > - if (ret < 0) > + if (ret < 0 || env->bpf_progs.btfs_cnt == 0) > goto out; > > root = &env->bpf_progs.btfs; > -- > 2.47.3 > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf: write bpf_prog (infos|btfs)_cnt to data file 2025-11-11 22:38 ` Namhyung Kim @ 2025-11-13 12:52 ` Arnaldo Carvalho de Melo 2025-11-14 7:21 ` Namhyung Kim 0 siblings, 1 reply; 5+ messages in thread From: Arnaldo Carvalho de Melo @ 2025-11-13 12:52 UTC (permalink / raw) To: Namhyung Kim Cc: Thomas Falcon, Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, linux-perf-users, linux-kernel On Tue, Nov 11, 2025 at 02:38:07PM -0800, Namhyung Kim wrote: > On Fri, Nov 07, 2025 at 11:31:50AM -0600, Thomas Falcon wrote: > > With commit f0d0f978f3f58 ("perf header: Don't write empty BPF/BTF > > info"), the write_bpf_( prog_info() | btf() ) functions exit > > without writing anything if env->bpf_prog.(infos| btfs)_cnt is zero. > > > > process_bpf_( prog_info() | btf() ), however, still expect a "count" > > value to exist in the data file. If btf information is empty, for > > example, process_bpf_btf will read garbage or some other data as the > > number of btf nodes in the data file. As a result, the data file will > > not be processed correctly. > > > > Instead, write the count to the data file and exit if it is zero. > > Oh, I'm afraid it'd create a compatibility problem. But I think this is > a right behavior and it's should be fine if it goes to the stable soon. > > Arnaldo, can you please take this into perf-tools tree for v6.18? Ok, agreed, I'm taking your request as an Acked-by, ok? - Arnaldo > Thanks, > Namhyung > > > > > Fixes: f0d0f978f3f58 ("perf header: Don't write empty BPF/BTF info") > > Signed-off-by: Thomas Falcon <thomas.falcon@intel.com> > > --- > > tools/perf/util/header.c | 10 ++-------- > > 1 file changed, 2 insertions(+), 8 deletions(-) > > > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c > > index db2ad19fa50d..54968881481c 100644 > > --- a/tools/perf/util/header.c > > +++ b/tools/perf/util/header.c > > @@ -1022,12 +1022,9 @@ static int write_bpf_prog_info(struct feat_fd *ff, > > > > down_read(&env->bpf_progs.lock); > > > > - if (env->bpf_progs.infos_cnt == 0) > > - goto out; > > - > > ret = do_write(ff, &env->bpf_progs.infos_cnt, > > sizeof(env->bpf_progs.infos_cnt)); > > - if (ret < 0) > > + if (ret < 0 || env->bpf_progs.infos_cnt == 0) > > goto out; > > > > root = &env->bpf_progs.infos; > > @@ -1067,13 +1064,10 @@ static int write_bpf_btf(struct feat_fd *ff, > > > > down_read(&env->bpf_progs.lock); > > > > - if (env->bpf_progs.btfs_cnt == 0) > > - goto out; > > - > > ret = do_write(ff, &env->bpf_progs.btfs_cnt, > > sizeof(env->bpf_progs.btfs_cnt)); > > > > - if (ret < 0) > > + if (ret < 0 || env->bpf_progs.btfs_cnt == 0) > > goto out; > > > > root = &env->bpf_progs.btfs; > > -- > > 2.47.3 > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] perf: write bpf_prog (infos|btfs)_cnt to data file 2025-11-13 12:52 ` Arnaldo Carvalho de Melo @ 2025-11-14 7:21 ` Namhyung Kim 0 siblings, 0 replies; 5+ messages in thread From: Namhyung Kim @ 2025-11-14 7:21 UTC (permalink / raw) To: Arnaldo Carvalho de Melo Cc: Thomas Falcon, Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin, Jiri Olsa, Ian Rogers, Adrian Hunter, linux-perf-users, linux-kernel On Thu, Nov 13, 2025 at 09:52:40AM -0300, Arnaldo Carvalho de Melo wrote: > On Tue, Nov 11, 2025 at 02:38:07PM -0800, Namhyung Kim wrote: > > On Fri, Nov 07, 2025 at 11:31:50AM -0600, Thomas Falcon wrote: > > > With commit f0d0f978f3f58 ("perf header: Don't write empty BPF/BTF > > > info"), the write_bpf_( prog_info() | btf() ) functions exit > > > without writing anything if env->bpf_prog.(infos| btfs)_cnt is zero. > > > > > > process_bpf_( prog_info() | btf() ), however, still expect a "count" > > > value to exist in the data file. If btf information is empty, for > > > example, process_bpf_btf will read garbage or some other data as the > > > number of btf nodes in the data file. As a result, the data file will > > > not be processed correctly. > > > > > > Instead, write the count to the data file and exit if it is zero. > > > > Oh, I'm afraid it'd create a compatibility problem. But I think this is > > a right behavior and it's should be fine if it goes to the stable soon. > > > > Arnaldo, can you please take this into perf-tools tree for v6.18? > > Ok, agreed, I'm taking your request as an Acked-by, ok? Sure, thanks! Namhyung > > > > > > > > Fixes: f0d0f978f3f58 ("perf header: Don't write empty BPF/BTF info") > > > Signed-off-by: Thomas Falcon <thomas.falcon@intel.com> > > > --- > > > tools/perf/util/header.c | 10 ++-------- > > > 1 file changed, 2 insertions(+), 8 deletions(-) > > > > > > diff --git a/tools/perf/util/header.c b/tools/perf/util/header.c > > > index db2ad19fa50d..54968881481c 100644 > > > --- a/tools/perf/util/header.c > > > +++ b/tools/perf/util/header.c > > > @@ -1022,12 +1022,9 @@ static int write_bpf_prog_info(struct feat_fd *ff, > > > > > > down_read(&env->bpf_progs.lock); > > > > > > - if (env->bpf_progs.infos_cnt == 0) > > > - goto out; > > > - > > > ret = do_write(ff, &env->bpf_progs.infos_cnt, > > > sizeof(env->bpf_progs.infos_cnt)); > > > - if (ret < 0) > > > + if (ret < 0 || env->bpf_progs.infos_cnt == 0) > > > goto out; > > > > > > root = &env->bpf_progs.infos; > > > @@ -1067,13 +1064,10 @@ static int write_bpf_btf(struct feat_fd *ff, > > > > > > down_read(&env->bpf_progs.lock); > > > > > > - if (env->bpf_progs.btfs_cnt == 0) > > > - goto out; > > > - > > > ret = do_write(ff, &env->bpf_progs.btfs_cnt, > > > sizeof(env->bpf_progs.btfs_cnt)); > > > > > > - if (ret < 0) > > > + if (ret < 0 || env->bpf_progs.btfs_cnt == 0) > > > goto out; > > > > > > root = &env->bpf_progs.btfs; > > > -- > > > 2.47.3 > > > ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-11-14 7:21 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-11-07 17:31 [PATCH] perf: write bpf_prog (infos|btfs)_cnt to data file Thomas Falcon 2025-11-11 22:07 ` Ian Rogers 2025-11-11 22:38 ` Namhyung Kim 2025-11-13 12:52 ` Arnaldo Carvalho de Melo 2025-11-14 7:21 ` Namhyung Kim
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).