bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 bpf-next 00/12] BTF-to-C converter
@ 2019-05-24 18:58 Andrii Nakryiko
  2019-05-24 18:58 ` [PATCH v3 bpf-next 01/12] libbpf: ensure libbpf.h is included along libbpf_internal.h Andrii Nakryiko
                   ` (12 more replies)
  0 siblings, 13 replies; 19+ messages in thread
From: Andrii Nakryiko @ 2019-05-24 18:58 UTC (permalink / raw)
  To: andrii.nakryiko, ast, daniel, netdev, bpf, kernel-team; +Cc: Andrii Nakryiko

This patch set adds BTF-to-C dumping APIs to libbpf, allowing to output
a subset of BTF types as a compilable C type definitions. This is useful by
itself, as raw BTF output is not easy to inspect and comprehend. But it's also
a big part of BPF CO-RE (compile once - run everywhere) initiative aimed at
allowing to write relocatable BPF programs, that won't require on-the-host
kernel headers (and would be able to inspect internal kernel structures, not
exposed through kernel headers).

This patch set consists of three groups of patches and one pre-patch, with the
BTF-to-C dumper API depending on the first two groups.

Pre-patch #1 fixes issue with libbpf_internal.h.

btf__parse_elf() API patches:
- patch #2 adds btf__parse_elf() API to libbpf, allowing to load BTF and/or
  BTF.ext from ELF file;
- patch #3 utilizies btf__parse_elf() from bpftool for `btf dump file` command;
- patch #4 switches test_btf.c to use btf__parse_elf() to check for presence
  of BTF data in object file.

libbpf's internal hashmap patches:
- patch #5 adds resizeable non-thread safe generic hashmap to libbpf;
- patch #6 adds tests for that hashmap;
- patch #7 migrates btf_dedup()'s dedup_table to use hashmap w/ APPEND.

BTF-to-C dumper API patches:
- patch #8 adds btf_dump APIs with all the logic for laying out type
  definitions in correct order and emitting C syntax for them;
- patch #9 adds lots of tests for common and quirky parts of C type system;
- patch #10 adds support for C-syntax btf dumping to bpftool;
- patch #11 updates bpftool documentation to mention C-syntax dump option;
- patch #12 update bash-completion for btf dump sub-command.

v2->v3:
- fix bpftool-btf.rst formatting (Quentin);
- simplify bash autocompletion script (Quentin);
- better error message in btf dump (Quentin);

v1->v2:
- removed unuseful file header (Jakub);
- removed inlines in .c (Jakub);
- added 'format {c|raw}' keyword/option (Jakub);
- re-use i var for iteration in btf_dump_c() (Jakub);
- bumped libbpf version to 0.0.4;

v0->v1:
- fix bug in hashmap__for_each_bucket_entry() not handling empty hashmap;
- removed `btf dump`-specific libbpf logging hook up (Quentin has more generic
  patchset);
- change btf__parse_elf() to always load .BTF and return it as a result, with
  .BTF.ext being optional and returned through struct btf_ext** arg (Alexei);
- endianness check to use __BYTE_ORDER__ (Alexei);
- bool:1 to __u8:1 in type_aux_state (Alexei);
- added HASHMAP_APPEND strategy to hashmap, changed
  hashmap__for_each_key_entry() to also check for key equality during
  iteration (multimap iteration for key);
- added new tests for empty hashmap and hashmap as a multimap;
- tried to clarify weak/strong dependency ordering comments (Alexei)
- btf dump test's expected output - support better commenting aproach (Alexei);
- added bash-completion for a new "c" option (Alexei).

