Skip to contentSkip to conversation

x86/cpufeature: Speedup cpu_feature_enabled()

PATCH New Borislav Petkov 2 participants 2 messages Feb 15, 2016 – Feb 16, 2016 x86

lore
Share & tools
lore

Borislav Petkov

author maintainer
#0 lore raw

PATCH 1/1 x86/cpufeature: Speedup cpu_feature_enabled()

From: Borislav Petkov <[email protected]>

When gcc cannot do constant folding for this macro, it falls back to cpu_has(). But static_cpu_has() is optimal and it works at all times now. So use it and speedup the fallback case.

Before we had this:

  mov    0x99d674(%rip),%rdx        # ffffffff81b0d9f4 <boot_cpu_data+0x34>
  shr    $0x2e,%rdx
  and    $0x1,%edx
  jne    ffffffff811704e9 <do_munmap+0x3f9>

After alternatives patching, it turns into:

		  jmp    0xffffffff81170390
		  nopl   (%rax)
		  ...
		  callq  ffffffff81056e00 <mpx_notify_unmap>

ffffffff81170390: mov 0x170(%r12),%rdi

---
 arch/x86/include/asm/cpufeature.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/include/asm/cpufeature.h +1 -2
index 9fba7a5dd24a..68e4e8258b84 100644
@@ -88,8 +88,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
  * is not relevant.
  */
 #define cpu_feature_enabled(bit)	\
-	(__builtin_constant_p(bit) && DISABLED_MASK_BIT_SET(bit) ? 0 :	\
-	 cpu_has(&boot_cpu_data, bit))
+	(__builtin_constant_p(bit) && DISABLED_MASK_BIT_SET(bit) ? 0 : static_cpu_has(bit))
 
 #define boot_cpu_has(bit)	cpu_has(&boot_cpu_data, bit)
 
Signature · 1 line
2.3.5
#1 lore raw

[tip:x86/asm] x86/cpufeature: Speed up cpu_feature_enabled()

x86/cpufeature: Speed up cpu_feature_enabled()
Commit-ID:  f2cc8e0791c70833758101d9756609a08dd601ec
Gitweb:     http://git.kernel.org/tip/f2cc8e0791c70833758101d9756609a08dd601ec
Author:     Borislav Petkov <[email protected]>
AuthorDate: Tue, 16 Feb 2016 00:19:18 +0100
Committer:  Ingo Molnar <[email protected]>
CommitDate: Tue, 16 Feb 2016 08:45:15 +0100

x86/cpufeature: Speed up cpu_feature_enabled()

When GCC cannot do constant folding for this macro, it falls back to cpu_has(). But static_cpu_has() is optimal and it works at all times now. So use it and speedup the fallback case.

Before we had this:

  mov    0x99d674(%rip),%rdx        # ffffffff81b0d9f4 <boot_cpu_data+0x34>
  shr    $0x2e,%rdx
  and    $0x1,%edx
  jne    ffffffff811704e9 <do_munmap+0x3f9>

After alternatives patching, it turns into:

		  jmp    0xffffffff81170390
		  nopl   (%rax)
		  ...
		  callq  ffffffff81056e00 <mpx_notify_unmap>

ffffffff81170390: mov 0x170(%r12),%rdi

---
 arch/x86/include/asm/cpufeature.h | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
arch/x86/include/asm/cpufeature.h +1 -2
index 9fba7a5..68e4e82 100644
@@ -88,8 +88,7 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
  * is not relevant.
  */
 #define cpu_feature_enabled(bit)	\
-	(__builtin_constant_p(bit) && DISABLED_MASK_BIT_SET(bit) ? 0 :	\
-	 cpu_has(&boot_cpu_data, bit))
+	(__builtin_constant_p(bit) && DISABLED_MASK_BIT_SET(bit) ? 0 : static_cpu_has(bit))
 
 #define boot_cpu_has(bit)	cpu_has(&boot_cpu_data, bit)