Skip to content

Commit 6083086

Browse files
Aaro Koskinenralfbaechle
authored andcommitted
MIPS: OCTEON: make get_system_type() thread-safe
get_system_type() is not thread-safe on OCTEON. It uses static data, also more dangerous issue is that it's calling cvmx_fuse_read_byte() every time without any synchronization. Currently it's possible to get processes stuck looping forever in kernel simply by launching multiple readers of /proc/cpuinfo: (while true; do cat /proc/cpuinfo > /dev/null; done) & (while true; do cat /proc/cpuinfo > /dev/null; done) & ... Fix by initializing the system type string only once during the early boot. Signed-off-by: Aaro Koskinen <[email protected]> Cc: [email protected] Reviewed-by: Markos Chandras <[email protected]> Patchwork: http://patchwork.linux-mips.org/patch/7437/ Signed-off-by: James Hogan <[email protected]>
1 parent 6521d9a commit 6083086

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

arch/mips/cavium-octeon/setup.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,18 +457,26 @@ static void octeon_halt(void)
457457
octeon_kill_core(NULL);
458458
}
459459

460+
static char __read_mostly octeon_system_type[80];
461+
462+
static int __init init_octeon_system_type(void)
463+
{
464+
snprintf(octeon_system_type, sizeof(octeon_system_type), "%s (%s)",
465+
cvmx_board_type_to_string(octeon_bootinfo->board_type),
466+
octeon_model_get_string(read_c0_prid()));
467+
468+
return 0;
469+
}
470+
early_initcall(init_octeon_system_type);
471+
460472
/**
461473
* Return a string representing the system type
462474
*
463475
* Returns
464476
*/
465477
const char *octeon_board_type_string(void)
466478
{
467-
static char name[80];
468-
sprintf(name, "%s (%s)",
469-
cvmx_board_type_to_string(octeon_bootinfo->board_type),
470-
octeon_model_get_string(read_c0_prid()));
471-
return name;
479+
return octeon_system_type;
472480
}
473481

474482
const char *get_system_type(void)

0 commit comments

Comments
 (0)