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)?

@throny throny added the goal:world-load Bears on the retail title getting past world loading label Nov 25, 2026
IvyNotFound added a commit to IvyNotFound/xcl that referenced this pull request Nov 25, 2026
@JJAutoCompare

Copy link
Copy Markdown

Empirical test report (2a3c7f4)

Hardware / environment

  • PR kernelx: keep physical page release local to the page ID #608 head 2a3c7f4c09ee70667f6dcb39ebef77f38d3ecec3, verified on a clean, detached HEAD.
  • Windows 11 Enterprise Evaluation, x64, build 26200. CPU reported by Windows as AuthenticAMD AMD64 Family 23, Model 113, Stepping 0, ~3900 MHz.
  • Rust 1.100.0 (0ef1bc386 2026-11-09), x86_64-pc-windows-msvc. DXC 1.9.2609.5 (01b62ad47).
  • The focused run used XCL_ADAPTER=NONE_CPU_ONLY and RUST_TEST_NOCAPTURE=1. Both commands ran directly through Cargo without the Arc GPU mutex wrapper.

Commands and results

  • cargo test --workspace --no-run exited 0. Workspace test binaries built. Test execution counts were 0 passed, 0 failed, 0 ignored, and 0 skipped.
  • cargo test -p xcl --lib physical_page exited 0. The log reports 6 passed, 0 failed, 0 ignored, 0 skipped and 661 filtered out. The skip count is the number of case-sensitive ^SKIPPED lines.
  • Cargo emitted a deprecation warning for AtomicU32::fetch_update in XGameRuntime.

Observed behavior

  • Both new kernelx tests ran and passed. Page liveness tracked releases across a bitmap-word boundary. Duplicate release left sibling pages live. Reads, writes, and maps of a released page ID were rejected, and the surviving sibling retained its bytes until it was freed.
  • Existing tests for UMA mappings, the scatter mapping model, overflow handling, and DirectStorage physical-page I/O passed. The DirectStorage diagnostic came from the test's deliberately invalid page ID.

Not tested

  • Full GPU workspace suite and game smoke runs.

AI use

Verified with T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high). Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr608-focused.log and published.

@thehollowedone

thehollowedone commented Nov 25, 2026 •

Copy link
Copy Markdown

I followed up on the requested away-mapping coverage at exact 2a3c7f4. The test-only extension maps a live sibling away from its home, verifies that a duplicate free of another page preserves this mapping, then frees the mapped sibling. It checks that physical_page_at clears, the former mapped VA retains its byte, and the remaining live sibling still reads correctly.

Tested

  • Windows 11 build 26300, Rust 1.99.1 MSVC, debug, CPU-only with XCL_ADAPTER=NONE_CPU_ONLY. The focused cargo test --offline --locked -p xcl --lib physical_page -- --test-threads=1 run passed 6, failed 0, ignored 0, skipped 0.
  • With only away.at.remove(&at) suppressed in a disposable copy, the extended repeated_physical_page_release_preserves_live_siblings test failed at the new physical_page_at assertion. Restoring the PR code made that exact test pass. The mutation shows the new assertion reaches the previously uncovered cleanup.

Test addition

-            let [mut first, second, mut sibling] = pages;
+            let [mut first, mut second, mut sibling] = pages;
+            let elsewhere = mem::VirtualAlloc(std::ptr::null(), PHYS_PAGE, mem::MEM_RESERVE | mem::MEM_COMMIT, mem::PAGE_READWRITE);
+            assert!(!elsewhere.is_null());
+            assert_ne!(elsewhere as usize, page_home(second).unwrap());
+            assert_eq!(MapTitlePhysicalPages(elsewhere, 1, 0, 0, &mut second), elsewhere);
+            assert!(physical_page_at(elsewhere as usize));
+            assert!(write_physical_pages(&[second], 0, &[0xB6]));
             assert!(write_physical_pages(&[sibling], 0, &[0x7d]));
@@
             assert!(page_home(second).is_some());
+            assert!(physical_page_at(elsewhere as usize), "freeing the first page must leave its sibling's mapping");
@@
             assert!(page_home(second).is_none());
+            assert!(!physical_page_at(elsewhere as usize), "the freed page must no longer own its away mapping");
+            assert_eq!(*(elsewhere as *const u8), 0xB6, "the mapped address retains its bytes");
+            assert_ne!(mem::VirtualFree(elsewhere, 0, mem::MEM_RELEASE), 0);
             assert!(read_physical_pages(&[sibling, sibling], PHYS_PAGE - 1, &mut bytes));

Not tested
Workspace suite, retail title, GPU behavior, or other Windows builds. The test-only patch remains local. The added lines in repeated_physical_page_release_preserves_live_siblings are below, so the author can incorporate the requested coverage without reconstructing the fixture.

AI use
Codex (GPT-6, exact variant unavailable) wrote and ran the extension and drafted this report.

@raylitebull

Copy link
Copy Markdown
Member

@Babyhamsta — @thehollowedone shared a tested, ready-to-apply patch for the requested away-mapping physical_page_at coverage on 2a3c7f4. Once folded in and Build and test finishes green, this is ready to merge!

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

Labels

goal:world-load Bears on the retail title getting past world loading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants