Skip to content

Commit 8fdddb2

Browse files
zongboxpalmer-dabbelt
authored andcommitted
riscv: patch code by fixmap mapping
On strict kernel memory permission, the ftrace have to change the permission of text for dynamic patching the intructions. Use riscv_patch_text_nosync() to patch code instead of probe_kernel_write. Signed-off-by: Zong Li <[email protected]> Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 043cb41 commit 8fdddb2

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

arch/riscv/kernel/ftrace.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <linux/ftrace.h>
99
#include <linux/uaccess.h>
1010
#include <asm/cacheflush.h>
11+
#include <asm/patch.h>
1112

1213
#ifdef CONFIG_DYNAMIC_FTRACE
1314
static int ftrace_check_current_call(unsigned long hook_pos,
@@ -46,20 +47,14 @@ static int __ftrace_modify_call(unsigned long hook_pos, unsigned long target,
4647
{
4748
unsigned int call[2];
4849
unsigned int nops[2] = {NOP4, NOP4};
49-
int ret = 0;
5050

5151
make_call(hook_pos, target, call);
5252

53-
/* replace the auipc-jalr pair at once */
54-
ret = probe_kernel_write((void *)hook_pos, enable ? call : nops,
55-
MCOUNT_INSN_SIZE);
56-
/* return must be -EPERM on write error */
57-
if (ret)
53+
/* Replace the auipc-jalr pair at once. Return -EPERM on write error. */
54+
if (riscv_patch_text_nosync
55+
((void *)hook_pos, enable ? call : nops, MCOUNT_INSN_SIZE))
5856
return -EPERM;
5957

60-
smp_mb();
61-
flush_icache_range((void *)hook_pos, (void *)hook_pos + MCOUNT_INSN_SIZE);
62-
6358
return 0;
6459
}
6560

0 commit comments

Comments
 (0)