Repository navigation
fix(libc): compare, not mark, writable pages in a failing macOS host write - #216
Conversation
|
Thanks, this is careful work. We traced it and found no path where a page that was really written stops being reported:
We also saw that the branch already contains #213, so merging this one brings both. One thing we'd like changed before merging: pages opened this way are Hot while their host write session is still open, and nothing stops Two smaller notes, not blockers:
CI is approved. The macOS job has to show |
…write A macOS host write session marked every writable watched page in its range written. When the range also covers a page the guest cannot write, the write fails partway, and a session opened only to test writability (videodec2's ClearOutput) dirtied the writable prefix without storing to it. Those pages are now opened as hot pages with a snapshot, so the next collection reports them only if their bytes changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A partial host write opens its writable pages as hot pages. HostWrites and Collect's re-arm after 256 unchanged collections could re-protect them while the session was still open, so the session's next host store would fault, which under Rosetta can fail to reach the watch. Both now skip a page inside an open host write. openCompared also falls back to the marking path when its mprotect fails. write_watch_host-partial-hot checks that the page stays writable through HostWrites and 300 collections during the session, and is re-armed after it ends. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9dd7abe to
6572bf1
Compare
|
Thanks for the review. I added |
|
Merged, thanks! The |
What
A macOS host write session (
GuestArena::HostWrite) marks every writable watched page in its range written when it opens, because once a page is opened the watch no longer sees stores to it. If the range also covers a page the guest cannot write, the session's write fails partway, and the pages before it can be marked written though nothing stored to them. videodec2'sClearOutput(upstream code, shared with Linux and Windows) opens a session only to test whether an output is writable. For an output that starts on a writable watched page and runs into an unwritable one,guest_videodec2_hevc_aliasesthen failsstraddling unwritable output dirtied watched prefix page. That is the check left after #213. Linux and Windows pass it.When a session's range covers a watched page without guest write access, its writable, still-protected pages are now opened as hot pages: snapshot first, then unprotect. The next collection reports them written only if their bytes changed, so a partial copy that did store to the prefix is still seen. Sessions over fully writable ranges, which are the normal case, keep the current path, so they pay for no snapshot. With hot pages turned off (
APS5_WRITE_WATCH_NO_HOT), pages fall back to being marked written as before.Pages opened this way stay hot until the session ends.
HostWritesand Collect's re-arm after 256 unchanged collections skipcool()for a page inside an open host write. Otherwise they could re-protect it mid-session, and the session's next host store would fault, which under Rosetta can fail to reach the watch. Once the session ends, both work on the page again.openComparedalso checks itsmprotectand falls back to the marking path if it fails.A known cost: a large session with one unwritable watched page snapshots every clean, writable, protected page in its range under the watch lock. Those pages are then compared at each collection until they re-arm.
guest_videodec2_hevc_aliasespasses and itsctest-known-failures.txtentry is removed.Tested
macOS 27.2.1, Apple silicon, x86-64 build under Rosetta 2 (AppleClang 21.0.0, Release), rebased on current
main(#213 merged):write_watch_host-partial-hot. It opens a host write over two writable pages and one read-only page, then checks four things:HostWritesand through 300 collections during the session;HostWritesskip: "HostWrites protected a page inside an open host write";write_watch_*tests andguest_videodec2_hevc_aliases: pass 3 runs out of 3.ctest -R 'write_watch|read_trap|ReadTrap|label_trap|guest_memory|import|agc_write|guest_arena|write_tracking|label|videodec2|host_write': 183 tests. All pass exceptguest_memory, which is listed and fails the same way onmain(b23fbf4): "fixed guest mapping 0x1000000000+0x4000 overlaps a host region in the guest arena".guest_videodec2_hevc_aliases: passes 3 runs out of 3. WithAPS5_WRITE_WATCH_NO_HOT=1, which skips the new path, it fails at the straddling check as before.ctest -j8(7,107 tests): every failure is already inctest-known-failures.txt(allormacos); no new failures.python3 tools/check_conventions.py --base origin/main: all checks passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code