From 16673071342a6c7524b51a6c25d4ef8ec69d6ff9 Mon Sep 17 00:00:00 2001 From: Alexandre Chartre Date: Tue, 11 Sep 2018 13:23:45 +0200 Subject: [PATCH] x86/speculation: Remove unnecessary retpoline alternatives Now that the X86_FEATURE_RETPOLINE is always set, some assembly alternatives can be simplied or even removed. Also add early check of retpoline_enabled_key in CALL_NOSPEC to avoid an extra call into thunk when retpoline is disabled. Signed-off-by: Alexandre Chartre Reviewed-by: Boris Ostrovsky Reviewed-by: Zhenzhong Duan (cherry picked from UEK5 commit eb88d822befdc73952ae7c00cfcbce9ff5aad574) Orabug: 28607548 Signed-off-by: Alexandre Chartre Reviewed-by: Darren Kenny Reviewed-by: Mihai Carabas Reviewed-by: Boris Ostrovsky Signed-off-by: Brian Maly --- arch/x86/include/asm/nospec-branch.h | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/arch/x86/include/asm/nospec-branch.h b/arch/x86/include/asm/nospec-branch.h index 7c9c2f337d4e..aed5f8476f3b 100644 --- a/arch/x86/include/asm/nospec-branch.h +++ b/arch/x86/include/asm/nospec-branch.h @@ -95,8 +95,7 @@ STATIC_JUMP_IF_TRUE .Lretpoline_jmp_\@, retpoline_enabled_key, def=0 jmp *\reg .Lretpoline_jmp_\@: - ALTERNATIVE_2 __stringify(jmp *\reg), \ - __stringify(RETPOLINE_JMP \reg), X86_FEATURE_RETPOLINE, \ + ALTERNATIVE __stringify(RETPOLINE_JMP \reg), \ __stringify(lfence; jmp *\reg), X86_FEATURE_RETPOLINE_AMD #else jmp *\reg @@ -109,8 +108,7 @@ call *\reg jmp .Ldone_call_\@ .Lretpoline_call_\@: - ALTERNATIVE_2 __stringify(call *\reg), \ - __stringify(RETPOLINE_CALL \reg), X86_FEATURE_RETPOLINE,\ + ALTERNATIVE __stringify(RETPOLINE_CALL \reg), \ __stringify(lfence; call *\reg), X86_FEATURE_RETPOLINE_AMD .Ldone_call_\@: #else @@ -140,10 +138,17 @@ * the 64-bit one is dependent on RETPOLINE not CONFIG_RETPOLINE. */ # define CALL_NOSPEC \ - ALTERNATIVE( \ - "call *%[thunk_target]\n", \ - "call __x86_indirect_thunk_%V[thunk_target]\n", \ - X86_FEATURE_RETPOLINE) + "901: .byte " __stringify(STATIC_KEY_INIT_NOP) "\n" \ + ".pushsection __jump_table, \"aw\"\n" \ + _ASM_ALIGN "\n" \ + _ASM_PTR "901b, 902f, retpoline_enabled_key\n" \ + ".popsection\n" \ + " call *%[thunk_target];\n" \ + " jmp 903f;\n" \ + " .align 16\n" \ + "902: call __x86_indirect_thunk_%V[thunk_target];\n" \ + "903:" + # define THUNK_TARGET(addr) [thunk_target] "r" (addr) #elif defined(CONFIG_X86_32) && defined(CONFIG_RETPOLINE) -- 2.50.1