d3d12: return committed guest pages after a failed buffer import retry #576

Merged
csj0oe merged 1 commit from upstream-pr/576 into main 2026-11-30 19:13:43 +00:00
csj0oe commented 2026-11-30 06:57:12 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by csj0oe on 2026-11-30T06:57:12Z.


What

When a buffer import fails, import_with_commit commits the guest pages and retries the same import. Today it commits the whole range even when nothing there is reserved; with this change it commits only the reserved spans and retries only when it committed something.

  • VirtualQuery the range first and commit only the spans that are still reserved.
  • When nothing in the range is reserved, do not commit and do not retry: that failure is not about missing pages. Return the original error unchanged.
  • A failed retry leaves the spans it committed committed, as before. An earlier draft decommitted them; that was removed, because between our commit and a MEM_DECOMMIT a title thread can commit and write the same pages, and the decommit would drop its data.
  • Hold the title's hang watchdog across the commit-and-retry block only; the initial import attempt still runs unpaused.

Why it matters

Measured, not assumed: with this change alone the frame-0 watchdog still fired in one run (run26, exit code 5 after 43.1 s, crash at game_scarlett_master.exe+0x2215C35). The pipeline-pause change is what changed that; this branch does not stop the watchdog, and the earlier claim that it did was wrong.

The remaining value is narrower: an import over a range with nothing reserved no longer pays for a pointless commit and retry, which on a full card repeated across the pages the title had touched. The pause covers the one retry that can still happen.

Verification

  • Four unit tests under GE-Proton: 4 passed.
    • a failed retry leaves the pages it committed committed;
    • an already committed range is not committed or retried;
    • a successful retry keeps the pages committed;
    • a failed retry keeps the title's page and the span it committed.
  • Failing first: with the pre-change commit-everything gate restored, an_already_committed_range_is_not_committed_or_retried fails with 1 retry instead of 0; the other three pass.
  • cargo fmt --all.
  • cargo clippy --locked --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --all-targets -- -D warnings -A clippy::redundant-clone.
  • python build.py d3d12.
  • NVIDIA: check 200 passed, 0 failed on an RTX 5090 (620.70.10, GE-Proton11-14) at head 337669e8, reported by @NickStallman. The current head differs from it by four lines in tests/device/heap_import.rs. That check does not drive a failed import on a full card, so it says nothing about the benefit or the race.
  • python3 tuxbox.py check --no-gpu: 11 passed, 1 failed. The failure is the pre-existing clippy::redundant-clone at runtime/dxbc/src/fssm.rs:121, which this branch does not touch; the package clippy above passes with that lint allowed.

Not run

NVIDIA, and the Lanes / d3d12-* / guest-frame / present GPU suites; no GPU was available in this session.

