Re: [PATCH] [GIT PULL] tracing: allow to change permissions fortext with dynamic ftrace enabled

From: Suresh Siddha
Date: Tue Oct 27 2009 - 18:25:35 EST


On Tue, 2009-10-27 at 14:35 -0700, Steven Rostedt wrote:
> On Tue, 2009-10-27 at 14:26 -0800, Suresh Siddha wrote:
> >
> > + /*
> > + * On x86_64, we use the kernel identity mapping instead of the
> > + * kernel text mapping to modify the kernel text. This is a nop
> > + * for 32bit kernels.
> > + */
>
> Is it really a nop on 32bit? Does it just turn into ip = ip?

Yes. it will be ip = ip for 32bit.

> > + if (within(ip, (unsigned long)_text, (unsigned long)_etext))
> > + ip = (unsigned long)__va(__pa(ip));
> > +
> > /* replace the text with the new text */
> > if (do_ftrace_mod_code(ip, new_code))
> > return -EPERM;
>
> I'll test it out, and if it does work, you can write up a formal patch
> and remove the !define that I added.

I just saw one more place calling do_ftrace_mod_code(). So moved this
check inside the do_ftrace_mod_code(). Does this cover all the cases?
Thanks.

diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
index 5a1b975..e239fd7 100644
--- a/arch/x86/kernel/ftrace.c
+++ b/arch/x86/kernel/ftrace.c
@@ -189,9 +189,23 @@ static void wait_for_nmi(void)
nmi_wait_count++;
}

+static inline int
+within(unsigned long addr, unsigned long start, unsigned long end)
+{
+ return addr >= start && addr < end;
+}
+
static int
do_ftrace_mod_code(unsigned long ip, void *new_code)
{
+ /*
+ * On x86_64, we use the kernel identity mapping instead of the
+ * kernel text mapping to modify the kernel text. For 32bit kernels,
+ * these mappings are same.
+ */
+ if (within(ip, (unsigned long)_text, (unsigned long)_etext))
+ ip = (unsigned long)__va(__pa(ip));
+
mod_code_ip = (void *)ip;
mod_code_newcode = new_code;





--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/