Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc: Avoid link stack corruption in MMU on syscall entry path

Currently we use the link register to branch up high in the early MMU on
syscall entry path. Unfortunately, this trashes the link stack as the
address we are going to is not associated with the earlier mflr.

This patch simply converts us to used the count register (volatile over
syscalls anyway) instead. This is much better at predicting in this
scenario and doesn't trash link stack causing a bunch of additional
branch mispredicts later. Benchmarking this on POWER8 saves a bunch of
cycles on Anton's null syscall benchmark here:
http://ozlabs.org/~anton/junkcode/null_syscall.c

Signed-off-by: Michael Neuling <mikey@neuling.org>
Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>

authored by

Michael Neuling and committed by
Benjamin Herrenschmidt
6a404806 9276dfd2

+2 -2
+2 -2
arch/powerpc/kernel/exceptions-64s.S
··· 74 74 mflr r10 ; \ 75 75 ld r12,PACAKBASE(r13) ; \ 76 76 LOAD_HANDLER(r12, system_call_entry_direct) ; \ 77 - mtlr r12 ; \ 77 + mtctr r12 ; \ 78 78 mfspr r12,SPRN_SRR1 ; \ 79 79 /* Re-use of r13... No spare regs to do this */ \ 80 80 li r13,MSR_RI ; \ 81 81 mtmsrd r13,1 ; \ 82 82 GET_PACA(r13) ; /* get r13 back */ \ 83 - blr ; 83 + bctr ; 84 84 #else 85 85 /* We can branch directly */ 86 86 #define SYSCALL_PSERIES_2_DIRECT \