Skip to content

Commit 3269701

Browse files
melverPeter Zijlstra
authored andcommitted
compiler-context-analysis: Add infrastructure for Context Analysis with Clang
Context Analysis is a language extension, which enables statically checking that required contexts are active (or inactive), by acquiring and releasing user-definable "context locks". An obvious application is lock-safety checking for the kernel's various synchronization primitives (each of which represents a "context lock"), and checking that locking rules are not violated. Clang originally called the feature "Thread Safety Analysis" [1]. This was later changed and the feature became more flexible, gaining the ability to define custom "capabilities". Its foundations can be found in "Capability Systems" [2], used to specify the permissibility of operations to depend on some "capability" being held (or not held). Because the feature is not just able to express "capabilities" related to synchronization primitives, and "capability" is already overloaded in the kernel, the naming chosen for the kernel departs from Clang's "Thread Safety" and "capability" nomenclature; we refer to the feature as "Context Analysis" to avoid confusion. The internal implementation still makes references to Clang's terminology in a few places, such as `-Wthread-safety` being the warning option that also still appears in diagnostic messages. [1] https://clang.llvm.org/docs/ThreadSafetyAnalysis.html [2] https://www.cs.cornell.edu/talc/papers/capabilities.pdf See more details in the kernel-doc documentation added in this and subsequent changes. Clang version 22+ is required. [peterz: disable the thing for __CHECKER__ builds] Signed-off-by: Marco Elver <elver@google.com> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Link: https://patch.msgid.link/20251219154418.3592607-3-elver@google.com
1 parent de15fec commit 3269701

File tree

5 files changed

+505
-7
lines changed

5 files changed

+505
-7
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,7 @@ include-$(CONFIG_RANDSTRUCT) += scripts/Makefile.randstruct
11181118
include-$(CONFIG_KSTACK_ERASE) += scripts/Makefile.kstack_erase
11191119
include-$(CONFIG_AUTOFDO_CLANG) += scripts/Makefile.autofdo
11201120
include-$(CONFIG_PROPELLER_CLANG) += scripts/Makefile.propeller
1121+
include-$(CONFIG_WARN_CONTEXT_ANALYSIS) += scripts/Makefile.context-analysis
11211122
include-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins
11221123

11231124
include $(addprefix $(srctree)/, $(include-y))

0 commit comments

Comments
 (0)