kernelx: keep physical page release local to the page ID #603
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/608"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Babyhamsta on 2026-11-24T02:24:59Z.
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
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
cargo test --workspace -- --test-threads=4 --show-outputreported 686 passed, 0 failed, 41 ignored. Two passes reported SKIPPED for unavailable wave64 execution (gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware).Regression run
Main
PR head
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.
Imported from ivall/xcl. Originally posted by MesshM on 2026-11-24T03:12:01Z.
Test run of
2a3c7f4c09ee70667f6dcb39ebef77f38d3ecec3on AMD RDNA4. I merged it onto currentmaindd2ae9alocally (clean merge) and tested that tree.Tested
stable-x86_64-pc-windows-msvc, debugcargo build --workspace+cargo test --workspace -- --test-threads=4on the merge: 692 passed, 0 failed, 41 ignored, exit code 0;xcllib tests 652 passed, 0 failed, 21 ignoredSKIPPED;repeated_physical_page_release_preserves_live_siblingsandphysical_page_liveness_crosses_bitmap_wordspass.Review: The per-block bitmap makes a second free of a page a no-op (
free_pagereturns false andlivedrops 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 ontomain.Run and review by Claude Code (Claude Opus 5.5) on this machine; the review points were checked against the code.
Imported from ivall/xcl. Originally posted by Kalmarv on 2026-11-24T02:50:08Z.
Tested
2a3c7f4merged onto mainbdab194(merge 6bff65c, no conflicts). The fix does what the description says, and both new tests test it.repeated_physical_page_release_preserves_live_siblings, added alone to mainbdab194, fails atassert!(!read_physical_pages(&[first], 0, &mut bytes)): a page freed twice is still read. It passes on the merge. The other new test usesPhysicalBlock, so it does not compile on main.free_pagecounting 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.FreeTitlePhysicalPagesnow holdsAWAYandPHYS_BLOCKStogether. Read, write and map takeAWAYfirst andPHYS_BLOCKSinsidepage_home, so the order is the same everywhere.note_mapping_atunder 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
siblingat an address of its own before freeing it and checkphysical_page_atafterwards?Tested
RTX 5070 Ti (NVIDIA 610.74), Ryzen 9 9950X, Windows 11 26200, debug.
cargo build --workspace, thencargo test --workspace -- --test-threads=4on the merge 6bff65c: 689 passed, 0 failed, 41 ignored. SKIPPED on this card:gpu_geometry_wave32_prefix_count_over_a_maskandgpu_wave32_program_in_wave64_hardware(no wave64).kernelx::tests), 2 runs each, same result both times:bdab194with the one test that compiles there: 23 passed, 1 failed;scripts/pr_check.pyfrom main on the description: ok.Not tested
Title smoke run
cargo build --release -p xcl) from clean checkouts9ce2070eccf436d7bd38601c90407da447df34f3(this PR's base); PR head:2a3c7f4c09ee70667f6dcb39ebef77f38d3ecec3, no uncommitted changesscripts/smoke.ps1 -Game <title folder> -Seconds 60on 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 sizeXCL_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 matchPair 1, main:
Pair 1, PR:
Pair 2, main:
Pair 2, PR:
Not tested: whether the title freed any physical pages in these runs, or freed one twice. It imports
XMemAllocatePhysicalPages,XMemFreePhysicalPages,XMemMapPhysicalPagesandXMemMapPhysicalPagesScatter, which xcl serves through the functions this PR changes, but the log has no count of those calls and noAllocateTitlePhysicalPages(...): no roomline 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
upstream-sync referenced this pull request2026-11-24 19:06:45 +00:00
Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T00:56:50Z.
Diff check on
2a3c7f4:PhysicalBlock::freed(bitset) sofree_pageis idempotent and releases only the requested page ID cleanly fixes double-free / live-sibling corruption inkernelx.RX 9060 XT) and NVIDIA, withPR descriptionpassing.Next step to unblock merge: Please rebase onto current
mainso CI runsBuild and test (Windows, no GPU)on the head.Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T01:06:07Z.
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)?Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T06:43:05Z.
Empirical test report (
2a3c7f4c)Hardware / environment
2a3c7f4c09ee70667f6dcb39ebef77f38d3ecec3, verified on a clean, detached HEAD.1.100.0 (0ef1bc386 2026-11-09),x86_64-pc-windows-msvc. DXC1.9.2609.5 (01b62ad47).XCL_ADAPTER=NONE_CPU_ONLYandRUST_TEST_NOCAPTURE=1. Both commands ran directly through Cargo without the Arc GPU mutex wrapper.Commands and results
cargo test --workspace --no-runexited 0. Workspace test binaries built. Test execution counts were 0 passed, 0 failed, 0 ignored, and 0 skipped.cargo test -p xcl --lib physical_pageexited 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^SKIPPEDlines.AtomicU32::fetch_updatein XGameRuntime.Observed behavior
Not tested
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.
Imported from ivall/xcl. Originally posted by thehollowedone on 2026-11-25T06:51:32Z.
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_atclears, the former mapped VA retains its byte, and the remaining live sibling still reads correctly.Tested
XCL_ADAPTER=NONE_CPU_ONLY. The focusedcargo test --offline --locked -p xcl --lib physical_page -- --test-threads=1run passed 6, failed 0, ignored 0, skipped 0.away.at.remove(&at)suppressed in a disposable copy, the extendedrepeated_physical_page_release_preserves_live_siblingstest failed at the newphysical_page_atassertion. Restoring the PR code made that exact test pass. The mutation shows the new assertion reaches the previously uncovered cleanup.Test addition
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_siblingsare 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.
Imported from ivall/xcl. Originally posted by raylitebull on 2026-11-25T10:43:00Z.
@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!Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T12:55:43Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-27T18:28:55Z.
merge-check
base:
6089122a1chead:
2a3c7f4c09merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1463 passed, 4 failed, 47 ignored; failing:
gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0to_3(CreateComputePipelineStateE_OUTOFMEMORY). They fail the same way on this machine without this PR (five suite runs today on branches based onmainf9a0cb80) and pass with #1919 merged, so they are not this PR's.physical_page_liveness_crosses_bitmap_wordsandrepeated_physical_page_release_preserves_live_siblingspass. 25SKIPPEDlines (no wave64, no heap windows, three recompiler forms refused as unsupported).review: no blocking finding; whole diff read (
hle/kernelx.rs, +112/-29). (1) Intended behaviour change: after a free,page_homereturns None for that one page while its siblings in the block stay live; before, a freed page could still be read, written and mapped until the whole block went. The callers onmainhandle None (read_physical_pages/write_physical_pages, the checks inMapTitlePhysicalPages,unmap_away); the onepage_home(p).unwrap()in the map path runs underAWAYafter its check, andFreeTitlePhysicalPagesnow takesAWAYfirst, so a free cannot land between them. (2) Lock order is the same everywhere I looked:AWAY, thenPHYS_BLOCKS. The sparse / UMA /VirtualFreerelease of a block's home now happens after both locks are dropped. (3) The double-release bug is real onmain: the old code decrements the live count once per array entry, so[first, first]releases a block whose other pages are still allocated; the bitmap refuses the repeat. (4) Not this PR's: a freed page's lazy mark and theaway.goneentries for its home are not cleaned, as before.mainhas changedkernelx.rsa lot since the PR's base (9ce2070e), but none of it overlaps these hunks.performance: reasoned, not measured. One bitmap of count/64 words per physical block;
FreeTitlePhysicalPagesholds both locks for its loop, O(pages freed), not on the per-frame path. I did not run a title on the merge result.verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), Ryzen 7 9800X3D, 32 GB RAM, Windows 11 Pro 26300, rustc 1.100.0, debug. Claude Code with Claude Fable 5.2 ran the merge, build and suite on my machine and wrote this; a Claude Opus 5.5 subagent reviewed the diff and Fable read it in full as well.
Imported from ivall/xcl. Originally posted by throny on 2026-11-27T18:56:57Z.
merge-check claim
head:
2a3c7f4c09Imported from ivall/xcl. Originally posted by throny on 2026-11-27T19:12:53Z.
merge-check
base:
6089122ahead:
2a3c7f4c09merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 1467 passed, 0 failed, 47 ignored (26 SKIPPED lines); base alone: 1465 passed, 0 failed, 47 ignored
review: none blocking. Bitmap lookup is bounds-checked; a repeated free or a page of a removed block returns false. Lock order AWAY then PHYS_BLOCKS matches read, write and map on main; homes are released after both locks are dropped. Intended change: a freed page fails page_home / physical_pages_live / map at once, not when its block goes. Still open from the first check: no test reaches the away-mapping drop (not blocking).
performance: none on the frame path: free and map keep one lookup; one bitmap word per 64 pages per block (reasoned).
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:48:05Z.
Triage (#1607) – head
2a3c7f4The bug is still on main:
FreeTitlePhysicalPagesdecrements the block's live count once per listed page without remembering which pages were freed, so freeing one page twice retires the whole block (and its live siblings), andpage_homekeeps resolving a freed page while any sibling is live. The per-page bitmap here fixes both, and the test (duplicate free, then a mixed free, then reading the sibling) fails without it.Overlap: #2004 adds the same kind of per-page freed bitmap (
PhysBlock) tokernelx.rs, inside a ~1400-line PR across ten files that also decommits partially freed homes. This PR is earlier and only does this fix.The PR conflicts with main, which has since added
lazy::unmark,mirrors::page_freed,away.titlecleanup andsource_goingtoFreeTitlePhysicalPages; the rebase has to keep those (and apply them only to pages actually freed).Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T19:12:57Z.
This conflicts with main now, so to get the fix in I opened #3608: your commit rebased onto main
6bfb5c51(you stay the author; the conflict inFreeTitlePhysicalPagesis resolved by keeping main's newer mirrors / lazy-unmark /source_goingsteps and running them only for pages the call actually frees), plus one test-only commit that covers a page freed while it is mapped away. Full suite and a smoke pair on that exact head are in its description. If you'd rather keep it here,Foniass/xclbranchready/608has the same commits, and I'll close #3608.AI-assisted: Claude Code (Claude Opus 5.5), posted by Foniass.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.