Skip to content

Commit ef85562

Browse files
Brian Gerstnumbqq
authored andcommitted
x86/alternatives: Discard dynamic check after init
commit 2476f2f upstream Move the code to do the dynamic check to the altinstr_aux section so that it is discarded after alternatives have run and a static branch has been chosen. This way we're changing the dynamic branch from C code to assembly, which makes it *substantially* smaller while avoiding a completely unnecessary call to an out of line function. Signed-off-by: Brian Gerst <[email protected]> [ Changed it to do TESTB, as hpa suggested. ] Signed-off-by: Borislav Petkov <[email protected]> Cc: Andrew Morton <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Andy Lutomirski <[email protected]> Cc: Boris Ostrovsky <[email protected]> Cc: Borislav Petkov <[email protected]> Cc: Dave Young <[email protected]> Cc: Denys Vlasenko <[email protected]> Cc: H. Peter Anvin <[email protected]> Cc: Kristen Carlson Accardi <[email protected]> Cc: Laura Abbott <[email protected]> Cc: Linus Torvalds <[email protected]> Cc: Peter Zijlstra (Intel) <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Prarit Bhargava <[email protected]> Cc: Ross Zwisler <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lkml.kernel.org/r/[email protected] Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: Ingo Molnar <[email protected]> Signed-off-by: Srivatsa S. Bhat <[email protected]> Reviewed-by: Matt Helsley (VMware) <[email protected]> Reviewed-by: Alexey Makhalov <[email protected]> Reviewed-by: Bo Gan <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 571d4e9 commit ef85562

File tree

2 files changed

+12
-13
lines changed

2 files changed

+12
-13
lines changed

arch/x86/include/asm/cpufeature.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,14 @@ extern const char * const x86_bug_flags[NBUGINTS*32];
132132
*/
133133

134134
#if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_X86_FAST_FEATURE_TESTS)
135-
extern bool __static_cpu_has(u16 bit);
136-
137135
/*
138136
* Static testing of CPU features. Used the same as boot_cpu_has().
139137
* These will statically patch the target code for additional
140138
* performance.
141139
*/
142140
static __always_inline __pure bool _static_cpu_has(u16 bit)
143141
{
144-
asm_volatile_goto("1: jmp %l[t_dynamic]\n"
142+
asm_volatile_goto("1: jmp 6f\n"
145143
"2:\n"
146144
".skip -(((5f-4f) - (2b-1b)) > 0) * "
147145
"((5f-4f) - (2b-1b)),0x90\n"
@@ -166,13 +164,20 @@ static __always_inline __pure bool _static_cpu_has(u16 bit)
166164
" .byte 0\n" /* repl len */
167165
" .byte 0\n" /* pad len */
168166
".previous\n"
169-
: : "i" (bit), "i" (X86_FEATURE_ALWAYS)
170-
: : t_dynamic, t_no);
167+
".section .altinstr_aux,\"ax\"\n"
168+
"6:\n"
169+
" testb %[bitnum],%[cap_byte]\n"
170+
" jnz %l[t_yes]\n"
171+
" jmp %l[t_no]\n"
172+
".previous\n"
173+
: : "i" (bit), "i" (X86_FEATURE_ALWAYS),
174+
[bitnum] "i" (1 << (bit & 7)),
175+
[cap_byte] "m" (((const char *)boot_cpu_data.x86_capability)[bit >> 3])
176+
: : t_yes, t_no);
177+
t_yes:
171178
return true;
172179
t_no:
173180
return false;
174-
t_dynamic:
175-
return __static_cpu_has(bit);
176181
}
177182

178183
#define static_cpu_has(bit) \

arch/x86/kernel/cpu/common.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,12 +1576,6 @@ void cpu_init(void)
15761576
}
15771577
#endif
15781578

1579-
inline bool __static_cpu_has(u16 bit)
1580-
{
1581-
return boot_cpu_has(bit);
1582-
}
1583-
EXPORT_SYMBOL_GPL(__static_cpu_has);
1584-
15851579
static void bsp_resume(void)
15861580
{
15871581
if (this_cpu->c_bsp_resume)

0 commit comments

Comments
 (0)