Page MenuHomeFreeBSD

locking.9: warn about using sleepable lock address as a sleep channel
ClosedPublic

Authored by kib on May 15 2026, 11:08 AM.
Tags
None
Referenced Files
F160407257: D57012.diff
Wed, Jun 24, 5:00 AM
Unknown Object (File)
Wed, Jun 17, 4:52 PM
Unknown Object (File)
Wed, Jun 10, 3:35 AM
Unknown Object (File)
Fri, Jun 5, 1:16 AM
Unknown Object (File)
Tue, Jun 2, 10:35 AM
Unknown Object (File)
Wed, May 27, 7:39 PM
Unknown Object (File)
Tue, May 26, 11:15 AM
Unknown Object (File)
May 25 2026, 6:40 PM
Subscribers

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kib requested review of this revision.May 15 2026, 11:08 AM
share/man/man9/locking.9
225
227

Why "must"? In the worst case one will observe spurious wakeups.

kib marked an inline comment as done.May 15 2026, 11:43 AM
kib added inline comments.
share/man/man9/locking.9
227

No, it is worse. Sleeps are normally used with an interlock, while locking primitives use their thread lock. As result, the sleepq code rightfully asserts, see the sleepq_add() branch for sq != NULL.

markj added inline comments.
share/man/man9/locking.9
227

Hmm, ok. It is a somewhat subtle constraint, e.g., one might put a sx at the beginning of a structure, and then the structure address cannot be used as a wait channel. (The sx implementation uses &sx->lock_object as the internal wait channel, which is the same as sx.)

This revision is now accepted and ready to land.May 17 2026, 7:52 PM
kib marked an inline comment as done.May 17 2026, 7:54 PM
kib added inline comments.
share/man/man9/locking.9
227

This is exactly how the thing beat me, and it took some efforts to realize the cause. So I prefer to keep it in the documentation.

This revision was automatically updated to reflect the committed changes.
kib marked an inline comment as done.
share/man/man9/locking.9
227

We could modify the sx implementation to use &sx->sx_lock as the wait channel instead, to make this scenario less likely. But sure, it is useful to document this anyway.