diff options
Diffstat (limited to 'arch/arm64')
-rw-r--r-- | arch/arm64/Kconfig | 1 | ||||
-rw-r--r-- | arch/arm64/include/asm/jump_label.h | 52 | ||||
-rw-r--r-- | arch/arm64/kernel/Makefile | 1 | ||||
-rw-r--r-- | arch/arm64/kernel/jump_label.c | 58 |
4 files changed, 112 insertions, 0 deletions
diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 249acb9da4e3..dd4327f09ba4 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig | |||
@@ -25,6 +25,7 @@ config ARM64 | |||
25 | select GENERIC_STRNLEN_USER | 25 | select GENERIC_STRNLEN_USER |
26 | select GENERIC_TIME_VSYSCALL | 26 | select GENERIC_TIME_VSYSCALL |
27 | select HARDIRQS_SW_RESEND | 27 | select HARDIRQS_SW_RESEND |
28 | select HAVE_ARCH_JUMP_LABEL | ||
28 | select HAVE_ARCH_TRACEHOOK | 29 | select HAVE_ARCH_TRACEHOOK |
29 | select HAVE_DEBUG_BUGVERBOSE | 30 | select HAVE_DEBUG_BUGVERBOSE |
30 | select HAVE_DEBUG_KMEMLEAK | 31 | select HAVE_DEBUG_KMEMLEAK |
diff --git a/arch/arm64/include/asm/jump_label.h b/arch/arm64/include/asm/jump_label.h new file mode 100644 index 000000000000..076a1c714049 --- /dev/null +++ b/arch/arm64/include/asm/jump_label.h | |||
@@ -0,0 +1,52 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 Huawei Ltd. | ||
3 | * Author: Jiang Liu <liuj97@gmail.com> | ||
4 | * | ||
5 | * Based on arch/arm/include/asm/jump_label.h | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | #ifndef __ASM_JUMP_LABEL_H | ||
20 | #define __ASM_JUMP_LABEL_H | ||
21 | #include <linux/types.h> | ||
22 | #include <asm/insn.h> | ||
23 | |||
24 | #ifdef __KERNEL__ | ||
25 | |||
26 | #define JUMP_LABEL_NOP_SIZE AARCH64_INSN_SIZE | ||
27 | |||
28 | static __always_inline bool arch_static_branch(struct static_key *key) | ||
29 | { | ||
30 | asm goto("1: nop\n\t" | ||
31 | ".pushsection __jump_table, \"aw\"\n\t" | ||
32 | ".align 3\n\t" | ||
33 | ".quad 1b, %l[l_yes], %c0\n\t" | ||
34 | ".popsection\n\t" | ||
35 | : : "i"(key) : : l_yes); | ||
36 | |||
37 | return false; | ||
38 | l_yes: | ||
39 | return true; | ||
40 | } | ||
41 | |||
42 | #endif /* __KERNEL__ */ | ||
43 | |||
44 | typedef u64 jump_label_t; | ||
45 | |||
46 | struct jump_entry { | ||
47 | jump_label_t code; | ||
48 | jump_label_t target; | ||
49 | jump_label_t key; | ||
50 | }; | ||
51 | |||
52 | #endif /* __ASM_JUMP_LABEL_H */ | ||
diff --git a/arch/arm64/kernel/Makefile b/arch/arm64/kernel/Makefile index 1ea7221f8853..2d4554b13410 100644 --- a/arch/arm64/kernel/Makefile +++ b/arch/arm64/kernel/Makefile | |||
@@ -19,6 +19,7 @@ arm64-obj-$(CONFIG_HW_PERF_EVENTS) += perf_event.o | |||
19 | arm64-obj-$(CONFIG_HAVE_HW_BREAKPOINT)+= hw_breakpoint.o | 19 | arm64-obj-$(CONFIG_HAVE_HW_BREAKPOINT)+= hw_breakpoint.o |
20 | arm64-obj-$(CONFIG_EARLY_PRINTK) += early_printk.o | 20 | arm64-obj-$(CONFIG_EARLY_PRINTK) += early_printk.o |
21 | arm64-obj-$(CONFIG_ARM64_CPU_SUSPEND) += sleep.o suspend.o | 21 | arm64-obj-$(CONFIG_ARM64_CPU_SUSPEND) += sleep.o suspend.o |
22 | arm64-obj-$(CONFIG_JUMP_LABEL) += jump_label.o | ||
22 | 23 | ||
23 | obj-y += $(arm64-obj-y) vdso/ | 24 | obj-y += $(arm64-obj-y) vdso/ |
24 | obj-m += $(arm64-obj-m) | 25 | obj-m += $(arm64-obj-m) |
diff --git a/arch/arm64/kernel/jump_label.c b/arch/arm64/kernel/jump_label.c new file mode 100644 index 000000000000..263a166291fb --- /dev/null +++ b/arch/arm64/kernel/jump_label.c | |||
@@ -0,0 +1,58 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2013 Huawei Ltd. | ||
3 | * Author: Jiang Liu <liuj97@gmail.com> | ||
4 | * | ||
5 | * Based on arch/arm/kernel/jump_label.c | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
18 | */ | ||
19 | #include <linux/kernel.h> | ||
20 | #include <linux/jump_label.h> | ||
21 | #include <asm/insn.h> | ||
22 | |||
23 | #ifdef HAVE_JUMP_LABEL | ||
24 | |||
25 | static void __arch_jump_label_transform(struct jump_entry *entry, | ||
26 | enum jump_label_type type, | ||
27 | bool is_static) | ||
28 | { | ||
29 | void *addr = (void *)entry->code; | ||
30 | u32 insn; | ||
31 | |||
32 | if (type == JUMP_LABEL_ENABLE) { | ||
33 | insn = aarch64_insn_gen_branch_imm(entry->code, | ||
34 | entry->target, | ||
35 | AARCH64_INSN_BRANCH_NOLINK); | ||
36 | } else { | ||
37 | insn = aarch64_insn_gen_nop(); | ||
38 | } | ||
39 | |||
40 | if (is_static) | ||
41 | aarch64_insn_patch_text_nosync(addr, insn); | ||
42 | else | ||
43 | aarch64_insn_patch_text(&addr, &insn, 1); | ||
44 | } | ||
45 | |||
46 | void arch_jump_label_transform(struct jump_entry *entry, | ||
47 | enum jump_label_type type) | ||
48 | { | ||
49 | __arch_jump_label_transform(entry, type, false); | ||
50 | } | ||
51 | |||
52 | void arch_jump_label_transform_static(struct jump_entry *entry, | ||
53 | enum jump_label_type type) | ||
54 | { | ||
55 | __arch_jump_label_transform(entry, type, true); | ||
56 | } | ||
57 | |||
58 | #endif /* HAVE_JUMP_LABEL */ | ||