Andrii Nakryiko (12):
  libbpf: ensure libbpf.h is included along libbpf_internal.h
  libbpf: add btf__parse_elf API to load .BTF and .BTF.ext
  bpftool: use libbpf's btf__parse_elf API
  selftests/bpf: use btf__parse_elf to check presence of BTF/BTF.ext
  libbpf: add resizable non-thread safe internal hashmap
  selftests/bpf: add tests for libbpf's hashmap
  libbpf: switch btf_dedup() to hashmap for dedup table
  libbpf: add btf_dump API for BTF-to-C conversion
  selftests/bpf: add btf_dump BTF-to-C conversion tests
  bpftool: add C output format option to btf dump subcommand
  bpftool/docs: add description of btf dump C option
  bpftool: update bash-completion w/ new c option for btf dump

 .../bpf/bpftool/Documentation/bpftool-btf.rst |   35 +-
 tools/bpf/bpftool/bash-completion/bpftool     |   21 +-
 tools/bpf/bpftool/btf.c                       |  162 +-
 tools/lib/bpf/Build                           |    4 +-
 tools/lib/bpf/btf.c                           |  329 ++--
 tools/lib/bpf/btf.h                           |   19 +
 tools/lib/bpf/btf_dump.c                      | 1336 +++++++++++++++++
 tools/lib/bpf/hashmap.c                       |  229 +++
 tools/lib/bpf/hashmap.h                       |  173 +++
 tools/lib/bpf/libbpf.map                      |    8 +
 tools/lib/bpf/libbpf_internal.h               |    2 +
 tools/testing/selftests/bpf/.gitignore        |    2 +
 tools/testing/selftests/bpf/Makefile          |    3 +-
 .../bpf/progs/btf_dump_test_case_bitfields.c  |   92 ++
 .../bpf/progs/btf_dump_test_case_multidim.c   |   35 +
 .../progs/btf_dump_test_case_namespacing.c    |   73 +
 .../bpf/progs/btf_dump_test_case_ordering.c   |   63 +
 .../bpf/progs/btf_dump_test_case_packing.c    |   75 +
 .../bpf/progs/btf_dump_test_case_padding.c    |  111 ++
 .../bpf/progs/btf_dump_test_case_syntax.c     |  229 +++
 tools/testing/selftests/bpf/test_btf.c        |   71 +-
 tools/testing/selftests/bpf/test_btf_dump.c   |  143 ++
 tools/testing/selftests/bpf/test_hashmap.c    |  382 +++++
 23 files changed, 3306 insertions(+), 291 deletions(-)
 create mode 100644 tools/lib/bpf/btf_dump.c
 create mode 100644 tools/lib/bpf/hashmap.c
 create mode 100644 tools/lib/bpf/hashmap.h
 create mode 100644 tools/testing/selftests/bpf/progs/btf_dump_test_case_bitfields.c
 create mode 100644 tools/testing/selftests/bpf/progs/btf_dump_test_case_multidim.c
 create mode 100644 tools/testing/selftests/bpf/progs/btf_dump_test_case_namespacing.c
 create mode 100644 tools/testing/selftests/bpf/progs/btf_dump_test_case_ordering.c
 create mode 100644 tools/testing/selftests/bpf/progs/btf_dump_test_case_packing.c
 create mode 100644 tools/testing/selftests/bpf/progs/btf_dump_test_case_padding.c
 create mode 100644 tools/testing/selftests/bpf/progs/btf_dump_test_case_syntax.c
 create mode 100644 tools/testing/selftests/bpf/test_btf_dump.c
 create mode 100644 tools/testing/selftests/bpf/test_hashmap.c

-- 
2.17.1


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2019-07-18  3:35 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-24 18:58 [PATCH v3 bpf-next 00/12] BTF-to-C converter Andrii Nakryiko
2019-05-24 18:58 ` [PATCH v3 bpf-next 01/12] libbpf: ensure libbpf.h is included along libbpf_internal.h Andrii Nakryiko
2019-05-24 18:58 ` [PATCH v3 bpf-next 02/12] libbpf: add btf__parse_elf API to load .BTF and .BTF.ext Andrii Nakryiko
2019-05-24 18:58 ` [PATCH v3 bpf-next 03/12] bpftool: use libbpf's btf__parse_elf API Andrii Nakryiko
2019-05-24 18:58 ` [PATCH v3 bpf-next 04/12] selftests/bpf: use btf__parse_elf to check presence of BTF/BTF.ext Andrii Nakryiko
2019-05-24 18:59 ` [PATCH v3 bpf-next 05/12] libbpf: add resizable non-thread safe internal hashmap Andrii Nakryiko
2019-07-18  0:24   ` Arnaldo Carvalho de Melo
2019-07-18  3:35     ` Andrii Nakryiko
2019-05-24 18:59 ` [PATCH v3 bpf-next 06/12] selftests/bpf: add tests for libbpf's hashmap Andrii Nakryiko
2019-05-24 18:59 ` [PATCH v3 bpf-next 07/12] libbpf: switch btf_dedup() to hashmap for dedup table Andrii Nakryiko
2019-05-24 18:59 ` [PATCH v3 bpf-next 08/12] libbpf: add btf_dump API for BTF-to-C conversion Andrii Nakryiko
2019-05-24 18:59 ` [PATCH v3 bpf-next 09/12] selftests/bpf: add btf_dump BTF-to-C conversion tests Andrii Nakryiko
2019-05-24 18:59 ` [PATCH v3 bpf-next 10/12] bpftool: add C output format option to btf dump subcommand Andrii Nakryiko
2019-05-24 19:49   ` Quentin Monnet
2019-05-24 18:59 ` [PATCH v3 bpf-next 11/12] bpftool/docs: add description of btf dump C option Andrii Nakryiko
2019-05-24 19:49   ` Quentin Monnet
2019-05-24 18:59 ` [PATCH v3 bpf-next 12/12] bpftool: update bash-completion w/ new c option for btf dump Andrii Nakryiko
2019-05-24 19:49   ` Quentin Monnet
2019-05-24 21:12 ` [PATCH v3 bpf-next 00/12] BTF-to-C converter Alexei Starovoitov

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).