xcrdapi: prefer live non-zero page tokens when TO_PAGES reads run #465

Merged
DrArroway merged 1 commit from upstream-pr/465 into main 2026-11-29 11:26:28 +00:00
DrArroway commented 2026-11-29 11:11:52 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by DrArroway on 2026-11-29T11:11:52Z.


Summary

Fixes #457 (crediting @Jerkin42's report and diagnosis).

TO_PAGES requests can point into reused page-token arrays that still hold stale non-zero tokens at EnqueueRequest and are overwritten with new tokens before Submit. Previously, Read::page_tokens only re-read the array when the enqueue snapshot contained 0, and kept every non-zero enqueue entry, causing writes to land in stale pages.

  • runtime/xcrdapi/src/queue.rs: Always re-read the live page-token array via ReadProcessMemory when a TO_PAGES request runs and prefer every live non-zero entry (merge_page_tokens), falling back to the enqueue snapshot only when an entry was cleared to 0 or the array is unreadable.
  • runtime/xcrdapi/src/diag.rs: Add diag::replaced_pages with its own capped counter so arrays whose non-zero tokens changed after EnqueueRequest are logged separately from zero-to-nonzero late_pages fills (log_page_change).
  • runtime/xcrdapi/src/tests/queue.rs: Add unit tests covering late fills, replaced non-zero tokens, cleared-to-zero fallback, and mixed multi-page arrays.
  • runtime/xcrdapi/guest.cpp & project_tuxbox/verify.py: Extend the xcrdapi guest fixture (pages=3) to enqueue a reused array whose non-zero token is overwritten before Submit, verifying the write lands in the new page and does not overwrite the stale page.

Tested

  • The checks relevant to this change passed
  • Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below (xcrdapi is a storage provider covered by its own guest fixture xcrdapi-read.exe, extended here from pages=2 to pages=3, plus Rust unit tests in runtime/xcrdapi/src/tests/queue.rs)
  • Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: xcrdapi is CPU/storage-only (tested on both AMD adapters below; native Windows / NVIDIA still need to run if desired)

GPU, driver and backend:

  • AMD Radeon RX 6900 XT (1002:73bf), Mesa RADV 26.3.1, GE-Proton11-14 (Linux 7.3.6)
  • AMD Raphael Radeon 610M (1002:164e), Mesa RADV 26.3.1, GE-Proton11-14 (Linux 7.3.6)

Commands run and their results:

tuxbox.py verify --only xcrdapi --adapter 1002:73bf
  PASS  xcrdapi  (raw=16 zlib=16 guards=2 errors=2 cancellation=2 bc1=4 bc7=2 pages=3 autosubmit=64 PASS)

tuxbox.py verify --only xcrdapi --adapter 1002:164e
  PASS  xcrdapi  (raw=16 zlib=16 guards=2 errors=2 cancellation=2 bc1=4 bc7=2 pages=3 autosubmit=64 PASS)

tuxbox-xcrdapi --lib (Windows unit tests under GE-Proton11-14 wine)
  4 passed; 0 failed; 0 ignored

cargo check --locked --target x86_64-pc-windows-msvc -p tuxbox-xcrdapi
  passed

cargo test --locked --target x86_64-unknown-linux-gnu -p tuxbox-xcrdapi-codec
  18 passed; 0 failed

python -m unittest tests.test_repository_hygiene tests.test_verify -q
  Ran 22 tests: OK

