Josh Poimboeuf | e6d6c07 | 2020-08-18 15:57:44 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | #ifndef _ASM_STATIC_CALL_H |
| 3 | #define _ASM_STATIC_CALL_H |
| 4 | |
| 5 | #include <asm/text-patching.h> |
| 6 | |
| 7 | /* |
Josh Poimboeuf | 1e7e478 | 2020-08-18 15:57:45 +0200 | [diff] [blame] | 8 | * For CONFIG_HAVE_STATIC_CALL_INLINE, this is a temporary trampoline which |
| 9 | * uses the current value of the key->func pointer to do an indirect jump to |
| 10 | * the function. This trampoline is only used during boot, before the call |
| 11 | * sites get patched by static_call_update(). The name of this trampoline has |
| 12 | * a magical aspect: objtool uses it to find static call sites so it can create |
| 13 | * the .static_call_sites section. |
| 14 | * |
Josh Poimboeuf | e6d6c07 | 2020-08-18 15:57:44 +0200 | [diff] [blame] | 15 | * For CONFIG_HAVE_STATIC_CALL, this is a permanent trampoline which |
| 16 | * does a direct jump to the function. The direct jump gets patched by |
| 17 | * static_call_update(). |
Josh Poimboeuf | 1e7e478 | 2020-08-18 15:57:45 +0200 | [diff] [blame] | 18 | * |
| 19 | * Having the trampoline in a special section forces GCC to emit a JMP.d32 when |
| 20 | * it does tail-call optimization on the call; since you cannot compute the |
| 21 | * relative displacement across sections. |
Josh Poimboeuf | e6d6c07 | 2020-08-18 15:57:44 +0200 | [diff] [blame] | 22 | */ |
Peter Zijlstra | 452cddb | 2020-08-18 15:57:48 +0200 | [diff] [blame] | 23 | |
| 24 | #define __ARCH_DEFINE_STATIC_CALL_TRAMP(name, insns) \ |
Josh Poimboeuf | 1e7e478 | 2020-08-18 15:57:45 +0200 | [diff] [blame] | 25 | asm(".pushsection .static_call.text, \"ax\" \n" \ |
Josh Poimboeuf | e6d6c07 | 2020-08-18 15:57:44 +0200 | [diff] [blame] | 26 | ".align 4 \n" \ |
| 27 | ".globl " STATIC_CALL_TRAMP_STR(name) " \n" \ |
| 28 | STATIC_CALL_TRAMP_STR(name) ": \n" \ |
Peter Zijlstra | 452cddb | 2020-08-18 15:57:48 +0200 | [diff] [blame] | 29 | insns " \n" \ |
Peter Zijlstra | 2105a92 | 2021-10-30 09:47:58 +0200 | [diff] [blame] | 30 | ".byte 0x53, 0x43, 0x54 \n" \ |
Josh Poimboeuf | e6d6c07 | 2020-08-18 15:57:44 +0200 | [diff] [blame] | 31 | ".type " STATIC_CALL_TRAMP_STR(name) ", @function \n" \ |
| 32 | ".size " STATIC_CALL_TRAMP_STR(name) ", . - " STATIC_CALL_TRAMP_STR(name) " \n" \ |
| 33 | ".popsection \n") |
| 34 | |
Peter Zijlstra | 452cddb | 2020-08-18 15:57:48 +0200 | [diff] [blame] | 35 | #define ARCH_DEFINE_STATIC_CALL_TRAMP(name, func) \ |
| 36 | __ARCH_DEFINE_STATIC_CALL_TRAMP(name, ".byte 0xe9; .long " #func " - (. + 4)") |
| 37 | |
| 38 | #define ARCH_DEFINE_STATIC_CALL_NULL_TRAMP(name) \ |
| 39 | __ARCH_DEFINE_STATIC_CALL_TRAMP(name, "ret; nop; nop; nop; nop") |
| 40 | |
Josh Poimboeuf | 73f44fe | 2021-01-27 17:18:37 -0600 | [diff] [blame] | 41 | |
| 42 | #define ARCH_ADD_TRAMP_KEY(name) \ |
| 43 | asm(".pushsection .static_call_tramp_key, \"a\" \n" \ |
| 44 | ".long " STATIC_CALL_TRAMP_STR(name) " - . \n" \ |
| 45 | ".long " STATIC_CALL_KEY_STR(name) " - . \n" \ |
| 46 | ".popsection \n") |
| 47 | |
Josh Poimboeuf | e6d6c07 | 2020-08-18 15:57:44 +0200 | [diff] [blame] | 48 | #endif /* _ASM_STATIC_CALL_H */ |