1 From 608308682addfdc7b8e2aee88f0e028331d88e4d Mon Sep 17 00:00:00 2001
2 From: Aaro Koskinen <aaro.koskinen@nsn.com>
3 Date: Tue, 22 Jul 2014 14:51:08 +0300
4 Subject: MIPS: OCTEON: make get_system_type() thread-safe
6 From: Aaro Koskinen <aaro.koskinen@nsn.com>
8 commit 608308682addfdc7b8e2aee88f0e028331d88e4d upstream.
10 get_system_type() is not thread-safe on OCTEON. It uses static data,
11 also more dangerous issue is that it's calling cvmx_fuse_read_byte()
12 every time without any synchronization. Currently it's possible to get
13 processes stuck looping forever in kernel simply by launching multiple
14 readers of /proc/cpuinfo:
16 (while true; do cat /proc/cpuinfo > /dev/null; done) &
17 (while true; do cat /proc/cpuinfo > /dev/null; done) &
20 Fix by initializing the system type string only once during the early
23 Signed-off-by: Aaro Koskinen <aaro.koskinen@nsn.com>
24 Reviewed-by: Markos Chandras <markos.chandras@imgtec.com>
25 Patchwork: http://patchwork.linux-mips.org/patch/7437/
26 Signed-off-by: James Hogan <james.hogan@imgtec.com>
27 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
30 arch/mips/cavium-octeon/setup.c | 18 +++++++++++++-----
31 1 file changed, 13 insertions(+), 5 deletions(-)
33 --- a/arch/mips/cavium-octeon/setup.c
34 +++ b/arch/mips/cavium-octeon/setup.c
35 @@ -458,6 +458,18 @@ static void octeon_halt(void)
36 octeon_kill_core(NULL);
39 +static char __read_mostly octeon_system_type[80];
41 +static int __init init_octeon_system_type(void)
43 + snprintf(octeon_system_type, sizeof(octeon_system_type), "%s (%s)",
44 + cvmx_board_type_to_string(octeon_bootinfo->board_type),
45 + octeon_model_get_string(read_c0_prid()));
49 +early_initcall(init_octeon_system_type);
52 * Return a string representing the system type
54 @@ -465,11 +477,7 @@ static void octeon_halt(void)
56 const char *octeon_board_type_string(void)
58 - static char name[80];
59 - sprintf(name, "%s (%s)",
60 - cvmx_board_type_to_string(octeon_bootinfo->board_type),
61 - octeon_model_get_string(read_c0_prid()));
63 + return octeon_system_type;
66 const char *get_system_type(void)