diff mbox series

[bpf-next] bpftool: Allow disabling features at compile time

Message ID 20220629143951.74851-1-quentin@isovalent.com (mailing list archive)
State Changes Requested
Delegated to: BPF
Headers show
Series [bpf-next] bpftool: Allow disabling features at compile time | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 4 maintainers not CCed: trix@redhat.com llvm@lists.linux.dev ndesaulniers@google.com nathan@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 26 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-3 fail Logs for Kernel LATEST on z15 with gcc
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on ubuntu-latest with llvm-15

Commit Message

Quentin Monnet June 29, 2022, 2:39 p.m. UTC
Some dependencies for bpftool are optional, and the associated features
may be left aside at compilation time depending on the available
components on the system (libraries, BTF, clang version, etc.).
Sometimes, it is useful to explicitly leave some of those features aside
when compiling, even though the system would support them. For example,
this can be useful:

    - for testing bpftool's behaviour when the feature is not present,
    - for copmiling for a different system, where some libraries are
      missing,
    - for producing a lighter binary,
    - for disabling features that do not compile correctly on older
      systems - although this is not supposed to happen, this is
      currently the case for skeletons support on Linux < 5.15, where
      struct bpf_perf_link is not defined in kernel BTF.

For such cases, we introduce, in the Makefile, some environment
variables that can be used to disable those features: namely,
BPFTOOL_FEATURE_NO_LIBBFD, BPFTOOL_FEATURE_NO_LIBCAP, and
BPFTOOL_FEATURE_NO_SKELETONS.

Signed-off-by: Quentin Monnet <quentin@isovalent.com>
---
 tools/bpf/bpftool/Makefile | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

Comments

Daniel Borkmann June 30, 2022, 3:16 p.m. UTC | #1
On 6/29/22 4:39 PM, Quentin Monnet wrote:
> Some dependencies for bpftool are optional, and the associated features
> may be left aside at compilation time depending on the available
> components on the system (libraries, BTF, clang version, etc.).
> Sometimes, it is useful to explicitly leave some of those features aside
> when compiling, even though the system would support them. For example,
> this can be useful:
> 
>      - for testing bpftool's behaviour when the feature is not present,
>      - for copmiling for a different system, where some libraries are
>        missing,
>      - for producing a lighter binary,
>      - for disabling features that do not compile correctly on older
>        systems - although this is not supposed to happen, this is
>        currently the case for skeletons support on Linux < 5.15, where
>        struct bpf_perf_link is not defined in kernel BTF.
> 
> For such cases, we introduce, in the Makefile, some environment
> variables that can be used to disable those features: namely,
> BPFTOOL_FEATURE_NO_LIBBFD, BPFTOOL_FEATURE_NO_LIBCAP, and
> BPFTOOL_FEATURE_NO_SKELETONS.
> 
> Signed-off-by: Quentin Monnet <quentin@isovalent.com>
> ---
>   tools/bpf/bpftool/Makefile | 20 ++++++++++++++++++--
>   1 file changed, 18 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index c19e0e4c41bd..b3dd6a1482f6 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -93,8 +93,24 @@ INSTALL ?= install
>   RM ?= rm -f
>   
>   FEATURE_USER = .bpftool
> -FEATURE_TESTS = libbfd disassembler-four-args zlib libcap \
> -	clang-bpf-co-re
> +FEATURE_TESTS := disassembler-four-args zlib
> +
> +# Disable libbfd (for disassembling JIT-compiled programs) by setting
> +# BPFTOOL_FEATURE_NO_LIBBFD
> +ifeq ($(BPFTOOL_FEATURE_NO_LIBBFD),)
> +  FEATURE_TESTS += libbfd
> +endif
> +# Disable libcap (for probing features available to unprivileged users) by
> +# setting BPFTOOL_FEATURE_NO_LIBCAP
> +ifeq ($(BPFTOOL_FEATURE_NO_LIBCAP),)
> +  FEATURE_TESTS += libcap
> +endif

The libcap one I think is not really crucial, so that lgtm. The other ones I would
keep as requirement so we don't encourage distros to strip away needed functionality
for odd reasons. At min, I think the libbfd is a must, imho.

