Skip to content

fix(libc): reset every page of a run view that Commit reprotects - #11344

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:fix/commit-every-view-of-a-run
Oct 27, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
thuanquang:fix/commit-every-view-of-a-run

Conversation

@thuanquang

@thuanquang thuanquang commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

What

Since #9505, a run of shared guest pages is mapped as one host view, with one View per 16 KiB page. In Commit, the branch for already committed memory reset only the View at the start of each VirtualQuery region (views.find(cursor)), then called VirtualProtect on the whole region. Once Collect has armed the pages of a run view alike, one region covers several pages. The other pages then became writable while their Views kept armed set and seen == generation. Stores to them never faulted, and Collect did not report them, so the GPU could keep stale copies.

Commit now resets every View in the range it reprotects, the same range as the VirtualProtect.

This is point 1 of the post-merge review of #9505, which its author asked us to fix (comment).

Tested

Windows 11 26200, Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release. Head 2b640c8ad0 on main 5b5d24cb22.

  • A new check in windows_write_watch covers this:
    • It maps a 4-page shared run as one view and collects it with All, so all four pages are armed read-only as one region.
    • It commits the run PAGE_READWRITE, stores into page 1, and requires Collect(Armed) to report the store.
    • It then requires page 1 to be armed again and to fault once on the next store.
    • Finally it requires Commit(PAGE_READONLY) to give all four Views PAGE_READONLY.
  • With main's WindowsMappings.hpp, the check fails in 3 of 3 runs: a store into the second page of a run that Commit reprotected was not collected. With this change it passes in 3 of 3 runs.
  • ^(windows_write_watch|windows_mappings_release.*|guest_memory|windows_shared_map_cost)$: 7 of 7 pass, in 3 of 3 rounds.

How a guest reaches it: guest mprotect calls GuestArenaSetProtection, which resets every View, before CommitArenaRange. A single-threaded mprotect is therefore fine on main. The defect needs a Collect between those two calls, or a direct Commit over an armed run.

Not tested: Linux and macOS (WindowsMappings is Windows-only). No title is known to hit this yet.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

@MarcZX10 MarcZX10 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.

The range iteration matches the protection operation: it starts at the aligned first mapped view, resets each view whose base is before the region end, and then applies VirtualProtect to that same region. The added regression arms a four-page shared run, verifies a later-page store is collected and rearmed, and checks the final protection on every page. The author reports the focused Windows suite passing 7/7 (including three repetitions of the new case); hosted conventions, relinker ASan, Windows relinker, macOS write-watch and register-context checks pass. I could not reproduce the Windows library test locally because the MinGW configuration lacks the Windows SDL2 package; the hosted full product jobs are path-skipped. No blocking issue found in the diff.

@github-actions github-actions Bot added the libc label Oct 26, 2026

@MarcZX10 MarcZX10 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.

The exact-head review and the reported regression are otherwise solid: the implementation clears each View whose base lies in the region being reprotected, and the new test exercises a multi-page shared run, a later-page write, re-arming, and final per-page protection. Current hosted policy, relinker, ASan, register-context and write-watch checks pass; the full Linux/Windows product jobs are path-skipped.

The branch is still 1 ahead and 20 behind current main (14c99b52ac); the report and the 3/3 negative-control runs are based on 442c43a574. CONTRIBUTING.md asks branches to stay up to date. Please refresh onto current main and rerun windows_write_watch plus the focused mapping tests on that exact head before merge. The merge preview is clean, and I found no intervening changes to WindowsMappings.hpp or WindowsWriteWatch.cpp, but that does not replace an exact-current-base run.

@thuanquang
thuanquang force-pushed the fix/commit-every-view-of-a-run branch from 10b38aa to 62d94f9 Compare October 26, 2026 06:04
@thuanquang

Copy link
Copy Markdown
Contributor Author

@MarcZX10 I refreshed the branch onto main 14c99b52ac; the head is now 62d94f9854, with the same single commit. On that exact head (Windows 11 26200, RX 6700 XT, WinLibs GCC 15.2.0 r7, Release):

  • windows_write_watch_tests passes in 3 of 3 runs.
  • ^(windows_write_watch|windows_mappings_release.*|guest_memory|windows_shared_map_cost)$: 7 of 7 pass, in 3 of 3 rounds.
  • Negative control, with WindowsMappings.hpp from 14c99b52ac and this head's tests: the new check fails in 3 of 3 runs with a store into the second page of a run that Commit reprotected was not collected. With the change restored, it passes in 3 of 3 runs again.

I've updated the description to match.

@MarcZX10 MarcZX10 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.

The requested current-main validation is complete: the refreshed head 62d94f9854c2093c074a1cc88403e89ff65f33e8 is one commit ahead of 14c99b52ace303eef1667764670d1d1540140b3d, with a clean merge preview. The implementation still resets every mapped view covered by the protection range, and the exact-head focused Windows tests and negative control reported in the updated description exercise the multi-page failure and recovery. The remaining hosted Windows and macOS x86_64 relinker jobs are infrastructure/build validation; all other relevant policy, ASan, register-context, write-watch and relinker checks have passed. No remaining actionable findings.

@MarcZX10

Copy link
Copy Markdown
Contributor

Current-base follow-up (main 5b5d24cb223ede690fe5eab1fe2f7a1736b801a5): the approved head 62d94f9854c2093c074a1cc88403e89ff65f33e8 is 1 commit ahead and 195 behind its merge base 14c99b52ace3. The current merge preview is clean, and neither touched file changed on main since that base, so I found no new code finding. The repository's branch rule still calls for updating to current main; please rebase and rerun the focused Windows write-watch/mapping tests on the resulting head. The current hosted relinker, ASan, register-context and write-watch jobs pass; full product jobs are skipped by path policy.

Co-Authored-By: Claude <noreply@anthropic.com>
@thuanquang
thuanquang force-pushed the fix/commit-every-view-of-a-run branch from 62d94f9 to 2b640c8 Compare October 26, 2026 11:07
@thuanquang

Copy link
Copy Markdown
Contributor Author

@MarcZX10 refreshed, picking this up for contact today: 62d94f9854 → 2b640c8ad0, one commit on main 5b5d24cb22. The rebase was clean and the diff is unchanged (WindowsMappings.hpp and WindowsWriteWatch.cpp). On the new head, Windows 11 26200, Ryzen 5 5600X, WinLibs GCC 15.2.0 r7, Release:

  • ^(windows_write_watch|windows_mappings_release.*|guest_memory|windows_shared_map_cost)$: 7 of 7 pass, in 3 of 3 rounds, and once more after the control below was undone.
  • Control: WindowsMappings.hpp taken from main with the new check kept, windows_write_watch fails in 3 of 3 runs with a store into the second page of a run that Commit reprotected was not collected.

The description's Tested line now names this head and base.

AI-assisted: yes (Claude Code)

@EagleBearerYS

Copy link
Copy Markdown
Contributor

@thuanquang looks right to me, from reading it against main's Commit. The committed branch now resets every View whose page starts in [cursor, stop), the range it then passes to VirtualProtect, with the same loop SetProtection uses, so a run view armed as one region gets all its Views reset instead of only the first. The new check follows the sequence from the review (four pages armed as one region, Commit read-write, a store to page 1, Collect(Armed)), and its last step also covers Commit back to read-only for all four Views.

@oneandonlydean oneandonlydean self-assigned this Oct 26, 2026
@oneandonlydean
oneandonlydean merged commit 801d5b9 into boykopovar:main Oct 27, 2026
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants