Skip to content

Commit e4ecbe8

Browse files
mrutland-armctmarinas
authored andcommitted
arm64: patching: Add aarch64_insn_write_literal_u64()
In subsequent patches we'll need to atomically write to a naturally-aligned 64-bit literal embedded within the kernel text. Add a helper for this. For consistency with other text patching code we use copy_to_kernel_nofault(), which is atomic for naturally-aligned accesses up to 64-bits. Signed-off-by: Mark Rutland <[email protected]> Cc: Florent Revest <[email protected]> Cc: Masami Hiramatsu <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Will Deacon <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Catalin Marinas <[email protected]>
1 parent 2bbbb40 commit e4ecbe8

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

arch/arm64/include/asm/patching.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
int aarch64_insn_read(void *addr, u32 *insnp);
88
int aarch64_insn_write(void *addr, u32 insn);
99

10+
int aarch64_insn_write_literal_u64(void *addr, u64 val);
11+
1012
int aarch64_insn_patch_text_nosync(void *addr, u32 insn);
1113
int aarch64_insn_patch_text(void *addrs[], u32 insns[], int cnt);
1214

arch/arm64/kernel/patching.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,23 @@ int __kprobes aarch64_insn_write(void *addr, u32 insn)
8888
return __aarch64_insn_write(addr, cpu_to_le32(insn));
8989
}
9090

91+
noinstr int aarch64_insn_write_literal_u64(void *addr, u64 val)
92+
{
93+
u64 *waddr;
94+
unsigned long flags;
95+
int ret;
96+
97+
raw_spin_lock_irqsave(&patch_lock, flags);
98+
waddr = patch_map(addr, FIX_TEXT_POKE0);
99+
100+
ret = copy_to_kernel_nofault(waddr, &val, sizeof(val));
101+
102+
patch_unmap(FIX_TEXT_POKE0);
103+
raw_spin_unlock_irqrestore(&patch_lock, flags);
104+
105+
return ret;
106+
}
107+
91108
int __kprobes aarch64_insn_patch_text_nosync(void *addr, u32 insn)
92109
{
93110
u32 *tp = addr;

0 commit comments

Comments
 (0)