Skip to content

kernelx: keep physical page release local to the page ID - #608

Open
Babyhamsta wants to merge 1 commit into
xcl-dev:mainfrom
Babyhamsta:fix/physical-page-liveness
Open

Babyhamsta wants to merge 1 commit into
xcl-dev:mainfrom
Babyhamsta:fix/physical-page-liveness

Conversation

@Babyhamsta

@Babyhamsta Babyhamsta commented Nov 24, 2026 •

Copy link
Copy Markdown

Freeing one physical page twice could retire a sibling the title still owned. A freed page could also continue resolving to its home until the last page in the allocation was released. Related PR #187 addressed when XCL returns backing memory.

What is in it

  • Track released page IDs with a bitmap in kernelx.rs. Preserve the existing return convention for repeated frees and permit repeated reads of live IDs. Tests cover reads, writes, mapping, and IDs on either side of a bitmap word boundary.

Tested

  • Windows 11 build 26300.9974, Core i7-13700K, RTX 4070 (621.35), Rust 1.94.1 MSVC. Debug workspace build passed. cargo test --workspace -- --test-threads=4 --show-output reported 686 passed, 0 failed, 41 ignored. Two passes reported SKIPPED for unavailable wave64 execution (gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware).
  • Release smoke tests used isolated data, networking off, the upstream default device profile, and the same title and duration. A separate fresh 1080p Lockhart run on each revision stopped at the same title breakpoint after about 19 seconds.

Regression run

Main

xcl-smoke v1
commit: 9ce2070eccf436d7bd38601c90407da447df34f3
gpu: NVIDIA GeForce RTX 4070
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 558 (PresentX 558)
presents per 2 s (last 3): 19 17 22
device removals: 0
crashes: 0
peak commit: 15502 MB

PR head

xcl-smoke v1
commit: 2a3c7f4c09ee70667f6dcb39ebef77f38d3ecec3
gpu: NVIDIA GeForce RTX 4070
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 607 (PresentX 607)
presents per 2 s (last 3): 18 19 19
device removals: 0
crashes: 0
peak commit: 15489 MB

Not tested

AMD or Intel GPUs, playable world loading, and how often retail titles repeat a release.

AI use

Codex (GPT-6.2 Sol) implemented the fix and regression tests. Codex (GPT-6) reviewed the diff, checked related PRs, ran the smoke comparison, and prepared this description.

Track released IDs within each allocation so a duplicate cannot consume a live sibling. Reject released IDs in home lookups while preserving repeated lookup of live pages.

Assisted-by: Codex (GPT-6.2 Sol)
@Kalmarv

