LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
Frederic Weisbecker <fweisbec@gmail.com>,
Abhishek Sagar <sagar.abhishek@gmail.com>,
"David S. Miller" <davem@davemloft.net>,
Thomas Gleixner <tglx@linutronix.de>,
Peter Zijlstra <peterz@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Steven Rostedt <srostedt@redhat.com>
Subject: [PATCH 03/13 v2] ftrace: return error on failed modified text.
Date: Wed, 22 Oct 2008 17:27:24 -0400 [thread overview]
Message-ID: <20081022213551.548023022@goodmis.org> (raw)
In-Reply-To: <20081022212721.167005680@goodmis.org>
[-- Attachment #1: ftrace-return-error-on-mod-code.patch --]
[-- Type: text/plain, Size: 4496 bytes --]
Have the ftrace_modify_code return error values:
-EFAULT on error of reading the address
-EINVAL if what is read does not match what it expected
-EPERM if the write fails to update after a successful match.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
arch/x86/kernel/ftrace.c | 12 +++++++-----
include/linux/ftrace.h | 24 ++++++++++++++++++++++--
kernel/trace/ftrace.c | 21 +++++++++++++++------
3 files changed, 44 insertions(+), 13 deletions(-)
Index: linux-compile.git/arch/x86/kernel/ftrace.c
===================================================================
--- linux-compile.git.orig/arch/x86/kernel/ftrace.c 2008-10-22 16:30:39.000000000 -0400
+++ linux-compile.git/arch/x86/kernel/ftrace.c 2008-10-22 16:30:45.000000000 -0400
@@ -71,14 +71,16 @@ ftrace_modify_code(unsigned long ip, uns
* No real locking needed, this code is run through
* kstop_machine, or before SMP starts.
*/
- if (__copy_from_user_inatomic(replaced, (char __user *)ip, MCOUNT_INSN_SIZE))
- return 1;
+ if (__copy_from_user_inatomic(replaced, (char __user *)ip,
+ MCOUNT_INSN_SIZE))
+ return -EFAULT;
if (memcmp(replaced, old_code, MCOUNT_INSN_SIZE) != 0)
- return 2;
+ return -EINVAL;
- WARN_ON_ONCE(__copy_to_user_inatomic((char __user *)ip, new_code,
- MCOUNT_INSN_SIZE));
+ if (__copy_to_user_inatomic((char __user *)ip, new_code,
+ MCOUNT_INSN_SIZE))
+ return -EPERM;
sync_core();
Index: linux-compile.git/kernel/trace/ftrace.c
===================================================================
--- linux-compile.git.orig/kernel/trace/ftrace.c 2008-10-22 16:30:39.000000000 -0400
+++ linux-compile.git/kernel/trace/ftrace.c 2008-10-22 16:30:45.000000000 -0400
@@ -591,22 +591,22 @@ ftrace_code_disable(struct dyn_ftrace *r
{
unsigned long ip;
unsigned char *nop, *call;
- int failed;
+ int ret;
ip = rec->ip;
nop = ftrace_nop_replace();
call = ftrace_call_replace(ip, mcount_addr);
- failed = ftrace_modify_code(ip, call, nop);
- if (failed) {
- switch (failed) {
- case 1:
+ ret = ftrace_modify_code(ip, call, nop);
+ if (ret) {
+ switch (ret) {
+ case -EFAULT:
WARN_ON_ONCE(1);
pr_info("ftrace faulted on modifying ");
print_ip_sym(ip);
break;
- case 2:
+ case -EINVAL:
WARN_ON_ONCE(1);
pr_info("ftrace failed to modify ");
print_ip_sym(ip);
@@ -615,6 +615,15 @@ ftrace_code_disable(struct dyn_ftrace *r
print_ip_ins(" replace: ", nop);
printk(KERN_CONT "\n");
break;
+ case -EPERM:
+ WARN_ON_ONCE(1);
+ pr_info("ftrace faulted on writing ");
+ print_ip_sym(ip);
+ break;
+ default:
+ WARN_ON_ONCE(1);
+ pr_info("ftrace faulted on unknown error ");
+ print_ip_sym(ip);
}
rec->flags |= FTRACE_FL_FAILED;
Index: linux-compile.git/include/linux/ftrace.h
===================================================================
--- linux-compile.git.orig/include/linux/ftrace.h 2008-10-22 16:30:39.000000000 -0400
+++ linux-compile.git/include/linux/ftrace.h 2008-10-22 16:31:37.000000000 -0400
@@ -72,13 +72,33 @@ extern unsigned char *ftrace_nop_replace
extern unsigned char *ftrace_call_replace(unsigned long ip, unsigned long addr);
extern int ftrace_dyn_arch_init(void *data);
extern int ftrace_mcount_set(unsigned long *data);
-extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
- unsigned char *new_code);
extern int ftrace_update_ftrace_func(ftrace_func_t func);
extern void ftrace_caller(void);
extern void ftrace_call(void);
extern void mcount_call(void);
+/**
+ * ftrace_modify_code - modify code segment
+ * @ip: the address of the code segment
+ * @old_code: the contents of what is expected to be there
+ * @new_code: the code to patch in
+ *
+ * This is a very sensitive operatation and great care needs
+ * to be taken by the arch. The operation should carefully
+ * read the location, check to see if what is read is indeed
+ * what we expect it to be, and then on success of the compare,
+ * it should write to the location.
+ *
+ * Return must be:
+ * 0 on success
+ * -EFAULT on error reading the location
+ * -EINVAL on a failed compare of the contents
+ * -EPERM on error writing to the location
+ * Any other value will be considered a failure.
+ */
+extern int ftrace_modify_code(unsigned long ip, unsigned char *old_code,
+ unsigned char *new_code);
+
extern int skip_trace(unsigned long ip);
extern void ftrace_release(void *start, unsigned long size);
--
next prev parent reply other threads:[~2008-10-22 21:37 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-10-22 21:27 [PATCH 00/13 v2] ftrace: clean ups and fixes Steven Rostedt
2008-10-22 21:27 ` [PATCH 01/13 v2] ftrace: handle generic arch calls Steven Rostedt
2008-10-27 15:35 ` Ingo Molnar
2008-10-22 21:27 ` [PATCH 02/13 v2] ftrace: dynamic ftrace process only text section Steven Rostedt
2008-10-22 21:27 ` Steven Rostedt [this message]
2008-10-22 21:27 ` [PATCH 04/13 v2] ftrace: comment arch ftrace code Steven Rostedt
2008-10-22 21:27 ` [PATCH 05/13 v2] ftrace: use probe_kernel Steven Rostedt
2008-10-22 21:27 ` [PATCH 06/13 v2] ftrace: only have ftrace_kill atomic Steven Rostedt
2008-10-22 21:27 ` [PATCH 07/13 v2] ftrace: add ftrace warn on to disable ftrace Steven Rostedt
2008-10-22 21:27 ` [PATCH 08/13 v2] ftrace: do not trace init sections Steven Rostedt
2008-10-23 11:15 ` Jan Kiszka
2008-10-23 11:36 ` Steven Rostedt
2008-10-23 14:30 ` Jan Kiszka
2008-10-23 16:05 ` Steven Rostedt
2008-10-23 16:40 ` Ingo Molnar
2008-10-23 16:51 ` Steven Rostedt
2008-10-22 21:27 ` [PATCH 09/13 v2] ftrace: disable dynamic ftrace for all archs that use daemon Steven Rostedt
2008-10-22 21:27 ` [PATCH 10/13 v2] ftrace: remove daemon Steven Rostedt
2008-10-22 21:27 ` [PATCH 11/13 v2] ftrace: remove mcount set Steven Rostedt
2008-10-22 21:27 ` [PATCH 12/13 v2] ftrace: remove ftrace hash Steven Rostedt
2008-10-22 21:27 ` [PATCH 13/13 v2] ftrace: remove notrace from arch ftrace file Steven Rostedt
2008-10-23 9:29 ` [PATCH 00/13 v2] ftrace: clean ups and fixes Wenji Huang
2008-10-23 10:49 ` 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=20081022213551.548023022@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=fweisbec@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=peterz@infradead.org \
--cc=sagar.abhishek@gmail.com \
--cc=srostedt@redhat.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--subject='Re: [PATCH 03/13 v2] ftrace: return error on failed modified text.' \
/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
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).