> +# Disable skeletons (e.g. for profiling programs or showing PIDs of processes
> +# associated to BPF objects) by setting BPFTOOL_FEATURE_NO_SKELETONS
> +ifeq ($(BPFTOOL_FEATURE_NO_SKELETONS),)
> +  FEATURE_TESTS += clang-bpf-co-re
> +endif
> +
>   FEATURE_DISPLAY = libbfd disassembler-four-args zlib libcap \
>   	clang-bpf-co-re
>   
>
Quentin Monnet June 30, 2022, 5:31 p.m. UTC | #2
On 30/06/2022 16:16, Daniel Borkmann wrote:
> On 6/29/22 4:39 PM, Quentin Monnet wrote:
>> Some dependencies for bpftool are optional, and the associated features
>> may be left aside at compilation time depending on the available
>> components on the system (libraries, BTF, clang version, etc.).
>> Sometimes, it is useful to explicitly leave some of those features aside
>> when compiling, even though the system would support them. For example,
>> this can be useful:
>>
>>      - for testing bpftool's behaviour when the feature is not present,
>>      - for copmiling for a different system, where some libraries are
>>        missing,
>>      - for producing a lighter binary,
>>      - for disabling features that do not compile correctly on older
>>        systems - although this is not supposed to happen, this is
>>        currently the case for skeletons support on Linux < 5.15, where
>>        struct bpf_perf_link is not defined in kernel BTF.
>>
>> For such cases, we introduce, in the Makefile, some environment
>> variables that can be used to disable those features: namely,
>> BPFTOOL_FEATURE_NO_LIBBFD, BPFTOOL_FEATURE_NO_LIBCAP, and
>> BPFTOOL_FEATURE_NO_SKELETONS.
>>
>> Signed-off-by: Quentin Monnet <quentin@isovalent.com>
>> ---
>>   tools/bpf/bpftool/Makefile | 20 ++++++++++++++++++--
>>   1 file changed, 18 insertions(+), 2 deletions(-)
>>
>> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
>> index c19e0e4c41bd..b3dd6a1482f6 100644
>> --- a/tools/bpf/bpftool/Makefile
>> +++ b/tools/bpf/bpftool/Makefile
>> @@ -93,8 +93,24 @@ INSTALL ?= install
>>   RM ?= rm -f
>>     FEATURE_USER = .bpftool
>> -FEATURE_TESTS = libbfd disassembler-four-args zlib libcap \
>> -    clang-bpf-co-re
>> +FEATURE_TESTS := disassembler-four-args zlib
>> +
>> +# Disable libbfd (for disassembling JIT-compiled programs) by setting
>> +# BPFTOOL_FEATURE_NO_LIBBFD
>> +ifeq ($(BPFTOOL_FEATURE_NO_LIBBFD),)
>> +  FEATURE_TESTS += libbfd
>> +endif
>> +# Disable libcap (for probing features available to unprivileged
>> users) by
>> +# setting BPFTOOL_FEATURE_NO_LIBCAP
>> +ifeq ($(BPFTOOL_FEATURE_NO_LIBCAP),)
>> +  FEATURE_TESTS += libcap
>> +endif
> 
> The libcap one I think is not really crucial, so that lgtm. The other
> ones I would
> keep as requirement so we don't encourage distros to strip away needed
> functionality
> for odd reasons. At min, I think the libbfd is a must, imho.

Thanks Daniel, that's a legitimate concern. Probably best to avoid
offering an easy option to disable the features in that case - I can
live with Makefile edits if I need to test a different feature set.
Please drop this patch.

Thanks,
Quentin
Andrii Nakryiko June 30, 2022, 7:25 p.m. UTC | #3
On Wed, Jun 29, 2022 at 7:40 AM Quentin Monnet <quentin@isovalent.com> wrote:
>
> Some dependencies for bpftool are optional, and the associated features
> may be left aside at compilation time depending on the available
> components on the system (libraries, BTF, clang version, etc.).
> Sometimes, it is useful to explicitly leave some of those features aside
> when compiling, even though the system would support them. For example,
> this can be useful:
>
>     - for testing bpftool's behaviour when the feature is not present,
>     - for copmiling for a different system, where some libraries are
>       missing,
>     - for producing a lighter binary,
>     - for disabling features that do not compile correctly on older
>       systems - although this is not supposed to happen, this is
>       currently the case for skeletons support on Linux < 5.15, where
>       struct bpf_perf_link is not defined in kernel BTF.
>
> For such cases, we introduce, in the Makefile, some environment
> variables that can be used to disable those features: namely,
> BPFTOOL_FEATURE_NO_LIBBFD, BPFTOOL_FEATURE_NO_LIBCAP, and
> BPFTOOL_FEATURE_NO_SKELETONS.
>
> Signed-off-by: Quentin Monnet <quentin@isovalent.com>
> ---
>  tools/bpf/bpftool/Makefile | 20 ++++++++++++++++++--
>  1 file changed, 18 insertions(+), 2 deletions(-)
>
> diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> index c19e0e4c41bd..b3dd6a1482f6 100644
> --- a/tools/bpf/bpftool/Makefile
> +++ b/tools/bpf/bpftool/Makefile
> @@ -93,8 +93,24 @@ INSTALL ?= install
>  RM ?= rm -f
>
>  FEATURE_USER = .bpftool
> -FEATURE_TESTS = libbfd disassembler-four-args zlib libcap \
> -       clang-bpf-co-re
> +FEATURE_TESTS := disassembler-four-args zlib

as an aside, zlib is not really optional, libbpf depends on it and
bpftool depends on libbpf, so... what's the point of a feature test?

