Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

compiler_types: Move lock checking attributes to compiler-context-analysis.h

The conditional definition of lock checking macros and attributes is
about to become more complex. Factor them out into their own header for
better readability, and to make it obvious which features are supported
by which mode (currently only Sparse). This is the first step towards
generalizing towards "context analysis".

No functional change intended.

Signed-off-by: Marco Elver <elver@google.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Link: https://patch.msgid.link/20251219154418.3592607-2-elver@google.com

authored by

Marco Elver and committed by
Peter Zijlstra
de15feca de2c5a15

+34 -16
+32
include/linux/compiler-context-analysis.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 */ 2 + /* 3 + * Macros and attributes for compiler-based static context analysis. 4 + */ 5 + 6 + #ifndef _LINUX_COMPILER_CONTEXT_ANALYSIS_H 7 + #define _LINUX_COMPILER_CONTEXT_ANALYSIS_H 8 + 9 + #ifdef __CHECKER__ 10 + 11 + /* Sparse context/lock checking support. */ 12 + # define __must_hold(x) __attribute__((context(x,1,1))) 13 + # define __acquires(x) __attribute__((context(x,0,1))) 14 + # define __cond_acquires(x) __attribute__((context(x,0,-1))) 15 + # define __releases(x) __attribute__((context(x,1,0))) 16 + # define __acquire(x) __context__(x,1) 17 + # define __release(x) __context__(x,-1) 18 + # define __cond_lock(x, c) ((c) ? ({ __acquire(x); 1; }) : 0) 19 + 20 + #else /* !__CHECKER__ */ 21 + 22 + # define __must_hold(x) 23 + # define __acquires(x) 24 + # define __cond_acquires(x) 25 + # define __releases(x) 26 + # define __acquire(x) (void)0 27 + # define __release(x) (void)0 28 + # define __cond_lock(x, c) (c) 29 + 30 + #endif /* __CHECKER__ */ 31 + 32 + #endif /* _LINUX_COMPILER_CONTEXT_ANALYSIS_H */
+2 -16
include/linux/compiler_types.h
··· 41 41 # define BTF_TYPE_TAG(value) /* nothing */ 42 42 #endif 43 43 44 + #include <linux/compiler-context-analysis.h> 45 + 44 46 /* sparse defines __CHECKER__; see Documentation/dev-tools/sparse.rst */ 45 47 #ifdef __CHECKER__ 46 48 /* address spaces */ ··· 53 51 # define __rcu __attribute__((noderef, address_space(__rcu))) 54 52 static inline void __chk_user_ptr(const volatile void __user *ptr) { } 55 53 static inline void __chk_io_ptr(const volatile void __iomem *ptr) { } 56 - /* context/locking */ 57 - # define __must_hold(x) __attribute__((context(x,1,1))) 58 - # define __acquires(x) __attribute__((context(x,0,1))) 59 - # define __cond_acquires(x) __attribute__((context(x,0,-1))) 60 - # define __releases(x) __attribute__((context(x,1,0))) 61 - # define __acquire(x) __context__(x,1) 62 - # define __release(x) __context__(x,-1) 63 - # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0) 64 54 /* other */ 65 55 # define __force __attribute__((force)) 66 56 # define __nocast __attribute__((nocast)) ··· 73 79 74 80 # define __chk_user_ptr(x) (void)0 75 81 # define __chk_io_ptr(x) (void)0 76 - /* context/locking */ 77 - # define __must_hold(x) 78 - # define __acquires(x) 79 - # define __cond_acquires(x) 80 - # define __releases(x) 81 - # define __acquire(x) (void)0 82 - # define __release(x) (void)0 83 - # define __cond_lock(x,c) (c) 84 82 /* other */ 85 83 # define __force 86 84 # define __nocast