ProjectScarlett 1.0.2.1 (offline, 3840x2160, RX 6900 XT 1002:73bf, clean main 75453953 + this branch)
  360.3s, 1,353 presented frames: >4,096 replaced non-zero token arrays caught (#1 [0x7ec40] -> [0x7fd90] through #4097 [0x5fd60] -> [0x1808b0]) alongside >20,481 late_pages zero-to-nonzero fills, 0 xcrdapi execution failures.
<!-- greyfinch-sync:brcly/TuxBox:issue:5550138359 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/465). Originally posted by [DrArroway](https://github.com/DrArroway) on 2026-11-29T11:11:52Z. --- ## Summary Fixes #457 (crediting `@Jerkin42`'s report and diagnosis). `TO_PAGES` requests can point into reused page-token arrays that still hold stale non-zero tokens at `EnqueueRequest` and are overwritten with new tokens before `Submit`. Previously, `Read::page_tokens` only re-read the array when the enqueue snapshot contained `0`, and kept every non-zero enqueue entry, causing writes to land in stale pages. - `runtime/xcrdapi/src/queue.rs`: Always re-read the live page-token array via `ReadProcessMemory` when a `TO_PAGES` request runs and prefer every live non-zero entry (`merge_page_tokens`), falling back to the enqueue snapshot only when an entry was cleared to `0` or the array is unreadable. - `runtime/xcrdapi/src/diag.rs`: Add `diag::replaced_pages` with its own capped counter so arrays whose non-zero tokens changed after `EnqueueRequest` are logged separately from zero-to-nonzero `late_pages` fills (`log_page_change`). - `runtime/xcrdapi/src/tests/queue.rs`: Add unit tests covering late fills, replaced non-zero tokens, cleared-to-zero fallback, and mixed multi-page arrays. - `runtime/xcrdapi/guest.cpp` & `project_tuxbox/verify.py`: Extend the `xcrdapi` guest fixture (`pages=3`) to enqueue a reused array whose non-zero token is overwritten before `Submit`, verifying the write lands in the new page and does not overwrite the stale page. ## Tested - [x] The checks relevant to this change passed - [x] Changed or new behaviour is covered by a Lanes scenario, or the reason it cannot be is stated below (`xcrdapi` is a storage provider covered by its own guest fixture `xcrdapi-read.exe`, extended here from `pages=2` to `pages=3`, plus Rust unit tests in `runtime/xcrdapi/src/tests/queue.rs`) - [ ] Where the table calls for AMD and NVIDIA, they passed on both. Otherwise, say which vendor still needs to run them: `xcrdapi` is CPU/storage-only (tested on both AMD adapters below; native Windows / NVIDIA still need to run if desired) GPU, driver and backend: - AMD Radeon RX 6900 XT (`1002:73bf`), Mesa RADV 26.3.1, `GE-Proton11-14` (Linux 7.3.6) - AMD Raphael Radeon 610M (`1002:164e`), Mesa RADV 26.3.1, `GE-Proton11-14` (Linux 7.3.6) Commands run and their results: ```text tuxbox.py verify --only xcrdapi --adapter 1002:73bf PASS xcrdapi (raw=16 zlib=16 guards=2 errors=2 cancellation=2 bc1=4 bc7=2 pages=3 autosubmit=64 PASS) tuxbox.py verify --only xcrdapi --adapter 1002:164e PASS xcrdapi (raw=16 zlib=16 guards=2 errors=2 cancellation=2 bc1=4 bc7=2 pages=3 autosubmit=64 PASS) tuxbox-xcrdapi --lib (Windows unit tests under GE-Proton11-14 wine) 4 passed; 0 failed; 0 ignored cargo check --locked --target x86_64-pc-windows-msvc -p tuxbox-xcrdapi passed cargo test --locked --target x86_64-unknown-linux-gnu -p tuxbox-xcrdapi-codec 18 passed; 0 failed python -m unittest tests.test_repository_hygiene tests.test_verify -q Ran 22 tests: OK ProjectScarlett 1.0.2.1 (offline, 3840x2160, RX 6900 XT 1002:73bf, clean main 75453953 + this branch) 360.3s, 1,353 presented frames: >4,096 replaced non-zero token arrays caught (#1 [0x7ec40] -> [0x7fd90] through #4097 [0x5fd60] -> [0x1808b0]) alongside >20,481 late_pages zero-to-nonzero fills, 0 xcrdapi execution failures. ```
NickStallman commented 2026-11-29 11:20:18 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T11:20:18Z.


Useful timing: I've queued the full NVIDIA check of fc69bc23 on an RTX 5090 (it includes the xcrdapi fixture) and will post it.

One data point from my own runs, which neither proves nor disproves #457: our build logs only the zero-to-filled case ("page array #N ... was filled after its request was enqueued"). In four ProjectScarlett runs on the 5090 that ended in a title CPU crash it went past #24577 in each, and every entry in the log's sampled lines was 0x0 at enqueue. A replaced non-zero token would not have been logged at all: that build has no line for it. Your replaced_pages counter is what can say whether those crashes are the same thing, so I'll put this branch in my next game build and post what it counts.

<!-- greyfinch-sync:brcly/TuxBox:comment:7255042589 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/465#issuecomment-7255042589). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T11:20:18Z. --- Useful timing: I've queued the full NVIDIA check of `fc69bc23` on an RTX 5090 (it includes the `xcrdapi` fixture) and will post it. One data point from my own runs, which neither proves nor disproves #457: our build logs only the zero-to-filled case ("page array #N ... was filled after its request was enqueued"). In four ProjectScarlett runs on the 5090 that ended in a title CPU crash it went past #24577 in each, and every entry in the log's sampled lines was `0x0` at enqueue. A replaced non-zero token would not have been logged at all: that build has no line for it. Your `replaced_pages` counter is what can say whether those crashes are the same thing, so I'll put this branch in my next game build and post what it counts.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
brcly/TuxBox!465
No description provided.