From: Catalin Marinas on
Rabin Vincent wrote:
> Fix the mcount routines to build and run on a kernel built with the
> Thumb-2 instruction set.
>
> Cc: Catalin Marinas <catalin.marinas(a)arm.com>
> Signed-off-by: Rabin Vincent <rabin(a)rab.in>
> ---
> arch/arm/kernel/entry-common.S | 8 +++++---
> 1 files changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
> index 42eb166..cd2a574 100644
> --- a/arch/arm/kernel/entry-common.S
> +++ b/arch/arm/kernel/entry-common.S
> @@ -156,7 +156,8 @@ ENTRY(__gnu_mcount_nc)
> stmdb sp!, {r0-r3, lr}
> ldr r0, =ftrace_trace_function
> ldr r2, [r0]
> - adr r0, ftrace_stub
> + THUMB( orr r2, r2, #1 )
> + adr r0, BSYM(ftrace_stub)
> cmp r0, r2

Does this code not give the correct result if not modified?

> bne gnu_trace
> ldmia sp!, {r0-r3, ip, lr}
> @@ -166,8 +167,9 @@ gnu_trace:
> ldr r1, [sp, #20] @ lr of instrumented routine
> mov r0, lr
> sub r0, r0, #MCOUNT_INSN_SIZE
> - mov lr, pc
> - mov pc, r2
> + ARM( mov lr, pc )
> + ARM( mov pc, r2 )
> + THUMB( blx r2 )
> ldmia sp!, {r0-r3, ip, lr}
> mov pc, ip
> ENDPROC(__gnu_mcount_nc)

As above, what does this need modifying? "mov pc, r2" wouldn't change
the mode to ARM even if the value in r2 is even. It may need THUMB(nop)
after this instruction.

I could of course miss something as I haven't actually tried this code.

--
Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Rabin Vincent on
On Sat, Feb 13, 2010 at 11:27:28PM +0000, Catalin Marinas wrote:
> >diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
> >index 42eb166..cd2a574 100644
> >--- a/arch/arm/kernel/entry-common.S
> >+++ b/arch/arm/kernel/entry-common.S
> >@@ -156,7 +156,8 @@ ENTRY(__gnu_mcount_nc)
> > stmdb sp!, {r0-r3, lr}
> > ldr r0, =ftrace_trace_function
> > ldr r2, [r0]
> >- adr r0, ftrace_stub
> >+ THUMB( orr r2, r2, #1 )
> >+ adr r0, BSYM(ftrace_stub)
> > cmp r0, r2
>
> Does this code not give the correct result if not modified?

Without the BSYM, I get assembler errors:

entry-common.S: Assembler messages:
entry-common.S:179: Error: invalid immediate for address calculation (value = 0x00000004)

Without the orr, the lsb is not set on the pointer loaded from
ftrace_trace_function, but is set on BSYM(ftrace_stub), leading to the
comparison failing even when the pointer is pointing to ftrace_stub.

>
> > bne gnu_trace
> > ldmia sp!, {r0-r3, ip, lr}
> >@@ -166,8 +167,9 @@ gnu_trace:
> > ldr r1, [sp, #20] @ lr of instrumented routine
> > mov r0, lr
> > sub r0, r0, #MCOUNT_INSN_SIZE
> >- mov lr, pc
> >- mov pc, r2
> >+ ARM( mov lr, pc )
> >+ ARM( mov pc, r2 )
> >+ THUMB( blx r2 )
> > ldmia sp!, {r0-r3, ip, lr}
> > mov pc, ip
> > ENDPROC(__gnu_mcount_nc)
>
> As above, what does this need modifying? "mov pc, r2" wouldn't
> change the mode to ARM even if the value in r2 is even. It may need
> THUMB(nop) after this instruction.

The "mov pc, r2" is not the problem. The problem is the "mov lr, pc",
which does not set the lsb when storing the pc in lr. The called
function returns with "bx lr", and the mode changes to ARM. The blx is
to avoid this.

Rabin
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Catalin Marinas on
On Sat, 2010-03-13 at 06:49 +0000, Rabin Vincent wrote:
> - The problem with the "mov lr, pc", is that it does not set the lsb when
> storing the pc in lr. The called function returns with "bx lr", and the
> mode changes to ARM. The blx is to avoid this.

I'm not familiar with ftrace but why does the called function returns
using "bx lr". Is this generated by the compiler? I had the impression
that if we don't enable interworking, we wouldn't get this instruction
(but haven't tried this yet).

--
Catalin

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Rabin Vincent on
On Sun, Mar 14, 2010 at 10:30:15PM +0000, Catalin Marinas wrote:
> On Sat, 2010-03-13 at 06:49 +0000, Rabin Vincent wrote:
> > - The problem with the "mov lr, pc", is that it does not set the lsb when
> > storing the pc in lr. The called function returns with "bx lr", and the
> > mode changes to ARM. The blx is to avoid this.
>
> I'm not familiar with ftrace but why does the called function returns
> using "bx lr". Is this generated by the compiler? I had the impression
> that if we don't enable interworking, we wouldn't get this instruction
> (but haven't tried this yet).

There's nothing special about the called function: it's just a regular C
function. GCC uses "bx lr" for the return.

Rabin
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
From: Catalin Marinas on
Hi Rabin,

Rabin Vincent <rabin(a)rab.in> wrote:
> Fix the mcount routines to build and run on a kernel built with the
> Thumb-2 instruction set:
>
> - Without the BSYM, the following assembler errors appear:
>
> entry-common.S: Assembler messages:
> entry-common.S:179: Error: invalid immediate for address calculation (value = 0x00000004)

I'm still confused by this. I think that's a compiler problem but need
to get some feedback from toolchain people.

> --- a/arch/arm/kernel/entry-common.S
> +++ b/arch/arm/kernel/entry-common.S
> @@ -167,7 +167,8 @@ ENTRY(__gnu_mcount_nc)
> stmdb sp!, {r0-r3, lr}
> ldr r0, =ftrace_trace_function
> ldr r2, [r0]
> - adr r0, ftrace_stub
> + THUMB( orr r2, r2, #1 )
> + adr r0, BSYM(ftrace_stub)

If the ftrace_stub isn't .globl, the code compiles fine. My approach
would be something like this:

diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
index d085033..5f5aef6 100644
--- a/arch/arm/kernel/entry-common.S
+++ b/arch/arm/kernel/entry-common.S
@@ -122,7 +122,7 @@ ENTRY(__gnu_mcount_nc)
stmdb sp!, {r0-r3, lr}
ldr r0, =ftrace_trace_function
ldr r2, [r0]
- adr r0, ftrace_stub
+ adr r0, 1f
cmp r0, r2
bne gnu_trace
ldmia sp!, {r0-r3, ip, lr}
@@ -132,8 +132,9 @@ gnu_trace:
ldr r1, [sp, #20] @ lr of instrumented routine
mov r0, lr
sub r0, r0, #MCOUNT_INSN_SIZE
- mov lr, pc
+ adr lr, BSYM(2f)
mov pc, r2
+2:
ldmia sp!, {r0-r3, ip, lr}
mov pc, ip

@@ -141,7 +142,7 @@ ENTRY(mcount)
stmdb sp!, {r0-r3, lr}
ldr r0, =ftrace_trace_function
ldr r2, [r0]
- adr r0, ftrace_stub
+ adr r0, 1f
cmp r0, r2
bne trace
ldr lr, [fp, #-4] @ restore lr
@@ -160,6 +161,7 @@ trace:

.globl ftrace_stub
ftrace_stub:
+1:
mov pc, lr

#endif /* CONFIG_FUNCTION_TRACER */

--
Catalin
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo(a)vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/