Skip to content

bpf zero struct handling testing #8959

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

Closed

Conversation

alan-maguire
Copy link
Contributor

test zero struct handling with CI

In the kernel we occasionally find empty structs as parameters to
functions, for example __io_run_local_work() and its empty typedef
struct parameter io_tw_token_t.

Ensure that when such structs are used as parameters to functions we
handle the fact that no registers are used in their representation for
most architectures; s390x is the exception where the usual calling
convention register is used [1].

[1] https://lore.kernel.org/bpf/[email protected]/

Signed-off-by: Alan Maguire <[email protected]>
Currently we forbid 0-sized parameters and complain that the function
has a malformed void argument, however now that we can handle 0-sized
structs using BPF_PROG2(), carve out an exception for them.  Also
support <= 8 byte return value structs since they can be represented in
a register.

Signed-off-by: Alan Maguire <[email protected]>
…struct

If a 0-length struct is passed as a parameter this throws off
assumptions that register N in calling convention will match parameter
N.  With [1], such function representations will correctly be emitted
in BTF because the register/param mismatch is not a result of an
optimization we cannot infer from the code alone.

Test that BPF_PROG2() macro can handle this situation by having
a function with a 0-length struct as first arg and verify that we
see expected 2nd, 3rd arg values.

Also test that returning a <= 8 byte struct works and we retrieve
the correct return value; returning a struct was previously disallowed
by the verifier.

[1] https://lore.kernel.org/dwarves/[email protected]/

Signed-off-by: Alan Maguire <[email protected]>
@kernel-patches-daemon-bpf kernel-patches-daemon-bpf bot force-pushed the bpf-next_base branch 7 times, most recently from 9857a0f to b93b30b Compare May 22, 2025 16:34
@kernel-patches-daemon-bpf
Copy link

Automatically cleaning up stale PR; feel free to reopen if needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant