mbox series

[bpf-next,0/3] Add generic and raw BTF parsing APIs to libbpf

Message ID 20200802013219.864880-1-andriin@fb.com
Headers show
Series Add generic and raw BTF parsing APIs to libbpf | expand

Message

Andrii Nakryiko Aug. 2, 2020, 1:32 a.m. UTC
It's pretty common for applications to want to parse raw (binary) BTF data
from file, as opposed to parsing it from ELF sections. It's also pretty common
for tools to not care whether given file is ELF or raw BTF format. This patch
series exposes internal raw BTF parsing API and adds generic variant of BTF
parsing, which will efficiently determine the format of a given fail and will
parse BTF appropriately.

Patches #2 and #3 removes re-implementations of such APIs from bpftool and
resolve_btfids tools.

Andrii Nakryiko (3):
  libbpf: add btf__parse_raw() and generic btf__parse() APIs
  tools/bpftool: use libbpf's btf__parse() API for parsing BTF from file
  tools/resolve_btfids: use libbpf's btf__parse() API

 tools/bpf/bpftool/btf.c             |  54 +------------
 tools/bpf/resolve_btfids/.gitignore |   4 +
 tools/bpf/resolve_btfids/main.c     |  58 +-------------
 tools/lib/bpf/btf.c                 | 114 +++++++++++++++++++---------
 tools/lib/bpf/btf.h                 |   5 +-
 tools/lib/bpf/libbpf.map            |   2 +
 6 files changed, 89 insertions(+), 148 deletions(-)
 create mode 100644 tools/bpf/resolve_btfids/.gitignore

Comments

Daniel Borkmann Aug. 3, 2020, 2:45 p.m. UTC | #1
On 8/2/20 3:32 AM, Andrii Nakryiko wrote:
> It's pretty common for applications to want to parse raw (binary) BTF data
> from file, as opposed to parsing it from ELF sections. It's also pretty common
> for tools to not care whether given file is ELF or raw BTF format. This patch
> series exposes internal raw BTF parsing API and adds generic variant of BTF
> parsing, which will efficiently determine the format of a given fail and will
> parse BTF appropriately.
> 
> Patches #2 and #3 removes re-implementations of such APIs from bpftool and
> resolve_btfids tools.
> 
> Andrii Nakryiko (3):
>    libbpf: add btf__parse_raw() and generic btf__parse() APIs
>    tools/bpftool: use libbpf's btf__parse() API for parsing BTF from file
>    tools/resolve_btfids: use libbpf's btf__parse() API
> 
>   tools/bpf/bpftool/btf.c             |  54 +------------
>   tools/bpf/resolve_btfids/.gitignore |   4 +
>   tools/bpf/resolve_btfids/main.c     |  58 +-------------
>   tools/lib/bpf/btf.c                 | 114 +++++++++++++++++++---------
>   tools/lib/bpf/btf.h                 |   5 +-
>   tools/lib/bpf/libbpf.map            |   2 +
>   6 files changed, 89 insertions(+), 148 deletions(-)
>   create mode 100644 tools/bpf/resolve_btfids/.gitignore
> 

Applied, thanks!
Arnaldo Carvalho de Melo Aug. 6, 2020, 5:39 p.m. UTC | #2
Em Sat, Aug 01, 2020 at 06:32:16PM -0700, Andrii Nakryiko escreveu:
> It's pretty common for applications to want to parse raw (binary) BTF data
> from file, as opposed to parsing it from ELF sections. It's also pretty common
> for tools to not care whether given file is ELF or raw BTF format. This patch
> series exposes internal raw BTF parsing API and adds generic variant of BTF
> parsing, which will efficiently determine the format of a given fail and will
> parse BTF appropriately.
> 
> Patches #2 and #3 removes re-implementations of such APIs from bpftool and
> resolve_btfids tools.
> 
> Andrii Nakryiko (3):
>   libbpf: add btf__parse_raw() and generic btf__parse() APIs
>   tools/bpftool: use libbpf's btf__parse() API for parsing BTF from file
>   tools/resolve_btfids: use libbpf's btf__parse() API

I haven't checked which of the patches, or some in other series caused
this on Clear Linux:

  21 clearlinux:latest             : FAIL gcc (Clear Linux OS for Intel Architecture) 10.2.1 20200723 releases/gcc-10.2.0-3-g677b80db41, clang ver
sion 10.0.1

  gcc (Clear Linux OS for Intel Architecture) 10.2.1 20200723 releases/gcc-10.2.0-3-g677b80db41

  btf.c: In function 'btf__parse_raw':
  btf.c:625:28: error: 'btf' may be used uninitialized in this function [-Werror=maybe-uninitialized]
    625 |  return err ? ERR_PTR(err) : btf;
        |         ~~~~~~~~~~~~~~~~~~~^~~~~

This is what I have:

[acme@quaco perf]$ git log -10 --oneline tools/lib/bpf
94a1fedd63ed libbpf: Add btf__parse_raw() and generic btf__parse() APIs
2e49527e5248 libbpf: Add bpf_link detach APIs
1acf8f90ea7e libbpf: Fix register in PT_REGS MIPS macros
50450fc716c1 libbpf: Make destructors more robust by handling ERR_PTR(err) cases
dc8698cac7aa libbpf: Add support for BPF XDP link
d4b4dd6ce770 libbpf: Print hint when PERF_EVENT_IOC_SET_BPF returns -EPROTO
cd31039a7347 tools/libbpf: Add support for bpf map element iterator
da7a35062bcc libbpf bpf_helpers: Use __builtin_offsetof for offsetof
499dd29d90bb libbpf: Add support for SK_LOOKUP program type
4be556cf5aef libbpf: Add SEC name for xdp programs attached to CPUMAP
[acme@quaco perf]$

