Merge branch 'linus' into core/objtool, to pick up dependent commits
[sfrench/cifs-2.6.git] / include / linux / compiler.h
index 08083186e54f5d75f594b0d0d749fc891c100da5..188ed9f65517453d5bb97f2466167c069a7c0ae2 100644 (file)
@@ -1,3 +1,4 @@
+/* SPDX-License-Identifier: GPL-2.0 */
 #ifndef __LINUX_COMPILER_H
 #define __LINUX_COMPILER_H
 
@@ -87,17 +88,22 @@ void ftrace_likely_update(struct ftrace_likely_data *f, int val,
 
 /* Unreachable code */
 #ifdef CONFIG_STACK_VALIDATION
+/*
+ * These macros help objtool understand GCC code flow for unreachable code.
+ * The __COUNTER__ based labels are a hack to make each instance of the macros
+ * unique, to convince GCC not to merge duplicate inline asm statements.
+ */
 #define annotate_reachable() ({                                                \
-       asm("%c0:\n\t"                                                  \
-           ".pushsection .discard.reachable\n\t"                       \
-           ".long %c0b - .\n\t"                                        \
-           ".popsection\n\t" : : "i" (__LINE__));                      \
+       asm volatile("%c0:\n\t"                                         \
+                    ".pushsection .discard.reachable\n\t"              \
+                    ".long %c0b - .\n\t"                               \
+                    ".popsection\n\t" : : "i" (__COUNTER__));          \
 })
 #define annotate_unreachable() ({                                      \
-       asm("%c0:\n\t"                                                  \
-           ".pushsection .discard.unreachable\n\t"                     \
-           ".long %c0b - .\n\t"                                        \
-           ".popsection\n\t" : : "i" (__LINE__));                      \
+       asm volatile("%c0:\n\t"                                         \
+                    ".pushsection .discard.unreachable\n\t"            \
+                    ".long %c0b - .\n\t"                               \
+                    ".popsection\n\t" : : "i" (__COUNTER__));          \
 })
 #define ASM_UNREACHABLE                                                        \
        "999:\n\t"                                                      \
@@ -242,6 +248,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
                __read_once_size(&(x), __u.__c, sizeof(x));             \
        else                                                            \
                __read_once_size_nocheck(&(x), __u.__c, sizeof(x));     \
+       smp_read_barrier_depends(); /* Enforce dependency ordering from x */ \
        __u.__val;                                                      \
 })
 #define READ_ONCE(x) __READ_ONCE(x, 1)
@@ -345,24 +352,4 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
        (volatile typeof(x) *)&(x); })
 #define ACCESS_ONCE(x) (*__ACCESS_ONCE(x))
 
-/**
- * lockless_dereference() - safely load a pointer for later dereference
- * @p: The pointer to load
- *
- * Similar to rcu_dereference(), but for situations where the pointed-to
- * object's lifetime is managed by something other than RCU.  That
- * "something other" might be reference counting or simple immortality.
- *
- * The seemingly unused variable ___typecheck_p validates that @p is
- * indeed a pointer type by using a pointer to typeof(*p) as the type.
- * Taking a pointer to typeof(*p) again is needed in case p is void *.
- */
-#define lockless_dereference(p) \
-({ \
-       typeof(p) _________p1 = READ_ONCE(p); \
-       typeof(*(p)) *___typecheck_p __maybe_unused; \
-       smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
-       (_________p1); \
-})
-
 #endif /* __LINUX_COMPILER_H */