-
Notifications
You must be signed in to change notification settings - Fork 5.4k
YJIT: Fix potential infinite loop when OOM #13186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
rianmcguire
commented
Apr 27, 2025
This comment has been minimized.
This comment has been minimized.
Thank you so much for the investigation and the thorough fix! 🙏🏼 |
XrXr
pushed a commit
to XrXr/ruby
that referenced
this pull request
Apr 28, 2025
Avoid generating an infinite loop in the case where: 1. Block `first` is adjacent to block `second`, and the branch from `first` to `second` is a fallthrough, and 2. Block `second` immediately exits to the interpreter, and 3. Block `second` is invalidated and YJIT is OOM While pondering how to fix this, I think I've stumbled on another related edge case: 1. Block `incoming_one` and `incoming_two` both branch to block `second`. Block `incoming_one` has a fallthrough 2. Block `second` immediately exits to the interpreter (so it starts with its exit) 3. When Block `second` is invalidated, the incoming fallthrough branch from `incoming_one` might be rewritten first, which overwrites the start of block `second` with a jump to a new branch stub. 4. YJIT runs of out memory 5. The incoming branch from `incoming_two` is then rewritten, but because we're OOM we can't generate a new stub, so we use `second`'s exit as the branch target. However `second`'s exit was already overwritten with a jump to the branch stub for `incoming_one`, so `incoming_two` will end up jumping to `incoming_one`'s branch stub. Backport [Bug #21257]
k0kubun
pushed a commit
that referenced
this pull request
Apr 28, 2025
Avoid generating an infinite loop in the case where: 1. Block `first` is adjacent to block `second`, and the branch from `first` to `second` is a fallthrough, and 2. Block `second` immediately exits to the interpreter, and 3. Block `second` is invalidated and YJIT is OOM While pondering how to fix this, I think I've stumbled on another related edge case: 1. Block `incoming_one` and `incoming_two` both branch to block `second`. Block `incoming_one` has a fallthrough 2. Block `second` immediately exits to the interpreter (so it starts with its exit) 3. When Block `second` is invalidated, the incoming fallthrough branch from `incoming_one` might be rewritten first, which overwrites the start of block `second` with a jump to a new branch stub. 4. YJIT runs of out memory 5. The incoming branch from `incoming_two` is then rewritten, but because we're OOM we can't generate a new stub, so we use `second`'s exit as the branch target. However `second`'s exit was already overwritten with a jump to the branch stub for `incoming_one`, so `incoming_two` will end up jumping to `incoming_one`'s branch stub. Backport [Bug #21257]
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.
Fixes https://bugs.ruby-lang.org/issues/21257 [Bug #21257]
Avoid generating an infinite loop in the case where:
first
is adjacent to blocksecond
, and the branch fromfirst
tosecond
is a fallthrough, andsecond
immediately exits to the interpreter, andsecond
is invalidated and YJIT is OOMWhile pondering how to fix this, I think I've stumbled on another related edge case:
incoming_one
andincoming_two
both branch to blocksecond
. Blockincoming_one
has a fallthroughsecond
immediately exits to the interpreter (so it starts with its exit)second
is invalidated, the incoming fallthrough branch fromincoming_one
might be rewritten first, which overwrites the start of blocksecond
with a jump to a new branch stub.incoming_two
is then rewritten, but because we're OOM we can't generate a new stub, so we usesecond
's exit as the branch target. Howeversecond
's exit was already overwritten with a jump to the branch stub forincoming_one
, soincoming_two
will end up jumping toincoming_one
's branch stub.I'm not sure what the consequences of calling the wrong branch stub are, but the comments in invalidate_block_version suggest the stubs are supposed to be unique.
I've attempted to address both of these cases with this change, but I can split it up if that would be preferable.