jump_label, x86: Factor out the __jump_table generation
authorPeter Zijlstra <peterz@infradead.org>
Thu, 6 May 2021 19:33:56 +0000 (21:33 +0200)
committerIngo Molnar <mingo@kernel.org>
Wed, 12 May 2021 12:54:55 +0000 (14:54 +0200)
Both arch_static_branch() and arch_static_branch_jump() have the same
blurb to generate the __jump_table entry, share it.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20210506194157.663132781@infradead.org
arch/x86/include/asm/jump_label.h

index 01de21e2d9679b1c41e0a39f56daf0d84cf1c010..dfdc2b1c17ddd7aa570638b8709b70d9afad2a9d 100644 (file)
 #include <linux/stringify.h>
 #include <linux/types.h>
 
+#define JUMP_TABLE_ENTRY                               \
+       ".pushsection __jump_table,  \"aw\" \n\t"       \
+       _ASM_ALIGN "\n\t"                               \
+       ".long 1b - . \n\t"                             \
+       ".long %l[l_yes] - . \n\t"                      \
+       _ASM_PTR "%c0 + %c1 - .\n\t"                    \
+       ".popsection \n\t"
+
 static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
 {
        asm_volatile_goto("1:"
                ".byte " __stringify(BYTES_NOP5) "\n\t"
-               ".pushsection __jump_table,  \"aw\" \n\t"
-               _ASM_ALIGN "\n\t"
-               ".long 1b - ., %l[l_yes] - . \n\t"
-               _ASM_PTR "%c0 + %c1 - .\n\t"
-               ".popsection \n\t"
+               JUMP_TABLE_ENTRY
                : :  "i" (key), "i" (branch) : : l_yes);
 
        return false;
@@ -33,13 +37,9 @@ l_yes:
 static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
 {
        asm_volatile_goto("1:"
-               ".byte 0xe9\n\t .long %l[l_yes] - 2f\n\t"
-               "2:\n\t"
-               ".pushsection __jump_table,  \"aw\" \n\t"
-               _ASM_ALIGN "\n\t"
-               ".long 1b - ., %l[l_yes] - . \n\t"
-               _ASM_PTR "%c0 + %c1 - .\n\t"
-               ".popsection \n\t"
+               ".byte 0xe9 \n\t"
+               ".long %l[l_yes] - (. + 4) \n\t"
+               JUMP_TABLE_ENTRY
                : :  "i" (key), "i" (branch) : : l_yes);
 
        return false;