ASSERT_EXCLUSIVE_WRITER(9)
π ASSERT_EXCLUSIVE_WRITER(9) β your fave kernel API manual bestie β¨
okay so before we even start: this is from the Kernel API Manual, section 9, and it's literally about catching people who write to your variable without permission. slay. let's get into it π
β¨ NAME β¨
ASSERT_EXCLUSIVE_WRITER β assert no concurrent writes to @var
like, be so fr, only ONE of you is allowed to write here bestie π«Ά
πΈ SYNOPSIS πΈ
ASSERT_EXCLUSIVE_WRITER (var );
yes that's the whole vibe. one argument. iconic. π
π¦ ARGUMENTS π¦
varβ the variable to assert on. that's it. that's the girl. the one we're guarding with our whole life π
π DESCRIPTION π
So basically this macro asserts that there are no concurrent writes to var β like, at all. Other readers though? totally allowed, they're welcome here, we love readers π«Ά
The whole point is that this assertion can be used to specify properties of concurrent code where a violation can't be detected as a normal data race. lowkey a menace, highkey useful.
For example β picture this: we only have a single writer, but multiple concurrent readers. To avoid data races, all of these accesses have to be marked. But here's the thing, and it's giving plot twist: even concurrent marked writes racing with the single writer are bugs. π And unfortunately, because they're marked, they're no longer data races. so the detector's just sitting there like ποΈπποΈ
For cases like these, we can use the macro as follows:
void writer(void) {
spin_lock(update_foo_lock);
ASSERT_EXCLUSIVE_WRITER(shared_foo);
WRITE_ONCE(shared_foo, ...);
spin_unlock(update_foo_lock);
}
void reader(void) {
// update_foo_lock does not need to be held!
... = READ_ONCE(shared_foo);
}
see how the reader literally does not need to hold update_foo_lock? yeah. she's free. she's unbothered. she's reading. π§
β NOTE β
ASSERT_EXCLUSIVE_WRITER_SCOPED, if applicable, performs more thorough checking β but only if there's a clear scope where no concurrent writes are expected. so if you've got that scope, she's the upgrade bestie, no cap π₯
π SEE ALSO π
All the related girls in the kernel file ./include/linux/kcsan-checks.h β go say hi π
__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_SCOPED(9)ASSERT_EXCLUSIVE_ACCESS(9)ASSERT_EXCLUSIVE_ACCESS_SCOPED(9)ASSERT_EXCLUSIVE_BITS(9)
and that's the whole page babes π
this one lives in ./include/linux and it's dated October 2026 β periodt, go assert those exclusive writers, ily, mwah πβ¨
π¦ 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