]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - releases/3.16.3/mips-octeon-make-get_system_type-thread-safe.patch
4.9-stable patches
[thirdparty/kernel/stable-queue.git] / releases / 3.16.3 / mips-octeon-make-get_system_type-thread-safe.patch
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
5
6 From: Aaro Koskinen <aaro.koskinen@nsn.com>
7
8 commit 608308682addfdc7b8e2aee88f0e028331d88e4d upstream.
9
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:
15
16 (while true; do cat /proc/cpuinfo > /dev/null; done) &
17 (while true; do cat /proc/cpuinfo > /dev/null; done) &
18 ...
19
20 Fix by initializing the system type string only once during the early
21 boot.
22
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>
28
29 ---
30 arch/mips/cavium-octeon/setup.c | 18 +++++++++++++-----
31 1 file changed, 13 insertions(+), 5 deletions(-)
32
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);
37 }
38
39 +static char __read_mostly octeon_system_type[80];
40 +
41 +static int __init init_octeon_system_type(void)
42 +{
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()));
46 +
47 + return 0;
48 +}
49 +early_initcall(init_octeon_system_type);
50 +
51 /**
52 * Return a string representing the system type
53 *
54 @@ -465,11 +477,7 @@ static void octeon_halt(void)
55 */
56 const char *octeon_board_type_string(void)
57 {
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()));
62 - return name;
63 + return octeon_system_type;
64 }
65
66 const char *get_system_type(void)