linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: rabin@rab.in (Rabin Vincent)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 1/4] ARM: ftrace: use canonical Thumb-2 wide instruction format
Date: Mon, 21 Nov 2011 20:43:46 +0530	[thread overview]
Message-ID: <1321888429-3519-1-git-send-email-rabin@rab.in> (raw)

As commit 592201a9f15 (ARM: Thumb-2: Support Thumb-2 in undefined
instruction handler) says:

    32-bit Thumb instructions are specified in the form:
        ((first_half << 16 ) | second_half)
    which matches the layout used by the ARM ARM.

Convert the ftrace code to use the same format to avoid the usage of
different formats in kernel code.

Signed-off-by: Rabin Vincent <rabin@rab.in>
---
 arch/arm/kernel/ftrace.c |   29 ++++++++++++++++++-----------
 1 files changed, 18 insertions(+), 11 deletions(-)

diff --git a/arch/arm/kernel/ftrace.c b/arch/arm/kernel/ftrace.c
index c0062ad..cdceb63 100644
--- a/arch/arm/kernel/ftrace.c
+++ b/arch/arm/kernel/ftrace.c
@@ -19,7 +19,7 @@
 #include <asm/ftrace.h>
 
 #ifdef CONFIG_THUMB2_KERNEL
-#define	NOP		0xeb04f85d	/* pop.w {lr} */
+#define	NOP		0xf85deb04	/* pop.w {lr} */
 #else
 #define	NOP		0xe8bd4000	/* pop {lr} */
 #endif
@@ -88,7 +88,7 @@ static unsigned long ftrace_gen_branch(unsigned long pc, unsigned long addr,
 	if (link)
 		second |= 1 << 14;
 
-	return (second << 16) | first;
+	return (first << 16) | second;
 }
 #else
 static unsigned long ftrace_gen_branch(unsigned long pc, unsigned long addr,
@@ -125,11 +125,20 @@ static int ftrace_modify_code(unsigned long pc, unsigned long old,
 {
 	unsigned long replaced;
 
-	if (probe_kernel_read(&replaced, (void *)pc, MCOUNT_INSN_SIZE))
-		return -EFAULT;
+#ifndef __ARMEB__
+	if (IS_ENABLED(CONFIG_THUMB2_KERNEL)) {
+		old = (old >> 16) | (old << 16);
+		new = (new >> 16) | (new << 16);
+	}
+#endif
 
-	if (replaced != old)
-		return -EINVAL;
+	if (old) {
+		if (probe_kernel_read(&replaced, (void *)pc, MCOUNT_INSN_SIZE))
+			return -EFAULT;
+
+		if (replaced != old)
+			return -EINVAL;
+	}
 
 	if (probe_kernel_write((void *)pc, &new, MCOUNT_INSN_SIZE))
 		return -EPERM;
@@ -141,23 +150,21 @@ static int ftrace_modify_code(unsigned long pc, unsigned long old,
 
 int ftrace_update_ftrace_func(ftrace_func_t func)
 {
-	unsigned long pc, old;
+	unsigned long pc;
 	unsigned long new;
 	int ret;
 
 	pc = (unsigned long)&ftrace_call;
-	memcpy(&old, &ftrace_call, MCOUNT_INSN_SIZE);
 	new = ftrace_call_replace(pc, (unsigned long)func);
 
-	ret = ftrace_modify_code(pc, old, new);
+	ret = ftrace_modify_code(pc, 0, new);
 
 #ifdef CONFIG_OLD_MCOUNT
 	if (!ret) {
 		pc = (unsigned long)&ftrace_call_old;
-		memcpy(&old, &ftrace_call_old, MCOUNT_INSN_SIZE);
 		new = ftrace_call_replace(pc, (unsigned long)func);
 
-		ret = ftrace_modify_code(pc, old, new);
+		ret = ftrace_modify_code(pc, 0, new);
 	}
 #endif
 
-- 
1.7.7.3

             reply	other threads:[~2011-11-21 15:13 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-21 15:13 Rabin Vincent [this message]
2011-11-21 15:13 ` [PATCH 2/4] ARM: extract out insn generation code from ftrace Rabin Vincent
2011-11-22 12:02   ` Dave Martin
2011-11-22 13:32     ` Rabin Vincent
2011-11-22 13:56       ` Dave Martin
2011-11-22 18:25         ` Rabin Vincent
2011-11-23 11:50           ` Dave Martin
2011-11-24 16:10             ` Rabin Vincent
2011-11-21 15:13 ` [PATCH 3/4] ARM: extract out code patch function from kprobes Rabin Vincent
2011-11-22  8:48   ` Tixy
2011-11-22 18:03     ` Rabin Vincent
2011-11-21 15:13 ` [PATCH 4/4] ARM: add jump label support Rabin Vincent
2011-11-22 19:42   ` Russell King - ARM Linux
2011-11-22 23:02     ` Stephen Boyd
2011-11-22 23:39       ` Jason Baron
2011-11-22 23:50         ` Jason Baron
2011-11-23 14:55           ` Rabin Vincent
2011-11-23 17:53             ` Russell King - ARM Linux
2011-11-28 17:04               ` Rabin Vincent
2012-01-24 15:43     ` Rabin Vincent
2012-01-24 16:05       ` Russell King - ARM Linux
2012-01-24 16:57         ` Rabin Vincent
2011-11-22 12:02 ` [PATCH 1/4] ARM: ftrace: use canonical Thumb-2 wide instruction format Dave Martin
2011-11-22 18:00   ` Rabin Vincent
2011-11-23 14:42     ` Dave Martin
2011-11-24  7:22       ` Bi Junxiao
2011-11-25 10:10         ` Dave Martin

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=1321888429-3519-1-git-send-email-rabin@rab.in \
    --to=rabin@rab.in \
    --cc=linux-arm-kernel@lists.infradead.org \
    /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 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).