fix(libc): close two write-watch report races on Linux #24008
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/24008"
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 chitters2004 on 2026-11-20T00:51:55Z.
What
Two ordering bugs in the Linux write watch (
core/libs/prx/libc/src/GuestWriteWatch.cpp, userfaultfd write protection), one commit each.takeFreshreported a never-armed range as written and only then write-protected it. A guest store between the report and the protect went through unfaulted and the protect then hid it, so the next collect did not list the page and a consumer that had already re-read the range kept stale data. It now protects every fresh piece first and reports afterwards: a store before the protect is covered by the fresh report, a store after it sets the written state the next scan lists. The protect-failure path is unchanged (marks put back, range reported).A collect resolved its alias plan before
takeFreshand the scan, and fanned every report through that snapshot. AnAliasthat linked the views in between left it stale: the scan cleared the written state of a store made through one view after the link and reported it to that view only, so the partner view never heard of it. Link changes are now counted (_linkVersion), and eachFanoutcompares its version at report time, which is after the scan that consumed the pages, and re-resolves its translations under the shared lock when they differ. Until then it points at the plan's translations, so a collect that sees no link change allocates and copies nothing (one acquire load per report). The protect-failure report intakeFreshmoved out of the lock, since a report can now take it.Tests in
core/libs/prx/libSceAgcDriver/tests/WriteTracking.cpp(agc_write_tracking, Linux only):CheckWriteAfterFreshReportstores from inside the fresh-range report callback and requires the store to be listed;CheckLinkDuringCollectlinks two views from inside the first collect's report callback, stores through the first view and requires the same collect to report the store at the second.Not covered, by design: a store made before an
Aliascall is not fanned out by this change (that is #23976,Watch::Aliasmarking both views fresh).Tested
895760f025, Linux gate on lavapipe and TSan),agc_write_trackingand neighbours: 3 passed, same as main; the same 3 pass under TSan with no report: https://github.com/chitters2004/AnyPS5/actions/runs/446470934648e158a83d9, the new tests without the fixes: both tests indraft/ci-ww-control, fails with "a store made after a fresh range was reported was never reported": https://github.com/chitters2004/AnyPS5/actions/runs/44644271669. With only the first commit's fix plus both tests, fails with "a store through a view linked during a collect was not reported at its alias": https://github.com/chitters2004/AnyPS5/actions/runs/44645409577Watch::Aliasfresh marking); conflicts textually with #12792 inCollectandFanout(it adds anunreachedargument to the same calls), mechanical to resolve.Checklist
main(8e158a83d9); 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
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T06:15:01Z.
Review: APPROVED
Reviewed — looks good
Nothing blocks this change; the Linux write-watch ordering fixes and their regression tests look sound based on the source reviewed.
What I ran
Reviewed head
895760f025bf4ea3737d2f53cb8d2f9be32cc4b4and inspected the prepared diff and targeted source ranges. No commands or tests were run by me; CI results in the description are author-reported.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run locally. The full repository files were not read; the review covered the prepared diff and targeted ranges from
GuestWriteWatch.cppandWriteTracking.cpp. Physical GPU behavior was not verified. The description reports Linux lavapipe and TSan CI results, which I did not independently confirm.To get this to a good state
Nothing is required.