Skip to content

bpf: Extend BPF syscall with common attributes support#10690

Closed
kernel-patches-daemon-bpf[bot] wants to merge 9 commits intobpf-next_basefrom
series/1041255=>bpf-next
Closed

bpf: Extend BPF syscall with common attributes support#10690
kernel-patches-daemon-bpf[bot] wants to merge 9 commits intobpf-next_basefrom
series/1041255=>bpf-next

Conversation

@kernel-patches-daemon-bpf
Copy link
Copy Markdown

Pull request for series with
subject: bpf: Extend BPF syscall with common attributes support
version: 5
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 5714ca8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255
version: 5

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 9c1a352
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255
version: 5

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 9c1a352
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255
version: 5

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 7af3339
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255
version: 5

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: da4ab5d
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255
version: 5

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: c9c9f6b
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255
version: 5

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: b9da173
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255
version: 5

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 9a403a4
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255
version: 5

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 934d974
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255
version: 5

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 2acbd05
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255
version: 5

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 <leon.hwang@linux.dev>
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 extended attributes.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
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 <leon.hwang@linux.dev>
The log buffer of common attributes would be confusing with the one in
'union bpf_attr' for BPF_PROG_LOAD.

In order to clarify the usage of these two log buffers, they both can be
used for logging if:

* They are same, including 'log_buf', 'log_level' and 'log_size'.
* One of them is missing, then another one will be used for logging.

If they both have 'log_buf' but they are not same totally, return -EUSERS.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
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 <leon.hwang@linux.dev>
Since bpf_log_attr_init() now supports struct bpf_common_attr, pass the
common attributes to it to enable syscall common attributes support for
BPF_BTF_LOAD.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Currently, many BPF_MAP_CREATE failures return -EINVAL without providing
any explanation to userspace.

With extended BPF syscall support, detailed error messages can now be
reported via the log buffer, allowing users to understand the specific
reason for a failed map creation.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
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_syscall_common_attr_opts with the following fields:
log_buf, log_size, log_level, and log_true_size.

Extend bpf_map_create_opts with a new field common_attr_opts, allowing
users to capture and inspect log messages on map creation failures.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
Add tests to verify that the kernel reports the expected error messages
when map creation fails.

Signed-off-by: Leon Hwang <leon.hwang@linux.dev>
@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

Upstream branch: 1700147
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255
version: 5

@kernel-patches-daemon-bpf
Copy link
Copy Markdown
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=1041255 expired. Closing PR.

@kernel-patches-daemon-bpf kernel-patches-daemon-bpf Bot deleted the series/1041255=>bpf-next branch January 18, 2026 22:56
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