Merge remote-tracking branch 'OE-2.1/master' into vuplus-3.0
[vuplus_openvuplus_3.0] / meta-bsp / common / recipes / linux / linux-vuplus-3.3.8 / kernel_miscompilation_with_gcc_4_8.patch
1 commit c022630633624a75b3b58f43dd3c6cc896a56cff
2 Author: Steven J. Hill <sjhill@mips.com>
3 Date:   Fri Jul 6 21:56:01 2012 +0200
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 57ba13e..3fc1691 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,12 @@ EXPORT_SYMBOL(memmove);
36  EXPORT_SYMBOL(kernel_thread);
37  
38  /*
39 + * Functions that operate on entire pages.  Mostly used by memory management.
40 + */
41 +EXPORT_SYMBOL(clear_page);
42 +EXPORT_SYMBOL(copy_page);
43 +
44 +/*
45   * Userspace access stuff.
46   */
47  EXPORT_SYMBOL(__copy_user);
48 diff --git a/arch/mips/mm/Makefile b/arch/mips/mm/Makefile
49 index 4aa2028..fd6203f 100644
50 --- a/arch/mips/mm/Makefile
51 +++ b/arch/mips/mm/Makefile
52 @@ -3,8 +3,8 @@
53  #
54  
55  obj-y                          += cache.o dma-default.o extable.o fault.o \
56 -                                  gup.o init.o mmap.o page.o tlbex.o \
57 -                                  tlbex-fault.o uasm.o
58 +                                  gup.o init.o mmap.o page.o page-funcs.o \
59 +                                  tlbex.o tlbex-fault.o uasm.o
60  
61  obj-$(CONFIG_32BIT)            += ioremap.o pgtable-32.o
62  obj-$(CONFIG_64BIT)            += pgtable-64.o
63 diff --git a/arch/mips/mm/page-funcs.S b/arch/mips/mm/page-funcs.S
64 new file mode 100644
65 index 0000000..48a6b38
66 --- /dev/null
67 +++ b/arch/mips/mm/page-funcs.S
68 @@ -0,0 +1,50 @@
69 +/*
70 + * This file is subject to the terms and conditions of the GNU General Public
71 + * License.  See the file "COPYING" in the main directory of this archive
72 + * for more details.
73 + *
74 + * Micro-assembler generated clear_page/copy_page functions.
75 + *
76 + * Copyright (C) 2012  MIPS Technologies, Inc.
77 + * Copyright (C) 2012  Ralf Baechle <ralf@linux-mips.org>
78 + */
79 +#include <asm/asm.h>
80 +#include <asm/regdef.h>
81 +
82 +#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
83 +#define cpu_clear_page_function_name   clear_page_cpu
84 +#define cpu_copy_page_function_name    copy_page_cpu
85 +#else
86 +#define cpu_clear_page_function_name   clear_page
87 +#define cpu_copy_page_function_name    copy_page
88 +#endif
89 +
90 +/*
91 + * Maximum sizes:
92 + *
93 + * R4000 128 bytes S-cache:            0x058 bytes
94 + * R4600 v1.7:                         0x05c bytes
95 + * R4600 v2.0:                         0x060 bytes
96 + * With prefetching, 16 word strides   0x120 bytes
97 + */
98 +EXPORT(__clear_page_start)
99 +LEAF(cpu_clear_page_function_name)
100 +1:     j       1b              /* Dummy, will be replaced. */
101 +       .space 288
102 +END(cpu_clear_page_function_name)
103 +EXPORT(__clear_page_end)
104 +
105 +/*
106 + * Maximum sizes:
107 + *
108 + * R4000 128 bytes S-cache:            0x11c bytes
109 + * R4600 v1.7:                         0x080 bytes
110 + * R4600 v2.0:                         0x07c bytes
111 + * With prefetching, 16 word strides   0x540 bytes
112 + */
113 +EXPORT(__copy_page_start)
114 +LEAF(cpu_copy_page_function_name)
115 +1:     j       1b              /* Dummy, will be replaced. */
116 +       .space 1344
117 +END(cpu_copy_page_function_name)
118 +EXPORT(__copy_page_end)
119 diff --git a/arch/mips/mm/page.c b/arch/mips/mm/page.c
120 index cc0b626..98f530e 100644
121 --- a/arch/mips/mm/page.c
122 +++ b/arch/mips/mm/page.c
123 @@ -6,6 +6,7 @@
124   * Copyright (C) 2003, 04, 05 Ralf Baechle (ralf@linux-mips.org)
125   * Copyright (C) 2007  Maciej W. Rozycki
126   * Copyright (C) 2008  Thiemo Seufer
127 + * Copyright (C) 2012  MIPS Technologies, Inc.
128   */
129  #include <linux/init.h>
130  #include <linux/kernel.h>
131 @@ -71,45 +72,6 @@ static struct uasm_reloc __cpuinitdata relocs[5];
132  #define cpu_is_r4600_v1_x()    ((read_c0_prid() & 0xfffffff0) == 0x00002010)
133  #define cpu_is_r4600_v2_x()    ((read_c0_prid() & 0xfffffff0) == 0x00002020)
134  
135 -/*
136 - * Maximum sizes:
137 - *
138 - * R4000 128 bytes S-cache:            0x058 bytes
139 - * R4600 v1.7:                         0x05c bytes
140 - * R4600 v2.0:                         0x060 bytes
141 - * With prefetching, 16 word strides   0x120 bytes
142 - */
143 -
144 -static u32 clear_page_array[0x120 / 4];
145 -
146 -#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
147 -void clear_page_cpu(void *page) __attribute__((alias("clear_page_array")));
148 -#else
149 -void clear_page(void *page) __attribute__((alias("clear_page_array")));
150 -#endif
151 -
152 -EXPORT_SYMBOL(clear_page);
153 -
154 -/*
155 - * Maximum sizes:
156 - *
157 - * R4000 128 bytes S-cache:            0x11c bytes
158 - * R4600 v1.7:                         0x080 bytes
159 - * R4600 v2.0:                         0x07c bytes
160 - * With prefetching, 16 word strides   0x540 bytes
161 - */
162 -static u32 copy_page_array[0x540 / 4];
163 -
164 -#ifdef CONFIG_SIBYTE_DMA_PAGEOPS
165 -void
166 -copy_page_cpu(void *to, void *from) __attribute__((alias("copy_page_array")));
167 -#else
168 -void copy_page(void *to, void *from) __attribute__((alias("copy_page_array")));
169 -#endif
170 -
171 -EXPORT_SYMBOL(copy_page);
172 -
173 -
174  static int pref_bias_clear_store __cpuinitdata;
175  static int pref_bias_copy_load __cpuinitdata;
176  static int pref_bias_copy_store __cpuinitdata;
177 @@ -282,10 +244,15 @@ static inline void __cpuinit build_clear_pref(u32 **buf, int off)
178                 }
179  }
180  
181 +extern u32 __clear_page_start;
182 +extern u32 __clear_page_end;
183 +extern u32 __copy_page_start;
184 +extern u32 __copy_page_end;
185 +
186  void __cpuinit build_clear_page(void)
187  {
188         int off;
189 -       u32 *buf = (u32 *)&clear_page_array;
190 +       u32 *buf = &__clear_page_start;
191         struct uasm_label *l = labels;
192         struct uasm_reloc *r = relocs;
193         int i;
194 @@ -356,17 +323,17 @@ void __cpuinit build_clear_page(void)
195         uasm_i_jr(&buf, RA);
196         uasm_i_nop(&buf);
197  
198 -       BUG_ON(buf > clear_page_array + ARRAY_SIZE(clear_page_array));
199 +       BUG_ON(buf > &__clear_page_end);
200  
201         uasm_resolve_relocs(relocs, labels);
202  
203         pr_debug("Synthesized clear page handler (%u instructions).\n",
204 -                (u32)(buf - clear_page_array));
205 +                (u32)(buf - &__clear_page_start));
206  
207         pr_debug("\t.set push\n");
208         pr_debug("\t.set noreorder\n");
209 -       for (i = 0; i < (buf - clear_page_array); i++)
210 -               pr_debug("\t.word 0x%08x\n", clear_page_array[i]);
211 +       for (i = 0; i < (buf - &__clear_page_start); i++)
212 +               pr_debug("\t.word 0x%08x\n", (&__clear_page_start)[i]);
213         pr_debug("\t.set pop\n");
214  }
215  
216 @@ -427,7 +394,7 @@ static inline void build_copy_store_pref(u32 **buf, int off)
217  void __cpuinit build_copy_page(void)
218  {
219         int off;
220 -       u32 *buf = (u32 *)&copy_page_array;
221 +       u32 *buf = &__copy_page_start;
222         struct uasm_label *l = labels;
223         struct uasm_reloc *r = relocs;
224         int i;
225 @@ -595,21 +562,23 @@ void __cpuinit build_copy_page(void)
226         uasm_i_jr(&buf, RA);
227         uasm_i_nop(&buf);
228  
229 -       BUG_ON(buf > copy_page_array + ARRAY_SIZE(copy_page_array));
230 +       BUG_ON(buf > &__copy_page_end);
231  
232         uasm_resolve_relocs(relocs, labels);
233  
234         pr_debug("Synthesized copy page handler (%u instructions).\n",
235 -                (u32)(buf - copy_page_array));
236 +                (u32)(buf - &__copy_page_start));
237  
238         pr_debug("\t.set push\n");
239         pr_debug("\t.set noreorder\n");
240 -       for (i = 0; i < (buf - copy_page_array); i++)
241 -               pr_debug("\t.word 0x%08x\n", copy_page_array[i]);
242 +       for (i = 0; i < (buf - &__copy_page_start); i++)
243 +               pr_debug("\t.word 0x%08x\n", (&__copy_page_start)[i]);
244         pr_debug("\t.set pop\n");
245  }
246  
247  #ifdef CONFIG_SIBYTE_DMA_PAGEOPS
248 +extern void clear_page_cpu(void *page);
249 +extern void copy_page_cpu(void *to, void *from);
250  
251  /*
252   * Pad descriptors to cacheline, since each is exclusively owned by a