kernelx: unmark lazy away mappings in FreeTitlePhysicalPages #1212
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1221"
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 b3IKK on 2026-11-24T13:22:13Z.
When a fresh physical page is mapped into a plain
MEM_RESERVEregion viaMapTitlePhysicalPages,map_pagesmarks that address inlazy::LAZY. Bothunmap_awayandmove_awaycalllazy::unmark(at), butFreeTitlePhysicalPagesremoved the entry fromAWAYwithout unmarking it—leaving a stale entry inlazy::LAZYthat could silently commit the address (even afterVirtualFreeand VA reuse) on a laterlazy::ensureor page fault, and could also cause silent data loss when another page B is later mapped atr, written, and mapped back home (unmap_away(r)returns early on the stalelazy::unmark(r)without copyingrback to B's home).This calls
lazy::unmark(at)whenFreeTitlePhysicalPagesremoves an away mapping.What is in it
crates/xcl/src/hle/kernelx.rs: calllazy::unmark(at)when removing an away mapping inFreeTitlePhysicalPages; add regression testsfree_physical_pages_unmarks_lazy_away_mappingandfree_physical_pages_stale_lazy_mark_does_not_lose_reused_reservation_writes.Tested
stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5, debug (scripts/test.ps1) and release (scripts/smoke.ps1).\scripts\test.ps1(cargo build --workspace+cargo test --workspace -- --test-threads=4): 743 passed, 0 failed, 41 ignored (SKIPPED GPU tests: 2no wave64—gpu::recomp::tests::gpu_geometry_wave32_prefix_count_over_a_mask,gpu::recomp::tests::gpu_wave32_program_in_wave64_hardware)cargo test -p xcl --lib free_physical_pages_: 2 passed, 0 failedRegression run
main:
PR:
Not tested
AI use
kernelx.rs, wrote the fix and regression tests (including the data-loss sequence suggested in review), ran the test suite andscripts/smoke.ps1regression runs, and drafted this PR description.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T13:47:21Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:Note: the full
d3d12xlib filter currently aborts with 0xc0000005 on unmodifiedmaintoo (pre-existing, unrelated to this PR); the PR's own tests were run by name and pass.Imported from ivall/xcl. Originally posted by pvfreis on 2026-11-24T14:23:41Z.
The fix is right, and on
main(930e8b4) the stale mark does more than commitrlater: it loses data. Read only; nothing built or run here. Sequence, all inkernelx.rsonmain:raway from home:lazy::mark(r)(:1284-1287).FreeTitlePhysicalPages([A])drops the mapping but not the mark (:1169-1175).r:ris committed and B's home is copied to it (:1290-1296); the home is given back at the end of the call.ris committed, so nothing faults and the mark stays.r, then maps B home again:commit_homesbrings the home back as zeros, andunmap_away(r)returns early becauselazy::unmark(r)is true (:1061-1066), soris never copied home. B reads zeros.A test of that sequence (assert B's home holds what was written at
r) fails onmainand should pass with the one-line fix here, which would cover the data loss as well as the stray commit your test checks.Reply by Claude Code (Claude Opus 5.5); checked by a person before posting.
Imported from ivall/xcl. Originally posted by b3IKK on 2026-11-24T18:54:05Z.
Great catch @pvfreis — added \ree_physical_pages_stale_lazy_mark_does_not_lose_reused_reservation_writes\ in \
34035fc\ covering that exact page A -> free -> page B away write -> map home data-loss sequence, and re-ran \scripts/test.ps1\ and the 60 s \scripts/smoke.ps1\ run.Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-26T04:05:33Z.
Re-verification on RTX 3060 Ti (Windows 11), new head merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, 27 ignored. The earlier merge conflict is resolved.Thanks!
— Devin
Imported from ivall/xcl. Originally posted by oni-swr on 2026-11-26T19:12:49Z.
AMD Windows test report for head
34035fc1b010450d4c2cb04835fd03c01aabb8fc(exact head, clean detached checkout, no local changes). Base:main47efa2ecea0a12934719ae69b81930cf02a4b1c3(the merge base; the PR is not merged with currentmain).Tested
stable-x86_64-pc-windows-msvc, DXC 1.8.2502.11 (Windows Kit 10.0.26100.0).XCL_ADAPTERunset, so the physical GPU was used, not WARP. Own target dir, rebuilt from scratch for this head.cargo build --workspace -j 4: ok.cargo test --workspace -j 4 --no-fail-fast -- --test-threads=4 --nocapture(debug): 743 passed, 0 failed, 41 ignored over 19 test binaries. NoSKIPPEDtest line.kernelx::tests::free_physical_pages_unmarks_lazy_away_mappingandfree_physical_pages_stale_lazy_mark_does_not_lose_reused_reservation_writesare among the passes. At this head the tree has nofuzz_tests, so the known AMD fuzz failure (#2115) does not come up.scripts/smoke.ps1of each commit, release builds, title run from a local copy): base47efa2etwice (the first run filled the shader cache), then this head. Peak commit and frames:47efa2e, run 1 (cold cache)34035fc47efa2e, run 2 (warm cache)The older
smoke.ps1at these commits prints the folder name astitle:; I replaced it withretail-titlein the blocks above and changed nothing else.Not tested
main(8b957bec): the suite and the smoke ran on this head and its merge base only.AI use: Claude Code (Claude Sonnet 5.5) ran the tests and drafted this report.
Imported from ivall/xcl. Originally posted by upipibi on 2026-11-26T20:41:02Z.
NVIDIA report, exact head
34035fc1b010450d4c2cb04835fd03c01aabb8fc, merge-base47efa2ecea0a12934719ae69b81930cf02a4b1c3. RTX 3070 8 GB (Ampere, wave32), driver 616.56, Windows 11, rustc 1.100.0.cargo test -p xcl --lib hle::kernelx::tests::free_physical_pages -- --test-threads=1x3: head 2 passed (the two new free_physical_pages tests) 3/3 runs; merge-base 0 tests, neither exists there, so no control.cargo test -p xcl --lib -- --skip hle::xaudio2 --test-threads=4: head 691 passed, 0 failed, 21 ignored; merge-base 689 passed, 0 failed, 21 ignored.AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).
Imported from ivall/xcl. Originally posted by Decodere on 2026-11-27T10:45:30Z.
Independent desktop NVIDIA verification of PR #1221 at head
34035fc1b010450d4c2cb04835fd03c01aabb8fc(1commit; exact parent & merge-base:47efa2ecea0a12934719ae69b81930cf02a4b1c3, pre-#2555ancestor ofmain).Environment
7956 MiBreported by D3D12, Wave32-only Ada), driver32.0.16.2114(NVIDIA621.14, WDDM 3.2)31.9 GiBusable), Windows 11 Home26200(Developer Mode off)rustc 1.100.0 (0ef1bc386 2026-11-09)MSVC, DXC1.9.2609.5,--releaseTargeted tests & build (
34035fc1)cargo test --release -p xcl --lib -- --nocapture free_physical_pages_unmarks_lazy_away_mapping free_physical_pages_stale_lazy_mark_does_not_lose_reused_reservation_writes(3 consecutive runs)2 passed; 0 failed; 0 ignored; 719 filtered out× 3 (0.02s,0.02s,0.02s,0skipped)cargo test --release -p xcl --lib hle::kernelx:: -- --nocapture(3 consecutive runs)33 passed; 0 failed; 1 ignored; 687 filtered out× 3 (0.21s,0.19s,0.20s,0runtime skips;1pre-existing#[ignore]timing testscatter_timing)cargo build --release -p xcl54.70s, exit0,0new warnings inkernelx.rs)Paired quiet 60 s retail smoke (
title: 29640639)(Note:
scripts/smoke.ps1at47efa2ecpredates9683e7a6and printed the local folder basename ontitle:; replaced below with the standard9683e7a6title hash29640639, with all measured fields verbatim.)Exact parent & merge-base (
47efa2ecea0a12934719ae69b81930cf02a4b1c3):PR #1221 (
34035fc1b010450d4c2cb04835fd03c01aabb8fc):Limits of coverage
FreeTitlePhysicalPageslazy-away-mapping regression tests and the fullhle::kernelx::suite (33/33active tests,0runtime skips) passed3/3on Windows 11.0device removals,0crashes); single-run frame/commit delta vs. parent reflects normal startup variance rather than this PR.AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
Imported from ivall/xcl. Originally posted by tiagonleal on 2026-11-30T03:55:10Z.
merge-check
base:
f97120dc19head:
34035fc1b0merge: clean
build: cargo build --workspace -> ok (also
cargo build --release -p xcl)tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 -> 2843 passed, 0 failed, 51 ignored; SKIPPED: 24 lines (22
no wave64, 2no heap windows), the same as on the base; failing: none. Base alone on this PC: 2841 passed, 0 failed, 51 ignored. The two new tests ran here and are real regression tests on this machine: with the addedlazy::unmark(at);line commented out in the merged tree,cargo test -p xcl --lib hle::kernelx::tests::free_physical_pages -- --test-threads=1fails both (freed away-mapped page must not remain in lazy::LAZYandstale lazy mark must not drop writes on B); with the line, 2 passed.review: whole diff read (+64/-0,
kernelx.rs). One line of fix:FreeTitlePhysicalPagesnow drops the lazy mark of the away address of each page it frees. Still needed on currentmain: the only otherlazy::unmarkcalls are inunmap_awayandmove_away, which the free path does not go through. It takes the lazy set after the away lock, the order those two functions use, and a page that was never lazy is a no-op. Two notes, neither a blocker. Both tests return without aSKIPPEDline when the page home is not sparse, so on such a machine they pass without testing anything (they did test here, see above). And open #2004 rewrites the same function with a batched unmark, so the second of the two to merge needs a rebase.performance: one set removal per freed away page. Measured with
scripts/smoke.ps1, 60 s of a retail title, release: 1678 frames and 15943 MB peak commit against 1635 and 1680 frames, 15366 and 16673 MB on the base (run before and after). No device removal, no crash.verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Fable 5.2 ran the build, suite, tests and smoke and wrote this; Claude Opus 5.5 read the diff first, and I checked its main points in the merged source)
Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T05:24:26Z.
merge-check claim
head:
34035fc1b0Imported from ivall/xcl. Originally posted by brainhay5 on 2026-11-30T05:32:46Z.
merge-check
base:
d52ff48caahead:
34035fc1b0merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2877 passed, 2 failed, 51 ignored; 29 SKIPPED lines
failing: test_title_runs_and_game_folder_is_untouched
review: automated overnight check — diff inspected for safety only (no build/CI/toolchain/script changes, no process/network/runtime-loading code); no duplicate search performed; no line-by-line code review.
performance: not assessed beyond the suite.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB, driver 610.88 (32.0.16.1088); Ryzen 7 5800X3D, 64 GB; Windows 11 22631; OpenCode agent, DeepSeek V4.1 Flash 1017
correction: this check first reported the PR as "not yet" because of a test failure that is not the PR's. The base-comparison step failed to run (test names contain a double colon, not a legal Windows filename), so an empty read was mistaken for "passes on base".
gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16fails on based52ff48cby itself (verified separately with the same command: "assertion failed: 2D D16 resinfo clobbered v2/v3"). Verdict corrected. Apologies for the noise.Imported from ivall/xcl. Originally posted by Elytes on 2026-11-30T08:24:30Z.
merge-check
base:
d52ff48caahead:
34035fc1b0merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2877 passed, 2 failed, 51 ignored; SKIPPED: 28 (22 no wave64, 2 no heap windows, 3 no D3D12 debug layer / d3d12SDKLayers.dll, 1 driver cache needs Developer Mode); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 and hle::kernelx::tests::xmem_virtual_query_marks_cpu_readable_memory, both also fail on the base alone (full lib run and isolated: base lib 2732 passed / 2 failed, merge lib 2734 passed / 2 failed, the +2 being this PR's tests)
review: no blocking finding after reading the whole diff (1 file, +64: a one-line fix and two tests). The fix matches unmap_away / move_away, which already unmark. Both new tests fail with the one-line fix removed (free_physical_pages_unmarks_lazy_away_mapping at the commit check; the reuse test loses the 0xCAFEBABE write) and pass with it, so they exercise the bug on this machine. Minor, not blocking: once a never-touched page is freed while still mapped at
at, an access toatnow faults instead of committing zeros, while a used page's address keeps its bytes (the comment above the loop says "that address keeps whatever it holds"); this only matters for a title touching memory whose page it freed. Overlap: #2004 (+1413/-257, conflicting) makes the same unmark inside a larger change (unmark_batch); this PR is the focused version. Another check on this PR reports gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16 as added by it: that test fails on main itself (based52ff48clib 2732 passed / 2 failed, merge 2734 passed / 2 failed, the same two tests; the +2 are this PR's).performance: no frame-time or memory cost by default: one BTreeSet removal under the lazy lock per freed page that is mapped away (reasoned, not measured).
verdict: safe to merge
hardware / tool and model: NVIDIA GeForce RTX 5090 (driver 32.0.16.1742, wave32), Intel Core i9-14900KS, 192 GB, Windows 11 build 26300.10075, rustc 1.92.0, debug / Claude Code (Claude Opus 5.5) ran the merge, build, suite, base reruns and the fix-removed run, searched for duplicates and reviewed the diff.