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)
Mon, Nov 18, 8:48 PM
Unknown Object (File)
Sun, Nov 17, 2:49 AM
Unknown Object (File)
Sat, Nov 16, 3:24 AM
Unknown Object (File)
Mon, Nov 11, 4:22 PM
Unknown Object (File)
Fri, Nov 1, 4:05 PM
Unknown Object (File)
Sep 28 2024, 12:38 PM
Unknown Object (File)
Sep 25 2024, 9:06 AM
Unknown Object (File)
Sep 24 2024, 4:03 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.