* [PATCH] kbuild: disable pahole multithreading for reproducible builds
@ 2024-03-22 8:31 Thomas Weißschuh
2024-03-22 10:07 ` Alan Maguire
0 siblings, 1 reply; 3+ messages in thread
From: Thomas Weißschuh @ 2024-03-22 8:31 UTC (permalink / raw)
To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
Martin KaFai Lau, Eduard Zingerman, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
Masahiro Yamada, Nathan Chancellor, Nicolas Schier
Cc: bpf, linux-kbuild, linux-kernel, Thomas Weißschuh
A BTF type_id is a numeric identifier allocated by pahole through
libbpfd. Ids are incremented for each allocation.
Running pahole multithreaded makes the sequence of allocations
non-deterministic which also makes the type_id itself non-deterministic.
As the type_id end up in the binary this breaks reproducibility.
Therefore, if the kernel is built reproducibly as indicated by
KBUILD_BUILD_TIMESTAMP, disable threading in pahole.
Fixes: b4f72786429c ("scripts/pahole-flags.sh: Parse DWARF and generate BTF with multithreading.")
Fixes: 72d091846de9 ("kbuild: avoid too many execution of scripts/pahole-flags.sh")
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
---
scripts/Makefile.btf | 3 +++
1 file changed, 3 insertions(+)
diff --git a/scripts/Makefile.btf b/scripts/Makefile.btf
index 82377e470aed..2356929e62e4 100644
--- a/scripts/Makefile.btf
+++ b/scripts/Makefile.btf
@@ -10,7 +10,10 @@ endif
pahole-flags-$(call test-ge, $(pahole-ver), 121) += --btf_gen_floats
+# threaded execution randomizes BTF type_id allocation, breaking reproducibility
+ifeq ($(KBUILD_BUILD_TIMESTAMP),)
pahole-flags-$(call test-ge, $(pahole-ver), 122) += -j
+endif
pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) += --lang_exclude=rust
---
base-commit: 8e938e39866920ddc266898e6ae1fffc5c8f51aa
change-id: 20240322-pahole-reprodicible-02e904e45686
Best regards,
--
Thomas Weißschuh <linux@weissschuh.net>
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] kbuild: disable pahole multithreading for reproducible builds
2024-03-22 8:31 [PATCH] kbuild: disable pahole multithreading for reproducible builds Thomas Weißschuh
@ 2024-03-22 10:07 ` Alan Maguire
2024-03-22 17:27 ` Arnaldo Carvalho de Melo
0 siblings, 1 reply; 3+ messages in thread
From: Alan Maguire @ 2024-03-22 10:07 UTC (permalink / raw)
To: Thomas Weißschuh, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier
Cc: bpf, linux-kbuild, linux-kernel
On 22/03/2024 08:31, Thomas Weißschuh wrote:
> A BTF type_id is a numeric identifier allocated by pahole through
> libbpfd. Ids are incremented for each allocation.
> Running pahole multithreaded makes the sequence of allocations
> non-deterministic which also makes the type_id itself non-deterministic.
> As the type_id end up in the binary this breaks reproducibility.
>
> Therefore, if the kernel is built reproducibly as indicated by
> KBUILD_BUILD_TIMESTAMP, disable threading in pahole.
>
> Fixes: b4f72786429c ("scripts/pahole-flags.sh: Parse DWARF and generate BTF with multithreading.")
> Fixes: 72d091846de9 ("kbuild: avoid too many execution of scripts/pahole-flags.sh")
> Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Yep, we've talked about sorting final BTF in various ways but until that
is implemented, non-parallel execution of pahole is the best way to get
reliabily-reproducing BTF ids. We should probably update the pahole
manpage to warn about parallel non-deterministic id allocation in the
meantime.
Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
> ---
> scripts/Makefile.btf | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/scripts/Makefile.btf b/scripts/Makefile.btf
> index 82377e470aed..2356929e62e4 100644
> --- a/scripts/Makefile.btf
> +++ b/scripts/Makefile.btf
> @@ -10,7 +10,10 @@ endif
>
> pahole-flags-$(call test-ge, $(pahole-ver), 121) += --btf_gen_floats
>
> +# threaded execution randomizes BTF type_id allocation, breaking reproducibility
> +ifeq ($(KBUILD_BUILD_TIMESTAMP),)
> pahole-flags-$(call test-ge, $(pahole-ver), 122) += -j
> +endif
>
> pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) += --lang_exclude=rust
>
>
> ---
> base-commit: 8e938e39866920ddc266898e6ae1fffc5c8f51aa
> change-id: 20240322-pahole-reprodicible-02e904e45686
>
> Best regards,
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] kbuild: disable pahole multithreading for reproducible builds
2024-03-22 10:07 ` Alan Maguire
@ 2024-03-22 17:27 ` Arnaldo Carvalho de Melo
0 siblings, 0 replies; 3+ messages in thread
From: Arnaldo Carvalho de Melo @ 2024-03-22 17:27 UTC (permalink / raw)
To: Alan Maguire
Cc: Thomas Weißschuh, Alexei Starovoitov, Daniel Borkmann,
Andrii Nakryiko, Martin KaFai Lau, Eduard Zingerman, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, Masahiro Yamada, Nathan Chancellor,
Nicolas Schier, bpf, linux-kbuild, linux-kernel
On Fri, Mar 22, 2024 at 10:07:00AM +0000, Alan Maguire wrote:
> On 22/03/2024 08:31, Thomas Weißschuh wrote:
> > A BTF type_id is a numeric identifier allocated by pahole through
> > libbpfd. Ids are incremented for each allocation.
> > Running pahole multithreaded makes the sequence of allocations
> > non-deterministic which also makes the type_id itself non-deterministic.
> > As the type_id end up in the binary this breaks reproducibility.
> >
> > Therefore, if the kernel is built reproducibly as indicated by
> > KBUILD_BUILD_TIMESTAMP, disable threading in pahole.
> >
> > Fixes: b4f72786429c ("scripts/pahole-flags.sh: Parse DWARF and generate BTF with multithreading.")
> > Fixes: 72d091846de9 ("kbuild: avoid too many execution of scripts/pahole-flags.sh")
> > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
>
> Yep, we've talked about sorting final BTF in various ways but until that
> is implemented, non-parallel execution of pahole is the best way to get
> reliabily-reproducing BTF ids. We should probably update the pahole
So, the problem is about parallel BTF encoding, not so much about
parallel DWARF loading, which speeds up the whole process and could
continue if we make sure that we feed the BTF encoder in the same order
as when not doing anything in parallel.
I.e. a serial BTF encoding done at the same time as a parallel DWARF
loading would produce a reproducible build faster than doing
_everything_ serially.
The important point would be to feed the btf encoder the DWARF CUs in
the same order as when doing it serially.
No need to order anything, just create a linked list/array of CUs and
then start loading them and leave the BTF encoder go on taking CUs from
that linked list/array in the order they are in vmlinux.
- Arnaldo
> manpage to warn about parallel non-deterministic id allocation in the
> meantime.
>
> Reviewed-by: Alan Maguire <alan.maguire@oracle.com>
>
> > ---
> > scripts/Makefile.btf | 3 +++
> > 1 file changed, 3 insertions(+)
> >
> > diff --git a/scripts/Makefile.btf b/scripts/Makefile.btf
> > index 82377e470aed..2356929e62e4 100644
> > --- a/scripts/Makefile.btf
> > +++ b/scripts/Makefile.btf
> > @@ -10,7 +10,10 @@ endif
> >
> > pahole-flags-$(call test-ge, $(pahole-ver), 121) += --btf_gen_floats
> >
> > +# threaded execution randomizes BTF type_id allocation, breaking reproducibility
> > +ifeq ($(KBUILD_BUILD_TIMESTAMP),)
> > pahole-flags-$(call test-ge, $(pahole-ver), 122) += -j
> > +endif
> >
> > pahole-flags-$(CONFIG_PAHOLE_HAS_LANG_EXCLUDE) += --lang_exclude=rust
> >
> >
> > ---
> > base-commit: 8e938e39866920ddc266898e6ae1fffc5c8f51aa
> > change-id: 20240322-pahole-reprodicible-02e904e45686
> >
> > Best regards,
>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-03-22 17:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-22 8:31 [PATCH] kbuild: disable pahole multithreading for reproducible builds Thomas Weißschuh
2024-03-22 10:07 ` Alan Maguire
2024-03-22 17:27 ` Arnaldo Carvalho de Melo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox