APPLIED Re: [P/U][PATCH v2] UBUNTU: [Packaging] bpftool: move to separate unversioned and unflavored binary package

Timo Aaltonen tjaalton at ubuntu.com
Mon Mar 3 15:55:03 UTC 2025


Frode Nordahl kirjoitti 1.3.2025 klo 0.03:
> The bpftool binary is used as build time dependency for multiple
> Debian packages.
> 
> Before this patch, bpftool was provided by the linux-tools-common
> package, which in reality shipped a shell script that attempted to
> locate the real binary in /usr/lib/linux-tools/$(uname -r)/,
> falling back to printing a human friendly message with
> instructions for what package to install.
> 
> This does not work well for multiple reasons:
> * Automated build pipelines are more often than not run in
>    containers.
> * Said containers usually host a user space filesystem that do
>    not contain nor have any way to install linux-tools-$(uname -r)
>    package.
> * Automated build pipelines declaring bpftool as a build time
>    dependency expect the functionality of bpftool when executing
>    bpftool, and have no way of interpreting the human friendly
>    message.
> * This deviation from Debian creates perpetual per release manual
>    work for Ubuntu for any Debian package depending on bpftool.
> 
> The BPF Compile Once - Run Everywhere (BPF CO-RE) concept revolves
> around using bpftool to dump BPF Type Format (BTF) information from
> the running kernel.
> 
> With this in mind, it comes across as counter intuitive that the
> bpftool binary needs to be distributed in a versioned and
> flavoured package.
> 
> Move bpftool into a separate unversioned and unflavoured binary
> package.
> 
> Prefix bpftool package version with the bpftool projects own
> versioning scheme.  This is aligned with the Debian packaging [0]
> and expectations created by upstream stand-alone distribution of
> bpftool [1].
> 
> Note that there are mulitple styles of variable use and gating in
> the package source, and every change in this patch is made matching
> local style.
> 
> 0: https://salsa.debian.org/kernel-team/linux/-/commit/b20f5b55eb30c2ba0e1fa8f5d241370225063321
> 1: https://lore.kernel.org/bpf/267a35a6-a045-c025-c2d9-78afbf6fc325@isovalent.com/
> BugLink: https://bugs.launchpad.net/bugs/2007308
> Signed-off-by: Frode Nordahl <fnordahl at ubuntu.com>
> ---
>   debian/control.d/bpftool.stub            | 10 +++++++
>   debian/control.d/linux-tools-common.stub |  3 ++-
>   debian/rules                             |  6 +++++
>   debian/rules.d/0-common-vars.mk          |  1 +
>   debian/rules.d/2-binary-arch.mk          | 33 +++++++++++++++++++++++-
>   debian/rules.d/3-binary-indep.mk         | 26 ++++++++++++++-----
>   debian/scripts/control-create            |  1 +
>   7 files changed, 71 insertions(+), 9 deletions(-)
>   create mode 100644 debian/control.d/bpftool.stub
> 
> NOTE:
> If anything comes across as inconsistent, it may be due to the
> many pre-existing styles of variable use and gating in the package
> source.  Every change in this patch is made matching local style.
> 
> Build tested at:
> https://launchpad.net/~fnordahl/+archive/ubuntu/bpftool-as-build-dep-fix
> 
> diff --git a/debian/control.d/bpftool.stub b/debian/control.d/bpftool.stub
> new file mode 100644
> index 000000000000..2bf370cf482d
> --- /dev/null
> +++ b/debian/control.d/bpftool.stub
> @@ -0,0 +1,10 @@
> +Package: bpftool
> +Architecture: amd64 armhf arm64 ppc64el s390x
> +Depends: ${misc:Depends}, ${shlibs:Depends}
> +Breaks:
> +  linux-tools-common (<< 6.14.0-8~),
> +Replaces:
> +  linux-tools-common (<< 6.14.0-8~),
> +Description: Inspection and simple manipulation of BPF programs and maps
> + The bpftool command allows for inspection and simple modification of
> + Berkeley Packet Filter (BPF) objects on the system.
> diff --git a/debian/control.d/linux-tools-common.stub b/debian/control.d/linux-tools-common.stub
> index 37d5bd17bd76..fc4b36927e56 100644
> --- a/debian/control.d/linux-tools-common.stub
> +++ b/debian/control.d/linux-tools-common.stub
> @@ -5,8 +5,9 @@ Multi-Arch: foreign
>   Section: kernel
>   Priority: optional
>   Provides:
> - bpftool,
>    linux-cpupower,
> +Recommends:
> + bpftool (>= 7.6.0+6.14.0-8~),
>   Depends: ${misc:Depends}, lsb-release, hwdata
>   Description: Linux kernel version specific tools for version PKGVER
>    This package provides the architecture independent parts for kernel
> diff --git a/debian/rules b/debian/rules
> index b1a133265836..3d7755b5b3a3 100755
> --- a/debian/rules
> +++ b/debian/rules
> @@ -53,6 +53,12 @@ ifeq ($(DEB_SOURCE),linux)
>   	do_tools_host = true
>   endif
>   
> +# The unversioned and unflavoured bpftools package should only be built for the
> +# linux source package.
> +ifneq ($(DEB_SOURCE),linux)
> +	do_tools_bpftool = false
> +endif
> +
>   # The linux-source package may only be built for the linux source package
>   # We need to explicitly turn this off here to override any (incorrect)
>   # statement in any of the above included makefile snippets
> diff --git a/debian/rules.d/0-common-vars.mk b/debian/rules.d/0-common-vars.mk
> index 4f8b430978b8..76871445b622 100644
> --- a/debian/rules.d/0-common-vars.mk
> +++ b/debian/rules.d/0-common-vars.mk
> @@ -135,6 +135,7 @@ ifneq ($(wildcard $(CURDIR)/tools),)
>   else
>   	do_tools?=false
>   endif
> +bpftool_pkg_name=bpftool
>   tools_pkg_name=$(DEB_SOURCE)-tools-$(abi_release)
>   tools_common_pkg_name=linux-tools-common
>   tools_flavour_pkg_name=linux-tools-$(abi_release)
> diff --git a/debian/rules.d/2-binary-arch.mk b/debian/rules.d/2-binary-arch.mk
> index 1dc6bdc574c0..d3d340222482 100644
> --- a/debian/rules.d/2-binary-arch.mk
> +++ b/debian/rules.d/2-binary-arch.mk
> @@ -8,6 +8,19 @@ build_dir = $(builddir)/build-$*
>   # TODO this is probably wrong, and should be using $(DEB_HOST_MULTIARCH)
>   shlibdeps_opts = $(if $(CROSS_COMPILE),-- -l$(CROSS_COMPILE:%-=/usr/%)/lib)
>   
> +# These are used by both binary-% and binary-perarch targets.
> +BPFTOOL_VERSION_MAJOR = $(shell sed -ne \
> +	's,^#define LIBBPF_MAJOR_VERSION \(.*\)$$,\1,p' \
> +	tools/lib/bpf/libbpf_version.h)
> +BPFTOOL_VERSION_MINOR = $(shell sed -ne \
> +	's,^#define LIBBPF_MINOR_VERSION \(.*\)$$,\1,p' \
> +	tools/lib/bpf/libbpf_version.h)
> +BPFTOOL_VERSION_PATCH = $(shell sed -ne \
> +	's,^#define BPFTOOL_PATCH_VERSION \(.*\)$$,\1,p' \
> +	tools/bpf/bpftool/main.c)
> +BPFTOOL_VERSION = $(shell expr $(BPFTOOL_VERSION_MAJOR) + 6).$(BPFTOOL_VERSION_MINOR).$(BPFTOOL_VERSION_PATCH)
> +BPFTOOL_GENCONTROL_ARGS = -v$(BPFTOOL_VERSION)+$(DEB_VERSION)
> +
>   debian/scripts/fix-filenames: debian/scripts/fix-filenames.c
>   	$(HOSTCC) $^ -o $@
>   
> @@ -111,6 +124,7 @@ $(stampdir)/stamp-install-%: signingv = $(CURDIR)/debian/$(bin_pkg_name)-signing
>   $(stampdir)/stamp-install-%: toolspkgdir = $(CURDIR)/debian/$(tools_flavour_pkg_name)-$*
>   $(stampdir)/stamp-install-%: cloudpkgdir = $(CURDIR)/debian/$(cloud_flavour_pkg_name)-$*
>   $(stampdir)/stamp-install-%: bpfdevpkgdir = $(CURDIR)/debian/linux-bpf-dev
> +$(stampdir)/stamp-install-%: bpftoolpkgdir = $(CURDIR)/debian/$(bpftool_pkg_name)
>   $(stampdir)/stamp-install-%: basepkg = $(hdrs_pkg_name)
>   $(stampdir)/stamp-install-%: baserustpkg = $(rust_pkg_name)
>   $(stampdir)/stamp-install-%: indeppkg = $(indep_hdrs_pkg_name)
> @@ -614,6 +628,11 @@ ifeq ($(do_linux_tools),true)
>   		$(call dh_all_inline,linux-bpf-dev) ; \
>   	fi
>     endif
> +  ifneq ($(filter $(bpftool_pkg_name),$(packages_enabled)),)
> +	if [ $* = $(firstword $(flavours)) ] ; then \
> +		$(call dh_all_inline,$(bpftool_pkg_name),$(BPFTOOL_GENCONTROL_ARGS)) ; \
> +	fi
> +  endif
>    endif
>   endif
>   
> @@ -679,6 +698,7 @@ endif
>   .PHONY: install-perarch
>   install-perarch: toolspkgdir = $(CURDIR)/debian/$(tools_pkg_name)
>   install-perarch: cloudpkgdir = $(CURDIR)/debian/$(cloud_pkg_name)
> +install-perarch: bpftoolpkgdir = $(CURDIR)/debian/$(bpftool_pkg_name)
>   install-perarch: $(stampdir)/stamp-build-perarch
>   	@echo Debug: $@
>   	# Add the tools.
> @@ -714,8 +734,9 @@ ifeq ($(do_tools_perf_python),true)
>   endif
>   endif # do_tools_perf
>   ifeq ($(do_tools_bpftool),true)
> +	install -d $(bpftoolpkgdir)/usr/sbin
>   	install -m755 $(builddirpa)/tools/bpf/bpftool/bpftool \
> -		$(toolspkgdir)/usr/lib/$(DEB_SOURCE)-tools-$(abi_release)
> +		$(bpftoolpkgdir)/usr/sbin/bpftool
>   endif
>   ifeq ($(do_tools_x86),true)
>   	install -m755 $(addprefix $(builddirpa)/tools/power/x86/, x86_energy_perf_policy/x86_energy_perf_policy turbostat/turbostat) \
> @@ -737,6 +758,7 @@ endif # do_cloud_tools
>   .PHONY: binary-perarch
>   binary-perarch: toolspkg = $(tools_pkg_name)
>   binary-perarch: cloudpkg = $(cloud_pkg_name)
> +binary-perarch: bpftoolpkg = $(bpftool_pkg_name)
>   binary-perarch: install-perarch
>   	@echo Debug: $@
>   ifeq ($(do_linux_tools),true)
> @@ -745,6 +767,15 @@ endif
>   ifeq ($(do_cloud_tools),true)
>   	$(call dh_all,$(cloudpkg))
>   endif
> +ifeq ($(do_linux_tools),true)
> +  ifeq ($(do_tools_bpftool),true)
> +    ifneq ($(filter $(bpftoolpkg),$(packages_enabled)),)
> +		if [ $* = $(firstword $(flavours)) ] ; then \
> +			$(call dh_all_inline,$(bpftoolpkg),$(BPFTOOL_GENCONTROL_ARGS)) ; \
> +		fi
> +    endif
> +  endif
> +endif
>   
>   .PHONY: binary-debs
>   binary-debs: binary-perarch $(addprefix binary-,$(flavours))
> diff --git a/debian/rules.d/3-binary-indep.mk b/debian/rules.d/3-binary-indep.mk
> index 72bcd37b53e8..1e33450437f7 100644
> --- a/debian/rules.d/3-binary-indep.mk
> +++ b/debian/rules.d/3-binary-indep.mk
> @@ -53,6 +53,10 @@ endif
>   endif
>   
>   .PHONY: install-tools
> +install-tools: bpftoolpkg = $(bpftool_pkg_name)
> +install-tools: bpftoolsbin = $(CURDIR)/debian/$(bpftoolpkg)/usr/sbin
> +install-tools: bpftoolman = $(CURDIR)/debian/$(bpftoolpkg)/usr/share/man
> +install-tools: bpftoolbashcomp = $(CURDIR)/debian/$(bpftoolpkg)/usr/share/bash-completion/completions
>   install-tools: toolspkg = $(tools_common_pkg_name)
>   install-tools: toolsbin = $(CURDIR)/debian/$(toolspkg)/usr/bin
>   install-tools: toolssbin = $(CURDIR)/debian/$(toolspkg)/usr/sbin
> @@ -97,13 +101,6 @@ ifeq ($(do_tools_common),true)
>   
>   	install -m755 debian/tools/generic $(toolsbin)/perf
>   
> -	install -m755 debian/tools/generic $(toolssbin)/bpftool
> -	make -C $(builddir)/tools/tools/bpf/bpftool doc
> -	install -m644 $(builddir)/tools/tools/bpf/bpftool/Documentation/*.8 \
> -		$(toolsman)/man8
> -	install -m644 $(builddir)/tools/tools/bpf/bpftool/bash-completion/bpftool \
> -		$(toolsbashcomp)
> -
>   	install -m755 debian/tools/generic $(toolsbin)/x86_energy_perf_policy
>   	install -m755 debian/tools/generic $(toolsbin)/turbostat
>   
> @@ -161,6 +158,21 @@ ifeq ($(do_tools_host),true)
>   		$(hosttoolsman)/man1
>   endif
>   
> +ifeq ($(do_linux_tools),true)
> +  ifeq ($(do_tools_bpftool),true)
> +	dh_prep -p$(bpftoolpkg)
> +
> +	install -d $(bpftoolsbin)
> +	install -d $(bpftoolman)/man8
> +	install -d $(bpftoolbashcomp)
> +	make -C $(builddir)/tools/tools/bpf/bpftool doc
> +	install -m644 $(builddir)/tools/tools/bpf/bpftool/Documentation/*.8 \
> +		$(bpftoolman)/man8
> +	install -m644 $(builddir)/tools/tools/bpf/bpftool/bash-completion/bpftool \
> +		$(bpftoolbashcomp)
> +  endif
> +endif
> +
>   .PHONY: install-indep
>   install-indep: $(stampdir)/stamp-install-headers install-source install-tools
>   	@echo Debug: $@
> diff --git a/debian/scripts/control-create b/debian/scripts/control-create
> index 87e5d248be27..efc1a66916b3 100755
> --- a/debian/scripts/control-create
> +++ b/debian/scripts/control-create
> @@ -24,6 +24,7 @@ gen_common () {
>   			debian/control.d/linux-source.stub
>   			debian/control.d/linux-doc.stub
>   			debian/control.d/linux-bpf-dev.stub
> +			debian/control.d/bpftool.stub
>   		)
>   	fi
>   

Thanks, I've tested this on my side with another flavor too, and things 
look as expected.

applied, will be in -8.8 or such.


-- 
t



More information about the kernel-team mailing list