Kalmarv commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Tested 2a3c7f4 merged onto main bdab194 (merge 6bff65c, no conflicts). The fix does what the description says, and both new tests test it.

  • Control on main: repeated_physical_page_release_preserves_live_siblings, added alone to main bdab194, fails at assert!(!read_physical_pages(&[first], 0, &mut bytes)): a page freed twice is still read. It passes on the merge. The other new test uses PhysicalBlock, so it does not compile on main.
  • Mutation: with free_page counting a page that is already freed again (main's behaviour), both new tests fail: the bitmap test at !block.free_page(boundary), the other at the read of the sibling.
  • Lock order, from reading: FreeTitlePhysicalPages now holds AWAY and PHYS_BLOCKS together. Read, write and map take AWAY first and PHYS_BLOCKS inside page_home, so the order is the same everywhere. note_mapping_at under both locks takes only the mirrors' own lock, and nothing under that lock takes these two.

One small thing, a question more than a finding: the block that drops a freed page's mapping away from home moved inside the new liveness check, and no kernelx test reaches it. With that block taken out, all 25 kernelx tests still pass, the two new ones included. Could the new test map sibling at an address of its own before freeing it and check physical_page_at afterwards?

Tested

RTX 5070 Ti (NVIDIA 610.74), Ryzen 9 9950X, Windows 11 26200, debug.

  • cargo build --workspace, then cargo test --workspace -- --test-threads=4 on the merge 6bff65c: 689 passed, 0 failed, 41 ignored. SKIPPED on this card: gpu_geometry_wave32_prefix_count_over_a_mask and gpu_wave32_program_in_wave64_hardware (no wave64).
  • The kernelx unit tests (each variant's lib test binary, run with the filter kernelx::tests), 2 runs each, same result both times:
    • merge 6bff65c: 25 passed, 0 failed, 1 ignored;
    • main bdab194 with the one test that compiles there: 23 passed, 1 failed;
    • merge with a repeated free counted again: 23 passed, 2 failed;
    • merge without the block that drops a freed page's mapping: 25 passed, 0 failed.
  • scripts/pr_check.py from main on the description: ok.

Not tested

  • A title: nothing here says how often one frees a page twice.
  • Two threads freeing and mapping at once. The lock order above is from reading.
  • AMD and Intel.

Title smoke run

  • Windows 11 Pro 25H2 (build 26200), AMD Ryzen 9 9950X, 32 GB RAM, NVIDIA GeForce RTX 5070 Ti (driver 610.74), Rust 1.99.0, release builds (cargo build --release -p xcl) from clean checkouts
  • main: 9ce2070eccf436d7bd38601c90407da447df34f3 (this PR's base); PR head: 2a3c7f4c09ee70667f6dcb39ebef77f38d3ecec3, no uncommitted changes
  • scripts/smoke.ps1 -Game <title folder> -Seconds 60 on a retail title, two pairs back to back, main first in each, after one 60 s warm-up run of main; all four runs start from the same learned coherent-window size
  • Pair 1: PR 1605 frames vs main 1577 (102 %), peak commit 14458 vs 16496 MB. Pair 2: PR 1549 vs main 1573 (98 %), peak commit 14555 vs 14429 MB (101 %). 0 crashes and 0 device removals in all four runs, all exited 0x0
  • No scripted input in any of these runs (no XCL_PRESS_AT). After its first load the title waits on its account picker (a steady 780 draws per 2 s, no file reads) for an A press, and the only presses were by hand at the test machine: the first A came at 32.8 s in the warm-up (next load from 34 s); pair 1 main 29.3 s (from 30 s), PR 57.4 s (from 58 s); pair 2 no press on either side, so both sat on the picker to the 60 s end. The PR's later load in pair 1 is the later hand press, not this PR. Pair 1's peak-commit gap follows it: main's 16496 MB comes after its second load, which the PR reached only at 58 s; in pair 2, where neither side got past the picker, the peaks match

Pair 1, main:

xcl-smoke v1
commit: 9ce2070eccf436d7bd38601c90407da447df34f3
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1577 (PresentX 1577)
presents per 2 s (last 3): 53 60 60
device removals: 0
crashes: 0
peak commit: 16496 MB

Pair 1, PR:

xcl-smoke v1
commit: 2a3c7f4c09ee70667f6dcb39ebef77f38d3ecec3
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1605 (PresentX 1605)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14458 MB

Pair 2, main:

xcl-smoke v1
commit: 9ce2070eccf436d7bd38601c90407da447df34f3
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1573 (PresentX 1573)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14429 MB

Pair 2, PR:

xcl-smoke v1
commit: 2a3c7f4c09ee70667f6dcb39ebef77f38d3ecec3
gpu: NVIDIA GeForce RTX 5070 Ti
title: GTA VI
seconds: 60
exit: 0x0
frames shown: 1549 (PresentX 1549)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14555 MB

Not tested: whether the title freed any physical pages in these runs, or freed one twice. It imports XMemAllocatePhysicalPages, XMemFreePhysicalPages, XMemMapPhysicalPages and XMemMapPhysicalPagesScatter, which xcl serves through the functions this PR changes, but the log has no count of those calls and no AllocateTitlePhysicalPages(...): no room line in any run, so these runs do not show the duplicate release this PR guards against. They ran on native Windows on an RTX 5070 Ti only; no AMD GPUs.

🤖 Claude Fable 5.2

@MesshM

MesshM commented Nov 24, 2026

Copy link
Copy Markdown

Test run of 2a3c7f4c09ee70667f6dcb39ebef77f38d3ecec3 on AMD RDNA4. I merged it onto current main dd2ae9a locally (clean merge) and tested that tree.

Tested

  • AMD Radeon RX 9060 XT 16 GB (RDNA4), driver 32.0.32029.2010; Ryzen 7 5700X, 64 GB RAM, Windows 11 Pro build 26200, Rust 1.100.0 stable-x86_64-pc-windows-msvc, debug
  • cargo build --workspace + cargo test --workspace -- --test-threads=4 on the merge: 692 passed, 0 failed, 41 ignored, exit code 0; xcl lib tests 652 passed, 0 failed, 21 ignored
  • 0 SKIPPED; repeated_physical_page_release_preserves_live_siblings and physical_page_liveness_crosses_bitmap_words pass.

Review: The per-block bitmap makes a second free of a page a no-op (free_page returns false and live drops once), and a freed page no longer resolves to its home even while siblings in the block are live. I found nothing to change.

Not tested: no retail title or regression run (I have no unpacked game), no XCL_SAMPLE_* tests, release build; the PR's head on its old base was not run, only its merge onto main.

Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.

@raylitebull

Copy link
Copy Markdown
Member

Diff check on 2a3c7f4:

  • Tracking per-page allocation state in PhysicalBlock::freed (bitset) so free_page is idempotent and releases only the requested page ID cleanly fixes double-free / live-sibling corruption in kernelx.
  • Already verified across both AMD (RX 9060 XT) and NVIDIA, with PR description passing.

Next step to unblock merge: Please rebase onto current main so CI runs Build and test (Windows, no GPU) on the head.

@raylitebull

Copy link
Copy Markdown
Member

Update: \Build and test (Windows, no GPU)\ is now green on \2a3c7f4\ (\CLEAN). Before merge, could @Babyhamsta\ follow up on @Kalmarv's test-coverage note above (exercising \physical_page_at\ when freeing a page that was mapped away from home)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants