* [PATCH] x86/ftrace: use ftrace_write to simplify code
@ 2020-01-14 1:52 Cheng Jian
2020-01-14 8:16 ` Peter Zijlstra
0 siblings, 1 reply; 4+ messages in thread
From: Cheng Jian @ 2020-01-14 1:52 UTC (permalink / raw)
To: xiexiuqi, huawei.libin, rostedt, tglx, x86, linux-kernel
Cc: cj.chengjian, bobo.shaobowang
ftrace_write() can be used in ftrace_modify_code_direct(),
that make the code more brief.
Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
---
arch/x86/kernel/ftrace.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 024c3053dbba..6b36ed2fd04d 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -114,6 +114,16 @@ static const unsigned char *ftrace_nop_replace(void)
return ideal_nops[NOP_ATOMIC5];
}
+static int ftrace_write(unsigned long ip, const char *val, int size)
+{
+ ip = text_ip_addr(ip);
+
+ if (probe_kernel_write((void *)ip, val, size))
+ return -EPERM;
+
+ return 0;
+}
+
static int
ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
unsigned const char *new_code)
@@ -138,10 +148,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
return -EINVAL;
- ip = text_ip_addr(ip);
-
/* replace the text with the new text */
- if (probe_kernel_write((void *)ip, new_code, MCOUNT_INSN_SIZE))
+ if (ftrace_write(ip, new_code, MCOUNT_INSN_SIZE))
return -EPERM;
sync_core();
@@ -326,16 +334,6 @@ int ftrace_int3_handler(struct pt_regs *regs)
}
NOKPROBE_SYMBOL(ftrace_int3_handler);
-static int ftrace_write(unsigned long ip, const char *val, int size)
-{
- ip = text_ip_addr(ip);
-
- if (probe_kernel_write((void *)ip, val, size))
- return -EPERM;
-
- return 0;
-}
-
static int add_break(unsigned long ip, const char *old)
{
unsigned char replaced[MCOUNT_INSN_SIZE];
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/ftrace: use ftrace_write to simplify code
2020-01-14 1:52 [PATCH] x86/ftrace: use ftrace_write to simplify code Cheng Jian
@ 2020-01-14 8:16 ` Peter Zijlstra
2020-01-14 9:20 ` chengjian (D)
0 siblings, 1 reply; 4+ messages in thread
From: Peter Zijlstra @ 2020-01-14 8:16 UTC (permalink / raw)
To: Cheng Jian
Cc: xiexiuqi, huawei.libin, rostedt, tglx, x86, linux-kernel,
bobo.shaobowang
On Tue, Jan 14, 2020 at 01:52:17AM +0000, Cheng Jian wrote:
> ftrace_write() can be used in ftrace_modify_code_direct(),
> that make the code more brief.
>
> Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
None of the code you're patching still exists. Please see tip/master.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/ftrace: use ftrace_write to simplify code
2020-01-14 8:16 ` Peter Zijlstra
@ 2020-01-14 9:20 ` chengjian (D)
2020-01-14 14:13 ` Steven Rostedt
0 siblings, 1 reply; 4+ messages in thread
From: chengjian (D) @ 2020-01-14 9:20 UTC (permalink / raw)
To: Peter Zijlstra, rostedt
Cc: xiexiuqi, huawei.libin, tglx, x86, linux-kernel, bobo.shaobowang
On 2020/1/14 16:16, Peter Zijlstra wrote:
> On Tue, Jan 14, 2020 at 01:52:17AM +0000, Cheng Jian wrote:
>> ftrace_write() can be used in ftrace_modify_code_direct(),
>> that make the code more brief.
>>
>> Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
> None of the code you're patching still exists. Please see tip/master.
>
> .
I find these patches in TIP. My patch may not be necessary.
https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=768ae4406a5cab7e8702550f2446dbeb377b798d
Thank you, Peter.
-- Cheng Jian
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] x86/ftrace: use ftrace_write to simplify code
2020-01-14 9:20 ` chengjian (D)
@ 2020-01-14 14:13 ` Steven Rostedt
0 siblings, 0 replies; 4+ messages in thread
From: Steven Rostedt @ 2020-01-14 14:13 UTC (permalink / raw)
To: chengjian (D)
Cc: Peter Zijlstra, xiexiuqi, huawei.libin, tglx, x86, linux-kernel,
bobo.shaobowang
On Tue, 14 Jan 2020 17:20:13 +0800
"chengjian (D)" <cj.chengjian@huawei.com> wrote:
> On 2020/1/14 16:16, Peter Zijlstra wrote:
> > On Tue, Jan 14, 2020 at 01:52:17AM +0000, Cheng Jian wrote:
> >> ftrace_write() can be used in ftrace_modify_code_direct(),
> >> that make the code more brief.
> >>
> >> Signed-off-by: Cheng Jian <cj.chengjian@huawei.com>
> > None of the code you're patching still exists. Please see tip/master.
> >
> > .
>
>
> I find these patches in TIP. My patch may not be necessary.
>
> https://git.kernel.org/pub/scm/linux/kernel/git/tip/tip.git/commit/?id=768ae4406a5cab7e8702550f2446dbeb377b798d
>
> Thank you, Peter.
>
I was thinking that Peter's changes made it to mainline already (and I
just rebased my next merge window work on 5.5-rc6).
I should have told you this :-/
-- Steve
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-01-14 14:13 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-14 1:52 [PATCH] x86/ftrace: use ftrace_write to simplify code Cheng Jian
2020-01-14 8:16 ` Peter Zijlstra
2020-01-14 9:20 ` chengjian (D)
2020-01-14 14:13 ` Steven Rostedt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).