Repository navigation
Conversation
Concurrent first registrations could observe the early inited flag before page geometry and hooks were ready. Publish initialization with pthread_once and cover partial initialization, actual fault/pre-write tracking, and simultaneous first calls with a fresh-process CPU/TSan fixture. Co-authored-by: Adam Kratch <70729875+akratch@users.noreply.github.com>
…2225) The page size, the timebase and both hooks (page fault, host pre-write) were set by the first nvn_dirty_add_range behind a plain flag, published before the geometry and the hooks and with no lock. A pool registered on another thread at that moment could get zero geometry or return before the hooks existed, and a host write into guest memory on another thread (hle_fs.c reading a file) read crash.c's hook table while that registration grew it, unsynchronized. They are now set by a load-time constructor, on one thread before main, so every registration, fault and host pre-write sees them complete; a game with no memory pool runs hooks that scan an empty table. t_dirty_init (new, with tsan-dirty-init, both in CI): eight threads register their first pools at once while another keeps doing host pre-writes; each pool must be tracked and see a direct write (fault hook) and a host write (pre-write hook). This code: 20/20 runs, 10/10 under ThreadSanitizer. Main's nvn_dirty.c under ThreadSanitizer: 5/5 runs report the race on inited, one earlier run the hook-table race at crash.c:139; without it 20/20 pass (the window is too narrow to hit unforced). t_dirty_slots, t_dirty_race, t_dirty_retire_race pass. Not run: a game, a full host build, iOS. Open: TSan also reports a race between reusing a pool slot (nvn_dirty_add_range writes the plain base/end) and a fault or pre-write scan that read the slot as live before it was retired; that is the lock-free table's design and is not changed here. The diagnosis is PR #2225's (the early flag, with a pthread_once fix and a fixture); the load-time setup, the hook-table race and this test are new here. Co-authored-by: akratch <70729875+akratch@users.noreply.github.com>
|
Thank you — the diagnosis is right, and it landed on main as de2018e, with you credited as co-author. It landed in a different form. The first pool registration was also where both hooks were added to crash.c's hook table, which
One more finding from this: TSan also reports a race when a pool slot is reused while a fault or pre-write scan is still reading it. That is part of the lock-free table's design and is listed as open in the commit message. |
…y pools are published (seedds) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
seedds#2182, seedds#2225, seedds#2194, seedds#2273 (mkw/sets.tsv) Each corrects wrong behaviour on code this game runs and brings a test that fails without it or a measurement; none changes the shader chain. Built on this Mac with 58 warnings as upstream; t_fstep passes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
…earlier case is in flight cut_boundary_case expects a commit "with nothing running", which the queue reads from g_seg_inflight. An earlier case's mtl_wait can return on the GPU's own signal of its fence (the early waiter, post_complete) before that command buffer's feedback handler has counted it out of g_seg_inflight; the handler comes about 0.3 ms after the GPU's end. The case then saw work still running and failed: on mkw-fin and every branch after it, from the first commit git bisect named, 2d35c08 (pull request seedds#2225: dirty tracking set up once before memory pools are published), which moved that timing; the base 352e4a6 passes. The host's count is right, the case read it too early. The case now waits for the count to reach 0 (up to 5 s) and checks that it did. t_feedback: 279 checks, 0 failed, in three runs of three. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
…y pools are published (seedds) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
seedds#2182, seedds#2225, seedds#2194, seedds#2273 (mkw/sets.tsv) Each corrects wrong behaviour on code this game runs and brings a test that fails without it or a measurement; none changes the shader chain. Built on this Mac with 58 warnings as upstream; t_fstep passes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
…earlier case is in flight cut_boundary_case expects a commit "with nothing running", which the queue reads from g_seg_inflight. An earlier case's mtl_wait can return on the GPU's own signal of its fence (the early waiter, post_complete) before that command buffer's feedback handler has counted it out of g_seg_inflight; the handler comes about 0.3 ms after the GPU's end. The case then saw work still running and failed: on mkw-fin and every branch after it, from the first commit git bisect named, b3e07bb (pull request seedds#2225: dirty tracking set up once before memory pools are published), which moved that timing; the base 352e4a6 passes. The host's count is right, the case read it too early. The case now waits for the count to reach 0 (up to 5 s) and checks that it did. t_feedback: 279 checks, 0 failed, in three runs of three. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
…y pools are published (seedds) Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
seedds#2182, seedds#2225, seedds#2194, seedds#2273 (mkw/sets.tsv) Each corrects wrong behaviour on code this game runs and brings a test that fails without it or a measurement; none changes the shader chain. Built on this Mac with 58 warnings as upstream; t_fstep passes. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
…earlier case is in flight cut_boundary_case expects a commit "with nothing running", which the queue reads from g_seg_inflight. An earlier case's mtl_wait can return on the GPU's own signal of its fence (the early waiter, post_complete) before that command buffer's feedback handler has counted it out of g_seg_inflight; the handler comes about 0.3 ms after the GPU's end. The case then saw work still running and failed: on mkw-fin and every branch after it, from the first commit git bisect named, b3e07bb (pull request seedds#2225: dirty tracking set up once before memory pools are published), which moved that timing; the base 352e4a6 passes. The host's count is right, the case read it too early. The case now waits for the count to reach 0 (up to 5 s) and checks that it did. t_feedback: 279 checks, 0 failed, in three runs of three. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JcmewFJDrDUooyBk9ygMAv
What and why
Concurrent first memory-pool registrations could observe an early initialization flag before dirty-tracker page geometry and both write hooks existed. The controlled reproduction leaves the second pool untracked; simultaneous first calls also race on the plain flag.
Publish initialization with
pthread_oncebefore registering any range. The signal handler does not enter the once. Page protection, generation stamps, pool lifetime and shader behavior are unchanged. This was found in an OOT source review and reproduced synthetically; it is not attributed to the reported terrain or lighting artifacts.See Concurrent first memory pools see incomplete dirty tracking.
Checked
inited. The standalone checks below ran on2d35c083dd95b3c42f3b7f2fc6c98fddd8f4b389against exact base4c574a6f055217ac0b6d5fbeccd1eb22b86dbe90; the negative control replaced onlynvn_dirty.cwith that base version and forced a rebuild. The integrated versione6fabaa695fcacb2ccfb12076bdb3acffa0e33b4independently passed the same checks plus ten fresh controlled runs and ten TSan concurrent runs; those repeats are separate evidence.getpagesizeinitialization seam and observespthread_onceentry without replacing its behavior. It does not reset tracker state. Actual protected writes and host pre-writes exercise the production crash hooks.memory-dirtypasses shared-page recommit, copyback and concurrent-protection checks.regress.py impact: Breath of the Wild, Pokémon Scarlet and Tears of the Kingdom use the affected pool entry points; 153 profiles lack usage manifests. Game regression runs remain pending.Docs