Skip to contentSkip to conversation

kprobes: only test 'sub pc, pc, #1b-2b+8-2' on ARMv6

PATCH New Rabin Vincent 3 participants 6 messages Jun 12, 2012 – Jun 15, 2012 Arm (32-bit)

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 kprobes: only test 'sub pc, pc, #1b-2b+8-2' on ARMv6

'sub pc, pc, #1b-2b+8-2' results in address<1:0> == '10'.

sub pc, pc, #const (== ADR pc, #const) performs an interworking branch (BXWritePC()) on ARMv7+ and a simple branch (BranchWritePC()) on earlier versions.

In ARM state, BXWritePC() is UNPREDICTABLE when address<1:0> == '10'.

In ARM state on ARMv6+, BranchWritePC() ignores address<1:0>. Before ARMv6, BranchWritePC() is UNPREDICTABLE if address<1:0> != '00'

So the instruction is UNPREDICTABLE both before and after v6.

---
 arch/arm/kernel/kprobes-test-arm.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/kernel/kprobes-test-arm.c +2 -2
index ba32b39..6c926d5 100644
@@ -187,8 +187,8 @@ void kprobe_arm_test_cases(void)
 	TEST_BF_R ("mov	pc, r",0,2f,"")
 	TEST_BF_RR("mov	pc, r",0,2f,", asl r",1,0,"")
 	TEST_BB(   "sub	pc, pc, #1b-2b+8")
-#if __LINUX_ARM_ARCH__ >= 6
-	TEST_BB(   "sub	pc, pc, #1b-2b+8-2") /* UNPREDICTABLE before ARMv6 */
+#if __LINUX_ARM_ARCH__ == 6
+	TEST_BB(   "sub	pc, pc, #1b-2b+8-2") /* UNPREDICTABLE before and after ARMv6 */
 #endif
 	TEST_BB_R( "sub	pc, pc, r",14, 1f-2f+8,"")
 	TEST_BB_R( "rsb	pc, r",14,1f-2f+8,", pc")
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/1 kprobes: only test 'sub pc, pc, #1b-2b+8-2' on ARMv6

Quoted 6 lines · Rabin Vincent

'sub pc, pc, #1b-2b+8-2' results in address<1:0> == '10'.

sub pc, pc, #const (== ADR pc, #const) performs an interworking branch (BXWritePC()) on ARMv7+ and a simple branch (BranchWritePC()) on earlier versions.

Quoted 6 lines

In ARM state, BXWritePC() is UNPREDICTABLE when address<1:0> == '10'.

In ARM state on ARMv6+, BranchWritePC() ignores address<1:0>. Before ARMv6, BranchWritePC() is UNPREDICTABLE if address<1:0> != '00'

So the instruction is UNPREDICTABLE both before and after v6.

I agree with this analysis. However, it is possible to have a kernel built to support both ARM v6 and v7 (e.g OMAP2+) in which case __LINUX_ARM_ARCH__ == 6 will be true but the code could be running on v7 hardware. Therefore a compile time check for ARM architecture isn't sufficient to fix the problem.

I can only suggest to remove the test case. That feels a bit wrong, but I'm not sure it's worth the effort to get the test code infrastructure to support runtime checks for architecture version.

Signature · 1 line
Tixy
Quoted 20 lines
---
 arch/arm/kernel/kprobes-test-arm.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/kernel/kprobes-test-arm.c +2 -2
index ba32b39..6c926d5 100644
@@ -187,8 +187,8 @@ void kprobe_arm_test_cases(void)
 	TEST_BF_R ("mov	pc, r",0,2f,"")
 	TEST_BF_RR("mov	pc, r",0,2f,", asl r",1,0,"")
 	TEST_BB(   "sub	pc, pc, #1b-2b+8")
