OSDN Git Service

bpf: btf: Change how section is supported in btf_header
authorMartin KaFai Lau <kafai@fb.com>
Tue, 22 May 2018 21:57:18 +0000 (14:57 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Wed, 23 May 2018 10:03:31 +0000 (12:03 +0200)
commitf80442a4cd1864154beaa060bb483a2c9f7d811f
tree1373326a94ac768a5ad034e1c554fd0731d7477c
parentdcab51f19b291d5ee23724c51b0a3a597c16451a
bpf: btf: Change how section is supported in btf_header

There are currently unused section descriptions in the btf_header.  Those
sections are here to support future BTF use cases.  For example, the
func section (func_off) is to support function signature (e.g. the BPF
prog function signature).

Instead of spelling out all potential sections up-front in the btf_header.
This patch makes changes to btf_header such that extending it (e.g. adding
a section) is possible later.  The unused ones can be removed for now and
they can be added back later.

This patch:
1. adds a hdr_len to the btf_header.  It will allow adding
sections (and other info like parent_label and parent_name)
later.  The check is similar to the existing bpf_attr.
If a user passes in a longer hdr_len, the kernel
ensures the extra tailing bytes are 0.

2. allows the section order in the BTF object to be
different from its sec_off order in btf_header.

3. each sec_off is followed by a sec_len.  It must not have gap or
overlapping among sections.

The string section is ensured to be at the end due to the 4 bytes
alignment requirement of the type section.

The above changes will allow enough flexibility to
add new sections (and other info) to the btf_header later.

This patch also removes an unnecessary !err check
at the end of btf_parse().

Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
include/uapi/linux/btf.h
kernel/bpf/btf.c