> +
> +# Disable libbfd (for disassembling JIT-compiled programs) by setting
> +# BPFTOOL_FEATURE_NO_LIBBFD
> +ifeq ($(BPFTOOL_FEATURE_NO_LIBBFD),)
> +  FEATURE_TESTS += libbfd
> +endif
> +# Disable libcap (for probing features available to unprivileged users) by
> +# setting BPFTOOL_FEATURE_NO_LIBCAP
> +ifeq ($(BPFTOOL_FEATURE_NO_LIBCAP),)
> +  FEATURE_TESTS += libcap
> +endif
> +# Disable skeletons (e.g. for profiling programs or showing PIDs of processes
> +# associated to BPF objects) by setting BPFTOOL_FEATURE_NO_SKELETONS
> +ifeq ($(BPFTOOL_FEATURE_NO_SKELETONS),)
> +  FEATURE_TESTS += clang-bpf-co-re
> +endif
> +
>  FEATURE_DISPLAY = libbfd disassembler-four-args zlib libcap \
>         clang-bpf-co-re
>
> --
> 2.34.1
>
Quentin Monnet June 30, 2022, 8:03 p.m. UTC | #4
On Thu, 30 Jun 2022 at 20:25, Andrii Nakryiko <andrii.nakryiko@gmail.com> wrote:
>
> On Wed, Jun 29, 2022 at 7:40 AM Quentin Monnet <quentin@isovalent.com> wrote:
> >
> > Some dependencies for bpftool are optional, and the associated features
> > may be left aside at compilation time depending on the available
> > components on the system (libraries, BTF, clang version, etc.).
> > Sometimes, it is useful to explicitly leave some of those features aside
> > when compiling, even though the system would support them. For example,
> > this can be useful:
> >
> >     - for testing bpftool's behaviour when the feature is not present,
> >     - for copmiling for a different system, where some libraries are
> >       missing,
> >     - for producing a lighter binary,
> >     - for disabling features that do not compile correctly on older
> >       systems - although this is not supposed to happen, this is
> >       currently the case for skeletons support on Linux < 5.15, where
> >       struct bpf_perf_link is not defined in kernel BTF.
> >
> > For such cases, we introduce, in the Makefile, some environment
> > variables that can be used to disable those features: namely,
> > BPFTOOL_FEATURE_NO_LIBBFD, BPFTOOL_FEATURE_NO_LIBCAP, and
> > BPFTOOL_FEATURE_NO_SKELETONS.
> >
> > Signed-off-by: Quentin Monnet <quentin@isovalent.com>
> > ---
> >  tools/bpf/bpftool/Makefile | 20 ++++++++++++++++++--
> >  1 file changed, 18 insertions(+), 2 deletions(-)
> >
> > diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
> > index c19e0e4c41bd..b3dd6a1482f6 100644
> > --- a/tools/bpf/bpftool/Makefile
> > +++ b/tools/bpf/bpftool/Makefile
> > @@ -93,8 +93,24 @@ INSTALL ?= install
> >  RM ?= rm -f
> >
> >  FEATURE_USER = .bpftool
> > -FEATURE_TESTS = libbfd disassembler-four-args zlib libcap \
> > -       clang-bpf-co-re
> > +FEATURE_TESTS := disassembler-four-args zlib
>
> as an aside, zlib is not really optional, libbpf depends on it and
> bpftool depends on libbpf, so... what's the point of a feature test?

I'm not sure either, it looks like it's mostly a way to print that the
lib is missing (when it's the case) before attempting to compile [0].
Probably something we can look into removing, I agree the feature test
doesn't bring much here. We'll soon need a new test for the latest
libbfd changes though [1].

[0] https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf.git/commit/?id=d66fa3c70e598746a907e5db5ed024035e01817a
[1] https://lore.kernel.org/bpf/20220622181918.ykrs5rsnmx3og4sv@alap3.anarazel.de/
diff mbox series

Patch

diff --git a/tools/bpf/bpftool/Makefile b/tools/bpf/bpftool/Makefile
index c19e0e4c41bd..b3dd6a1482f6 100644
--- a/tools/bpf/bpftool/Makefile
+++ b/tools/bpf/bpftool/Makefile
@@ -93,8 +93,24 @@  INSTALL ?= install
 RM ?= rm -f
 
 FEATURE_USER = .bpftool
-FEATURE_TESTS = libbfd disassembler-four-args zlib libcap \
-	clang-bpf-co-re
+FEATURE_TESTS := disassembler-four-args zlib
+
+# Disable libbfd (for disassembling JIT-compiled programs) by setting
+# BPFTOOL_FEATURE_NO_LIBBFD
+ifeq ($(BPFTOOL_FEATURE_NO_LIBBFD),)
+  FEATURE_TESTS += libbfd
+endif
+# Disable libcap (for probing features available to unprivileged users) by
+# setting BPFTOOL_FEATURE_NO_LIBCAP
+ifeq ($(BPFTOOL_FEATURE_NO_LIBCAP),)
+  FEATURE_TESTS += libcap
+endif
+# Disable skeletons (e.g. for profiling programs or showing PIDs of processes
+# associated to BPF objects) by setting BPFTOOL_FEATURE_NO_SKELETONS
+ifeq ($(BPFTOOL_FEATURE_NO_SKELETONS),)
+  FEATURE_TESTS += clang-bpf-co-re
+endif
+
 FEATURE_DISPLAY = libbfd disassembler-four-args zlib libcap \
 	clang-bpf-co-re