-#if __LINUX_ARM_ARCH__ >= 6
-	TEST_BB(   "sub	pc, pc, #1b-2b+8-2") /* UNPREDICTABLE before ARMv6 */
+#if __LINUX_ARM_ARCH__ == 6
+	TEST_BB(   "sub	pc, pc, #1b-2b+8-2") /* UNPREDICTABLE before and after ARMv6 */
 #endif
 	TEST_BB_R( "sub	pc, pc, r",14, 1f-2f+8,"")
 	TEST_BB_R( "rsb	pc, r",14,1f-2f+8,", pc")
#2 lore raw

PATCH 1/1 kprobes: only test 'sub pc, pc, #1b-2b+8-2' on ARMv6

Quoted 5 lines · Tixy

I agree with this analysis. However, it is possible to have a kernel built to support both ARM v6 and v7 (e.g OMAP2+) in which case __LINUX_ARM_ARCH__ == 6 will be true but the code could be running on v7 hardware. Therefore a compile time check for ARM architecture isn't sufficient to fix the problem.

How about the following check instead? At least one other place uses it.

8<---

Quoted 1 line

From f1e1794c0c12e39e99d4169c934fd43feb889d7b Mon Sep 17 00:00:00 2001

From: Rabin Vincent <[email protected]>
Date: Mon, 11 Jun 2012 16:55:37 +0530
Subject: [PATCH] ARM: kprobes: only test 'sub pc, pc, #1b-2b+8-2' on ARMv6

'sub pc, pc, #1b-2b+8-2' results in address<1:0> == '10'.

sub pc, pc, #const (== ADR pc, #const) performs an interworking branch (BXWritePC()) on ARMv7+ and a simple branch (BranchWritePC()) on earlier versions.

In ARM state, BXWritePC() is UNPREDICTABLE when address<1:0> == '10'.

In ARM state on ARMv6+, BranchWritePC() ignores address<1:0>. Before ARMv6, BranchWritePC() is UNPREDICTABLE if address<1:0> != '00'

So the instruction is UNPREDICTABLE both before and after v6.

---
 arch/arm/kernel/kprobes-test-arm.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
(quoted diff) +0 -0

b/arch/arm/kernel/kprobes-test-arm.c
index ba32b39..38c1a3b 100644

arch/arm/kernel/kprobes-test-arm.c +2 -2
@@ -187,8 +187,8 @@ void kprobe_arm_test_cases(void)
 	TEST_BF_R ("mov	pc, r",0,2f,"")
 	TEST_BF_RR("mov	pc, r",0,2f,", asl r",1,0,"")
 	TEST_BB(   "sub	pc, pc, #1b-2b+8")
-#if __LINUX_ARM_ARCH__ >= 6
-	TEST_BB(   "sub	pc, pc, #1b-2b+8-2") /* UNPREDICTABLE before ARMv6 */
+#if __LINUX_ARM_ARCH__ == 6 && !defined(CONFIG_CPU_V7)
+	TEST_BB(   "sub	pc, pc, #1b-2b+8-2") /* UNPREDICTABLE before and

after ARMv6 */
#endif
TEST_BB_R( "sub pc, pc, r",14, 1f-2f+8,"")
TEST_BB_R( "rsb pc, r",14,1f-2f+8,", pc")

Signature · 1 line
1.7.9.5
#3 lore raw

PATCH 1/1 kprobes: only test 'sub pc, pc, #1b-2b+8-2' on ARMv6

Quoted 9 lines · Rabin Vincent
Quoted 5 lines · Tixy

I agree with this analysis. However, it is possible to have a kernel built to support both ARM v6 and v7 (e.g OMAP2+) in which case __LINUX_ARM_ARCH__ == 6 will be true but the code could be running on v7 hardware. Therefore a compile time check for ARM architecture isn't sufficient to fix the problem.

How about the following check instead? At least one other place uses it.

Can't you point out the other place which uses it, I couldn't find it.

The proposed patch below would work, but feels slightly off as it assumes that no one will build a kernel to support V6 and V8, but without V7. That does seem highly unlikely though, so I personally wouldn't object to the patch.

Signature · 1 line
Tixy
Quoted 42 lines

