-
Notifications
You must be signed in to change notification settings - Fork 152
Add kind layout to BTF #10468
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: bpf-next_base
Are you sure you want to change the base?
Add kind layout to BTF #10468
Conversation
|
Upstream branch: 759377d |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
AI reviewed your patch. Please fix the bug or email reply why it's not a bug. In-Reply-To-Subject: |
|
Forwarding comment 3642882607 via email |
|
Forwarding comment 3642892492 via email |
3119ae5 to
162c0b3
Compare
BTF kind layouts provide information to parse BTF kinds. By separating parsing BTF from using all the information it provides, we allow BTF to encode new features even if they cannot be used by readers. This will be helpful in particular for cases where older tools are used to parse newer BTF with kinds the older tools do not recognize; the BTF can still be parsed in such cases using kind layout. The intent is to support encoding of kind layouts optionally so that tools like pahole can add this information. For each kind, we record - length of singular element following struct btf_type - length of each of the btf_vlen() elements following The ideas here were discussed at [1], [2]; hence Suggested-by: Andrii Nakryiko <[email protected]> Signed-off-by: Alan Maguire <[email protected]> [1] https://lore.kernel.org/bpf/CAEf4BzYjWHRdNNw4B=eOXOs_ONrDwrgX4bn=Nuc1g8JPFC34MA@mail.gmail.com/ [2] https://lore.kernel.org/bpf/[email protected]/
Support reading in kind layout fixing endian issues on reading; also support writing kind layout section to raw BTF object. There is not yet an API to populate the kind layout with meaningful information. As part of this, we need to consider multiple valid BTF header sizes; the original or the kind layout-extended headers. So to support this, the "struct btf" representation is modified to always allocate a "struct btf_header" and copy the valid portion from the raw data to it; this means we can always safely check fields like btf->hdr->kind_layout_len. Signed-off-by: Alan Maguire <[email protected]>
This allows BTF parsing to proceed even if we do not know the kind. Signed-off-by: Alan Maguire <[email protected]>
Support encoding of BTF kind layout data via btf__new_empty_opts(). Current supported opts are base_btf and add_kind_layout. Kind layout information is maintained in btf.c in the kind_layouts[] array; when BTF is created with the add_kind_layout option it represents the current view of supported BTF kinds. Signed-off-by: Alan Maguire <[email protected]>
BTF parsing can use kind layout to navigate unknown kinds, so btf_validate_type() should take kind layout information into account to avoid failure when an unrecognized kind is met. Signed-off-by: Alan Maguire <[email protected]>
Validate kind layout if present, but because the kernel must be strict in what it accepts, reject BTF with unsupported kinds, even if they are in the kind layout information. Signed-off-by: Alan Maguire <[email protected]>
verify btf__new_empty_opts() adds kind layouts for all kinds supported, and after adding kind-related types for an unknown kind, ensure that parsing uses this info when that kind is encountered rather than giving up. Signed-off-by: Alan Maguire <[email protected]>
Provide a way to dump BTF metadata info via bpftool; this
consists of BTF size, header fields and kind layout info
(if available); for example
$ bpftool btf dump file vmlinux format meta
size 5460436
magic 0xeb9f
version 1
flags 0x0
hdr_len 32
type_len 3194640
type_off 0
str_len 2265721
str_off 3194640
kind_layout_len 40
kind_layout_off 5460364
kind 0 UNKNOWN info_sz 0 elem_sz 0
kind 1 INT info_sz 4 elem_sz 0
kind 2 PTR info_sz 0 elem_sz 0
kind 3 ARRAY info_sz 12 elem_sz 0
kind 4 STRUCT info_sz 0 elem_sz 12
kind 5 UNION info_sz 0 elem_sz 12
kind 6 ENUM info_sz 0 elem_sz 8
kind 7 FWD info_sz 0 elem_sz 0
kind 8 TYPEDEF info_sz 0 elem_sz 0
kind 9 VOLATILE info_sz 0 elem_sz 0
kind 10 CONST info_sz 0 elem_sz 0
kind 11 RESTRICT info_sz 0 elem_sz 0
kind 12 FUNC info_sz 0 elem_sz 0
kind 13 FUNC_PROTO info_sz 0 elem_sz 8
kind 14 VAR info_sz 4 elem_sz 0
kind 15 DATASEC info_sz 0 elem_sz 12
kind 16 FLOAT info_sz 0 elem_sz 0
kind 17 DECL_TAG info_sz 4 elem_sz 0
kind 18 TYPE_TAG info_sz 0 elem_sz 0
kind 19 ENUM64 info_sz 0 elem_sz 12
JSON output is also supported:
$ $ bpftool -p btf dump file /var/tmp/vmlinux.kind_layout format meta
{
"size": 5460436,
"header": {
"magic": 60319,
"version": 1,
"flags": 0,
"hdr_len": 32,
"type_len": 3194640,
"type_off": 0,
"str_len": 2265721,
"str_off": 3194640,
"kind_layout_len": 40,
"kind_layout_offset": 5460364
},
"kind_layouts": [{
"kind": 0,
"name": "UNKNOWN",
"info_sz": 0,
"elem_sz": 0
},{
"kind": 1,
"name": "INT",
"info_sz": 4,
"elem_sz": 0
},{
...
Signed-off-by: Alan Maguire <[email protected]>
...and provide an example of output. Signed-off-by: Alan Maguire <[email protected]>
The "kind_layout" feature will add metadata about BTF kinds to the generated BTF; its absence in pahole will not trigger an error so it is safe to add unconditionally as it will simply be ignored if pahole does not support it. Signed-off-by: Alan Maguire <[email protected]>
|
Upstream branch: 6f0b824 |
56b4965 to
d2f323c
Compare
Pull request for series with
subject: Add kind layout to BTF
version: 7
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1032375