On Mon, Mar 15, 2021 at 11:59:12AM -0700, Linus Torvalds wrote:
> Is it only the static_call_sites entry itself that needs the
> alignment? Or do we end up depending on the static call function being
> at least 4-byte aligned too? The way it plays games with the key makes
> me worry.
The only thing that absolutely needs to be aligned is the
struct static_call_key address. We use the 2 LSB there.
The code address has no alignment requirements, due to x86 instruction
coding the actual CALL (or JMP for tail-calls) can be anywhere.
Now, static_call_site is PC32 encoded, that is:
struct static_call_key *key =
(void *)((unsigned long)&site->key + site->key);
And assuming &site->key is aligned, then site->key & 3 == key & 3.
Per the missing alignment for modules, the above went side-ways. The
patch in question fixed this by not relying on that and always computing
the absolute address first, then transfer the LSBs and then re-encoding
it.
Anyway, still good to also fix the alignment.