fix(libc): stop macOS write-watch fault-ahead at the end of a driver's own store #20126
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/20126"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by XIIYAZ on 2026-11-14T17:08:06Z.
What
On macOS,
agc_driver_native_depth_publicationstops in the casesamples=2 write=None unmap=Middle:There is no guest write in that case. The macOS write watch tracks writes by write-protecting pages and handling the fault. Its fault-ahead (
_faultAhead, default 32) works like this: when a write faults on a page and the two pages before it were just opened for writing, the handler opens the following pages of the same 64 KiB block in onemprotectand marks themWrittenbefore anything writes them.The publication commits one plane in parts, because the hole splits it.
WriteChangedIfHeldwrites each part throughstoreOwn, which walks the write watch over the part's own pages before and after the store. I traced the runs those walks stamp, with addresses from one run:Part A's sequential store faulted through its pages, and fault-ahead opened
10a454000..10a458000too. Those pages are outside part A's span, so its post-walk did not take them. Part B's pre-walk then collected them as a CPU store.cpuUnchangedfailed for the whole part,lostwas the part's size, and publication refused. WithAPS5_WRITE_WATCH_FAULT_AHEAD=1the whole--publicationrun passes (76 cases). Linux and Windows do not track writes through faults, so they never see these pages.A driver store should not open pages beyond the range it stores.
storeOwnnow registers its page span with the write watch for the duration of the store (GuestWriteWatchBeginOwnStore/GuestWriteWatchEndOwnStore, through a scopedOwnStoreFaults):_ownStoresunder its existing mutex, like_hostWrites.storeOwn's own post-walk, as before.FaultLock, so nothing allocates in the signal handler.Tested
Setup:
-DCMAKE_OSX_ARCHITECTURES=x86_64; tests run under RosettaANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1mainwith the open macOS build fixes appliedResults:
agc_driver_native_depth_publicationfails before this change and passes after it, with fault-ahead at its default.write_watch_*andguest_arena_host*tests pass.ctest -R 'native_depth|native_multisample|write_watch|write_tracking|guest_arena'(68 tests): all pass exceptagc_write_tracking, which fails the same way before and after. That one is the import window's host write marking every page of its range, not fault-ahead.ctest -R '^(agc|shader|job)'(1578 tests,-j 1) and compared it with the same run before this change:agc_driver_native_depth_publicationis fixed and nothing new fails (14 failures before, 13 after).Linux and Windows are unchanged.
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)Imported from boykopovar/AnyPS5. Originally posted by kurexw on 2026-11-16T20:51:57Z.
Review: COMMENTED
Tested on an Apple GPU: Apple M4, macOS 27.2, MoltenVK 1.4.2 (Vulkan 1.4), with the Vulkan loader and validation layers from LunarG SDK 1.4.363.1. Full build, x86-64 under Rosetta 2. This PR was merged alone onto
main3b17977ba6withgit merge --no-ff.All 30 ctest entries that run
agc_driver_native_multisample_depth_tests(one per argument mode, from no arguments to--driver-queued-fill) were run once onmainand once with this PR, and--publicationthree times on each side. Every run usedANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer.--publication(agc_driver_native_depth_publication) fails in all 3 runs onmainwith "AGC graphics: guest writes raced native multisample depth publication", right after thesamples=2 write=3cases. It passes in all 3 runs with this PR.Insert instance layer "VK_LAYER_KHRONOS_validation", none containswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither side logs anyVUID-error.Not run here: the write-watch suite (CI covers it on macOS) and an Intel Mac.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-30T10:31:20Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the inspected implementation bounds write-watch fault-ahead to the active own-store span on macOS.
What I ran
Reviewed head
422efbbb6aa06ac05ba0fba525a50c7356ca3837. Read the prepared description, commit list, manifest, diff, and all changed lines in the three changed files. Usedrepo_read.pyto inspect the nearby fault-lock, write-watch range, and store call paths. No build or tests were run in this review.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No build, test suite, or physical macOS/Linux/Windows runtime was run. The author-reported test results were not independently verified.
To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:24:06Z.
Review: COMMENTED
The trial merge onto
a1b75b0947was clean.OwnStoreFaultsregisters a page-aligned scope around the actual write and removes it on exit, and the fault handler clips its look-ahead at the registered end. Please retain the split-depth-publication case with default fault-ahead enabled. Disabling fault-ahead avoids the failing path altogether. The platform-specific behavior needs the paired macOS logs. My review is source-based.AI-assisted: yes.