ASSERT_EXCLUSIVE_WRITER(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… 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 πŸ’œ


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