1 diff --git b/include/linux/compiler-gcc.h a/include/linux/compiler-gcc.h
2 index e057bd2..22ab246 100644
3 --- b/include/linux/compiler-gcc.h
4 +++ a/include/linux/compiler-gcc.h
7 * Common definitions for all gcc versions go here.
9 -#define GCC_VERSION (__GNUC__ * 10000 \
10 - + __GNUC_MINOR__ * 100 \
11 - + __GNUC_PATCHLEVEL__)
13 +#define GCC_VERSION (__GNUC__ * 10000 \
14 + + __GNUC_MINOR__ * 100 \
15 + + __GNUC_PATCHLEVEL__)
17 /* Optimization barrier */
19 /* The "volatile" is due to gcc bugs */
20 #define barrier() __asm__ __volatile__("": : :"memory")
22 + * This version is i.e. to prevent dead stores elimination on @ptr
23 + * where gcc and llvm may behave differently when otherwise using
24 + * normal barrier(): while gcc behavior gets along with a normal
25 + * barrier(), llvm needs an explicit input variable to be assumed
26 + * clobbered. The issue is as follows: while the inline asm might
27 + * access any memory it wants, the compiler could have fit all of
28 + * @ptr into memory registers instead, and since @ptr never escaped
29 + * from that, it proofed that the inline asm wasn't touching any of
30 + * it. This version works well with both compilers, i.e. we're telling
31 + * the compiler that the inline asm absolutely may see the contents
32 + * of @ptr. See also: https://llvm.org/bugs/show_bug.cgi?id=15495
34 +#define barrier_data(ptr) __asm__ __volatile__("": :"r"(ptr) :"memory")
37 * This macro obfuscates arithmetic on a variable address so that gcc
39 * the inline assembly constraint from =g to =r, in this particular
40 * case either is valid.
42 -#define RELOC_HIDE(ptr, off) \
43 - ({ unsigned long __ptr; \
44 - __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
45 - (typeof(ptr)) (__ptr + (off)); })
46 +#define RELOC_HIDE(ptr, off) \
48 + unsigned long __ptr; \
49 + __asm__ ("" : "=r"(__ptr) : "0"(ptr)); \
50 + (typeof(ptr)) (__ptr + (off)); \
53 /* Make the optimizer believe the variable can be manipulated arbitrarily. */
54 -#define OPTIMIZER_HIDE_VAR(var) __asm__ ("" : "=r" (var) : "0" (var))
55 +#define OPTIMIZER_HIDE_VAR(var) \
56 + __asm__ ("" : "=r" (var) : "0" (var))
59 -#define __must_be_array(arr) 0
60 +#define __must_be_array(a) 0
62 /* &a[0] degrades to a pointer: a different type from an array */
63 -#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
64 +#define __must_be_array(a) BUILD_BUG_ON_ZERO(__same_type((a), &(a)[0]))
68 * Force always-inline if the user requests it so via the .config,
69 * or if gcc is too old:
71 -#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
72 +#if !defined(CONFIG_ARCH_SUPPORTS_OPTIMIZED_INLINING) || \
73 !defined(CONFIG_OPTIMIZE_INLINING) || (__GNUC__ < 4)
74 -# define inline inline __attribute__((always_inline)) notrace
75 -# define __inline__ __inline__ __attribute__((always_inline)) notrace
76 -# define __inline __inline __attribute__((always_inline)) notrace
77 +#define inline inline __attribute__((always_inline)) notrace
78 +#define __inline__ __inline__ __attribute__((always_inline)) notrace
79 +#define __inline __inline __attribute__((always_inline)) notrace
81 /* A lot of inline functions can cause havoc with function tracing */
82 -# define inline inline notrace
83 -# define __inline__ __inline__ notrace
84 -# define __inline __inline notrace
85 +#define inline inline notrace
86 +#define __inline__ __inline__ notrace
87 +#define __inline __inline notrace
90 -#define __deprecated __attribute__((deprecated))
92 -#define __packed __attribute__((packed))
95 -#define __weak __attribute__((weak))
97 +#define __always_inline inline __attribute__((always_inline))
98 +#define noinline __attribute__((noinline))
100 +#define __deprecated __attribute__((deprecated))
101 +#define __packed __attribute__((packed))
102 +#define __weak __attribute__((weak))
103 +#define __alias(symbol) __attribute__((alias(#symbol)))
106 - * it doesn't make sense on ARM (currently the only user of __naked) to trace
107 - * naked functions because then mcount is called without stack and frame pointer
108 - * being set up and there is no chance to restore the lr register to the value
109 - * before mcount was called.
110 + * it doesn't make sense on ARM (currently the only user of __naked)
111 + * to trace naked functions because then mcount is called without
112 + * stack and frame pointer being set up and there is no chance to
113 + * restore the lr register to the value before mcount was called.
115 + * The asm() bodies of naked functions often depend on standard calling
116 + * conventions, therefore they must be noinline and noclone.
118 - * The asm() bodies of naked functions often depend on standard calling conventions,
119 - * therefore they must be noinline and noclone. GCC 4.[56] currently fail to enforce
120 - * this, so we must do so ourselves. See GCC PR44290.
121 + * GCC 4.[56] currently fail to enforce this, so we must do so ourselves.
124 -#define __naked __attribute__((naked)) noinline __noclone notrace
125 +#define __naked __attribute__((naked)) noinline __noclone notrace
127 -#define __noreturn __attribute__((noreturn))
128 +#define __noreturn __attribute__((noreturn))
131 * From the GCC manual:
132 @@ -95,34 +114,170 @@
137 -#define __pure __attribute__((pure))
138 +#define __pure __attribute__((pure))
139 +#define __aligned(x) __attribute__((aligned(x)))
140 +#define __printf(a, b) __attribute__((format(printf, a, b)))
141 +#define __scanf(a, b) __attribute__((format(scanf, a, b)))
142 +#define __attribute_const__ __attribute__((__const__))
143 +#define __maybe_unused __attribute__((unused))
144 +#define __always_unused __attribute__((unused))
146 +/* gcc version specific checks */
148 +#if GCC_VERSION < 30200
149 +# error Sorry, your compiler is too old - please upgrade it.
152 +#if GCC_VERSION < 30300
153 +# define __used __attribute__((__unused__))
155 +# define __used __attribute__((__used__))
158 +#ifdef CONFIG_GCOV_KERNEL
159 +# if GCC_VERSION < 30400
160 +# error "GCOV profiling support for gcc versions below 3.4 not included"
161 +# endif /* __GNUC_MINOR__ */
162 +#endif /* CONFIG_GCOV_KERNEL */
164 +#if GCC_VERSION >= 30400
165 +#define __must_check __attribute__((warn_unused_result))
168 +#if GCC_VERSION >= 40000
170 +/* GCC 4.1.[01] miscompiles __weak */
172 +# if GCC_VERSION >= 40100 && GCC_VERSION <= 40101
173 +# error Your version of gcc miscompiles the __weak directive
177 +#define __used __attribute__((__used__))
178 +#define __compiler_offsetof(a, b) \
179 + __builtin_offsetof(a, b)
181 +#if GCC_VERSION >= 40100 && GCC_VERSION < 40600
182 +# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
185 +#if GCC_VERSION >= 40300
186 +/* Mark functions as cold. gcc will assume any path leading to a call
187 + * to them will be unlikely. This means a lot of manual unlikely()s
188 + * are unnecessary now for any paths leading to the usual suspects
189 + * like BUG(), printk(), panic() etc. [but let's keep them for now for
192 + * Early snapshots of gcc 4.3 don't support this and we can't detect this
193 + * in the preprocessor, but we can live with this because they're unreleased.
194 + * Maketime probing would be overkill here.
196 + * gcc also has a __attribute__((__hot__)) to move hot functions into
197 + * a special section, but I don't see any sense in this right now in
198 + * the kernel context
200 +#define __cold __attribute__((__cold__))
202 +#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
205 +# define __compiletime_warning(message) __attribute__((warning(message)))
206 +# define __compiletime_error(message) __attribute__((error(message)))
207 +#endif /* __CHECKER__ */
208 +#endif /* GCC_VERSION >= 40300 */
210 +#if GCC_VERSION >= 40500
212 + * Mark a position in code as unreachable. This can be used to
213 + * suppress control flow warnings after asm blocks that transfer
214 + * control elsewhere.
216 + * Early snapshots of gcc 4.5 don't support this and we can't detect
217 + * this in the preprocessor, but we can live with this because they're
218 + * unreleased. Really, we need to have autoconf for the kernel.
220 +#define unreachable() __builtin_unreachable()
222 +/* Mark a function definition as prohibited from being cloned. */
223 +#define __noclone __attribute__((__noclone__))
225 +#endif /* GCC_VERSION >= 40500 */
227 +#if GCC_VERSION >= 40600
229 + * When used with Link Time Optimization, gcc can optimize away C functions or
230 + * variables which are referenced only from assembly code. __visible tells the
231 + * optimizer that something else uses this function or variable, thus preventing
234 +#define __visible __attribute__((externally_visible))
237 -#define __aligned(x) __attribute__((aligned(x)))
240 +#if GCC_VERSION >= 40900 && !defined(__CHECKER__)
242 + * __assume_aligned(n, k): Tell the optimizer that the returned
243 + * pointer can be assumed to be k modulo n. The second argument is
244 + * optional (default 0), so we use a variadic macro to make the
247 + * Beware: Do not apply this to functions which may return
248 + * ERR_PTRs. Also, it is probably unwise to apply it to functions
249 + * returning extra information in the low bits (but in that case the
250 + * compiler should see some alignment anyway, when the return value is
251 + * massaged by 'flags = ptr & 3; ptr &= ~3;').
253 +#define __assume_aligned(a, ...) __attribute__((__assume_aligned__(a, ## __VA_ARGS__)))
255 -#define __printf(a, b) __attribute__((format(printf, a, b)))
256 -#define __scanf(a, b) __attribute__((format(scanf, a, b)))
257 -#define noinline __attribute__((noinline))
258 -#define __attribute_const__ __attribute__((__const__))
259 -#define __maybe_unused __attribute__((unused))
260 -#define __always_unused __attribute__((unused))
262 -#define __gcc_header(x) #x
263 -#define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
264 -#define gcc_header(x) _gcc_header(x)
265 -#include gcc_header(__GNUC__)
267 + * GCC 'asm goto' miscompiles certain code sequences:
269 + * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
271 + * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
273 + * (asm goto is automatically volatile - the naming reflects this.)
275 +#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
277 +#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
278 +#if GCC_VERSION >= 40400
279 +#define __HAVE_BUILTIN_BSWAP32__
280 +#define __HAVE_BUILTIN_BSWAP64__
282 +#if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
283 +#define __HAVE_BUILTIN_BSWAP16__
285 +#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
287 +#if GCC_VERSION >= 50000
288 +#define KASAN_ABI_VERSION 4
289 +#elif GCC_VERSION >= 40902
290 +#define KASAN_ABI_VERSION 3
293 +#if GCC_VERSION >= 40902
295 + * Tell the compiler that address safety instrumentation (KASAN)
296 + * should not be applied to that function.
297 + * Conflicts with inlining: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
299 +#define __no_sanitize_address __attribute__((no_sanitize_address))
302 +#endif /* gcc version >= 40000 specific checks */
304 #if !defined(__noclone)
305 #define __noclone /* not needed */
308 +#if !defined(__no_sanitize_address)
309 +#define __no_sanitize_address
313 * A trick to suppress uninitialized variable warning without generating any
316 #define uninitialized_var(x) x = x
318 -#ifndef __always_inline
319 -#define __always_inline inline __attribute__((always_inline))
321 diff --git b/include/linux/compiler-gcc3.h a/include/linux/compiler-gcc3.h
322 deleted file mode 100644
323 index 7d89feb..0000000
324 --- b/include/linux/compiler-gcc3.h
327 -#ifndef __LINUX_COMPILER_H
328 -#error "Please don't include <linux/compiler-gcc3.h> directly, include <linux/compiler.h> instead."
331 -#if GCC_VERSION < 30200
332 -# error Sorry, your compiler is too old - please upgrade it.
335 -#if GCC_VERSION >= 30300
336 -# define __used __attribute__((__used__))
338 -# define __used __attribute__((__unused__))
341 -#if GCC_VERSION >= 30400
342 -#define __must_check __attribute__((warn_unused_result))
345 -#ifdef CONFIG_GCOV_KERNEL
346 -# if GCC_VERSION < 30400
347 -# error "GCOV profiling support for gcc versions below 3.4 not included"
348 -# endif /* __GNUC_MINOR__ */
349 -#endif /* CONFIG_GCOV_KERNEL */
350 diff --git b/include/linux/compiler-gcc4.h a/include/linux/compiler-gcc4.h
351 deleted file mode 100644
352 index c982a09..0000000
353 --- b/include/linux/compiler-gcc4.h
356 -#ifndef __LINUX_COMPILER_H
357 -#error "Please don't include <linux/compiler-gcc4.h> directly, include <linux/compiler.h> instead."
360 -#define __used __attribute__((__used__))
361 -#define __must_check __attribute__((warn_unused_result))
362 -#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
364 -#if GCC_VERSION >= 40100 && GCC_VERSION < 40600
365 -# define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
368 -#if GCC_VERSION >= 40300
369 -/* Mark functions as cold. gcc will assume any path leading to a call
370 - to them will be unlikely. This means a lot of manual unlikely()s
371 - are unnecessary now for any paths leading to the usual suspects
372 - like BUG(), printk(), panic() etc. [but let's keep them for now for
375 - Early snapshots of gcc 4.3 don't support this and we can't detect this
376 - in the preprocessor, but we can live with this because they're unreleased.
377 - Maketime probing would be overkill here.
379 - gcc also has a __attribute__((__hot__)) to move hot functions into
380 - a special section, but I don't see any sense in this right now in
381 - the kernel context */
382 -#define __cold __attribute__((__cold__))
384 -#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
387 -# define __compiletime_warning(message) __attribute__((warning(message)))
388 -# define __compiletime_error(message) __attribute__((error(message)))
389 -#endif /* __CHECKER__ */
390 -#endif /* GCC_VERSION >= 40300 */
392 -#if GCC_VERSION >= 40500
394 - * Mark a position in code as unreachable. This can be used to
395 - * suppress control flow warnings after asm blocks that transfer
396 - * control elsewhere.
398 - * Early snapshots of gcc 4.5 don't support this and we can't detect
399 - * this in the preprocessor, but we can live with this because they're
400 - * unreleased. Really, we need to have autoconf for the kernel.
402 -#define unreachable() __builtin_unreachable()
404 -/* Mark a function definition as prohibited from being cloned. */
405 -#define __noclone __attribute__((__noclone__))
407 -#endif /* GCC_VERSION >= 40500 */
409 -#if GCC_VERSION >= 40600
411 - * Tell the optimizer that something else uses this function or variable.
413 -#define __visible __attribute__((externally_visible))
417 - * GCC 'asm goto' miscompiles certain code sequences:
419 - * http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58670
421 - * Work it around via a compiler barrier quirk suggested by Jakub Jelinek.
422 - * Fixed in GCC 4.8.2 and later versions.
424 - * (asm goto is automatically volatile - the naming reflects this.)
426 -#define asm_volatile_goto(x...) do { asm goto(x); asm (""); } while (0)
428 -#ifdef CONFIG_ARCH_USE_BUILTIN_BSWAP
429 -#if GCC_VERSION >= 40400
430 -#define __HAVE_BUILTIN_BSWAP32__
431 -#define __HAVE_BUILTIN_BSWAP64__
433 -#if GCC_VERSION >= 40800 || (defined(__powerpc__) && GCC_VERSION >= 40600)
434 -#define __HAVE_BUILTIN_BSWAP16__
436 -#endif /* CONFIG_ARCH_USE_BUILTIN_BSWAP */
437 diff --git b/include/linux/compiler-intel.h a/include/linux/compiler-intel.h
438 index ba147a1..d4c7113 100644
439 --- b/include/linux/compiler-intel.h
440 +++ a/include/linux/compiler-intel.h
442 /* Intel ECC compiler doesn't support gcc specific asm stmts.
443 * It uses intrinsics to do the equivalent things.
448 #undef OPTIMIZER_HIDE_VAR
450 +#define barrier() __memory_barrier()
451 +#define barrier_data(ptr) barrier()
453 #define RELOC_HIDE(ptr, off) \
454 ({ unsigned long __ptr; \
455 __ptr = (unsigned long) (ptr); \
456 diff --git b/include/linux/compiler.h a/include/linux/compiler.h
457 index d5ad7b1..020ad16 100644
458 --- b/include/linux/compiler.h
459 +++ a/include/linux/compiler.h
461 # define __release(x) __context__(x,-1)
462 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
463 # define __percpu __attribute__((noderef, address_space(3)))
464 +# define __pmem __attribute__((noderef, address_space(5)))
465 #ifdef CONFIG_SPARSE_RCU_POINTER
466 # define __rcu __attribute__((noderef, address_space(4)))
468 @@ -42,6 +43,7 @@ extern void __chk_io_ptr(const volatile void __iomem *);
469 # define __cond_lock(x,c) (c)
475 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
476 @@ -54,7 +56,11 @@ extern void __chk_io_ptr(const volatile void __iomem *);
477 #include <linux/compiler-gcc.h>
480 +#if defined(CC_USING_HOTPATCH) && !defined(__CHECKER__)
481 +#define notrace __attribute__((hotpatch(0,0)))
483 #define notrace __attribute__((no_instrument_function))
486 /* Intel compiler defines __GNUC__. So we will overwrite implementations
487 * coming from above header files here
488 @@ -138,7 +144,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
490 #define if(cond, ...) __trace_if( (cond , ## __VA_ARGS__) )
491 #define __trace_if(cond) \
492 - if (__builtin_constant_p((cond)) ? !!(cond) : \
493 + if (__builtin_constant_p(!!(cond)) ? !!(cond) : \
496 static struct ftrace_branch_data \
497 @@ -165,6 +171,10 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
498 # define barrier() __memory_barrier()
501 +#ifndef barrier_data
502 +# define barrier_data(ptr) barrier()
505 /* Unreachable code */
507 # define unreachable() do { } while (1)
508 @@ -186,6 +196,126 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
509 # define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __LINE__)
512 +#include <linux/types.h>
514 +#define __READ_ONCE_SIZE \
517 + case 1: *(__u8 *)res = *(volatile __u8 *)p; break; \
518 + case 2: *(__u16 *)res = *(volatile __u16 *)p; break; \
519 + case 4: *(__u32 *)res = *(volatile __u32 *)p; break; \
520 + case 8: *(__u64 *)res = *(volatile __u64 *)p; break; \
523 + __builtin_memcpy((void *)res, (const void *)p, size); \
528 +static __always_inline
529 +void __read_once_size(const volatile void *p, void *res, int size)
536 + * This function is not 'inline' because __no_sanitize_address confilcts
537 + * with inlining. Attempt to inline it may cause a build failure.
538 + * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368
539 + * '__maybe_unused' allows us to avoid defined-but-not-used warnings.
541 +static __no_sanitize_address __maybe_unused
542 +void __read_once_size_nocheck(const volatile void *p, void *res, int size)
547 +static __always_inline
548 +void __read_once_size_nocheck(const volatile void *p, void *res, int size)
554 +static __always_inline void __write_once_size(volatile void *p, void *res, int size)
557 + case 1: *(volatile __u8 *)p = *(__u8 *)res; break;
558 + case 2: *(volatile __u16 *)p = *(__u16 *)res; break;
559 + case 4: *(volatile __u32 *)p = *(__u32 *)res; break;
560 + case 8: *(volatile __u64 *)p = *(__u64 *)res; break;
563 + __builtin_memcpy((void *)p, (const void *)res, size);
569 + * Prevent the compiler from merging or refetching reads or writes. The
570 + * compiler is also forbidden from reordering successive instances of
571 + * READ_ONCE, WRITE_ONCE and ACCESS_ONCE (see below), but only when the
572 + * compiler is aware of some particular ordering. One way to make the
573 + * compiler aware of ordering is to put the two invocations of READ_ONCE,
574 + * WRITE_ONCE or ACCESS_ONCE() in different C statements.
576 + * In contrast to ACCESS_ONCE these two macros will also work on aggregate
577 + * data types like structs or unions. If the size of the accessed data
578 + * type exceeds the word size of the machine (e.g., 32 bits or 64 bits)
579 + * READ_ONCE() and WRITE_ONCE() will fall back to memcpy and print a
580 + * compile-time warning.
582 + * Their two major use cases are: (1) Mediating communication between
583 + * process-level code and irq/NMI handlers, all running on the same CPU,
584 + * and (2) Ensuring that the compiler does not fold, spindle, or otherwise
585 + * mutilate accesses that either do not require ordering or that interact
586 + * with an explicit memory barrier or atomic instruction that provides the
587 + * required ordering.
590 +#define __READ_ONCE(x, check) \
592 + union { typeof(x) __val; char __c[1]; } __u; \
594 + __read_once_size(&(x), __u.__c, sizeof(x)); \
596 + __read_once_size_nocheck(&(x), __u.__c, sizeof(x)); \
599 +#define READ_ONCE(x) __READ_ONCE(x, 1)
602 + * Use READ_ONCE_NOCHECK() instead of READ_ONCE() if you need
603 + * to hide memory access from KASAN.
605 +#define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0)
607 +#define WRITE_ONCE(x, val) \
609 + union { typeof(x) __val; char __c[1]; } __u = \
610 + { .__val = (__force typeof(x)) (val) }; \
611 + __write_once_size(&(x), __u.__c, sizeof(x)); \
616 + * smp_cond_acquire() - Spin wait for cond with ACQUIRE ordering
617 + * @cond: boolean expression to wait for
619 + * Equivalent to using smp_load_acquire() on the condition variable but employs
620 + * the control dependency of the wait to reduce the barrier on many platforms.
622 + * The control dependency provides a LOAD->STORE order, the additional RMB
623 + * provides LOAD->LOAD order, together they provide LOAD->{LOAD,STORE} order,
626 +#define smp_cond_acquire(cond) do { \
629 + smp_rmb(); /* ctrl + rmb := acquire */ \
632 #endif /* __KERNEL__ */
634 #endif /* __ASSEMBLY__ */
635 @@ -304,6 +434,14 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
640 + * Assume alignment of return value.
642 +#ifndef __assume_aligned
643 +#define __assume_aligned(a, ...)
647 /* Are two types/vars the same type (ignoring qualifiers)? */
649 # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
650 @@ -311,7 +449,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
652 /* Is this type a native word size -- useful for atomic operations */
653 #ifndef __native_word
654 -# define __native_word(t) (sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
655 +# define __native_word(t) (sizeof(t) == sizeof(char) || sizeof(t) == sizeof(short) || sizeof(t) == sizeof(int) || sizeof(t) == sizeof(long))
658 /* Compile time object size, -1 for unknown */
659 @@ -373,12 +511,38 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
660 * to make the compiler aware of ordering is to put the two invocations of
661 * ACCESS_ONCE() in different C statements.
663 - * This macro does absolutely -nothing- to prevent the CPU from reordering,
664 - * merging, or refetching absolutely anything at any time. Its main intended
665 - * use is to mediate communication between process-level code and irq/NMI
666 - * handlers, all running on the same CPU.
667 + * ACCESS_ONCE will only work on scalar types. For union types, ACCESS_ONCE
668 + * on a union member will work as long as the size of the member matches the
669 + * size of the union and the size is smaller than word size.
671 + * The major use cases of ACCESS_ONCE used to be (1) Mediating communication
672 + * between process-level code and irq/NMI handlers, all running on the same CPU,
673 + * and (2) Ensuring that the compiler does not fold, spindle, or otherwise
674 + * mutilate accesses that either do not require ordering or that interact
675 + * with an explicit memory barrier or atomic instruction that provides the
676 + * required ordering.
678 + * If possible use READ_ONCE()/WRITE_ONCE() instead.
680 +#define __ACCESS_ONCE(x) ({ \
681 + __maybe_unused typeof(x) __var = (__force typeof(x)) 0; \
682 + (volatile typeof(x) *)&(x); })
683 +#define ACCESS_ONCE(x) (*__ACCESS_ONCE(x))
686 + * lockless_dereference() - safely load a pointer for later dereference
687 + * @p: The pointer to load
689 + * Similar to rcu_dereference(), but for situations where the pointed-to
690 + * object's lifetime is managed by something other than RCU. That
691 + * "something other" might be reference counting or simple immortality.
693 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
694 +#define lockless_dereference(p) \
696 + typeof(p) _________p1 = READ_ONCE(p); \
697 + smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
701 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
702 #ifdef CONFIG_KPROBES