powerpc/ftrace: Remove mod_return_to_handler

mod_return_to_handler is the same as return_to_handler, except
it handles the change of the TOC (r2). Add this into
return_to_handler and remove mod_return_to_handler.

Signed-off-by: Anton Blanchard <anton@samba.org>
powerpc/ftrace: simplify prepare_ftrace_return

Instead of passing in the stack address of the link register
to be modified, just pass in the old value and return the
new value and rely on ftrace_graph_caller to do the
modification.

This removes the exception handling around the stack update -
it isn't needed and we weren't consistent about it. Later on
we would do an unprotected modification:

       if (!ftrace_graph_entry(&trace)) {
               *parent = old;

Signed-off-by: Anton Blanchard <anton@samba.org>
powerpc/module: Simplify 64bit toc relative load

Instead of adding a magic offset to the toc relative address,
factor in the offset when creating the address in the first
place.

Signed-off-by: Anton Blanchard <anton@samba.org>
powerpc/ftrace: Remove 64bit return_to_handler redundant stack pointer save

We spill r31 and save the stack pointer there. We never use
the value so we can get rid of it.

We can also simplify the restore of the stack pointer since we know
how large our stack frame is.

Signed-off-by: Anton Blanchard <anton@samba.org>
powerpc/ftrace: Add lighter weight -pg profiling with -mprofile-kernel

The current ppc64 -pg profiling treats the mcount handler as a
normal function call. This is costly, and means ftrace function
trace has a high overhead when enabled.

Alan Modra added a gcc option for us 11 years ago (-mprofile-kernel).
Not a moment too soon, here is the kernel support for it.

This example shows the gains to be made.

void zot1(int a, int b, int c, int d, int e, int f, int g, int h)
{
        zot2(a, b, c, d, e, f, g, h);
}

Before:
	mflr 0
	std 0,16(1)
	stdu 1,-160(1)
	std 3,96(1)
	std 4,104(1)
	std 5,112(1)
	std 6,120(1)
	std 7,128(1)
	std 8,136(1)
	std 9,144(1)
	std 10,152(1)
	bl _mcount
	nop
	ld 3,96(1)
	ld 4,104(1)
	ld 5,112(1)
	ld 6,120(1)
	ld 7,128(1)
	ld 8,136(1)
	ld 9,144(1)
	ld 10,152(1)
	bl zot2
	nop
	addi 1,1,160
	ld 0,16(1)
	mtlr 0
	blr

After:
	std 0,16(1)
	bl _mcount
	mflr 0
	std 0,16(1)
	stdu 1,-96(1)
	bl zot2
	nop
	addi 1,1,96
	ld 0,16(1)
	mtlr 0
	blr

Signed-off-by: Anton Blanchard <anton@samba.org>
powerpc/ftrace: Test for bug free -mprofile-kernel gcc support

Unfortunately we had a bug in the gcc -mprofile-kernel option.
Basically it would ignore the no_instrument_function attribute.

Create a runtime check to ensure the bug does not exist in the
toolchain being used.

Signed-off-by: Anton Blanchard <anton@samba.org>