Repository navigation
[Backport releases/v4.35.0] fix: mark the children of objects whose single-threaded count overflowed - #15306
Merged
Conversation
…wed (#15288) This PR fixes potential undefined behavior when an object with a huge number of incoming references is shared between threads. Specifically, it makes sharing an object with other threads mark everything it points to as thread-shared even when the object's reference count has overflowed. Previously such objects were shared without their children, so other threads could update the children's reference counts non-atomically and free them while still in use. Overflowing single-threaded counts land at or below the new `LEAN_RC_STUCK_ST`: the inline increment wraps below it, and `lean_inc_ref_huge_n` freezes counts there instead of at `LEAN_RC_STICKY`. `lean_mark_mt` treats counts at or below it as unshared, visits their children, and freezes the object's count at `LEAN_RC_STICKY`. A frozen thread-shared count only reaches `LEAN_RC_STUCK_ST` with more than 4094 maximal increments in flight at once, two fewer than the sticky range already allows before a frozen count wraps. `lean_mark_mt` also freezes single-threaded counts too large for the live thread-shared range at `LEAN_RC_STICKY` rather than negating them. Negating a count near `INT_MAX` would land at or below `LEAN_RC_STUCK_ST`, where a later `lean_mark_mt` would take the shared object for an unshared one and walk it while other threads use it. The model gains `isUnshared` and `markMtRc` for `is_unshared` and the count `lean_mark_mt` leaves on each object it visits. `incRefN_spec` and `incRefHugeMt_spec` now state that an overflowing single-threaded count lands in the band `isStuckSt` reserves and that a thread-shared count never reaches it, and `markMtRc_shared`, `decRef_stays_shared` and `frozen_shared_count_stays_shared` show that a shared count never reads as unshared again. `rc_sticky` checks sharing after each overflow route and with a count near `INT_MAX`, as well as a frozen shared count drifted by the most increments in flight the bound admits. Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]> (cherry picked from commit 2b21d8b)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport 2b21d8b from #15288.