xcrdapi: a TO_PAGES read keeps page tokens the array held at enqueue, though the title fills the array after enqueueing #457

Closed
opened 2026-11-29 07:54:19 +00:00 by Jerkin42 · 1 comment
Jerkin42 commented 2026-11-29 07:54:19 +00:00 (Migrated from github.com)
Contributor

Imported from brcly/TuxBox. Originally posted by Jerkin42 on 2026-11-29T07:54:19Z.


Seen on: RX 9060 XT (RADV), ProjectScarlett 1.0.2.1, first on main b8355fa2 with open PRs of the time; page_tokens() is unchanged on main 28717263.

What the code does. queue.rs capture() snapshots a TO_PAGES request's token array at enqueue, because "the title may reuse it after enqueueing". When the request runs, page_tokens() reads the array again, but only to fill entries that were 0 at enqueue. An entry that was non-zero at enqueue keeps its enqueue-time value.

What the title does. It fills page arrays after enqueueing them, thousands of times per run ("page array #8193 … was filled after its request was enqueued: [0x0] then, [0x…] when it ran"). An array whose memory still holds an earlier request's tokens at enqueue is non-zero then, so the snapshot keeps the earlier request's pages, and the read lands there:

  • in one run, a local log of entries that changed from one non-zero token to another while the request was queued fired 42 times before the opening mission started. The first was array 0x54b7738: [0x72b00] at enqueue, [0x73c50] when the request ran.

On the console the DMA engine reads the page array when the request executes, so the run-time contents are the ones that count.

Possible effect. The read writes into pages that now belong to another allocation, and the intended destination keeps stale bytes. In our runs the game later stops in its resource pointer fix-up (an int3 when a pointer lies in none of the resource's regions; the pointer was 0x69689788 against regions at most 0x1630 long), or reads a -1 pointer, about 90 game frames after the first story mission starts. Re-reading the array at run time (below) did not move that crash, so we can't say this bug causes it. It is a correctness problem either way.

Local change we ran. In page_tokens(), always read the array when the request runs and prefer each live non-zero entry, falling back to the snapshot only where the live entry is 0. Happy to open a PR with a unit test if that's the right reading of the contract, or to hear why the enqueue snapshot is needed (a title that rewrites the array for a later request before this one runs?).

<!-- greyfinch-sync:brcly/TuxBox:issue:6676347538 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/457). Originally posted by [Jerkin42](https://github.com/Jerkin42) on 2026-11-29T07:54:19Z. --- **Seen on:** RX 9060 XT (RADV), ProjectScarlett 1.0.2.1, first on `main` b8355fa2 with open PRs of the time; `page_tokens()` is unchanged on `main` 28717263. **What the code does.** `queue.rs` `capture()` snapshots a TO_PAGES request's token array at enqueue, because "the title may reuse it after enqueueing". When the request runs, `page_tokens()` reads the array again, but only to fill entries that were **0** at enqueue. An entry that was non-zero at enqueue keeps its enqueue-time value. **What the title does.** It fills page arrays after enqueueing them, thousands of times per run ("page array #8193 … was filled after its request was enqueued: [0x0] then, [0x…] when it ran"). An array whose memory still holds an earlier request's tokens at enqueue is non-zero then, so the snapshot keeps the **earlier request's pages**, and the read lands there: - in one run, a local log of entries that changed from one non-zero token to another while the request was queued fired **42 times** before the opening mission started. The first was array 0x54b7738: `[0x72b00]` at enqueue, `[0x73c50]` when the request ran. On the console the DMA engine reads the page array when the request executes, so the run-time contents are the ones that count. **Possible effect.** The read writes into pages that now belong to another allocation, and the intended destination keeps stale bytes. In our runs the game later stops in its resource pointer fix-up (an `int3` when a pointer lies in none of the resource's regions; the pointer was `0x69689788` against regions at most 0x1630 long), or reads a `-1` pointer, about 90 game frames after the first story mission starts. Re-reading the array at run time (below) did not move that crash, so we can't say this bug causes it. It is a correctness problem either way. **Local change we ran.** In `page_tokens()`, always read the array when the request runs and prefer each live non-zero entry, falling back to the snapshot only where the live entry is 0. Happy to open a PR with a unit test if that's the right reading of the contract, or to hear why the enqueue snapshot is needed (a title that rewrites the array for a *later* request before this one runs?).
NickStallman commented 2026-11-29 12:19:19 +00:00 (Migrated from github.com)
Author
Contributor

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-29T12:19:19Z.


Now that it has merged, a game run with it on an RTX 5090 (a build on main d2eb99ed with #462, #463, #455, #461 and others; one run, about 7 minutes after the first story load): replaced_pages was logged on 20 sampled lines, and the counter passed #16385. So a title replacing non-zero tokens after EnqueueRequest is the normal case here, not a rare one:

page array #1 at 0x57b70e8 replaced non-zero tokens after its request was enqueued: [0x7ec10] then, [0x7fd60] when it ran
page array #16385 at 0x55d0358 replaced non-zero tokens after its request was enqueued: [0xc9200 0x1815f0] then, [0xeadf0 0xeae00] when it ran

Every one of those writes would have gone to a stale page before. My earlier builds only logged the zero-to-filled kind, so they couldn't see this. I can't tell which of my older crashes it explains. This run had none of the title CPU crashes; it ended on an Xid 109 timeout instead.

<!-- greyfinch-sync:brcly/TuxBox:comment:7255727327 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/issues/457#issuecomment-7255727327). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-29T12:19:19Z. --- Now that it has merged, a game run with it on an RTX 5090 (a build on `main` `d2eb99ed` with #462, #463, #455, #461 and others; one run, about 7 minutes after the first story load): `replaced_pages` was logged on 20 sampled lines, and the counter passed #16385. So a title replacing non-zero tokens after `EnqueueRequest` is the normal case here, not a rare one: page array #1 at 0x57b70e8 replaced non-zero tokens after its request was enqueued: [0x7ec10] then, [0x7fd60] when it ran page array #16385 at 0x55d0358 replaced non-zero tokens after its request was enqueued: [0xc9200 0x1815f0] then, [0xeadf0 0xeae00] when it ran Every one of those writes would have gone to a stale page before. My earlier builds only logged the zero-to-filled kind, so they couldn't see this. I can't tell which of my older crashes it explains. This run had none of the title CPU crashes; it ended on an Xid 109 timeout instead.
Sign in to join this conversation.
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#457
No description provided.