Commit 8fdddb2e authored by Zong Li's avatar Zong Li Committed by Palmer Dabbelt

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: default avatarZong Li <zong.li@sifive.com>
Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
parent 043cb41a
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <linux/ftrace.h> #include <linux/ftrace.h>
#include <linux/uaccess.h> #include <linux/uaccess.h>
#include <asm/cacheflush.h> #include <asm/cacheflush.h>
#include <asm/patch.h>
#ifdef CONFIG_DYNAMIC_FTRACE #ifdef CONFIG_DYNAMIC_FTRACE
static int ftrace_check_current_call(unsigned long hook_pos, 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, ...@@ -46,20 +47,14 @@ static int __ftrace_modify_call(unsigned long hook_pos, unsigned long target,
{ {
unsigned int call[2]; unsigned int call[2];
unsigned int nops[2] = {NOP4, NOP4}; unsigned int nops[2] = {NOP4, NOP4};
int ret = 0;
make_call(hook_pos, target, call); make_call(hook_pos, target, call);
/* replace the auipc-jalr pair at once */ /* Replace the auipc-jalr pair at once. Return -EPERM on write error. */
ret = probe_kernel_write((void *)hook_pos, enable ? call : nops, if (riscv_patch_text_nosync
MCOUNT_INSN_SIZE); ((void *)hook_pos, enable ? call : nops, MCOUNT_INSN_SIZE))
/* return must be -EPERM on write error */
if (ret)
return -EPERM; return -EPERM;
smp_mb();
flush_icache_range((void *)hook_pos, (void *)hook_pos + MCOUNT_INSN_SIZE);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment