Re: [PATCH] [v2] smp: fix smp_call_function_single_async prototype

From: Arnd Bergmann
Date: Thu May 06 2021 - 10:31:33 EST


On Thu, May 6, 2021 at 2:03 PM Huang, Ying <ying.huang@xxxxxxxxx> wrote:
> Arnd Bergmann <arnd@xxxxxxxxxx> writes:
> > On Thu, May 6, 2021 at 10:14 AM Huang, Ying <ying.huang@xxxxxxxxx> wrote:
> >>
> >> We cannot avoid type cast in Linux kernel, such as container_of(), is
> >> there some difference here?
> >
> > container_of() does not cause any alignment problems. Assuming the outer
> > structure is aligned correctly, then the inner structure also is.
>
> So you think that the compiler may generate different code depends on
> the data structure alignment (8 vs. 32 here)? I think that it doesn't
> on x86. Do you know it does that on any architecture? But I understand
> that this is possible at least in theory.

It probably won't generate any different code because that would be silly, but
it's also not a good idea to rely on that. In theory the compiler might e.g.
construct an offset into the structure using a bitwise-or instruction instead of
an addition if the alignment tells it that the lower bits are always zero.

Arnd