Re: [RFC bpf-next 0/3] bpf: handle 0-sized structs properly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, May 8, 2025 at 6:22 AM Alan Maguire <alan.maguire@xxxxxxxxxx> wrote:
>
> When testing v1 of [1] we noticed that functions with 0-sized structs
> as parameters were not part of BTF encoding; this was fixed in v2.
> However we need to make sure we handle such zero-sized structs
> correctly since they confound the calling convention expectations -
> no registers are used for the empty struct so this has knock-on effects
> for subsequent register-parameter matching.

Do you have a list (or at least an example) of the function we are
talking about, just curious to see what's that.

The question I have is whether it's safe to assume that regardless of
architecture we can assume that zero-sized struct has no effect on
register allocation (which would seem logical, but is that true for
all ABIs).

BTW, while looking at patch #2, I noticed that
btf_distill_func_proto() disallows functions returning
struct-by-value, which seems overly aggressive, at least for structs
of up to 8 bytes. So maybe if we can validate that both cases are not
introducing any new quirks across all supported architectures, we can
solve both limitations?

P.S., oh, and s390x selftest (test_struct_args) isn't happy, please check.


>
> Patch 1 updates BPF_PROG2() to handle the zero-sized struct case.
> Patch 2 makes 0-sized structs a special case, allowing them to exist
> as parameter representations in BTF without failing verification.
> Patch 3 is a selftest that ensures the parameters after the 0-sized
> struct are represented correctly.
>
> [1] https://lore.kernel.org/dwarves/20250502070318.1561924-1-tony.ambardar@xxxxxxxxx/
>
> Alan Maguire (3):
>   libbpf: update BPF_PROG2() to handle empty structs
>   bpf: allow 0-sized structs as function parameters
>   selftests/bpf: add 0-length struct testing to tracing_struct tests
>
>  kernel/bpf/btf.c                                     |  2 +-
>  tools/lib/bpf/bpf_tracing.h                          |  6 ++++--
>  .../selftests/bpf/prog_tests/tracing_struct.c        |  2 ++
>  tools/testing/selftests/bpf/progs/tracing_struct.c   | 11 +++++++++++
>  tools/testing/selftests/bpf/test_kmods/bpf_testmod.c | 12 ++++++++++++
>  5 files changed, 30 insertions(+), 3 deletions(-)
>
> --
> 2.39.3
>





[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux