Re: [RESEND][PATCH v3 06/17] static_call: Add basic static call infrastructure

From: Peter Zijlstra
Date: Thu Mar 26 2020 - 14:28:35 EST


On Thu, Mar 26, 2020 at 06:09:07PM +0000, Nadav Amit wrote:

> I think that the kernel underutilizes the pure attribute in general.
> Building it with "-Wsuggest-attribute=pureâ results in many warnings.
> Function pointers such kvm_x86_ops.get_XXX() could have been candidates to
> use the âpureâ attribute.
>
> The syntax is what you would expect:
>
> static void __attribute__((pure))(*ptr)(void);
>

Well, I didn't in fact expect that, because an attribute is not a
type qualifier.

> However, you have a point, gcc does not appear to respect âpureâ for
> function pointers and emits a warning it is ignored. GCC apparently only
> respects âconstâ. In contrast clang appears to respect the pure attribute
> for function pointers.

Still, we can probably make it happen for static_call(), since it is a
direct call to the trampoline, all we need to do is make sure the
trampoline is declared pure.

It does however mean that static_call() inherits all the dangers and
pit-falls of function pointers with some extra on top. It will be
impossible to validate this stuff.

That is, you can static_call_update() with a pointer to a !pure function
and you get to keep the pieces.