bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH bpf-next 0/2] bpf, libbpf: share BTF data show functionality
@ 2021-01-11 17:32 Alan Maguire
  2021-01-11 17:32 ` [RFC PATCH bpf-next 2/2] selftests/bpf: test libbpf-based type display Alan Maguire
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alan Maguire @ 2021-01-11 17:32 UTC (permalink / raw)
  To: ast, daniel, andrii
  Cc: kafai, songliubraving, yhs, john.fastabend, kpsingh, rostedt,
	mingo, haoluo, jolsa, linux-kernel, netdev, bpf, linux-kselftest,
	shuah

The BPF Type Format (BTF) can be used in conjunction with the helper
bpf_snprintf_btf() to display kernel data with type information.

This series generalizes that support and shares it with libbpf so
that libbpf can display typed data.  BTF display functionality is
factored out of kernel/bpf/btf.c into kernel/bpf/btf_show_common.c,
and that file is duplicated in tools/lib/bpf.  Similarly, common
definitions and inline functions needed for this support are
extracted into include/linux/btf_common.h and this header is again
duplicated in tools/lib/bpf.

Patch 1 carries out the refactoring, for which no kernel changes
are intended, and introduces btf__snprintf() a libbpf function
that supports dumping a string representation of typed data using
the struct btf * and id associated with that type.

Patch 2 tests btf__snprintf() with built-in and kernel types to
ensure data is of expected format.  The test closely mirrors
the BPF program associated with the snprintf_btf.c; in this case
however the string representations are verified in userspace rather
than in BPF program context.

Alan Maguire (2):
  bpf: share BTF "show" implementation between kernel and libbpf
  selftests/bpf: test libbpf-based type display

 include/linux/btf.h                                |  121 +-
 include/linux/btf_common.h                         |  286 +++++
 kernel/bpf/Makefile                                |    2 +-
 kernel/bpf/arraymap.c                              |    1 +
 kernel/bpf/bpf_struct_ops.c                        |    1 +
 kernel/bpf/btf.c                                   | 1215 +------------------
 kernel/bpf/btf_show_common.c                       | 1218 ++++++++++++++++++++
 kernel/bpf/core.c                                  |    1 +
 kernel/bpf/hashtab.c                               |    1 +
 kernel/bpf/local_storage.c                         |    1 +
 kernel/bpf/verifier.c                              |    1 +
 kernel/trace/bpf_trace.c                           |    1 +
 tools/lib/bpf/Build                                |    2 +-
 tools/lib/bpf/btf.h                                |    7 +
 tools/lib/bpf/btf_common.h                         |  286 +++++
 tools/lib/bpf/btf_show_common.c                    | 1218 ++++++++++++++++++++
 tools/lib/bpf/libbpf.map                           |    1 +
 .../selftests/bpf/prog_tests/snprintf_btf_user.c   |  192 +++
 18 files changed, 3236 insertions(+), 1319 deletions(-)
 create mode 100644 include/linux/btf_common.h
 create mode 100644 kernel/bpf/btf_show_common.c
 create mode 100644 tools/lib/bpf/btf_common.h
 create mode 100644 tools/lib/bpf/btf_show_common.c
 create mode 100644 tools/testing/selftests/bpf/prog_tests/snprintf_btf_user.c

-- 
1.8.3.1


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

end of thread, other threads:[~2021-01-15  3:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-11 17:32 [RFC PATCH bpf-next 0/2] bpf, libbpf: share BTF data show functionality Alan Maguire
2021-01-11 17:32 ` [RFC PATCH bpf-next 2/2] selftests/bpf: test libbpf-based type display Alan Maguire
2021-01-12  2:45 ` [RFC PATCH bpf-next 0/2] bpf, libbpf: share BTF data show functionality Alexei Starovoitov
     [not found] ` <1610386373-24162-2-git-send-email-alan.maguire@oracle.com>
2021-01-12  7:48   ` [RFC PATCH bpf-next 1/2] bpf: share BTF "show" implementation between kernel and libbpf Andrii Nakryiko
2021-01-14 15:37     ` Alan Maguire
2021-01-15  3:51       ` Andrii Nakryiko

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