Skip to content

[release/10.0] [mono][interp] Avoid leaving around pages without access#119885

Closed
github-actions[bot] wants to merge 2 commits intorelease/10.0from
backport/pr-119754-to-release/10.0
Closed

[release/10.0] [mono][interp] Avoid leaving around pages without access#119885
github-actions[bot] wants to merge 2 commits intorelease/10.0from
backport/pr-119754-to-release/10.0

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Sep 19, 2025

Backport of #119754 to release/10.0

/cc @BrzVlad

Customer Impact

  • Customer reported
  • Found internally

Profiling with instruments doesn't work on maui maccatalyst/ios primarily when interpreter is enabled.

Regression

  • Yes
  • No

This is not really a regression on maui, but the problematic code is usually executed when interpreter is enabled. Given that on Xamarin the interpreter was less likely to be enabled, this could be a regression for some users.

Testing

Tested locally on ios and maccatalyst with complex enough applications that trigger this.

Risk

Low. This fix just a minor change to the order in which we map pages as part of the implementation for process wide memory barrier.

Otherwise it would crash instruments when trying to access it.
@jkotas
Copy link
Member

jkotas commented Sep 19, 2025

Mono implementation of memory_barrier_process_wide_helper_page is not 100% reliable. There are situations where the OS detects that the IPC interrupt is unnecessary and skips sending it. It is why CoreCLR has different implementation - this implementation was built after discussions with Apple.

Can this "minor" change in ordering make the implementation even less reliable than it is currently and introduce frequent-enough intermittent crashes in customer apps?

@BrzVlad
Copy link
Member

BrzVlad commented Sep 22, 2025

I don't have an answer to this because we are pretty much relying on behavior that is not well defined and not in our control. I don't believe reusing the CoreCLR implementation is on the table, I don't think the code ever ran on ios/maccatalyst and the net10 branch doesn't contain the move of this code to the shared minipal. So, for .net10 we are left either with this PR or with https://gist.github.com/rolfbjarne/26c49b8d8ced32f6688024b7a691fcb6, but I think the same argument could be made about each one of them. I'm fine with the second option, if you think it feels less risky.

@jkotas
Copy link
Member

jkotas commented Sep 22, 2025

I don't have an answer to this because we are pretty much relying on behavior that is not well defined and not in our control

The risk should not be qualified as "low" then.

Isn't the actual problem that we are modifying protection of pages from regular C heap? It is not ok to do that. It can cause all sorts of problems. For example, if the C heap uses large pages, we would have a problem as well since the protections would be modified on the whole large page and affected unrelated memory.

Should the fix rather be to allocate the page using mmap instead of posix_memalign? I would expect that Instruments will be fine with noaccess pages allocated using mmap.

@BrzVlad
Copy link
Member

BrzVlad commented Sep 22, 2025

Yes, normally we should be using mmap here as a fix, but I wasn't sure if that would have even more side effects that would change the behavior.

@jkotas
Copy link
Member

jkotas commented Sep 22, 2025

I think switching the allocation to mmap would be lower risk than changing the protection ordering, and it would be more complete fix for the Instruments issue. With the current fix, there is still window where the page protection is none and the Instruments can crash.

@BrzVlad
Copy link
Member

BrzVlad commented Oct 1, 2025

closed in favor of #120293

@BrzVlad BrzVlad closed this Oct 1, 2025
@jkotas jkotas deleted the backport/pr-119754-to-release/10.0 branch October 1, 2025 18:46
@github-actions github-actions bot locked and limited conversation to collaborators Nov 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants