Re: [PATCH v3 9/9] x86: jump-labels: use macros instead of inline assembly

From: Peter Zijlstra
Date: Mon Jun 11 2018 - 03:50:43 EST


On Sun, Jun 10, 2018 at 07:19:11AM -0700, Nadav Amit wrote:
> static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
> {
> + asm_volatile_goto("STATIC_BRANCH_GOTO l_yes=\"%l[l_yes]\" key=\"%c0\" "
> + "branch=\"%c1\""
> + : : "i" (key), "i" (branch) : : l_yes);
>
> return false;
> l_yes:
> @@ -48,13 +44,8 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
>
> static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
> {
> + asm_volatile_goto("STATIC_BRANCH_JUMP_GOTO l_yes=\"%l[l_yes]\" key=\"%c0\" "
> + "branch=\"%c1\""
> : : "i" (key), "i" (branch) : : l_yes);
>
> return false;
> @@ -108,6 +99,26 @@ struct jump_entry {
> .popsection
> .endm
>
> +.macro STATIC_BRANCH_GOTO l_yes:req key:req branch:req

STATIC_BRANCH_NOP

> +1:
> + .byte STATIC_KEY_INIT_NOP
> + .pushsection __jump_table, "aw"
> + _ASM_ALIGN
> + _ASM_PTR 1b, \l_yes, \key + \branch
> + .popsection
> +.endm
> +
> +.macro STATIC_BRANCH_JUMP_GOTO l_yes:req key:req branch:req

STATIC_BRANCH_JMP

> +1:
> + .byte 0xe9
> + .long \l_yes - 2f
> +2:
> + .pushsection __jump_table, "aw"
> + _ASM_ALIGN
> + _ASM_PTR 1b, \l_yes, \key + \branch
> + .popsection
> +.endm
> +
> #endif /* __ASSEMBLY__ */