af4da8e6945d1cfb45b2b85bda80fab0c4e83408
[openwrt/staging/blogic.git] / package / boot / uboot-imx6 / patches / 104-gcc-compiler-linux-4-5.patch
1 From 9b2c282b348dfe966bbba967dc7a45ce817cce50 Mon Sep 17 00:00:00 2001
2 From: Tom Rini <trini@konsulko.com>
3 Date: Mon, 29 Feb 2016 11:34:15 -0500
4 Subject: compiler*.h: sync include/linux/compiler*.h with Linux 4.5-rc6
5
6 Copy these from Linux v4.5-rc6 tag.
7
8 This is needed so that we can keep up with newer gcc versions. Note
9 that we don't have the uapi/ hierarchy from the kernel so continue to
10 use <linux/types.h>
11
12 Signed-off-by: Tom Rini <trini@konsulko.com>
13 ---
14 include/linux/compiler-gcc.h | 259 ++++++++++++++++++++++++++++++++---------
15 include/linux/compiler-gcc3.h | 23 ----
16 include/linux/compiler-gcc4.h | 88 --------------
17 include/linux/compiler-gcc5.h | 65 -----------
18 include/linux/compiler-intel.h | 5 +
19 include/linux/compiler.h | 178 ++++++++++++++++++++++++++--
20 6 files changed, 383 insertions(+), 235 deletions(-)
21 delete mode 100644 include/linux/compiler-gcc3.h
22 delete mode 100644 include/linux/compiler-gcc4.h
23 delete mode 100644 include/linux/compiler-gcc5.h
24
25 --- a/include/linux/compiler-gcc.h
26 +++ b/include/linux/compiler-gcc.h
27 @@ -5,14 +5,28 @@
28 /*
29 * Common definitions for all gcc versions go here.
30 */
31 -#define GCC_VERSION (__GNUC__ * 10000 \
32 - + __GNUC_MINOR__ * 100 \
33 - + __GNUC_PATCHLEVEL__)
34 -
35 +#define GCC_VERSION (__GNUC__ * 10000 \
36 + + __GNUC_MINOR__ * 100 \
37 + + __GNUC_PATCHLEVEL__)
38
39 /* Optimization barrier */
40 +
41 /* The "volatile" is due to gcc bugs */
42 #define barrier() __asm__ __volatile__("": : :"memory")
43 +/*
44 + * This version is i.e. to prevent dead stores elimination on @ptr
45 + * where gcc and llvm may behave differently when otherwise using
46 + * normal barrier(): while gcc behavior gets along with a normal
47 + * barrier(), llvm needs an explicit input variable to be assumed
48 + * clobbered. The issue is as follows: while the inline asm might
49 + * access any memory it wants, the compiler could have fit all of
50 + * @ptr into memory registers instead, and since @ptr never escaped
51 + * from that, it proofed that the inline asm wasn't touching any of
52 + * it. This version works well with both compilers, i.e. we're telling
53 + * the compiler that the inline asm absolutely may see the contents
54 + * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495
55 + */
56 +#define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory")
57
58 /*
59 * This macro obfuscates arithmetic on a variable address so that gcc
60 @@ -32,58 +46,63 @@
61 * the inline assembly constraint from =g to =r, in this particular
62 * case either is valid.
63 */
64 -#define RELOC_HIDE(ptr, off) \
65 - ({ unsigned long __ptr; \
66 - __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
67 - (typeof(ptr)) (__ptr + (off)); })
68 +#define RELOC_HIDE(ptr, off) \
69 +({ \
70 + unsigned long __ptr; \
71 + __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
72 + (typeof(ptr)) (__ptr + (off)); \
73 +})
74
75 /* Make the optimizer believe the variable can be manipulated arbitrarily. */
76 -#define OPTIMIZER_HIDE_VAR(var) __asm__ ("" : "=r" (var) : "0" (var))
77 +#define OPTIMIZER_HIDE_VAR(var) \
78 + __asm__ ("" : "=r" (var) : "0" (var))
79
80 #ifdef __CHECKER__
81 -#define __must_be_array(arr) 0
82 +#define __must_be_array(a) 0
83 #else
84 /* &a[0] degrades to a pointer: a different type from an array */
85 -#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
86 +#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
87 #endif
88
89 /*
90 * Force always-inline if the user requests it so via the .config,
91 * or if gcc is too old:
92 */
93 -#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
94 +#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
95 !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
96 -# define inline inline __attribute__((always_inline)) notrace
97 -# define __inline__ __inline__ __attribute__((always_inline)) notrace
98 -# define __inline __inline __attribute__((always_inline)) notrace
99 +#define inline inline __attribute__((always_inline)) notrace
100 +#define __inline__ __inline__ __attribute__((always_inline)) notrace
101 +#define __inline __inline __attribute__((always_inline)) notrace
102 #else
103 /* A lot of inline functions can cause havoc with function tracing */
104 -# define inline inline notrace
105 -# define __inline__ __inline__ notrace
106 -# define __inline __inline notrace
107 +#define inline inline notrace
108 +#define __inline__ __inline__ notrace
109 +#define __inline __inline notrace
110 #endif
111
112 -#define __deprecated __attribute__((deprecated))
113 -#ifndef __packed
114 -#define __packed __attribute__((packed))
115 -#endif
116 -#ifndef __weak
117 -#define __weak __attribute__((weak))
118 -#endif
119 +#define __always_inline inline __attribute__((always_inline))
120 +#define noinline __attribute__((noinline))
121 +
122 +#define __deprecated __attribute__((deprecated))
123 +#define __packed __attribute__((packed))
124 +#define __weak __attribute__((weak))
125 +#define __alias(symbol) __attribute__((alias(#symbol)))
126
127 /*
128 - * it doesn't make sense on ARM (currently the only user of __naked) to trace
129 - * naked functions because then mcount is called without stack and frame pointer
130 - * being set up and there is no chance to restore the lr register to the value
131 - * before mcount was called.
132 + * it doesn't make sense on ARM (currently the only user of __naked)
133 + * to trace naked functions because then mcount is called without
134 + * stack and frame pointer being set up and there is no chance to
135 + * restore the lr register to the value before mcount was called.
136 + *
137 + * The asm() bodies of naked functions often depend on standard calling
138 + * conventions, therefore they must be noinline and noclone.
139 *
140 - * The asm() bodies of naked functions often depend on standard calling conventions,
141 - * therefore they must be noinline and noclone. GCC 4.[56] currently fail to enforce
142 - * this, so we must do so ourselves. See GCC PR44290.
143 + * GCC 4.[56] currently fail to enforce this, so we must do so ourselves.
144 + * See GCC PR44290.
145 */
146 -#define __naked __attribute__((naked)) noinline __noclone notrace
147 +#define __naked __attribute__((naked)) noinline __noclone notrace
148
149 -#define __noreturn __attribute__((noreturn))
150 +#define __noreturn __attribute__((noreturn))
151
152 /*
153 * From the GCC manual:
154 @@ -95,34 +114,170 @@
155 * would be.
156 * [...]
157 */
158 -#ifndef __pure
159 -#define __pure __attribute__((pure))
160 +#define __pure __attribute__((pure))
161 +#define __aligned(x) __attribute__((aligned(x)))
162 +#define __printf(a, b) __attribute__((format(printf, a, b)))
163 +#define __scanf(a, b) __attribute__((format(scanf, a, b)))
164 +#define __attribute_const__ __attribute__((__const__))
165 +#define __maybe_unused __attribute__((unused))
166 +#define __always_unused __attribute__((unused))
167 +
168 +/* gcc version specific checks */
169 +
170 +#if GCC_VERSION < 30200
171 +# error Sorry, your compiler is too old - please upgrade it.
172 +#endif
173 +
174 +#if GCC_VERSION < 30300
175 +# define __used __attribute__((__unused__))
176 +#else
177 +# define __used __attribute__((__used__))
178 +#endif
179 +
180 +#ifdef CONFIG_GCOV_KERNEL
181 +# if GCC_VERSION < 30400
182 +# error "GCOV profiling support for gcc versions below 3.4 not included"
183 +# endif /* __GNUC_MINOR__ */
184 +#endif /* CONFIG_GCOV_KERNEL */
185 +
186 +#if GCC_VERSION >= 30400
187 +#define __must_check __attribute__((warn_unused_result))
188 #endif
189 -#ifndef __aligned
190 -#define __aligned(x) __attribute__((aligned(x)))
191 +
192 +#if GCC_VERSION >= 40000
193 +
194 +/* GCC 4.1.[01] miscompiles __weak */
195 +#ifdef __KERNEL__
196 +# if GCC_VERSION >= 40100 && GCC_VERSION <= 40101
197 +# error Your version of gcc miscompiles the __weak directive
198 +# endif
199 +#endif
200 +
201 +#define __used __attribute__((__used__))
202 +#define __compiler_offsetof(a, b) \
203 + __builtin_offsetof(a, b)
204 +
205 +#if GCC_VERSION >= 40100 && GCC_VERSION < 40600
206 +# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
207 #endif
208 -#define __printf(a, b) __attribute__((format(printf, a, b)))
209 -#define __scanf(a, b) __attribute__((format(scanf, a, b)))
210 -#define noinline __attribute__((noinline))
211 -#define __attribute_const__ __attribute__((__const__))
212 -#define __maybe_unused __attribute__((unused))
213 -#define __always_unused __attribute__((unused))
214 -
215 -#define __gcc_header(x) #x
216 -#define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
217 -#define gcc_header(x) _gcc_header(x)
218 -#include gcc_header(__GNUC__)
219 +
220 +#if GCC_VERSION >= 40300
221 +/* Mark functions as cold. gcc will assume any path leading to a call
222 + * to them will be unlikely. This means a lot of manual unlikely()s
223 + * are unnecessary now for any paths leading to the usual suspects
224 + * like BUG(), printk(), panic() etc. [but let's keep them for now for
225 + * older compilers]
226 + *
227 + * Early snapshots of gcc 4.3 don't support this and we can't detect this
228 + * in the preprocessor, but we can live with this because they're unreleased.
229 + * Maketime probing would be overkill here.
230 + *
231 + * gcc also has a __attribute__((__hot__)) to move hot functions into
232 + * a special section, but I don't see any sense in this right now in
233 + * the kernel context
234 + */
235 +#define __cold __attribute__((__cold__))
236 +
237 +#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
238 +
239 +#ifndef __CHECKER__
240 +# define __compiletime_warning(message) __attribute__((warning(message)))
241 +# define __compiletime_error(message) __attribute__((error(message)))
242 +#endif /* __CHECKER__ */
243 +#endif /* GCC_VERSION >= 40300 */
244 +
245 +#if GCC_VERSION >= 40500
246 +/*
247 + * Mark a position in code as unreachable. This can be used to
248 + * suppress control flow warnings after asm blocks that transfer
249 + * control elsewhere.
250 + *
251 + * Early snapshots of gcc 4.5 don't support this and we can't detect
252 + * this in the preprocessor, but we can live with this because they're
253 + * unreleased. Really, we need to have autoconf for the kernel.
254 + */
255 +#define unreachable() __builtin_unreachable()
256 +
257 +/* Mark a function definition as prohibited from being cloned. */
258 +#define __noclone __attribute__((__noclone__))
259 +
260 +#endif /* GCC_VERSION >= 40500 */
261 +
262 +#if GCC_VERSION >= 40600
263 +/*
264 + * When used with Link Time Optimization, gcc can optimize away C functions or
265 + * variables which are referenced only from assembly code. __visible tells the
266 + * optimizer that something else uses this function or variable, thus preventing
267 + * this.
268 + */
269 +#define __visible __attribute__((externally_visible))
270 +#endif
271 +
272 +
273 +#if GCC_VERSION >= 40900 && !defined(__CHECKER__)
274 +/*
275 + * __assume_aligned(n, k): Tell the optimizer that the returned
276 + * pointer can be assumed to be k modulo n. The second argument is
277 + * optional (default 0), so we use a variadic macro to make the
278 + * shorthand.
279 + *
280 + * Beware: Do not apply this to functions which may return
281 + * ERR_PTRs. Also, it is probably unwise to apply it to functions
282 + * returning extra information in the low bits (but in that case the
283 + * compiler should see some alignment anyway, when the return value is
284 + * massaged by 'flags = ptr & 3; ptr &= ~3;').
285 + */
286 +#define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__)))
287 +#endif
288 +
289 +/*
290 + * GCC 'asm goto' miscompiles certain code sequences:
291 + *
292 + * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
293 + *
294 + * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
295 + *
296 + * (asm goto is automatically volatile - the naming reflects this.)
297 + */
298 +#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
299 +
300 +#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
301 +#if GCC_VERSION >= 40400
302 +#define __HAVE_BUILTIN_BSWAP32__
303 +#define __HAVE_BUILTIN_BSWAP64__
304 +#endif
305 +#if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
306 +#define __HAVE_BUILTIN_BSWAP16__
307 +#endif
308 +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
309 +
310 +#if GCC_VERSION >= 50000
311 +#define KASAN_ABI_VERSION 4
312 +#elif GCC_VERSION >= 40902
313 +#define KASAN_ABI_VERSION 3
314 +#endif
315 +
316 +#if GCC_VERSION >= 40902
317 +/*
318 + * Tell the compiler that address safety instrumentation (KASAN)
319 + * should not be applied to that function.
320 + * Conflicts with inlining: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
321 + */
322 +#define __no_sanitize_address __attribute__((no_sanitize_address))
323 +#endif
324 +
325 +#endif /* gcc version >= 40000 specific checks */
326
327 #if !defined(__noclone)
328 #define __noclone /* not needed */
329 #endif
330
331 +#if !defined(__no_sanitize_address)
332 +#define __no_sanitize_address
333 +#endif
334 +
335 /*
336 * A trick to suppress uninitialized variable warning without generating any
337 * code
338 */
339 #define uninitialized_var(x) x = x
340 -
341 -#ifndef __always_inline
342 -#define __always_inline inline __attribute__((always_inline))
343 -#endif
344 --- a/include/linux/compiler-gcc3.h
345 +++ /dev/null
346 @@ -1,23 +0,0 @@
347 -#ifndef __LINUX_COMPILER_H
348 -#error "Please don't include <linux/compiler-gcc3.h> directly, include <linux/compiler.h> instead."
349 -#endif
350 -
351 -#if GCC_VERSION < 30200
352 -# error Sorry, your compiler is too old - please upgrade it.
353 -#endif
354 -
355 -#if GCC_VERSION >= 30300
356 -# define __used __attribute__((__used__))
357 -#else
358 -# define __used __attribute__((__unused__))
359 -#endif
360 -
361 -#if GCC_VERSION >= 30400
362 -#define __must_check __attribute__((warn_unused_result))
363 -#endif
364 -
365 -#ifdef CONFIG_GCOV_KERNEL
366 -# if GCC_VERSION < 30400
367 -# error "GCOV profiling support for gcc versions below 3.4 not included"
368 -# endif /* __GNUC_MINOR__ */
369 -#endif /* CONFIG_GCOV_KERNEL */
370 --- a/include/linux/compiler-gcc4.h
371 +++ /dev/null
372 @@ -1,88 +0,0 @@
373 -#ifndef __LINUX_COMPILER_H
374 -#error "Please don't include <linux/compiler-gcc4.h> directly, include <linux/compiler.h> instead."
375 -#endif
376 -
377 -/* GCC 4.1.[01] miscompiles __weak */
378 -#ifdef __KERNEL__
379 -# if GCC_VERSION >= 40100 && GCC_VERSION <= 40101
380 -# error Your version of gcc miscompiles the __weak directive
381 -# endif
382 -#endif
383 -
384 -#define __used __attribute__((__used__))
385 -#define __must_check __attribute__((warn_unused_result))
386 -#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
387 -
388 -#if GCC_VERSION >= 40100 && GCC_VERSION < 40600
389 -# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
390 -#endif
391 -
392 -#if GCC_VERSION >= 40300
393 -/* Mark functions as cold. gcc will assume any path leading to a call
394 - to them will be unlikely. This means a lot of manual unlikely()s
395 - are unnecessary now for any paths leading to the usual suspects
396 - like BUG(), printk(), panic() etc. [but let's keep them for now for
397 - older compilers]
398 -
399 - Early snapshots of gcc 4.3 don't support this and we can't detect this
400 - in the preprocessor, but we can live with this because they're unreleased.
401 - Maketime probing would be overkill here.
402 -
403 - gcc also has a __attribute__((__hot__)) to move hot functions into
404 - a special section, but I don't see any sense in this right now in
405 - the kernel context */
406 -#define __cold __attribute__((__cold__))
407 -
408 -#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
409 -
410 -#ifndef __CHECKER__
411 -# define __compiletime_warning(message) __attribute__((warning(message)))
412 -# define __compiletime_error(message) __attribute__((error(message)))
413 -#endif /* __CHECKER__ */
414 -#endif /* GCC_VERSION >= 40300 */
415 -
416 -#if GCC_VERSION >= 40500
417 -/*
418 - * Mark a position in code as unreachable. This can be used to
419 - * suppress control flow warnings after asm blocks that transfer
420 - * control elsewhere.
421 - *
422 - * Early snapshots of gcc 4.5 don't support this and we can't detect
423 - * this in the preprocessor, but we can live with this because they're
424 - * unreleased. Really, we need to have autoconf for the kernel.
425 - */
426 -#define unreachable() __builtin_unreachable()
427 -
428 -/* Mark a function definition as prohibited from being cloned. */
429 -#define __noclone __attribute__((__noclone__))
430 -
431 -#endif /* GCC_VERSION >= 40500 */
432 -
433 -#if GCC_VERSION >= 40600
434 -/*
435 - * Tell the optimizer that something else uses this function or variable.
436 - */
437 -#define __visible __attribute__((externally_visible))
438 -#endif
439 -
440 -/*
441 - * GCC 'asm goto' miscompiles certain code sequences:
442 - *
443 - * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
444 - *
445 - * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
446 - * Fixed in GCC 4.8.2 and later versions.
447 - *
448 - * (asm goto is automatically volatile - the naming reflects this.)
449 - */
450 -#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
451 -
452 -#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
453 -#if GCC_VERSION >= 40400
454 -#define __HAVE_BUILTIN_BSWAP32__
455 -#define __HAVE_BUILTIN_BSWAP64__
456 -#endif
457 -#if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
458 -#define __HAVE_BUILTIN_BSWAP16__
459 -#endif
460 -#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
461 --- a/include/linux/compiler-gcc5.h
462 +++ /dev/null
463 @@ -1,65 +0,0 @@
464 -#ifndef __LINUX_COMPILER_H
465 -#error "Please don't include <linux/compiler-gcc5.h> directly, include <linux/compiler.h> instead."
466 -#endif
467 -
468 -#define __used __attribute__((__used__))
469 -#define __must_check __attribute__((warn_unused_result))
470 -#define __compiler_offsetof(a, b) __builtin_offsetof(a, b)
471 -
472 -/* Mark functions as cold. gcc will assume any path leading to a call
473 - to them will be unlikely. This means a lot of manual unlikely()s
474 - are unnecessary now for any paths leading to the usual suspects
475 - like BUG(), printk(), panic() etc. [but let's keep them for now for
476 - older compilers]
477 -
478 - Early snapshots of gcc 4.3 don't support this and we can't detect this
479 - in the preprocessor, but we can live with this because they're unreleased.
480 - Maketime probing would be overkill here.
481 -
482 - gcc also has a __attribute__((__hot__)) to move hot functions into
483 - a special section, but I don't see any sense in this right now in
484 - the kernel context */
485 -#define __cold __attribute__((__cold__))
486 -
487 -#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
488 -
489 -#ifndef __CHECKER__
490 -# define __compiletime_warning(message) __attribute__((warning(message)))
491 -# define __compiletime_error(message) __attribute__((error(message)))
492 -#endif /* __CHECKER__ */
493 -
494 -/*
495 - * Mark a position in code as unreachable. This can be used to
496 - * suppress control flow warnings after asm blocks that transfer
497 - * control elsewhere.
498 - *
499 - * Early snapshots of gcc 4.5 don't support this and we can't detect
500 - * this in the preprocessor, but we can live with this because they're
501 - * unreleased. Really, we need to have autoconf for the kernel.
502 - */
503 -#define unreachable() __builtin_unreachable()
504 -
505 -/* Mark a function definition as prohibited from being cloned. */
506 -#define __noclone __attribute__((__noclone__))
507 -
508 -/*
509 - * Tell the optimizer that something else uses this function or variable.
510 - */
511 -#define __visible __attribute__((externally_visible))
512 -
513 -/*
514 - * GCC 'asm goto' miscompiles certain code sequences:
515 - *
516 - * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
517 - *
518 - * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
519 - *
520 - * (asm goto is automatically volatile - the naming reflects this.)
521 - */
522 -#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
523 -
524 -#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
525 -#define __HAVE_BUILTIN_BSWAP32__
526 -#define __HAVE_BUILTIN_BSWAP64__
527 -#define __HAVE_BUILTIN_BSWAP16__
528 -#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
529 --- a/include/linux/compiler-intel.h
530 +++ b/include/linux/compiler-intel.h
531 @@ -13,9 +13,14 @@
532 /* Intel ECC compiler doesn't support gcc specific asm stmts.
533 * It uses intrinsics to do the equivalent things.
534 */
535 +#undef barrier
536 +#undef barrier_data
537 #undef RELOC_HIDE
538 #undef OPTIMIZER_HIDE_VAR
539
540 +#define barrier() __memory_barrier()
541 +#define barrier_data(ptr) barrier()
542 +
543 #define RELOC_HIDE(ptr, off) \
544 ({ unsigned long __ptr; \
545 __ptr = (unsigned long) (ptr); \
546 --- a/include/linux/compiler.h
547 +++ b/include/linux/compiler.h
548 @@ -17,6 +17,7 @@
549 # define __release(x) __context__(x,-1)
550 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
551 # define __percpu __attribute__((noderef, address_space(3)))
552 +# define __pmem __attribute__((noderef, address_space(5)))
553 #ifdef CONFIG_SPARSE_RCU_POINTER
554 # define __rcu __attribute__((noderef, address_space(4)))
555 #else
556 @@ -42,6 +43,7 @@ extern void __chk_io_ptr(const volatile
557 # define __cond_lock(x,c) (c)
558 # define __percpu
559 # define __rcu
560 +# define __pmem
561 #endif
562
563 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
564 @@ -54,7 +56,11 @@ extern void __chk_io_ptr(const volatile
565 #include <linux/compiler-gcc.h>
566 #endif
567
568 +#if defined(CC_USING_HOTPATCH) && !defined(__CHECKER__)
569 +#define notrace __attribute__((hotpatch(0,0)))
570 +#else
571 #define notrace __attribute__((no_instrument_function))
572 +#endif
573
574 /* Intel compiler defines __GNUC__. So we will overwrite implementations
575 * coming from above header files here
576 @@ -138,7 +144,7 @@ void ftrace_likely_update(struct ftrace_
577 */
578 #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
579 #define __trace_if(cond) \
580 - if (__builtin_constant_p((cond)) ? !!(cond) : \
581 + if (__builtin_constant_p(!!(cond)) ? !!(cond) : \
582 ({ \
583 int ______r; \
584 static struct ftrace_branch_data \
585 @@ -165,6 +171,10 @@ void ftrace_likely_update(struct ftrace_
586 # define barrier() __memory_barrier()
587 #endif
588
589 +#ifndef barrier_data
590 +# define barrier_data(ptr) barrier()
591 +#endif
592 +
593 /* Unreachable code */
594 #ifndef unreachable
595 # define unreachable() do { } while (1)
596 @@ -186,6 +196,126 @@ void ftrace_likely_update(struct ftrace_
597 # define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __LINE__)
598 #endif
599
600 +#include <linux/types.h>
601 +
602 +#define __READ_ONCE_SIZE \
603 +({ \
604 + switch (size) { \
605 + case 1: *(__u8 *)res = *(volatile __u8 *)p; break; \
606 + case 2: *(__u16 *)res = *(volatile __u16 *)p; break; \
607 + case 4: *(__u32 *)res = *(volatile __u32 *)p; break; \
608 + case 8: *(__u64 *)res = *(volatile __u64 *)p; break; \
609 + default: \
610 + barrier(); \
611 + __builtin_memcpy((void *)res, (const void *)p, size); \
612 + barrier(); \
613 + } \
614 +})
615 +
616 +static __always_inline
617 +void __read_once_size(const volatile void *p, void *res, int size)
618 +{
619 + __READ_ONCE_SIZE;
620 +}
621 +
622 +#ifdef CONFIG_KASAN
623 +/*
624 + * This function is not 'inline' because __no_sanitize_address confilcts
625 + * with inlining. Attempt to inline it may cause a build failure.
626 + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
627 + * '__maybe_unused' allows us to avoid defined-but-not-used warnings.
628 + */
629 +static __no_sanitize_address __maybe_unused
630 +void __read_once_size_nocheck(const volatile void *p, void *res, int size)
631 +{
632 + __READ_ONCE_SIZE;
633 +}
634 +#else
635 +static __always_inline
636 +void __read_once_size_nocheck(const volatile void *p, void *res, int size)
637 +{
638 + __READ_ONCE_SIZE;
639 +}
640 +#endif
641 +
642 +static __always_inline void __write_once_size(volatile void *p, void *res, int size)
643 +{
644 + switch (size) {
645 + case 1: *(volatile __u8 *)p = *(__u8 *)res; break;
646 + case 2: *(volatile __u16 *)p = *(__u16 *)res; break;
647 + case 4: *(volatile __u32 *)p = *(__u32 *)res; break;
648 + case 8: *(volatile __u64 *)p = *(__u64 *)res; break;
649 + default:
650 + barrier();
651 + __builtin_memcpy((void *)p, (const void *)res, size);
652 + barrier();
653 + }
654 +}
655 +
656 +/*
657 + * Prevent the compiler from merging or refetching reads or writes. The
658 + * compiler is also forbidden from reordering successive instances of
659 + * READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the
660 + * compiler is aware of some particular ordering. One way to make the
661 + * compiler aware of ordering is to put the two invocations of READ_ONCE,
662 + * WRITE_ONCE or ACCESS_ONCE() in different C statements.
663 + *
664 + * In contrast to ACCESS_ONCE these two macros will also work on aggregate
665 + * data types like structs or unions. If the size of the accessed data
666 + * type exceeds the word size of the machine (e.g., 32 bits or 64 bits)
667 + * READ_ONCE() and WRITE_ONCE() will fall back to memcpy and print a
668 + * compile-time warning.
669 + *
670 + * Their two major use cases are: (1) Mediating communication between
671 + * process-level code and irq/NMI handlers, all running on the same CPU,
672 + * and (2) Ensuring that the compiler does not fold, spindle, or otherwise
673 + * mutilate accesses that either do not require ordering or that interact
674 + * with an explicit memory barrier or atomic instruction that provides the
675 + * required ordering.
676 + */
677 +
678 +#define __READ_ONCE(x, check) \
679 +({ \
680 + union { typeof(x) __val; char __c[1]; } __u; \
681 + if (check) \
682 + __read_once_size(&(x), __u.__c, sizeof(x)); \
683 + else \
684 + __read_once_size_nocheck(&(x), __u.__c, sizeof(x)); \
685 + __u.__val; \
686 +})
687 +#define READ_ONCE(x) __READ_ONCE(x, 1)
688 +
689 +/*
690 + * Use READ_ONCE_NOCHECK() instead of READ_ONCE() if you need
691 + * to hide memory access from KASAN.
692 + */
693 +#define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0)
694 +
695 +#define WRITE_ONCE(x, val) \
696 +({ \
697 + union { typeof(x) __val; char __c[1]; } __u = \
698 + { .__val = (__force typeof(x)) (val) }; \
699 + __write_once_size(&(x), __u.__c, sizeof(x)); \
700 + __u.__val; \
701 +})
702 +
703 +/**
704 + * smp_cond_acquire() - Spin wait for cond with ACQUIRE ordering
705 + * @cond: boolean expression to wait for
706 + *
707 + * Equivalent to using smp_load_acquire() on the condition variable but employs
708 + * the control dependency of the wait to reduce the barrier on many platforms.
709 + *
710 + * The control dependency provides a LOAD->STORE order, the additional RMB
711 + * provides LOAD->LOAD order, together they provide LOAD->{LOAD,STORE} order,
712 + * aka. ACQUIRE.
713 + */
714 +#define smp_cond_acquire(cond) do { \
715 + while (!(cond)) \
716 + cpu_relax(); \
717 + smp_rmb(); /* ctrl + rmb := acquire */ \
718 +} while (0)
719 +
720 #endif /* __KERNEL__ */
721
722 #endif /* __ASSEMBLY__ */
723 @@ -304,6 +434,14 @@ void ftrace_likely_update(struct ftrace_
724 #define __visible
725 #endif
726
727 +/*
728 + * Assume alignment of return value.
729 + */
730 +#ifndef __assume_aligned
731 +#define __assume_aligned(a, ...)
732 +#endif
733 +
734 +
735 /* Are two types/vars the same type (ignoring qualifiers)? */
736 #ifndef __same_type
737 # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
738 @@ -311,7 +449,7 @@ void ftrace_likely_update(struct ftrace_
739
740 /* Is this type a native word size -- useful for atomic operations */
741 #ifndef __native_word
742 -# define __native_word(t) (sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
743 +# define __native_word(t) (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
744 #endif
745
746 /* Compile time object size, -1 for unknown */
747 @@ -373,12 +511,38 @@ void ftrace_likely_update(struct ftrace_
748 * to make the compiler aware of ordering is to put the two invocations of
749 * ACCESS_ONCE() in different C statements.
750 *
751 - * This macro does absolutely -nothing- to prevent the CPU from reordering,
752 - * merging, or refetching absolutely anything at any time. Its main intended
753 - * use is to mediate communication between process-level code and irq/NMI
754 - * handlers, all running on the same CPU.
755 + * ACCESS_ONCE will only work on scalar types. For union types, ACCESS_ONCE
756 + * on a union member will work as long as the size of the member matches the
757 + * size of the union and the size is smaller than word size.
758 + *
759 + * The major use cases of ACCESS_ONCE used to be (1) Mediating communication
760 + * between process-level code and irq/NMI handlers, all running on the same CPU,
761 + * and (2) Ensuring that the compiler does not fold, spindle, or otherwise
762 + * mutilate accesses that either do not require ordering or that interact
763 + * with an explicit memory barrier or atomic instruction that provides the
764 + * required ordering.
765 + *
766 + * If possible use READ_ONCE()/WRITE_ONCE() instead.
767 */
768 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
769 +#define __ACCESS_ONCE(x) ({ \
770 + __maybe_unused typeof(x) __var = (__force typeof(x)) 0; \
771 + (volatile typeof(x) *)&(x); })
772 +#define ACCESS_ONCE(x) (*__ACCESS_ONCE(x))
773 +
774 +/**
775 + * lockless_dereference() - safely load a pointer for later dereference
776 + * @p: The pointer to load
777 + *
778 + * Similar to rcu_dereference(), but for situations where the pointed-to
779 + * object's lifetime is managed by something other than RCU. That
780 + * "something other" might be reference counting or simple immortality.
781 + */
782 +#define lockless_dereference(p) \
783 +({ \
784 + typeof(p) _________p1 = READ_ONCE(p); \
785 + smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
786 + (_________p1); \
787 +})
788
789 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
790 #ifdef CONFIG_KPROBES