diff options
Diffstat (limited to 'include/linux/compiler.h')
-rw-r--r-- | include/linux/compiler.h | 92 |
1 files changed, 62 insertions, 30 deletions
diff --git a/include/linux/compiler.h b/include/linux/compiler.h index c836eb2dc44d..4dac1036594f 100644 --- a/include/linux/compiler.h +++ b/include/linux/compiler.h | |||
@@ -56,7 +56,7 @@ extern void __chk_io_ptr(const volatile void __iomem *); | |||
56 | #include <linux/compiler-gcc.h> | 56 | #include <linux/compiler-gcc.h> |
57 | #endif | 57 | #endif |
58 | 58 | ||
59 | #ifdef CC_USING_HOTPATCH | 59 | #if defined(CC_USING_HOTPATCH) && !defined(__CHECKER__) |
60 | #define notrace __attribute__((hotpatch(0,0))) | 60 | #define notrace __attribute__((hotpatch(0,0))) |
61 | #else | 61 | #else |
62 | #define notrace __attribute__((no_instrument_function)) | 62 | #define notrace __attribute__((no_instrument_function)) |
@@ -198,19 +198,45 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect); | |||
198 | 198 | ||
199 | #include <uapi/linux/types.h> | 199 | #include <uapi/linux/types.h> |
200 | 200 | ||
201 | static __always_inline void __read_once_size(const volatile void *p, void *res, int size) | 201 | #define __READ_ONCE_SIZE \ |
202 | ({ \ | ||
203 | switch (size) { \ | ||
204 | case 1: *(__u8 *)res = *(volatile __u8 *)p; break; \ | ||
205 | case 2: *(__u16 *)res = *(volatile __u16 *)p; break; \ | ||
206 | case 4: *(__u32 *)res = *(volatile __u32 *)p; break; \ | ||
207 | case 8: *(__u64 *)res = *(volatile __u64 *)p; break; \ | ||
208 | default: \ | ||
209 | barrier(); \ | ||
210 | __builtin_memcpy((void *)res, (const void *)p, size); \ | ||
211 | barrier(); \ | ||
212 | } \ | ||
213 | }) | ||
214 | |||
215 | static __always_inline | ||
216 | void __read_once_size(const volatile void *p, void *res, int size) | ||
202 | { | 217 | { |
203 | switch (size) { | 218 | __READ_ONCE_SIZE; |
204 | case 1: *(__u8 *)res = *(volatile __u8 *)p; break; | 219 | } |
205 | case 2: *(__u16 *)res = *(volatile __u16 *)p; break; | 220 | |
206 | case 4: *(__u32 *)res = *(volatile __u32 *)p; break; | 221 | #ifdef CONFIG_KASAN |
207 | case 8: *(__u64 *)res = *(volatile __u64 *)p; break; | 222 | /* |
208 | default: | 223 | * This function is not 'inline' because __no_sanitize_address confilcts |
209 | barrier(); | 224 | * with inlining. Attempt to inline it may cause a build failure. |
210 | __builtin_memcpy((void *)res, (const void *)p, size); | 225 | * https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67368 |
211 | barrier(); | 226 | * '__maybe_unused' allows us to avoid defined-but-not-used warnings. |
212 | } | 227 | */ |
228 | static __no_sanitize_address __maybe_unused | ||
229 | void __read_once_size_nocheck(const volatile void *p, void *res, int size) | ||
230 | { | ||
231 | __READ_ONCE_SIZE; | ||
213 | } | 232 | } |
233 | #else | ||
234 | static __always_inline | ||
235 | void __read_once_size_nocheck(const volatile void *p, void *res, int size) | ||
236 | { | ||
237 | __READ_ONCE_SIZE; | ||
238 | } | ||
239 | #endif | ||
214 | 240 | ||
215 | static __always_inline void __write_once_size(volatile void *p, void *res, int size) | 241 | static __always_inline void __write_once_size(volatile void *p, void *res, int size) |
216 | { | 242 | { |
@@ -248,8 +274,22 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s | |||
248 | * required ordering. | 274 | * required ordering. |
249 | */ | 275 | */ |
250 | 276 | ||
251 | #define READ_ONCE(x) \ | 277 | #define __READ_ONCE(x, check) \ |
252 | ({ union { typeof(x) __val; char __c[1]; } __u; __read_once_size(&(x), __u.__c, sizeof(x)); __u.__val; }) | 278 | ({ \ |
279 | union { typeof(x) __val; char __c[1]; } __u; \ | ||
280 | if (check) \ | ||
281 | __read_once_size(&(x), __u.__c, sizeof(x)); \ | ||
282 | else \ | ||
283 | __read_once_size_nocheck(&(x), __u.__c, sizeof(x)); \ | ||
284 | __u.__val; \ | ||
285 | }) | ||
286 | #define READ_ONCE(x) __READ_ONCE(x, 1) | ||
287 | |||
288 | /* | ||
289 | * Use READ_ONCE_NOCHECK() instead of READ_ONCE() if you need | ||
290 | * to hide memory access from KASAN. | ||
291 | */ | ||
292 | #define READ_ONCE_NOCHECK(x) __READ_ONCE(x, 0) | ||
253 | 293 | ||
254 | #define WRITE_ONCE(x, val) \ | 294 | #define WRITE_ONCE(x, val) \ |
255 | ({ \ | 295 | ({ \ |
@@ -259,22 +299,6 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s | |||
259 | __u.__val; \ | 299 | __u.__val; \ |
260 | }) | 300 | }) |
261 | 301 | ||
262 | /** | ||
263 | * READ_ONCE_CTRL - Read a value heading a control dependency | ||
264 | * @x: The value to be read, heading the control dependency | ||
265 | * | ||
266 | * Control dependencies are tricky. See Documentation/memory-barriers.txt | ||
267 | * for important information on how to use them. Note that in many cases, | ||
268 | * use of smp_load_acquire() will be much simpler. Control dependencies | ||
269 | * should be avoided except on the hottest of hotpaths. | ||
270 | */ | ||
271 | #define READ_ONCE_CTRL(x) \ | ||
272 | ({ \ | ||
273 | typeof(x) __val = READ_ONCE(x); \ | ||
274 | smp_read_barrier_depends(); /* Enforce control dependency. */ \ | ||
275 | __val; \ | ||
276 | }) | ||
277 | |||
278 | #endif /* __KERNEL__ */ | 302 | #endif /* __KERNEL__ */ |
279 | 303 | ||
280 | #endif /* __ASSEMBLY__ */ | 304 | #endif /* __ASSEMBLY__ */ |
@@ -393,6 +417,14 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s | |||
393 | #define __visible | 417 | #define __visible |
394 | #endif | 418 | #endif |
395 | 419 | ||
420 | /* | ||
421 | * Assume alignment of return value. | ||
422 | */ | ||
423 | #ifndef __assume_aligned | ||
424 | #define __assume_aligned(a, ...) | ||
425 | #endif | ||
426 | |||
427 | |||
396 | /* Are two types/vars the same type (ignoring qualifiers)? */ | 428 | /* Are two types/vars the same type (ignoring qualifiers)? */ |
397 | #ifndef __same_type | 429 | #ifndef __same_type |
398 | # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) | 430 | # define __same_type(a, b) __builtin_types_compatible_p(typeof(a), typeof(b)) |