[release/10.0] [mono][sgen] Fix card scanning in LOS non-array objects#125213
Open
github-actions[bot] wants to merge 1 commit intorelease/10.0from
Open
[release/10.0] [mono][sgen] Fix card scanning in LOS non-array objects#125213github-actions[bot] wants to merge 1 commit intorelease/10.0from
github-actions[bot] wants to merge 1 commit intorelease/10.0from
Conversation
`sgen_card_table_region_begin_scanning` needs to determine whether any cards are marked in the object starting at `start` address. The current card size in 512 bytes. Consider an object with start 500 and size 20, so this object lives within 2 cards. We will check the card associated with the address 500. Once this iteration is done, we will check whether `start + card_size < end` => `500 + 512 < 520`. This is false, so we will no longer scan the second card. The algorithm was expecting the start address to be aligned to the card start, which is what the fix does. This bug is severe, but, in practice, this code path is not as frequent. This bug would only affect objects greater than 8k, that are not arrays.
BrzVlad
approved these changes
Mar 5, 2026
This was referenced Mar 5, 2026
Open
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 of #125116 to release/10.0
/cc @BrzVlad
Customer Impact
In some cases, cards marked for non-array LOS objects (objects with size greater than 8K) were being ignored. This means that the GC could fail to observe that some object refs were stored inside these large objects. This can result in GC crashes or other undefined behavior. This can impact all mono workloads. This issue was confirmed to be hit by a customer who also investigated it via a GC debug flag. There are other undiagnosed GC crashes that might hopefully be fixed by this.
Regression
Testing
Was able to create a console app reproducing this bug. Validated the fix.
Risk
Low. The fix just does an address alignment, in order to scan correctly an additional card.