In ftrace_modify_code_direct(), if the target instruction has already been modified by other to the desire instruction, don't return error.
This patch is for early kprobe. If an early kprobe is unregistered before ftrace is ready, the instruction may have already been restored to NOP. Signed-off-by: Wang Nan <wangn...@huawei.com> --- arch/x86/kernel/ftrace.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c index 0a86c7c..fba1779 100644 --- a/arch/x86/kernel/ftrace.c +++ b/arch/x86/kernel/ftrace.c @@ -121,8 +121,13 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code, return -EFAULT; /* Make sure it is what we expect it to be */ - if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0) - return -EINVAL; + if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0) { + /* Check if someone else has already done it */ + if (memcmp(replaced, new_code, MCOUNT_INSN_SIZE) != 0) + return -EINVAL; + else + return 0; + } ip = text_ip_addr(ip); -- 1.8.4 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/