Merge remote-tracking branch 'oe21/master' into vuplus-3.0
[vuplus_openvuplus_3.0] / meta-bsp / common / recipes / linux / linux-vuplus-3.1.1 / kernel_miscompilation_with_gcc_4_8.patch
1 commit 8511b7b083db01ad0538bea6a8af79f88fe02a8b
2 Author: hschang <chang@dev3>
3 Date:   Wed Jan 8 20:32:42 2014 +0900
4
5     MIPS: Refactor 'clear_page' and 'copy_page' functions.
6     
7         Remove usage of the '__attribute__((alias("...")))' hack that aliased
8         to integer arrays containing micro-assembled instructions. This hack
9         breaks when building a microMIPS kernel. It also makes the code much
10         easier to understand.
11     
12         [ralf@linux-mips.org: Added back export of the clear_page and copy_page
13         symbols so certain modules will work again.  Also fixed build with
14         CONFIG_SIBYTE_DMA_PAGEOPS enabled.]
15     
16         Signed-off-by: Steven J. Hill <sjhill@mips.com>
17         Cc: linux-mips@linux-mips.org
18         Patchwork: https://patchwork.linux-mips.org/patch/3866/
19         Acked-by: David Daney <david.daney@cavium.com>
20         Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
21
22 diff --git a/arch/mips/kernel/mips_ksyms.c b/arch/mips/kernel/mips_ksyms.c
23 index 1d04807..17160bf 100644
24 --- a/arch/mips/kernel/mips_ksyms.c
25 +++ b/arch/mips/kernel/mips_ksyms.c
26 @@ -5,7 +5,7 @@
27   * License.  See the file "COPYING" in the main directory of this archive
28   * for more details.
29   *
30 - * Copyright (C) 1996, 97, 98, 99, 2000, 01, 03, 04, 05 by Ralf Baechle
31 + * Copyright (C) 1996, 97, 98, 99, 2000, 01, 03, 04, 05, 12 by Ralf Baechle
32   * Copyright (C) 1999, 2000, 01 Silicon Graphics, Inc.
33   */
34  #include <linux/interrupt.h>
35 @@ -35,6 +35,13 @@ EXPORT_SYMBOL(memmove);
36  EXPORT_SYMBOL(kernel_thread);
37  
38  /*
39 + * Functions that operate on entire pages.  Mostly used by memory management.
40 + */
41 +
42 +EXPORT_SYMBOL(clear_page);
43 +EXPORT_SYMBOL(copy_page);
44 +
45 +/*
46   * Userspace access stuff.
47   */
48  EXPORT_SYMBOL(__copy_user);
49 diff --git a/arch/mips/mm/Makefile b/arch/mips/mm/Makefile
50 index 95e5ccb..2f2dc25 100644
51 --- a/arch/mips/mm/Makefile
52 +++ b/arch/mips/mm/Makefile
53 @@ -4,7 +4,7 @@
54  
55  obj-y                          += cache.o dma-default.o extable.o fault.o \
56                                    init.o mmap.o tlbex.o tlbex-fault.o uasm.o \
57 -                                  page.o
58 +                                  page.o page-funcs.o
59  
60  obj-$(CONFIG_32BIT)            += ioremap.o pgtable-32.o
61  obj-$(CONFIG_64BIT)            += pgtable-64.o
62 diff --git a/arch/mips/mm/page-funcs.S b/arch/mips/mm/page-funcs.S
63 new file mode 100644
64 index 0000000..48a6b38
65 --- /dev/null
66 +++ b/arch/mips/mm/page-funcs.S
67 @@ -0,0 +1,50 @@
68 +/*
69 + * This file is subject to the terms and conditions of the GNU General Public
70 + * License.  See the file "COPYING" in the main directory of this archive
71 + * for more details.
72 + *
73 + * Micro-assembler generated clear_page/copy_page functions.
74 + *
75 + * Copyright (C) 2012  MIPS Technologies, Inc.
76 + * Copyright (C) 2012  Ralf Baechle <ralf@linux-mips.org>
77 + */
78 +#include <asm/asm.h>
79 +#include <asm/regdef.h>
80 +
81 +#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
82 +#define cpu_clear_page_function_name   clear_page_cpu
83 +#define cpu_copy_page_function_name    copy_page_cpu
84 +#else
85 +#define cpu_clear_page_function_name   clear_page
86 +#define cpu_copy_page_function_name    copy_page
87 +#endif
88 +
89 +/*
90 + * Maximum sizes:
91 + *
92 + * R4000 128 bytes S-cache:            0x058 bytes
93 + * R4600 v1.7:                         0x05c bytes
94 + * R4600 v2.0:                         0x060 bytes
95 + * With prefetching, 16 word strides   0x120 bytes
96 + */
97 +EXPORT(__clear_page_start)
98 +LEAF(cpu_clear_page_function_name)
99 +1:     j       1b              /* Dummy, will be replaced. */
100 +       .space 288
101 +END(cpu_clear_page_function_name)
102 +EXPORT(__clear_page_end)
103 +
104 +/*
105 + * Maximum sizes:
106 + *
107 + * R4000 128 bytes S-cache:            0x11c bytes
108 + * R4600 v1.7:                         0x080 bytes
109 + * R4600 v2.0:                         0x07c bytes
110 + * With prefetching, 16 word strides   0x540 bytes
111 + */
112 +EXPORT(__copy_page_start)
113 +LEAF(cpu_copy_page_function_name)
114 +1:     j       1b              /* Dummy, will be replaced. */
115 +       .space 1344
116 +END(cpu_copy_page_function_name)
117 +EXPORT(__copy_page_end)
118 diff --git a/arch/mips/mm/page.c b/arch/mips/mm/page.c
119 index 36272f7..a22bd40 100644
120 --- a/arch/mips/mm/page.c
121 +++ b/arch/mips/mm/page.c
122 @@ -6,6 +6,7 @@
123   * Copyright (C) 2003, 04, 05 Ralf Baechle (ralf@linux-mips.org)
124   * Copyright (C) 2007  Maciej W. Rozycki
125   * Copyright (C) 2008  Thiemo Seufer
126 + * Copyright (C) 2012  MIPS Technologies, Inc.
127   */
128  #include <linux/init.h>
129  #include <linux/kernel.h>
130 @@ -72,45 +73,6 @@ static struct uasm_reloc __cpuinitdata relocs[5];
131  #define cpu_is_r4600_v1_x()    ((read_c0_prid() & 0xfffffff0) == 0x00002010)
132  #define cpu_is_r4600_v2_x()    ((read_c0_prid() & 0xfffffff0) == 0x00002020)
133  
134 -/*
135 - * Maximum sizes:
136 - *
137 - * R4000 128 bytes S-cache:            0x058 bytes
138 - * R4600 v1.7:                         0x05c bytes
139 - * R4600 v2.0:                         0x060 bytes
140 - * With prefetching, 16 word strides   0x120 bytes
141 - */
142 -
143 -static u32 clear_page_array[0x120 / 4];
144 -
145 -#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
146 -void clear_page_cpu(void *page) __attribute__((alias("clear_page_array")));
147 -#else
148 -void clear_page(void *page) __attribute__((alias("clear_page_array")));
149 -#endif
150 -
151 -EXPORT_SYMBOL(clear_page);
152 -
153 -/*
154 - * Maximum sizes:
155 - *
156 - * R4000 128 bytes S-cache:            0x11c bytes
157 - * R4600 v1.7:                         0x080 bytes
158 - * R4600 v2.0:                         0x07c bytes
159 - * With prefetching, 16 word strides   0x540 bytes
160 - */
161 -static u32 copy_page_array[0x540 / 4];
162 -
163 -#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
164 -void
165 -copy_page_cpu(void *to, void *from) __attribute__((alias("copy_page_array")));
166 -#else
167 -void copy_page(void *to, void *from) __attribute__((alias("copy_page_array")));
168 -#endif
169 -
170 -EXPORT_SYMBOL(copy_page);
171 -
172 -
173  static int pref_bias_clear_store __cpuinitdata;
174  static int pref_bias_copy_load __cpuinitdata;
175  static int pref_bias_copy_store __cpuinitdata;
176 @@ -283,10 +245,15 @@ static inline void __cpuinit build_clear_pref(u32 **buf, int off)
177                 }
178  }
179  
180 +extern u32 __clear_page_start;
181 +extern u32 __clear_page_end;
182 +extern u32 __copy_page_start;
183 +extern u32 __copy_page_end;
184 +
185  void __cpuinit build_clear_page(void)
186  {
187         int off;
188 -       u32 *buf = (u32 *)&clear_page_array;
189 +       u32 *buf = &__clear_page_start;
190         struct uasm_label *l = labels;
191         struct uasm_reloc *r = relocs;
192         int i;
193 @@ -357,17 +324,17 @@ void __cpuinit build_clear_page(void)
194         uasm_i_jr(&buf, RA);
195         uasm_i_nop(&buf);
196  
197 -       BUG_ON(buf > clear_page_array + ARRAY_SIZE(clear_page_array));
198 +       BUG_ON(buf > &__clear_page_end);
199  
200         uasm_resolve_relocs(relocs, labels);
201  
202         pr_debug("Synthesized clear page handler (%u instructions).\n",
203 -                (u32)(buf - clear_page_array));
204 +                (u32)(buf - &__clear_page_start));
205  
206         pr_debug("\t.set push\n");
207         pr_debug("\t.set noreorder\n");
208 -       for (i = 0; i < (buf - clear_page_array); i++)
209 -               pr_debug("\t.word 0x%08x\n", clear_page_array[i]);
210 +       for (i = 0; i < (buf - &__clear_page_start); i++)
211 +               pr_debug("\t.word 0x%08x\n", (&__clear_page_start)[i]);
212         pr_debug("\t.set pop\n");
213  }
214  
215 @@ -428,7 +395,7 @@ static inline void build_copy_store_pref(u32 **buf, int off)
216  void __cpuinit build_copy_page(void)
217  {
218         int off;
219 -       u32 *buf = (u32 *)&copy_page_array;
220 +       u32 *buf = &__copy_page_start;
221         struct uasm_label *l = labels;
222         struct uasm_reloc *r = relocs;
223         int i;
224 @@ -596,21 +563,23 @@ void __cpuinit build_copy_page(void)
225         uasm_i_jr(&buf, RA);
226         uasm_i_nop(&buf);
227  
228 -       BUG_ON(buf > copy_page_array + ARRAY_SIZE(copy_page_array));
229 +       BUG_ON(buf > &__copy_page_end);
230  
231         uasm_resolve_relocs(relocs, labels);
232  
233         pr_debug("Synthesized copy page handler (%u instructions).\n",
234 -                (u32)(buf - copy_page_array));
235 +                (u32)(buf - &__copy_page_start));
236  
237         pr_debug("\t.set push\n");
238         pr_debug("\t.set noreorder\n");
239 -       for (i = 0; i < (buf - copy_page_array); i++)
240 -               pr_debug("\t.word 0x%08x\n", copy_page_array[i]);
241 +       for (i = 0; i < (buf - &__copy_page_start); i++)
242 +               pr_debug("\t.word 0x%08x\n", (&__copy_page_start)[i]);
243         pr_debug("\t.set pop\n");
244  }
245  
246  #ifdef CONFIG_SIBYTE_DMA_PAGEOPS
247 +extern void clear_page_cpu(void *page);
248 +extern void copy_page_cpu(void *to, void *from);
249  
250  /*
251   * Pad descriptors to cacheline, since each is exclusively owned by a