aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm64/kernel/jump_label.c
diff options
context:
space:
mode:
authorMark Rutland <mark.rutland@arm.com>2014-11-25 10:44:18 -0500
committerWill Deacon <will.deacon@arm.com>2014-11-26 12:19:47 -0500
commit6ddae4186886a81e22ad78ad7c6936ed36bc8225 (patch)
tree93d27ac66aeb01ae0c51364215a890eb301a91ef /arch/arm64/kernel/jump_label.c
parentc9465b4ec37a68425c5a574b56280dc1a7e34070 (diff)
arm64: jump labels: NOP out NOP -> NOP replacement
In the arm64 arch_static_branch implementation we place an A64 NOP into the instruction stream and log relevant details to a jump_entry in a __jump_table section. Later this may be replaced with an immediate branch without link to the code for the unlikely case. At init time, the core calls arch_jump_label_transform_static to initialise the NOPs. On x86 this involves inserting the optimal NOP for a given microarchitecture, but on arm64 we only use the architectural NOP, and hence replace each NOP with the exact same NOP. This is somewhat pointless. Additionally, at module load time we don't call jump_label_apply_nops to patch the optimal NOPs in, unlike other architectures, but get away with this because we only use the architectural NOP anyway. A later notifier will patch NOPs with branches as required. Similarly to x86 commit 11570da1c5b1dee1 (x86/jump-label: Do not bother updating NOPs if they are correct), we can avoid patching NOPs with identical NOPs. Given that we only use a single NOP encoding, this means we can NOP-out the body of arch_jump_label_transform_static entirely. As the default __weak arch_jump_label_transform_static implementation performs a patch, we must use an empty function to achieve this. Cc: Catalin Marinas <catalin.marinas@arm.com> Cc: Jiang Liu <liuj97@gmail.com> Cc: Laura Abbott <lauraa@codeaurora.org> Acked-by: Will Deacon <will.deacon@arm.com> Signed-off-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
Diffstat (limited to 'arch/arm64/kernel/jump_label.c')
-rw-r--r--arch/arm64/kernel/jump_label.c23
1 files changed, 9 insertions, 14 deletions
diff --git a/arch/arm64/kernel/jump_label.c b/arch/arm64/kernel/jump_label.c
index 263a166291fb..4f1fec7a46db 100644
--- a/arch/arm64/kernel/jump_label.c
+++ b/arch/arm64/kernel/jump_label.c
@@ -22,9 +22,8 @@
22 22
23#ifdef HAVE_JUMP_LABEL 23#ifdef HAVE_JUMP_LABEL
24 24
25static void __arch_jump_label_transform(struct jump_entry *entry, 25void arch_jump_label_transform(struct jump_entry *entry,
26 enum jump_label_type type, 26 enum jump_label_type type)
27 bool is_static)
28{ 27{
29 void *addr = (void *)entry->code; 28 void *addr = (void *)entry->code;
30 u32 insn; 29 u32 insn;
@@ -37,22 +36,18 @@ static void __arch_jump_label_transform(struct jump_entry *entry,
37 insn = aarch64_insn_gen_nop(); 36 insn = aarch64_insn_gen_nop();
38 } 37 }
39 38
40 if (is_static) 39 aarch64_insn_patch_text(&addr, &insn, 1);
41 aarch64_insn_patch_text_nosync(addr, insn);
42 else
43 aarch64_insn_patch_text(&addr, &insn, 1);
44}
45
46void arch_jump_label_transform(struct jump_entry *entry,
47 enum jump_label_type type)
48{
49 __arch_jump_label_transform(entry, type, false);
50} 40}
51 41
52void arch_jump_label_transform_static(struct jump_entry *entry, 42void arch_jump_label_transform_static(struct jump_entry *entry,
53 enum jump_label_type type) 43 enum jump_label_type type)
54{ 44{
55 __arch_jump_label_transform(entry, type, true); 45 /*
46 * We use the architected A64 NOP in arch_static_branch, so there's no
47 * need to patch an identical A64 NOP over the top of it here. The core
48 * will call arch_jump_label_transform from a module notifier if the
49 * NOP needs to be replaced by a branch.
50 */
56} 51}
57 52
58#endif /* HAVE_JUMP_LABEL */ 53#endif /* HAVE_JUMP_LABEL */