kernel/kcsan/permissive.h

Source file repositories/reference/linux-study-clean/kernel/kcsan/permissive.h

File Facts

System
Linux kernel
Corpus path
kernel/kcsan/permissive.h
Extension
.h
Size
2716 bytes
Lines
95
Domain
Core OS
Bucket
Scheduler, Processes, Timers, Sync, And Syscalls
Inferred role
Core OS: implementation source
Status
source implementation candidate

Why This File Exists

Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.

Dependency Surface

Detected Declarations

Annotated Snippet

*	if (flags & SOME_FLAG) { ... }
	 *
	 * and elsewhere flags is updated concurrently:
	 *
	 *	flags |= SOME_OTHER_FLAG; // just 1 bit
	 *
	 * While it is still recommended that such accesses be marked
	 * appropriately, in many cases these types of data races are so common
	 * that marking them all is often unrealistic and left to maintainer
	 * preference.
	 *
	 * The assumption in all cases is that with all known compiler
	 * optimizations (including those that tear accesses), because no more
	 * than 1 bit changed, the plain accesses are safe despite the presence
	 * of data races.
	 *
	 * The rules here will ignore the data races if we observe no more than
	 * 1 bit changed.
	 *
	 * Of course many operations can effecively change just 1 bit, but the
	 * general assuption that data races involving 1-bit changes can be
	 * tolerated still applies.
	 *
	 * And in case a true bug is missed, the bug likely manifests as a
	 * reportable data race elsewhere.
	 */
	if (hweight64(diff) == 1) {
		/*
		 * Exception: Report data races where the values look like
		 * ordinary booleans (one of them was 0 and the 0th bit was
		 * changed) More often than not, they come with interesting
		 * memory ordering requirements, so let's report them.
		 */
		if (!((!old || !new) && diff == 1))
			return true;
	}

	return false;
}

#endif /* _KERNEL_KCSAN_PERMISSIVE_H */

Annotation

Implementation Notes