kernel/kcsan/kcsan_test.c
Source file repositories/reference/linux-study-clean/kernel/kcsan/kcsan_test.c
File Facts
- System
- Linux kernel
- Corpus path
kernel/kcsan/kcsan_test.c- Extension
.c- Size
- 52323 bytes
- Lines
- 1626
- 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.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
kunit/test.hlinux/atomic.hlinux/bitops.hlinux/jiffies.hlinux/kcsan-checks.hlinux/kernel.hlinux/mutex.hlinux/sched.hlinux/seqlock.hlinux/spinlock.hlinux/string.hlinux/timer.hlinux/torture.hlinux/tracepoint.hlinux/types.htrace/events/printk.h
Detected Declarations
struct expect_reportfunction begin_test_checksfunction end_test_checksfunction probe_consolefunction report_availablefunction __report_matchesfunction __report_set_scopedfunction report_matches_any_reorderedfunction sink_valuefunction test_delayfunction test_kernel_readfunction test_kernel_writefunction test_kernel_write_nochangefunction test_kernel_write_nochange_rcufunction test_kernel_read_atomicfunction test_kernel_write_atomicfunction test_kernel_atomic_rmwfunction test_kernel_write_uninstrumentedfunction test_kernel_data_racefunction test_kernel_data_racy_qualifierfunction test_kernel_assert_writerfunction test_kernel_assert_accessfunction test_kernel_change_bitsfunction test_kernel_assert_bits_changefunction test_kernel_assert_bits_nochangefunction test_enter_scopefunction test_kernel_assert_writer_scopedfunction test_kernel_assert_access_scopedfunction test_kernel_rmw_arrayfunction test_kernel_write_structfunction test_kernel_write_struct_partfunction test_kernel_read_struct_zero_sizefunction test_kernel_jiffies_readerfunction test_kernel_seqlock_readerfunction test_kernel_seqlock_writerfunction test_kernel_atomic_builtinsfunction test_kernel_xor_1bitfunction test_barrier_nothreadsfunction test_basicfunction test_concurrent_racesfunction test_novalue_changefunction test_novalue_change_exceptionfunction test_unknown_originfunction test_write_write_assume_atomicfunction test_write_write_structfunction test_write_write_struct_partfunction test_read_atomic_write_atomicfunction test_read_plain_atomic_write
Annotated Snippet
struct expect_report {
/* Access information of both accesses. */
struct {
void *fn; /* Function pointer to expected function of top frame. */
void *addr; /* Address of access; unchecked if NULL. */
size_t size; /* Size of access; unchecked if @addr is NULL. */
int type; /* Access type, see KCSAN_ACCESS definitions. */
} access[2];
};
/* Check observed report matches information in @r. */
__no_kcsan
static bool __report_matches(const struct expect_report *r)
{
const bool is_assert = (r->access[0].type | r->access[1].type) & KCSAN_ACCESS_ASSERT;
bool ret = false;
unsigned long flags;
typeof(*observed.lines) *expect;
const char *end;
char *cur;
int i;
/* Doubled-checked locking. */
if (!report_available())
return false;
expect = (typeof(expect))kmalloc_obj(observed.lines);
if (WARN_ON(!expect))
return false;
/* Generate expected report contents. */
/* Title */
cur = expect[0];
end = ARRAY_END(expect[0]);
cur += scnprintf(cur, end - cur, "BUG: KCSAN: %s in ",
is_assert ? "assert: race" : "data-race");
if (r->access[1].fn) {
char tmp[2][64];
int cmp;
/* Expect lexographically sorted function names in title. */
scnprintf(tmp[0], sizeof(tmp[0]), "%pS", r->access[0].fn);
scnprintf(tmp[1], sizeof(tmp[1]), "%pS", r->access[1].fn);
cmp = strcmp(tmp[0], tmp[1]);
cur += scnprintf(cur, end - cur, "%ps / %ps",
cmp < 0 ? r->access[0].fn : r->access[1].fn,
cmp < 0 ? r->access[1].fn : r->access[0].fn);
} else {
scnprintf(cur, end - cur, "%pS", r->access[0].fn);
/* The exact offset won't match, remove it. */
cur = strchr(expect[0], '+');
if (cur)
*cur = '\0';
}
/* Access 1 */
cur = expect[1];
end = ARRAY_END(expect[1]);
if (!r->access[1].fn)
cur += scnprintf(cur, end - cur, "race at unknown origin, with ");
/* Access 1 & 2 */
for (i = 0; i < 2; ++i) {
const int ty = r->access[i].type;
const char *const access_type =
(ty & KCSAN_ACCESS_ASSERT) ?
((ty & KCSAN_ACCESS_WRITE) ?
"assert no accesses" :
"assert no writes") :
((ty & KCSAN_ACCESS_WRITE) ?
((ty & KCSAN_ACCESS_COMPOUND) ?
"read-write" :
"write") :
"read");
const bool is_atomic = (ty & KCSAN_ACCESS_ATOMIC);
const bool is_scoped = (ty & KCSAN_ACCESS_SCOPED);
const char *const access_type_aux =
(is_atomic && is_scoped) ? " (marked, reordered)"
: (is_atomic ? " (marked)"
: (is_scoped ? " (reordered)" : ""));
if (i == 1) {
/* Access 2 */
cur = expect[2];
end = &expect[2][sizeof(expect[2]) - 1];
if (!r->access[1].fn) {
/* Dummy string if no second access is available. */
strscpy(expect[2], "<none>");
Annotation
- Immediate include surface: `kunit/test.h`, `linux/atomic.h`, `linux/bitops.h`, `linux/jiffies.h`, `linux/kcsan-checks.h`, `linux/kernel.h`, `linux/mutex.h`, `linux/sched.h`.
- Detected declarations: `struct expect_report`, `function begin_test_checks`, `function end_test_checks`, `function probe_console`, `function report_available`, `function __report_matches`, `function __report_set_scoped`, `function report_matches_any_reordered`, `function sink_value`, `function test_delay`.
- Atlas domain: Core OS / Scheduler, Processes, Timers, Sync, And Syscalls.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.