ASSERT_EXCLU...RITER_SCOPED(9)
π ASSERT_EXCLU...RITER_SCOPED(9) β the Kernel API Manual, bestie edition π
okay so picture this: you're deep in the kernel, it's from the Kernel API Manual, the title's literally ASSERT_EXCLU...RITER_SCOPED(9) (yes it's truncated, that's just how the man page header rolls, don't come for me), and you need to prove nobody else is out here writing to your variable. That's this macro. Let's get into it π¦
β¨ NAME β¨
ASSERT_EXCLUSIVE_WRITER_SCOPED β asserts there are no concurrent writes to @var in scope π
πΈ SYNOPSIS πΈ
ASSERT_EXCLUSIVE_WRITER_SCOPED (var );
yes the spacing is exactly like that, don't @ me, that's the man page's canon β¨
π ARGUMENTS π
varβ the variable you're asserting on. that's it. that's the whole argument list, she's low-maintenance π
π₯ DESCRIPTION π₯
So this is the scoped variant of ASSERT_EXCLUSIVE_WRITER β think of the original as the single-serve snack pack and this one as the full meal π
It asserts that there are no concurrent writes to var for the duration of the scope it's introduced in. And honestly? It's giving main character energy compared to stacking up multiple ASSERT_EXCLUSIVE_WRITER calls β it's a better way to fully cover the enclosing scope, and it increases the likelihood for KCSAN to detect racing accesses πβ¨
Like, this is the upgrade. The glow-up. The reason it exists:
It lets you find race-condition bugs that only happen because of state changes within the scope itself π«Ά
And here's the vibe in code, exactly as written:
void writer(void) {
spin_lock(update_foo_lock);
{
ASSERT_EXCLUSIVE_WRITER_SCOPED(shared_foo);
WRITE_ONCE(shared_foo, 42);
...
// shared_foo should still be 42 here!
}
spin_unlock(update_foo_lock);
}
void buggy(void) {
if (READ_ONCE(shared_foo) == 42)
WRITE_ONCE(shared_foo, 1); // bug!
}
see how writer() is just out here setting shared_foo to 42 and expecting it to stay 42? and then buggy() rolls in, peeks with READ_ONCE, sees 42, and goes WRITE_ONCE(shared_foo, 1) β comment says it all bestie: // bug! π caught red-handed by the scoped check. iconic behavior from the assertion, honestly π§
π SEE ALSO π
Kernel file ./include/linux/kcsan-checks.h π and all her friends:
__kcsan_check_access(9)__kcsan_mb(9)__kcsan_wmb(9)__kcsan_rmb(9)__kcsan_release(9)kcsan_disable_current(9)kcsan_enable_current(9)kcsan_nestable_atomic_begin(9)kcsan_nestable_atomic_end(9)kcsan_flat_atomic_begin(9)kcsan_flat_atomic_end(9)kcsan_atomic_next(9)kcsan_set_access_mask(9)kcsan_begin_scoped_access(9)kcsan_end_scoped_access(9)__kcsan_check_read(9)__kcsan_check_write(9)__kcsan_check_read_write(9)kcsan_check_read(9)kcsan_check_write(9)kcsan_check_read_write(9)ASSERT_EXCLUSIVE_WRITER(9)ASSERT_EXCLUSIVE_ACCESS(9)ASSERT_EXCLUSIVE_ACCESS_SCOPED(9)ASSERT_EXCLUSIVE_BITS(9)
that's the whole group chat, no cap π
k bye bestie, go assert those exclusive writers β¨ β this little love letter came from ./include/linux, dated October 2026, and the header still insists on calling itself ASSERT_EXCLU...RITER_SCOPED(9). periodt ππ¦π
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms