1 /* SPDX-License-Identifier: GPL-2.0 */ 2 #ifndef _ASM_X86_JUMP_LABEL_H 3 #define _ASM_X86_JUMP_LABEL_H 4 5 #define JUMP_LABEL_NOP_SIZE 5 6 7 #ifdef CONFIG_X86_64 8 # define STATIC_KEY_INIT_NOP P6_NOP5_ATOMIC 9 #else 10 # define STATIC_KEY_INIT_NOP GENERIC_NOP5_ATOMIC 11 #endif 12 13 #include <asm/asm.h> 14 #include <asm/nops.h> 15 16 #ifndef __ASSEMBLY__ 17 18 #include <linux/stringify.h> 19 #include <linux/types.h> 20 21 static __always_inline bool arch_static_branch(struct static_key *key, bool branch) 22 { 23 asm_volatile_goto("1:" 24 ".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t" 25 ".pushsection __jump_table, \"aw\" \n\t" 26 _ASM_ALIGN "\n\t" 27 ".long 1b - ., %l[l_yes] - . \n\t" 28 _ASM_PTR "%c0 + %c1 - .\n\t" 29 ".popsection \n\t" 30 : : "i" (key), "i" (branch) : : l_yes); 31 32 return false; 33 l_yes: 34 return true; 35 } 36 37 static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch) 38 { 39 asm_volatile_goto("1:" 40 ".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t" 41 "2:\n\t" 42 ".pushsection __jump_table, \"aw\" \n\t" 43 _ASM_ALIGN "\n\t" 44 ".long 1b - ., %l[l_yes] - . \n\t" 45 _ASM_PTR "%c0 + %c1 - .\n\t" 46 ".popsection \n\t" 47 : : "i" (key), "i" (branch) : : l_yes); 48 49 return false; 50 l_yes: 51 return true; 52 } 53 54 #else /* __ASSEMBLY__ */ 55 56 .macro STATIC_JUMP_IF_TRUE target, key, def 57 .Lstatic_jump_\@: 58 .if \def 59 /* Equivalent to "jmp.d32 \target" */ 60 .byte 0xe9 61 .long \target - .Lstatic_jump_after_\@ 62 .Lstatic_jump_after_\@: 63 .else 64 .byte STATIC_KEY_INIT_NOP 65 .endif 66 .pushsection __jump_table, "aw" 67 _ASM_ALIGN 68 .long .Lstatic_jump_\@ - ., \target - . 69 _ASM_PTR \key - . 70 .popsection 71 .endm 72 73 .macro STATIC_JUMP_IF_FALSE target, key, def 74 .Lstatic_jump_\@: 75 .if \def 76 .byte STATIC_KEY_INIT_NOP 77 .else 78 /* Equivalent to "jmp.d32 \target" */ 79 .byte 0xe9 80 .long \target - .Lstatic_jump_after_\@ 81 .Lstatic_jump_after_\@: 82 .endif 83 .pushsection __jump_table, "aw" 84 _ASM_ALIGN 85 .long .Lstatic_jump_\@ - ., \target - . 86 _ASM_PTR \key + 1 - . 87 .popsection 88 .endm 89 90 #endif /* __ASSEMBLY__ */ 91 92 #endif 93