<!-- greyfinch-sync:brcly/TuxBox:issue:5560568360 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/576). Originally posted by [csj0oe](https://github.com/csj0oe) on 2026-11-30T06:57:12Z. --- ## What When a buffer import fails, `import_with_commit` commits the guest pages and retries the same import. Today it commits the whole range even when nothing there is reserved; with this change it commits only the reserved spans and retries only when it committed something. - `VirtualQuery` the range first and commit only the spans that are still reserved. - When nothing in the range is reserved, do not commit and do not retry: that failure is not about missing pages. Return the original error unchanged. - A failed retry leaves the spans it committed committed, as before. An earlier draft decommitted them; that was removed, because between our commit and a `MEM_DECOMMIT` a title thread can commit and write the same pages, and the decommit would drop its data. - Hold the title's hang watchdog across the commit-and-retry block only; the initial import attempt still runs unpaused. ## Why it matters Measured, not assumed: with this change alone the frame-0 watchdog still fired in one run (run26, exit code 5 after 43.1 s, crash at `game_scarlett_master.exe+0x2215C35`). The pipeline-pause change is what changed that; this branch does not stop the watchdog, and the earlier claim that it did was wrong. The remaining value is narrower: an import over a range with nothing reserved no longer pays for a pointless commit and retry, which on a full card repeated across the pages the title had touched. The pause covers the one retry that can still happen. ## Verification - Four unit tests under GE-Proton: 4 passed. - a failed retry leaves the pages it committed committed; - an already committed range is not committed or retried; - a successful retry keeps the pages committed; - a failed retry keeps the title's page and the span it committed. - Failing first: with the pre-change commit-everything gate restored, `an_already_committed_range_is_not_committed_or_retried` fails with 1 retry instead of 0; the other three pass. - `cargo fmt --all`. - `cargo clippy --locked --target x86_64-pc-windows-msvc -p tuxbox-d3d12 --all-targets -- -D warnings -A clippy::redundant-clone`. - `python build.py d3d12`. - NVIDIA: `check` 200 passed, 0 failed on an RTX 5090 (620.70.10, GE-Proton11-14) at head `337669e8`, reported by @NickStallman. The current head differs from it by four lines in `tests/device/heap_import.rs`. That check does not drive a failed import on a full card, so it says nothing about the benefit or the race. - `python3 tuxbox.py check --no-gpu`: 11 passed, 1 failed. The failure is the pre-existing `clippy::redundant-clone` at `runtime/dxbc/src/fssm.rs:121`, which this branch does not touch; the package clippy above passes with that lint allowed. ## Not run NVIDIA, and the Lanes / `d3d12-*` / `guest-frame` / `present` GPU suites; no GPU was available in this session.
brcly commented 2026-11-30 09:41:14 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by brcly on 2026-11-30T09:41:14Z.


Thanks. The tests are good, and skipping the retry when nothing in the range is reserved is a clear improvement. I'm holding the PR for now, though, because the part with the most risk is also the part whose benefit hasn't been shown.

  1. The benefit isn't measured yet. The description says nothing here makes the import succeed. Its stated effect is that the title's watchdog at +0x2215C35 stops firing. Could you boot your 7.5 GB card before and after, and say whether the frame-0 crash goes away? A log showing the watchdog firing while the commit-and-retry runs would also help, because the crash may come from the failed import itself rather than from time spent inside it.
  2. Decommitting brings the retry loop back. After a failed retry the range is reserved again, so the next import over the same pages commits, retries and decommits all over again. Before this change, the second attempt at least found the pages committed. On a full card that repeats every time, so the "loop across the pages the title had touched" isn't stopped for reserved ranges. It's only stopped for ranges that were already committed.
  3. Decommitting can race the title. Between our commit and our MEM_DECOMMIT, a title thread can commit and write the same pages. Its commit succeeds silently because the pages are already committed. Our decommit then drops its data, and its next access faults. The window is small, but the old code couldn't lose title memory this way.

The simplest version that is clearly safe would keep only the reserved_spans check (no commit and no retry when nothing is reserved) plus the watchdog pause. The decommit could follow in a separate PR once a run shows it's needed. If you'd rather keep the decommit, please show a boot with it and explain how (3) is ruled out.

<!-- greyfinch-sync:brcly/TuxBox:comment:7274548012 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/576#issuecomment-7274548012). Originally posted by [brcly](https://github.com/brcly) on 2026-11-30T09:41:14Z. --- Thanks. The tests are good, and skipping the retry when nothing in the range is reserved is a clear improvement. I'm holding the PR for now, though, because the part with the most risk is also the part whose benefit hasn't been shown. 1. **The benefit isn't measured yet.** The description says nothing here makes the import succeed. Its stated effect is that the title's watchdog at `+0x2215C35` stops firing. Could you boot your 7.5 GB card before and after, and say whether the frame-0 crash goes away? A log showing the watchdog firing *while* the commit-and-retry runs would also help, because the crash may come from the failed import itself rather than from time spent inside it. 2. **Decommitting brings the retry loop back.** After a failed retry the range is reserved again, so the next import over the same pages commits, retries and decommits all over again. Before this change, the second attempt at least found the pages committed. On a full card that repeats every time, so the "loop across the pages the title had touched" isn't stopped for reserved ranges. It's only stopped for ranges that were already committed. 3. **Decommitting can race the title.** Between our commit and our `MEM_DECOMMIT`, a title thread can commit and write the same pages. Its commit succeeds silently because the pages are already committed. Our decommit then drops its data, and its next access faults. The window is small, but the old code couldn't lose title memory this way. The simplest version that is clearly safe would keep only the `reserved_spans` check (no commit and no retry when nothing is reserved) plus the watchdog pause. The decommit could follow in a separate PR once a run shows it's needed. If you'd rather keep the decommit, please show a boot with it and explain how (3) is ruled out.
csj0oe commented 2026-11-30 09:58:35 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by csj0oe on 2026-11-30T09:58:35Z.


Took your simpler version, and this is now the whole change:

  • GuestCommit::commit still VirtualQuerys the range and commits only the spans that are reserved.
  • When nothing is reserved, no commit and no retry; the original error is returned unchanged.
  • The retry is still paused across the watchdog, but the decommit is gone entirely — roll_back, disarm, the Drop impl and MEM_DECOMMIT are removed. A failed retry leaves the pages committed, and the log line says kept them committed instead of claiming a rollback.
  • commit_guest_pages keeps its old meaning for the placed-image caller: true when it committed or the range is already valid.

On your first point, I cannot offer a before/after boot that credits this change, and I am not going to imply one: with this branch alone the frame-0 watchdog still fired (run26, exit code 5 at 43.1 s, crash at game_scarlett_master.exe+0x2215C35). The body now says that instead of the old claim.

Measured on the branch, four tests under GE-Proton (4 passed): a_failed_retry_leaves_the_pages_it_committed (asserts MEM_COMMIT/PAGE_READWRITE across the range after a failed retry), an_already_committed_range_is_not_committed_or_retried (data stays 0x5a), a_failed_retry_keeps_the_title_page_and_the_span_it_committed (both stay committed), and the success case.

Failing first: with the pre-change gate (if !commit_guest_pages(base, bytes) { return None; }) restored in a throwaway copy, an_already_committed_range_is_not_committed_or_retried fails with retries left: 1, right: 0; with the branch code it passes. The other three pass on both, so that one is the gate this change actually moves.

<!-- greyfinch-sync:brcly/TuxBox:comment:7274940990 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/576#issuecomment-7274940990). Originally posted by [csj0oe](https://github.com/csj0oe) on 2026-11-30T09:58:35Z. --- Took your simpler version, and this is now the whole change: - `GuestCommit::commit` still `VirtualQuery`s the range and commits only the spans that are reserved. - When nothing is reserved, no commit and no retry; the original error is returned unchanged. - The retry is still paused across the watchdog, but the decommit is gone entirely — `roll_back`, `disarm`, the `Drop` impl and `MEM_DECOMMIT` are removed. A failed retry leaves the pages committed, and the log line says `kept them committed` instead of claiming a rollback. - `commit_guest_pages` keeps its old meaning for the placed-image caller: true when it committed or the range is already valid. On your first point, I cannot offer a before/after boot that credits this change, and I am not going to imply one: with this branch alone the frame-0 watchdog still fired (run26, exit code 5 at 43.1 s, crash at `game_scarlett_master.exe+0x2215C35`). The body now says that instead of the old claim. Measured on the branch, four tests under GE-Proton (4 passed): `a_failed_retry_leaves_the_pages_it_committed` (asserts `MEM_COMMIT`/`PAGE_READWRITE` across the range after a failed retry), `an_already_committed_range_is_not_committed_or_retried` (data stays `0x5a`), `a_failed_retry_keeps_the_title_page_and_the_span_it_committed` (both stay committed), and the success case. Failing first: with the pre-change gate (`if !commit_guest_pages(base, bytes) { return None; }`) restored in a throwaway copy, `an_already_committed_range_is_not_committed_or_retried` fails with retries `left: 1, right: 0`; with the branch code it passes. The other three pass on both, so that one is the gate this change actually moves.
NickStallman commented 2026-11-30 10:06:29 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by NickStallman on 2026-11-30T10:06:29Z.


@csj0oe NVIDIA check, RTX 5090 (10de:2b85, 620.70.10, GE-Proton11-14), full python tuxbox.py check at 337669e8 (your earlier head, on e5d2e913): 200 pass, 0 fail. The current head d58798e8 differs only by four lines in tests/device/heap_import.rs, which I haven't run. This says nothing about brcly's question on the race or on the benefit; the check doesn't drive a failed import on a full card.

Evidence: TuxBox check of 337669e8c6, no uncommitted changes, GPU 10de:2b85: 16 passed, 0 failed, 0 not run

<!-- greyfinch-sync:brcly/TuxBox:comment:7275134977 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/576#issuecomment-7275134977). Originally posted by [NickStallman](https://github.com/NickStallman) on 2026-11-30T10:06:29Z. --- @csj0oe NVIDIA check, RTX 5090 (`10de:2b85`, 620.70.10, GE-Proton11-14), full `python tuxbox.py check` at 337669e8 (your earlier head, on e5d2e913): **200 pass, 0 fail**. The current head d58798e8 differs only by four lines in `tests/device/heap_import.rs`, which I haven't run. This says nothing about brcly's question on the race or on the benefit; the check doesn't drive a failed import on a full card. Evidence: TuxBox check of 337669e8c611, no uncommitted changes, GPU 10de:2b85: 16 passed, 0 failed, 0 not run
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!576
No description provided.