Skip to content

Commit 1cd0389

Browse files
chleroympe
authored andcommitted
powerpc32: memcpy: only use dcbz once cache is enabled
memcpy() uses instruction dcbz to speed up copy by not wasting time loading cache line with data that will be overwritten. Some platform like mpc52xx do no have cache active at startup and can therefore not use memcpy(). Allthough no part of the code explicitly uses memcpy(), GCC makes calls to it. This patch modifies memcpy() such that at startup, memcpy() unconditionally jumps to generic_memcpy() which doesn't use the dcbz instruction. Once the initial MMU is set up, in machine_init() we patch memcpy() by replacing this inconditional jump by a NOP Reported-by: Michal Sojka <sojkam1@fel.cvut.cz> Tested-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Christophe Leroy <christophe.leroy@c-s.fr> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
1 parent 36b35d5 commit 1cd0389

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

arch/powerpc/kernel/setup_32.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include <asm/udbg.h>
3939
#include <asm/mmu_context.h>
4040
#include <asm/epapr_hcalls.h>
41+
#include <asm/code-patching.h>
4142

4243
#define DBG(fmt...)
4344

@@ -116,6 +117,8 @@ notrace void __init machine_init(u64 dt_ptr)
116117
/* Enable early debugging if any specified (see udbg.h) */
117118
udbg_early_init();
118119

120+
patch_instruction((unsigned int *)&memcpy, PPC_INST_NOP);
121+
119122
/* Do some early initialization based on the flat device tree */
120123
early_init_devtree(__va(dt_ptr));
121124

arch/powerpc/lib/copy_32.S

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,18 @@ _GLOBAL(memset)
128128
* the destination area is cacheable.
129129
* We only use this version if the source and dest don't overlap.
130130
* -- paulus.
131+
*
132+
* During early init, cache might not be active yet, so dcbz cannot be used.
133+
* We therefore jump to generic_memcpy which doesn't use dcbz. This jump is
134+
* replaced by a nop once cache is active. This is done in machine_init()
131135
*/
132136
_GLOBAL(memmove)
133137
cmplw 0,r3,r4
134138
bgt backwards_memcpy
135139
/* fall through */
136140

137141
_GLOBAL(memcpy)
142+
b generic_memcpy
138143
add r7,r3,r5 /* test if the src & dst overlap */
139144
add r8,r4,r5
140145
cmplw 0,r4,r7

0 commit comments

Comments
 (0)