On Fri, May 09, 2025 at 11:40:47AM -0700, Andrii Nakryiko wrote: > 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. > BTW, Alan shared an example in the other pahole patch thread: https://lore.kernel.org/dwarves/07d92da1-36f3-44d2-a0a4-cf7dabf278c6@xxxxxxxxxx/ > 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? > Given pahole (and my related patch) assume pass-by-value for well-sized structs, I'd like to see this too. But while the pahole patch works on 64/32-bit archs, I noticed from patch #1 that e.g. ___bpf_treg_cnt() seems to hard-code a 64-bit register size. Perhaps we can fix that too? > 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 > >