linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: taras.kondratiuk@linaro.org (Taras Kondratiuk)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC] kprobes/kprobes-test fixes, .inst updates
Date: Fri, 29 Nov 2013 20:00:14 +0200	[thread overview]
Message-ID: <5298D62E.2000208@linaro.org> (raw)
In-Reply-To: <1383935832-20865-1-git-send-email-ben.dooks@codethink.co.uk>

On 11/08/2013 08:37 PM, Ben Dooks wrote:
> This is a series to fix kprobes and kprobes-test, as well as tidy
> up the <asm/opcodes.h> use of data instructions to output code and
> a missed bug in traps.
> 
> I have not had time to test these, or push to the new git server we
> are using. I will try and sort this out on monday.
> 
> This is an initial review series and I would appreicate testing.

kprobes-thumb.c fixes are missed in this series. Patch is below.

I've tested the series with all my comments addressed,
Dave's patch instead of 9/9 and with the patch below.
Kprobes-test passed for all combinations ARM/Thumb LE/BE.


From: Taras Kondratiuk <taras.kondratiuk@linaro.org>
Date: Fri, 29 Nov 2013 19:15:53 +0200
Subject: [PATCH] ARM: kprobes-thumb: fix instruction fetch order with <asm/opcodes.h>

If we are running BE8, the data and instruction endianness
do not match, so use <asm/opcodes.h> to correctly
translate memory accesses into ARM instructions.

Signed-off-by: Taras Kondratiuk <taras.kondratiuk@linaro.org>
---
 arch/arm/kernel/kprobes-thumb.c |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/arch/arm/kernel/kprobes-thumb.c b/arch/arm/kernel/kprobes-thumb.c
index 6123daf..b82e798 100644
--- a/arch/arm/kernel/kprobes-thumb.c
+++ b/arch/arm/kernel/kprobes-thumb.c
@@ -163,9 +163,9 @@ t32_decode_ldmstm(kprobe_opcode_t insn, struct arch_specific_insn *asi)
 	enum kprobe_insn ret = kprobe_decode_ldmstm(insn, asi);
 
 	/* Fixup modified instruction to have halfwords in correct order...*/
-	insn = asi->insn[0];
-	((u16 *)asi->insn)[0] = insn >> 16;
-	((u16 *)asi->insn)[1] = insn & 0xffff;
+	insn = __mem_to_opcode_arm(asi->insn[0]);
+	((u16 *)asi->insn)[0] = __opcode_to_mem_thumb16(insn >> 16);
+	((u16 *)asi->insn)[1] = __opcode_to_mem_thumb16(insn & 0xffff);
 
 	return ret;
 }
@@ -1153,7 +1153,7 @@ t16_decode_hiregs(kprobe_opcode_t insn, struct arch_specific_insn *asi)
 {
 	insn &= ~0x00ff;
 	insn |= 0x001; /* Set Rdn = R1 and Rm = R0 */
-	((u16 *)asi->insn)[0] = insn;
+	((u16 *)asi->insn)[0] = __opcode_to_mem_thumb16(insn);
 	asi->insn_handler = t16_emulate_hiregs;
 	return INSN_GOOD;
 }
@@ -1182,8 +1182,10 @@ t16_decode_push(kprobe_opcode_t insn, struct arch_specific_insn *asi)
 	 * and call it with R9=SP and LR in the register list represented
 	 * by R8.
 	 */
-	((u16 *)asi->insn)[0] = 0xe929;		/* 1st half STMDB R9!,{} */
-	((u16 *)asi->insn)[1] = insn & 0x1ff;	/* 2nd half (register list) */
+	/* 1st half STMDB R9!,{} */
+	((u16 *)asi->insn)[0] = __opcode_to_mem_thumb16(0xe929);
+	/* 2nd half (register list) */
+	((u16 *)asi->insn)[1] = __opcode_to_mem_thumb16(insn & 0x1ff);
 	asi->insn_handler = t16_emulate_push;
 	return INSN_GOOD;
 }
@@ -1232,8 +1234,10 @@ t16_decode_pop(kprobe_opcode_t insn, struct arch_specific_insn *asi)
 	 * and call it with R9=SP and PC in the register list represented
 	 * by R8.
 	 */
-	((u16 *)asi->insn)[0] = 0xe8b9;		/* 1st half LDMIA R9!,{} */
-	((u16 *)asi->insn)[1] = insn & 0x1ff;	/* 2nd half (register list) */
+	/* 1st half LDMIA R9!,{} */
+	((u16 *)asi->insn)[0] = __opcode_to_mem_thumb16(0xe8b9);
+	/* 2nd half (register list) */
+	((u16 *)asi->insn)[1] = __opcode_to_mem_thumb16(insn & 0x1ff);
 	asi->insn_handler = insn & 0x100 ? t16_emulate_pop_pc
 					 : t16_emulate_pop_nopc;
 	return INSN_GOOD;
-- 
1.7.9.5



-- 
Taras Kondratiuk

      parent reply	other threads:[~2013-11-29 18:00 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-08 18:37 [RFC] kprobes/kprobes-test fixes, .inst updates Ben Dooks
2013-11-08 18:37 ` [PATCH 1/9] ARM: fix missed big-endian fix in traps.c Ben Dooks
2013-11-08 18:37 ` [PATCH 2/9] ARM: kprobes: fix instruction fetch order with <asm/opcodes.h> Ben Dooks
2013-11-29 13:01   ` Taras Kondratiuk
2013-11-29 17:55     ` Ben Dooks
2013-11-08 18:37 ` [PATCH 3/9] ARM: kprobes-test: use <asm/opcodes.h> for instruction accesses Ben Dooks
2013-11-08 18:37 ` [PATCH 4/9] ARM: kprobes-test: Use <asm/opcodes.h> for ARM instruction building Ben Dooks
2013-11-29 11:55   ` Taras Kondratiuk
2013-11-08 18:37 ` [PATCH 5/9] ARM: kprobes-test: Use <asm/opcodes.h> for thumb instruction nuilding Ben Dooks
2013-11-08 18:37 ` [PATCH 6/9] ARM: kprobes-test: Workaround GAS .align bug Ben Dooks
2013-11-08 18:37 ` [PATCH 7/9] ARM: kprobes-test: fix next_instruction() Ben Dooks
2013-11-08 18:37 ` [PATCH 8/9] ARM: add test for as supporting '.inst' Ben Dooks
2013-11-11 18:16   ` Dave Martin
2013-11-08 18:37 ` [PATCH 9/9] ARM: asm/opcodes.h: use ARM_HAVE_INST to use .inst to build instructions Ben Dooks
2013-11-11 16:18   ` Dave Martin
2013-11-11 18:40     ` Dave Martin
2013-11-29 17:57   ` Taras Kondratiuk
2013-11-29 18:00 ` Taras Kondratiuk [this message]

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=5298D62E.2000208@linaro.org \
    --to=taras.kondratiuk@linaro.org \
    --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).