Skip to content

Commit a0caebb

Browse files
Liao Changctmarinas
authored andcommitted
arm64/kprobe: Optimize the performance of patching single-step slot
Single-step slot would not be used until kprobe is enabled, that means no race condition occurs on it under SMP, hence it is safe to pacth ss slot without stopping machine. Since I and D caches are coherent within single-step slot from aarch64_insn_patch_text_nosync(), hence no need to do it again via flush_icache_range(). Acked-by: Will Deacon <[email protected]> Acked-by: Masami Hiramatsu (Google) <[email protected]> Signed-off-by: Liao Chang <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 8c6e365 commit a0caebb

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

arch/arm64/kernel/probes/kprobes.c

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,28 @@ post_kprobe_handler(struct kprobe *, struct kprobe_ctlblk *, struct pt_regs *);
4444
static void __kprobes arch_prepare_ss_slot(struct kprobe *p)
4545
{
4646
kprobe_opcode_t *addr = p->ainsn.api.insn;
47-
void *addrs[] = {addr, addr + 1};
48-
u32 insns[] = {p->opcode, BRK64_OPCODE_KPROBES_SS};
4947

50-
/* prepare insn slot */
51-
aarch64_insn_patch_text(addrs, insns, 2);
52-
53-
flush_icache_range((uintptr_t)addr, (uintptr_t)(addr + MAX_INSN_SIZE));
48+
/*
49+
* Prepare insn slot, Mark Rutland points out it depends on a coupe of
50+
* subtleties:
51+
*
52+
* - That the I-cache maintenance for these instructions is complete
53+
* *before* the kprobe BRK is written (and aarch64_insn_patch_text_nosync()
54+
* ensures this, but just omits causing a Context-Synchronization-Event
55+
* on all CPUS).
56+
*
57+
* - That the kprobe BRK results in an exception (and consequently a
58+
* Context-Synchronoization-Event), which ensures that the CPU will
59+
* fetch thesingle-step slot instructions *after* this, ensuring that
60+
* the new instructions are used
61+
*
62+
* It supposes to place ISB after patching to guarantee I-cache maintenance
63+
* is observed on all CPUS, however, single-step slot is installed in
64+
* the BRK exception handler, so it is unnecessary to generate
65+
* Contex-Synchronization-Event via ISB again.
66+
*/
67+
aarch64_insn_patch_text_nosync(addr, p->opcode);
68+
aarch64_insn_patch_text_nosync(addr + 1, BRK64_OPCODE_KPROBES_SS);
5469

5570
/*
5671
* Needs restoring of return address after stepping xol.

0 commit comments

Comments
 (0)