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

powerpc32: memset: only use dcbz once cache is enabled

memset() uses instruction dcbz to speed up clearing 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 memset(). Allthough no part of the code
explicitly uses memset(), GCC may make calls to it.

This patch modifies memset() such that at startup, memset()
unconditionally skip the optimised bloc that uses dcbz instruction.

Once the initial MMU is set up, in machine_init() we patch memset()
by replacing this inconditional jump by a NOP

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>

authored by

LEROY Christophe and committed by
Michael Ellerman
400c47d8 1cd03890

+9
+3
arch/powerpc/kernel/setup_32.c
··· 110 110 * This is called very early on the boot process, after a minimal 111 111 * MMU environment has been set up but before MMU_init is called. 112 112 */ 113 + extern unsigned int memset_nocache_branch; /* Insn to be replaced by NOP */ 114 + 113 115 notrace void __init machine_init(u64 dt_ptr) 114 116 { 115 117 lockdep_init(); ··· 120 118 udbg_early_init(); 121 119 122 120 patch_instruction((unsigned int *)&memcpy, PPC_INST_NOP); 121 + patch_instruction(&memset_nocache_branch, PPC_INST_NOP); 123 122 124 123 /* Do some early initialization based on the flat device tree */ 125 124 early_init_devtree(__va(dt_ptr));
+6
arch/powerpc/lib/copy_32.S
··· 73 73 * Use dcbz on the complete cache lines in the destination 74 74 * to set them to zero. This requires that the destination 75 75 * area is cacheable. -- paulus 76 + * 77 + * During early init, cache might not be active yet, so dcbz cannot be used. 78 + * We therefore skip the optimised bloc that uses dcbz. This jump is 79 + * replaced by a nop once cache is active. This is done in machine_init() 76 80 */ 77 81 _GLOBAL(memset) 78 82 rlwimi r4,r4,8,16,23 ··· 92 88 subf r6,r0,r6 93 89 cmplwi 0,r4,0 94 90 bne 2f /* Use normal procedure if r4 is not zero */ 91 + _GLOBAL(memset_nocache_branch) 92 + b 2f /* Skip optimised bloc until cache is enabled */ 95 93 96 94 clrlwi r7,r6,32-LG_CACHELINE_BYTES 97 95 add r8,r7,r5