>  tools/bpf/bpftool/btf.c             |  54 +------------
>  tools/bpf/resolve_btfids/.gitignore |   4 +
>  tools/bpf/resolve_btfids/main.c     |  58 +-------------
>  tools/lib/bpf/btf.c                 | 114 +++++++++++++++++++---------
>  tools/lib/bpf/btf.h                 |   5 +-
>  tools/lib/bpf/libbpf.map            |   2 +
>  6 files changed, 89 insertions(+), 148 deletions(-)
>  create mode 100644 tools/bpf/resolve_btfids/.gitignore
> 
> -- 
> 2.24.1
>
Andrii Nakryiko Aug. 6, 2020, 5:49 p.m. UTC | #3
On Thu, Aug 6, 2020 at 10:39 AM Arnaldo Carvalho de Melo
<arnaldo.melo@gmail.com> wrote:
>
> Em Sat, Aug 01, 2020 at 06:32:16PM -0700, Andrii Nakryiko escreveu:
> > It's pretty common for applications to want to parse raw (binary) BTF data
> > from file, as opposed to parsing it from ELF sections. It's also pretty common
> > for tools to not care whether given file is ELF or raw BTF format. This patch
> > series exposes internal raw BTF parsing API and adds generic variant of BTF
> > parsing, which will efficiently determine the format of a given fail and will
> > parse BTF appropriately.
> >
> > Patches #2 and #3 removes re-implementations of such APIs from bpftool and
> > resolve_btfids tools.
> >
> > Andrii Nakryiko (3):
> >   libbpf: add btf__parse_raw() and generic btf__parse() APIs
> >   tools/bpftool: use libbpf's btf__parse() API for parsing BTF from file
> >   tools/resolve_btfids: use libbpf's btf__parse() API
>
> I haven't checked which of the patches, or some in other series caused
> this on Clear Linux:
>
>   21 clearlinux:latest             : FAIL gcc (Clear Linux OS for Intel Architecture) 10.2.1 20200723 releases/gcc-10.2.0-3-g677b80db41, clang ver
> sion 10.0.1
>
>   gcc (Clear Linux OS for Intel Architecture) 10.2.1 20200723 releases/gcc-10.2.0-3-g677b80db41
>
>   btf.c: In function 'btf__parse_raw':
>   btf.c:625:28: error: 'btf' may be used uninitialized in this function [-Werror=maybe-uninitialized]
>     625 |  return err ? ERR_PTR(err) : btf;
>         |         ~~~~~~~~~~~~~~~~~~~^~~~~
>

Yeah, fixed in https://patchwork.ozlabs.org/project/netdev/patch/20200805223359.32109-1-danieltimlee@gmail.com/

> This is what I have:
>
> [acme@quaco perf]$ git log -10 --oneline tools/lib/bpf
> 94a1fedd63ed libbpf: Add btf__parse_raw() and generic btf__parse() APIs
> 2e49527e5248 libbpf: Add bpf_link detach APIs
> 1acf8f90ea7e libbpf: Fix register in PT_REGS MIPS macros
> 50450fc716c1 libbpf: Make destructors more robust by handling ERR_PTR(err) cases
> dc8698cac7aa libbpf: Add support for BPF XDP link
> d4b4dd6ce770 libbpf: Print hint when PERF_EVENT_IOC_SET_BPF returns -EPROTO
> cd31039a7347 tools/libbpf: Add support for bpf map element iterator
> da7a35062bcc libbpf bpf_helpers: Use __builtin_offsetof for offsetof
> 499dd29d90bb libbpf: Add support for SK_LOOKUP program type
> 4be556cf5aef libbpf: Add SEC name for xdp programs attached to CPUMAP
> [acme@quaco perf]$
>
> >  tools/bpf/bpftool/btf.c             |  54 +------------
> >  tools/bpf/resolve_btfids/.gitignore |   4 +
> >  tools/bpf/resolve_btfids/main.c     |  58 +-------------
> >  tools/lib/bpf/btf.c                 | 114 +++++++++++++++++++---------
> >  tools/lib/bpf/btf.h                 |   5 +-
> >  tools/lib/bpf/libbpf.map            |   2 +
> >  6 files changed, 89 insertions(+), 148 deletions(-)
> >  create mode 100644 tools/bpf/resolve_btfids/.gitignore
> >
> > --
> > 2.24.1
> >
>
> --
>
> - Arnaldo
Alexei Starovoitov Aug. 6, 2020, 6:01 p.m. UTC | #4
On Thu, Aug 6, 2020 at 10:51 AM Andrii Nakryiko
<andrii.nakryiko@gmail.com> wrote:
> > I haven't checked which of the patches, or some in other series caused
> > this on Clear Linux:
> >
> >   21 clearlinux:latest             : FAIL gcc (Clear Linux OS for Intel Architecture) 10.2.1 20200723 releases/gcc-10.2.0-3-g677b80db41, clang ver
> > sion 10.0.1
> >
> >   gcc (Clear Linux OS for Intel Architecture) 10.2.1 20200723 releases/gcc-10.2.0-3-g677b80db41
> >
> >   btf.c: In function 'btf__parse_raw':
> >   btf.c:625:28: error: 'btf' may be used uninitialized in this function [-Werror=maybe-uninitialized]
> >     625 |  return err ? ERR_PTR(err) : btf;
> >         |         ~~~~~~~~~~~~~~~~~~~^~~~~
> >
>
> Yeah, fixed in https://patchwork.ozlabs.org/project/netdev/patch/20200805223359.32109-1-danieltimlee@gmail.com/
>

Thanks for headsup.
The fix will be pushed to bpf tree when net tree gets ffwd-ed to
Linus. Hopefully today.