8<---
From f1e1794c0c12e39e99d4169c934fd43feb889d7b Mon Sep 17 00:00:00 2001
From: Rabin Vincent <[email protected]>
Date: Mon, 11 Jun 2012 16:55:37 +0530
Subject: [PATCH] ARM: kprobes: only test 'sub pc, pc, #1b-2b+8-2' on ARMv6

'sub pc, pc, #1b-2b+8-2' results in address<1:0> == '10'.

sub pc, pc, #const (== ADR pc, #const) performs an interworking branch (BXWritePC()) on ARMv7+ and a simple branch (BranchWritePC()) on earlier versions.

In ARM state, BXWritePC() is UNPREDICTABLE when address<1:0> == '10'.

In ARM state on ARMv6+, BranchWritePC() ignores address<1:0>. Before ARMv6, BranchWritePC() is UNPREDICTABLE if address<1:0> != '00'

So the instruction is UNPREDICTABLE both before and after v6.

---
 arch/arm/kernel/kprobes-test-arm.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm/kernel/kprobes-test-arm.c +2 -2
index ba32b39..38c1a3b 100644
@@ -187,8 +187,8 @@ void kprobe_arm_test_cases(void)
 	TEST_BF_R ("mov	pc, r",0,2f,"")
 	TEST_BF_RR("mov	pc, r",0,2f,", asl r",1,0,"")
 	TEST_BB(   "sub	pc, pc, #1b-2b+8")
-#if __LINUX_ARM_ARCH__ >= 6
-	TEST_BB(   "sub	pc, pc, #1b-2b+8-2") /* UNPREDICTABLE before ARMv6 */
+#if __LINUX_ARM_ARCH__ == 6 && !defined(CONFIG_CPU_V7)
+	TEST_BB(   "sub	pc, pc, #1b-2b+8-2") /* UNPREDICTABLE before and

after ARMv6 */
#endif

arch/arm/kernel/kprobes-test-arm.c +0 -0
 	TEST_BB_R( "sub	pc, pc, r",14, 1f-2f+8,"")
 	TEST_BB_R( "rsb	pc, r",14,1f-2f+8,", pc")
#4 lore raw

PATCH 1/1 kprobes: only test 'sub pc, pc, #1b-2b+8-2' on ARMv6

Quoted 4 lines · Tixy
Quoted 2 lines

How about the following check instead? ?At least one other place uses it.

Can't you point out the other place which uses it, I couldn't find it.

arch/arm/kernel/entry-armv.S:445
#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7

Quoted 4 lines

The proposed patch below would work, but feels slightly off as it assumes that no one will build a kernel to support V6 and V8, but without V7. That does seem highly unlikely though, so I personally wouldn't object to the patch.

I've no preference either way, so if a deletion of the test case would get your acked-by instead of just a non-objection, I'll do that.

#5 lore raw

PATCH 1/1 kprobes: only test 'sub pc, pc, #1b-2b+8-2' on ARMv6

Quoted 8 lines · Rabin Vincent
Quoted 4 lines · Tixy
Quoted 2 lines

How about the following check instead? At least one other place uses it.

Can't you point out the other place which uses it, I couldn't find it.

arch/arm/kernel/entry-armv.S:445
#if CONFIG_ARM_THUMB && __LINUX_ARM_ARCH__ >= 6 && CONFIG_CPU_V7

Yes, that's going to need looking at too when V8 arrives.

Quoted 7 lines
Quoted 4 lines

The proposed patch below would work, but feels slightly off as it assumes that no one will build a kernel to support V6 and V8, but without V7. That does seem highly unlikely though, so I personally wouldn't object to the patch.

I've no preference either way, so if a deletion of the test case would get your acked-by instead of just a non-objection, I'll do that.

Actually, the kprobes implementation and test code will need looking at again when V8 hits mainline, so lets not worry about it for the moment. So, in that case, I agree with your revised patch which tests for not CONFIG_CPU_V7 and you have:

Thanks for looking at kprobes and contributing fixes.

As Russell King is the official maintainer of this code, can you add your patches to his patch system?

Thanks again.

Signature · 1 line
Tixy