Skip to content

[wasm] Fix sharing of wbarrier card between los object and wbarrier roots - #118271

Merged
lewing merged 1 commit into
dotnet:mainfrom
BrzVlad:fix-wasm-los
Aug 1, 2025
Merged

lewing merged 1 commit into
dotnet:mainfrom
BrzVlad:fix-wasm-los

Conversation

@BrzVlad

@BrzVlad BrzVlad commented Aug 1, 2025

Copy link
Copy Markdown
Member

In the change disabling los section allocator on wasm (via sgen_los_enable_sections_allocator), we aligned these los objects to 512 bytes, which is the memory range mapped by a card byte. This alignment prevented two los objects having memory mapped to the same card. Sharing with other objects is impossible since they are allocated in separate spaces with high alignment (the nursery and major blocks). There was however an oversight, which is the possibility of having wbarrier roots allocated in this space (These roots are just variable sized memory ranges containing refs, that are scanned only if the corresponding card is marked). In this situation, scanning the cards for the los object could end up clearing cards for these roots that will no longer be scanned.

We fix this by reserving the memory for the los object up to the full card range. We could alternatively fix this by adding alignment card size in the place where we allocate the wbarrier roots.

…oots

In the change disabling los section allocator on wasm (via sgen_los_enable_sections_allocator), we aligned these los objects to 512 bytes, which is the memory range mapped by a card byte. This alignment prevented two los objects having memory mapped to the same card. Sharing with other objects is impossible since they are allocated in separate spaces with high alignment (the nursery and major blocks). There was however an oversight, which is the possibility of having wbarrier roots allocated in this space (These roots are just variable sized memory ranges containing refs, that are scanned only if the corresponding card is marked). In this situation, scanning the cards for the los object could end up clearing cards for these roots that will no longer be scanned
Copilot AI review requested due to automatic review settings August 1, 2025 10:17
@github-actions github-actions Bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Aug 1, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a potential issue in WebAssembly garbage collection where write barrier cards could be incorrectly shared between large object space (LOS) objects and write barrier roots, leading to missed reference scanning.

  • Ensures LOS objects on WASM reserve the full card range to prevent sharing with write barrier roots
  • Moves conditional compilation directives to improve code clarity and maintainability

Comment thread src/mono/mono/sgen/sgen-los.c Resolved
@BrzVlad

BrzVlad commented Aug 1, 2025

Copy link
Copy Markdown
Member Author

Wasn't able to reproduce locally, but hopefully it fixes #118253 and #118244

@BrzVlad
BrzVlad requested a review from pavelsavara August 1, 2025 10:19
@pavelsavara pavelsavara added area-GC-mono and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Aug 1, 2025
@pavelsavara

Copy link
Copy Markdown
Member

/azp run runtime-extra-platforms

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants