Re: [PATCH] arm: Silence gcc warnings about arch ABI drift

Arnd Bergmann
2024-02-19T07:57:20Z

On Mon, Feb 19, 2024, at 07:25, Kent Overstreet wrote:
> On Mon, Feb 19, 2024 at 07:21:11AM +0100, Arnd Bergmann wrote:
>>
>> This is not something that should ever be passed by value
>> into a function.
>
> Why?

Mostly because of the size, as 8 registers (on 32-bit) or
4 registers (on 64 bit) mean that even in the best case
passing these through argument registers is going to cause
spills if anything else gets passed as well. Passing them
through the stack in turn requires the same number of
registers to get copied in and out for every call, which
in turn can evict other registers that hold local variables.

On top of that, you have all the complications that make
passing them inconsistent and possibly worse depending
on how exactly a particular ABI passes structures:

- If each struct member is passed individually, you always
need eight registers
- bitfields tend to get the compiler into corner cases
that are not as optimized
- __u64 members tend to need even/odd register pairs on
many 32-bit architectures.
- on big-endian kernels, two __u64 members are
misaligned, which causes them to be in two halves
of separate registers if the struct gets passed as
four 64-bit regs.

I can't think of any platform where passing the structure
through a const pointer ends up worse than passing
by value.

Arnd