x86/cpufeature: Remove __pure attribute to _static_cpu_has()
authorBorislav Petkov <bp@suse.de>
Thu, 7 Mar 2019 14:54:51 +0000 (15:54 +0100)
committerBorislav Petkov <bp@suse.de>
Fri, 29 Mar 2019 18:13:48 +0000 (19:13 +0100)
commitae37a8cd9b0ad3416d71e54cfaeb3744178189a8
tree807987660e89b2add2218bd5cbbb75b94984835e
parent9e98c678c2d6ae3a17cb2de55d17f69dddaa231b
x86/cpufeature: Remove __pure attribute to _static_cpu_has()

__pure is used to make gcc do Common Subexpression Elimination (CSE)
and thus save subsequent invocations of a function which does a complex
computation (without side effects). As a simple example:

  bool a = _static_cpu_has(x);
  bool b = _static_cpu_has(x);

gets turned into

  bool a = _static_cpu_has(x);
  bool b = a;

However, gcc doesn't do CSE with asm()s when those get inlined - like it
is done with _static_cpu_has() - because, for example, the t_yes/t_no
labels are different for each inlined function body and thus cannot be
detected as equivalent anymore for the CSE heuristic to hit.

However, this all is beside the point because best it should be avoided
to have more than one call to _static_cpu_has(X) in the same function
due to the fact that each such call is an alternatives patch site and it
is simply pointless.

Therefore, drop the __pure attribute as it is not doing anything.

Reported-by: Nadav Amit <nadav.amit@gmail.com>
Signed-off-by: Borislav Petkov <bp@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: x86@kernel.org
Link: https://lkml.kernel.org/r/20190307151036.GD26566@zn.tnic
arch/x86/include/asm/cpufeature.h