From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Thomas Gleixner <tglx@linutronix.de>,
Milton Miller <miltonm@bga.com>,
linuxppc-dev@ozlabs.org, Steven Rostedt <srostedt@redhat.com>,
Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH 3/5] powerpc: ftrace, use probe_kernel API to modify code
Date: Thu, 20 Nov 2008 14:09:51 -0500 [thread overview]
Message-ID: <20081120191149.518690949@goodmis.org> (raw)
In-Reply-To: 20081120190948.057007623@goodmis.org
From: Steven Rostedt <srostedt@redhat.com>
Impact: use cleaner probe_kernel API over assembly
Using probe_kernel_read/write interface is a much cleaner approach
than the current assembly version.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
arch/powerpc/kernel/ftrace.c | 53 ++++++++++++++++-------------------------
1 files changed, 21 insertions(+), 32 deletions(-)
diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
index 24c023a..1adfbb2 100644
--- a/arch/powerpc/kernel/ftrace.c
+++ b/arch/powerpc/kernel/ftrace.c
@@ -9,6 +9,7 @@
#include <linux/spinlock.h>
#include <linux/hardirq.h>
+#include <linux/uaccess.h>
#include <linux/ftrace.h>
#include <linux/percpu.h>
#include <linux/init.h>
@@ -72,45 +73,33 @@ static int
ftrace_modify_code(unsigned long ip, unsigned char *old_code,
unsigned char *new_code)
{
- unsigned replaced;
- unsigned old = *(unsigned *)old_code;
- unsigned new = *(unsigned *)new_code;
- int faulted = 0;
+ unsigned char replaced[MCOUNT_INSN_SIZE];
/*
* Note: Due to modules and __init, code can
* disappear and change, we need to protect against faulting
- * as well as code changing.
+ * as well as code changing. We do this by using the
+ * probe_kernel_* functions.
*
* No real locking needed, this code is run through
- * kstop_machine.
+ * kstop_machine, or before SMP starts.
*/
- asm volatile (
- "1: lwz %1, 0(%2)\n"
- " cmpw %1, %5\n"
- " bne 2f\n"
- " stwu %3, 0(%2)\n"
- "2:\n"
- ".section .fixup, \"ax\"\n"
- "3: li %0, 1\n"
- " b 2b\n"
- ".previous\n"
- ".section __ex_table,\"a\"\n"
- _ASM_ALIGN "\n"
- _ASM_PTR "1b, 3b\n"
- ".previous"
- : "=r"(faulted), "=r"(replaced)
- : "r"(ip), "r"(new),
- "0"(faulted), "r"(old)
- : "memory");
-
- if (replaced != old && replaced != new)
- faulted = 2;
-
- if (!faulted)
- flush_icache_range(ip, ip + 8);
-
- return faulted;
+
+ /* read the text we want to modify */
+ if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
+ return -EFAULT;
+
+ /* Make sure it is what we expect it to be */
+ if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
+ return -EINVAL;
+
+ /* replace the text with the new text */
+ if (probe_kernel_write((void *)ip, new_code, MCOUNT_INSN_SIZE))
+ return -EPERM;
+
+ flush_icache_range(ip, ip + 8);
+
+ return 0;
}
static int test_24bit_addr(unsigned long ip, unsigned long addr)
--
1.5.6.5
--
WARNING: multiple messages have this Message-ID (diff)
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Andrew Morton <akpm@linux-foundation.org>,
Paul Mackerras <paulus@samba.org>,
Benjamin Herrenschmidt <benh@kernel.crashing.org>,
Thomas Gleixner <tglx@linutronix.de>,
linuxppc-dev@ozlabs.org, Milton Miller <miltonm@bga.com>,
Steven Rostedt <srostedt@redhat.com>
Subject: [PATCH 3/5] powerpc: ftrace, use probe_kernel API to modify code
Date: Thu, 20 Nov 2008 14:09:51 -0500 [thread overview]
Message-ID: <20081120191149.518690949@goodmis.org> (raw)
In-Reply-To: 20081120190948.057007623@goodmis.org
[-- Attachment #1: 0003-powerpc-ftrace-use-probe_kernel-API-to-modify-code.patch --]
[-- Type: text/plain, Size: 2441 bytes --]
From: Steven Rostedt <srostedt@redhat.com>
Impact: use cleaner probe_kernel API over assembly
Using probe_kernel_read/write interface is a much cleaner approach
than the current assembly version.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
arch/powerpc/kernel/ftrace.c | 53 ++++++++++++++++-------------------------
1 files changed, 21 insertions(+), 32 deletions(-)
diff --git a/arch/powerpc/kernel/ftrace.c b/arch/powerpc/kernel/ftrace.c
index 24c023a..1adfbb2 100644
--- a/arch/powerpc/kernel/ftrace.c
+++ b/arch/powerpc/kernel/ftrace.c
@@ -9,6 +9,7 @@
#include <linux/spinlock.h>
#include <linux/hardirq.h>
+#include <linux/uaccess.h>
#include <linux/ftrace.h>
#include <linux/percpu.h>
#include <linux/init.h>
@@ -72,45 +73,33 @@ static int
ftrace_modify_code(unsigned long ip, unsigned char *old_code,
unsigned char *new_code)
{
- unsigned replaced;
- unsigned old = *(unsigned *)old_code;
- unsigned new = *(unsigned *)new_code;
- int faulted = 0;
+ unsigned char replaced[MCOUNT_INSN_SIZE];
/*
* Note: Due to modules and __init, code can
* disappear and change, we need to protect against faulting
- * as well as code changing.
+ * as well as code changing. We do this by using the
+ * probe_kernel_* functions.
*
* No real locking needed, this code is run through
- * kstop_machine.
+ * kstop_machine, or before SMP starts.
*/
- asm volatile (
- "1: lwz %1, 0(%2)\n"
- " cmpw %1, %5\n"
- " bne 2f\n"
- " stwu %3, 0(%2)\n"
- "2:\n"
- ".section .fixup, \"ax\"\n"
- "3: li %0, 1\n"
- " b 2b\n"
- ".previous\n"
- ".section __ex_table,\"a\"\n"
- _ASM_ALIGN "\n"
- _ASM_PTR "1b, 3b\n"
- ".previous"
- : "=r"(faulted), "=r"(replaced)
- : "r"(ip), "r"(new),
- "0"(faulted), "r"(old)
- : "memory");
-
- if (replaced != old && replaced != new)
- faulted = 2;
-
- if (!faulted)
- flush_icache_range(ip, ip + 8);
-
- return faulted;
+
+ /* read the text we want to modify */
+ if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
+ return -EFAULT;
+
+ /* Make sure it is what we expect it to be */
+ if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
+ return -EINVAL;
+
+ /* replace the text with the new text */
+ if (probe_kernel_write((void *)ip, new_code, MCOUNT_INSN_SIZE))
+ return -EPERM;
+
+ flush_icache_range(ip, ip + 8);
+
+ return 0;
}
static int test_24bit_addr(unsigned long ip, unsigned long addr)
--
1.5.6.5
--
next prev parent reply other threads:[~2008-11-20 19:11 UTC|newest]
Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-20 19:09 [PATCH 0/5] powerpc: dynamic ftrace port Steven Rostedt
2008-11-20 19:09 ` Steven Rostedt
2008-11-20 19:09 ` [PATCH 1/5] powerpc: ftrace, do not latency trace idle Steven Rostedt
2008-11-20 19:09 ` Steven Rostedt
2008-11-20 19:09 ` [PATCH 2/5] powerpc: ftrace, convert to new dynamic ftrace arch API Steven Rostedt
2008-11-20 19:09 ` Steven Rostedt
2008-11-24 1:43 ` Paul Mackerras
2008-11-24 1:43 ` Paul Mackerras
2008-11-24 2:49 ` Michael Ellerman
2008-11-24 2:49 ` Michael Ellerman
2008-11-24 18:00 ` Steven Rostedt
2008-11-24 18:00 ` Steven Rostedt
2008-11-20 19:09 ` Steven Rostedt [this message]
2008-11-20 19:09 ` [PATCH 3/5] powerpc: ftrace, use probe_kernel API to modify code Steven Rostedt
2008-11-20 19:09 ` [PATCH 4/5] powerpc/ppc64: ftrace, handle module trampolines for dyn ftrace Steven Rostedt
2008-11-20 19:09 ` Steven Rostedt
2008-11-24 2:26 ` Paul Mackerras
2008-11-24 2:26 ` Paul Mackerras
2008-11-24 17:56 ` Steven Rostedt
2008-11-24 17:56 ` Steven Rostedt
2008-11-24 20:59 ` Steven Rostedt
2008-11-24 20:59 ` Steven Rostedt
2008-11-20 19:09 ` [PATCH 5/5] powerpc/ppc32: ftrace, dynamic ftrace to handle modules Steven Rostedt
2008-11-20 19:09 ` Steven Rostedt
2008-11-24 2:35 ` Paul Mackerras
2008-11-24 2:35 ` Paul Mackerras
2008-11-20 19:15 ` [PATCH 0/5] powerpc: dynamic ftrace port Steven Rostedt
2008-11-20 19:15 ` Steven Rostedt
2008-11-20 19:20 ` Ingo Molnar
2008-11-20 19:20 ` Ingo Molnar
2008-11-20 19:16 ` Ingo Molnar
2008-11-20 19:16 ` Ingo Molnar
2008-11-20 19:24 ` Steven Rostedt
2008-11-20 19:24 ` Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20081120191149.518690949@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@ozlabs.org \
--cc=miltonm@bga.com \
--cc=mingo@elte.hu \
--cc=paulus@samba.org \
--cc=srostedt@redhat.com \
--cc=tglx@linutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.