-
Notifications
You must be signed in to change notification settings - Fork 159
bpf: Extend BPF syscall with common attributes support #10924
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?
Conversation
|
Upstream branch: 4bebb99 |
e6f7b68 to
af9bd6d
Compare
|
Upstream branch: 6b95cc5 |
05db443 to
08d4bd1
Compare
af9bd6d to
cecc6f5
Compare
|
Upstream branch: 6b95cc5 |
08d4bd1 to
4729a3a
Compare
cecc6f5 to
68193d8
Compare
|
Upstream branch: d95d76a |
4729a3a to
fbec573
Compare
68193d8 to
f129d4b
Compare
|
Upstream branch: f941479 |
fbec573 to
a04cb11
Compare
f129d4b to
8d76c66
Compare
|
Upstream branch: f11f7cf |
a04cb11 to
f1314b4
Compare
8d76c66 to
eec9a8d
Compare
Extend the BPF syscall to support a set of common attributes shared
across all BPF commands:
1. 'log_buf': User-provided buffer for storing logs.
2. 'log_size': Size of the log buffer.
3. 'log_level': Log verbosity level.
4. 'log_true_size': The size of log reported by kernel.
These common attributes are passed as the 4th argument to the BPF
syscall, with the 5th argument specifying the size of this structure.
To indicate the use of these common attributes from userspace, a new flag
'BPF_COMMON_ATTRS' ('1 << 16') is introduced. This flag is OR-ed into the
'cmd' field of the syscall.
When 'cmd & BPF_COMMON_ATTRS' is set, the kernel will copy the common
attributes from userspace into kernel space for use.
Signed-off-by: Leon Hwang <[email protected]>
To support the extended BPF syscall introduced in the previous commit, introduce the following internal APIs: * 'sys_bpf_ext()' * 'sys_bpf_ext_fd()' They wrap the raw 'syscall()' interface to support passing extended attributes. * 'probe_sys_bpf_ext()' Check whether current kernel supports the BPF syscall common attributes. Signed-off-by: Leon Hwang <[email protected]>
The next commit will add support for reporting logs via extended common attributes, including 'log_true_size'. To prepare for that, refactor the 'log_true_size' reporting logic by introducing a new struct bpf_log_attr to encapsulate log-related behavior: * bpf_prog_load_log_attr_init(): initialize the log fields, which will support extended common attributes in the next commit. * bpf_log_attr_finalize(): handle log finalization and write back 'log_true_size' to userspace. Signed-off-by: Leon Hwang <[email protected]>
BPF_PROG_LOAD can now provide log parameters through both union bpf_attr and struct bpf_common_attr. Define clear conflict and precedence rules: - if both are provided and log_buf/log_size/log_level match, use them; - if only one side provides a log buffer, use that one; - if both provide log buffers but differ, return -EINVAL. Signed-off-by: Leon Hwang <[email protected]>
In the next commit, it will be able to report logs via extended common attributes, which will report 'log_true_size' via the extended common attributes meanwhile. Therefore, refactor the way of 'btf_log_true_size' reporting in order to report 'log_true_size' via the extended common attributes easily. Signed-off-by: Leon Hwang <[email protected]>
BPF_BTF_LOAD can now provide log parameters through both union bpf_attr and bpf_common_attr. Apply the same conflict and precedence rules as prog_load: - if both are provided and btf_log_buf/btf_log_size/btf_log_level match, use them; - if only one side provides a log buffer, use that one; - if both provide log buffers but differ, return -EINVAL. Signed-off-by: Leon Hwang <[email protected]>
Many BPF_MAP_CREATE validation failures currently return -EINVAL without any explanation to userspace. Plumb common syscall log attributes into map_create(), create a verifier log from bpf_common_attr::log_buf/log_size/log_level, and report map-creation failure reasons through that buffer. This improves debuggability by allowing userspace to inspect why map creation failed and read back log_true_size from common attributes. Signed-off-by: Leon Hwang <[email protected]>
With the previous commit adding common attribute support for BPF_MAP_CREATE, users can now retrieve detailed error messages when map creation fails via the log_buf field. Introduce struct bpf_log_opts with the following fields: log_buf, log_size, log_level, and log_true_size. Extend bpf_map_create_opts with a new field log_opts, allowing users to capture and inspect log messages on map creation failures. Signed-off-by: Leon Hwang <[email protected]>
Add tests to verify that the kernel reports the expected error messages when map creation fails. Signed-off-by: Leon Hwang <[email protected]>
|
Upstream branch: b28dac3 |
f1314b4 to
857acc3
Compare
Pull request for series with
subject: bpf: Extend BPF syscall with common attributes support
version: 9
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1049814