Page MenuHomeFreeBSD

Add INVARIANTS-only fences to synchronize lockless refcount updates.
ClosedPublic

Authored by markj on Aug 16 2018, 9:16 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Aug 8, 11:12 PM
Unknown Object (File)
Tue, Aug 6, 7:06 PM
Unknown Object (File)
Thu, Jul 25, 12:24 AM
Unknown Object (File)
Mon, Jul 22, 12:10 PM
Unknown Object (File)
Mon, Jul 22, 4:43 AM
Unknown Object (File)
Sun, Jul 21, 11:49 AM
Unknown Object (File)
Sun, Jul 21, 10:09 AM
Unknown Object (File)
Jul 16 2024, 1:01 PM
Subscribers

Details

Summary

This is based on the discussion around the (now reverted) r334708.
Some internal routines inspect v_iflags after a lockless refcount bump.
In general the locking protocol requires the interlock for this, and
without it memory reordering introduces races that can cause spurious
assertion failures. Add some INVARIANTS-only macros to address some
known races. I don't claim that this is an exhaustive fix, though.
Please feel free to suggest alternate names for the macros.

Test Plan

Ask Justin to test.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

markj added reviewers: kib, mjg, rlibby.
markj added a subscriber: jhibbits.

Please add comments explaining that these fences are used to ensure visibility of the v_iflags vs v_holdcnt updates.

This revision is now accepted and ready to land.Aug 16 2018, 9:59 PM

Survives a buildworld, something it couldn't do before.

  • Make the comment more explicit.
This revision now requires review to proceed.Aug 16 2018, 10:53 PM

I think the current names while justifiable only add confusion (why is refcount *acquire* paired with fence *rel*?). How about 'VNODE_REFCOUNT_FENCE_BEFORE' and after.

No strong opinions though.

This revision is now accepted and ready to land.Aug 17 2018, 2:53 PM
In D16756#356654, @mjg wrote:

I think the current names while justifiable only add confusion (why is refcount *acquire* paired with fence *rel*?). How about 'VNODE_REFCOUNT_FENCE_BEFORE' and after.

I'm not crazy about the names, but I do think it's reasonably clear that "acquire" refers to the fence and not a refcount operation. At least, the naming is consistent with atomic(9). _BEFORE and _AFTER is tied too closely to the existing uses IMHO. We might want to add uses where those suffixes don't make much sense.

This revision was automatically updated to reflect the committed changes.