Skip to content

Conversation

@kernel-patches-daemon-bpf
Copy link

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

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 4bebb99
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1049814
version: 9

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 6b95cc5
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1049814
version: 9

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: 6b95cc5
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1049814
version: 9

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: d95d76a
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1049814
version: 9

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: f941479
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1049814
version: 9

@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: f11f7cf
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1049814
version: 9

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]>
@kernel-patches-daemon-bpf
Copy link
Author

Upstream branch: b28dac3
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1049814
version: 9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant